- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.0"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
- <display-name></display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <servlet>
- <servlet-name>CXF</servlet-name>
- <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
- </servlet>
- <!-- 所有来自/ws/*的请求交给cxf处理 -->
- <servlet-mapping>
- <servlet-name>CXF</servlet-name>
- <url-pattern>/ws/*</url-pattern>
- </servlet-mapping>
- </web-app>
- <?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:oxm="http://www.springframework.org/schema/oxm"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/oxm
- http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
- http://cxf.apache.org/jaxws
- http://cxf.apache.org/schemas/jaxws.xsd">
- <import resource="classpath:META-INF/cxf/cxf.xml" />
- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
- <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
- <!--
- 第一种方式
- <jaxws:endpoint
- implementor="com.kenan.cxf.ws.impl.HelloWorldImpl"
- address="/ws" >
- </jaxws:endpoint> -->
- <!-- 第二种方式 -->
- <bean id="webServiceName" class="com.kenan.cxf.ws.impl.HelloWorldImpl" >
- </bean>
- <!-- #代表使用spring容器中的类 -->
- <jaxws:endpoint
- implementor="#webServiceName"
- address="/ws" >
- <jaxws:inInterceptors>
- <bean class="com.kenan.cxf.auth.AuthInterceptor"/>
- </jaxws:inInterceptors>
- </jaxws:endpoint>
- </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:oxm="http://www.springframework.org/schema/oxm"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/oxm
- http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
- http://cxf.apache.org/jaxws
- http://cxf.apache.org/schemas/jaxws.xsd">
- <jaxws:client id="hw"
- serviceClass="com.kenan.cxf.ws.HelloWorld"
- address="http://localhost:8080/ws_03_server_cxf_spring3.1/ws/ws?wsdl">
- <jaxws:outInterceptors>
- <bean class="com.kenan.cxf.auth.AuthOutInterceptor">
- <constructor-arg value="admin" />
- <constructor-arg value="admin" />
- </bean>
- </jaxws:outInterceptors>
- </jaxws:client>
- </beans>
- package test;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.kenan.cxf.ws.HelloWorld;
- import com.kenan.cxf.ws.impl.HelloWorldImpl;
- import com.sun.security.ntlm.Client;
- public class Test {
- /**
- * @param args
- */
- public static void main(String[] args) {
- ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
- HelloWorld hello = context.getBean("hw", HelloWorld.class);
- // HelloWorldImpl helloWorld = new HelloWorldImpl();
- // com.kenan.cxf.ws.HelloWorld hello = helloWorld.getHelloWorldImplPort();
- //拦截器
- // Client client = ClientProxy.getClient(hello);
- // client.getOutInterceptors().add(new AuthOutInterceptor("admin", "admin"));
- // client.getOutInterceptors().add(new LoggingOutInterceptor());
- hello.hello("你好");
- // User user = new User();
- // user.setName("柯南");
- // List<Cat> l = hello.getCatsByUser(user);
- // for(Cat cat:l){
- // System.out.println(cat.getName());
- // }
- // StringCat s = hello.getAllCats();
- // for(Entry entry:s.getEntries()){
- // System.out.println(entry.getKey()+":"+entry.getValue());
- // }
- }
- }