码迷,mamicode.com
首页 > 其他好文 > 详细

CXF - getting started

时间:2016-07-04 11:30:14      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://cxf.apache.org/configuration/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:core="http://cxf.apache.org/core"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/configuration/beans http://cxf.apache.org/schemas/configuration/cxf-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
    ">

    <jaxws:endpoint id="helloWorld1" 
        implementor="idv.steven.cxf.helloworld.HelloWorldImpl" address="http://localhost:9000/CXF/HelloWorld" />

    <jaxws:client id="client" 
        serviceClass="idv.steven.cxf.helloworld.HelloWorld"
        address="http://localhost:9000/CXF/HelloWorld" />
</beans>

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
>

    <context:component-scan base-package="idv.steven.mvc.controller" />
    <mvc:annotation-driven />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/jsp/"
        p:suffix=".jsp"
    />
</beans>

 

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>CXF</display-name>
  
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:beans-config.xml</param-value>
    </context-param>
  
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:mvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
  
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

package idv.steven.cxf.helloworld;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface HelloWorld {
    String sayHello(@WebParam(name="text") String text);
}

 

package idv.steven.cxf.helloworld;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    @Override
    public String sayHello(@WebParam(name="text") String text) {
        System.out.println("sayHello called");
        return "Hello " + text + "!";
    }
}

 

 

package idv.steven.mvc.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import idv.steven.cxf.helloworld.HelloWorld;

@Controller
public class SayHelloController {
    @Autowired
    private HelloWorld client;
    
    @RequestMapping(value="/say", method=RequestMethod.GET)
    public @ResponseBody Map<String, Object> getHelloWorld(String name) {
        Map<String, Object> result = new HashMap<String, Object>();
        String respText = client.sayHello(name);
        result.put("result", respText);
        
        return result;
    }
}

 

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-3.0.0.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SayHello</title>
<script type="text/javascript">
var message;

$(function() {
    $("#say").bind("click", function(e) {
        var myUrl = "<%=request.getContextPath()%>/say.do?name=" + $(#name).val();
        
        $.ajax({
            type: get,
            url: myUrl,
            dataType: json,
            success: function(data, result) {
                alert(data.result);
            },
            error: function() {
                alert(error);
            }
        });
    });
});
</script>
</head>
<body>

<form id="helloForm" name="helloForm" method="post">
    Name: <input type="text" id="name" name="name" />&nbsp;
    <input type="button" id="say" name="say" value="哈囉"/>
</form>

</body>
</html>

 

CXF - getting started

标签:

原文地址:http://www.cnblogs.com/stevwn/p/5639770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!