CXF结合spring的配置和开发流程1
1、引入需要的jar包http://cxf.apache.org/download.html可以下载相应jar包,本次使用的是apache-cxf-2.2.12
2、在web.xml中配置cxf
3、编写applicationContext.xml
xmlns:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://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 id="helloWorld"implementor="com.fxb.webservice.service.impl.HelloServiceImpl"address="/HelloWorld"><jaxws:inInterceptors><bean encoding="UTF-8"?><!-- START SNIPPET: beans --><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd"> <bean id="client" factory-bean="clientFactory" factory-method="create"/> <bean id="clientFactory" value="com.fxb.webservice.service.HelloService"/> <property name="address" value="http://localhost:8080/CXFSpring/HelloWorld"/></bean> </beans><!-- END SNIPPET: beans -->6、编写客户端类
?package com.fxb.webservice.interceptor;import org.apache.cxf.interceptor.Fault;import org.apache.cxf.message.Message;import org.apache.cxf.phase.AbstractPhaseInterceptor;import org.apache.cxf.phase.Phase;import org.apache.log4j.Logger;public class MyInterceptor extends AbstractPhaseInterceptor<Message> {private Logger log = Logger.getLogger(MyInterceptor.class);public MyInterceptor(String phase) {super(phase);}public MyInterceptor() {super(Phase.RECEIVE);}@SuppressWarnings("static-access")public void handleMessage(Message msg) throws Fault {String uri = String.valueOf(msg.get(msg.REQUEST_URI));StringBuffer bf = new StringBuffer(uri + ".xml");msg.put(msg.REQUEST_URI, String.valueOf(bf));System.out.println("in my intercetptor11111111111111111111");System.out.println(msg.get(msg.REQUEST_URI));log.info("in my interceptor:");}@Overridepublic void handleFault(Message message) {super.handleFault(message);System.out.println("handleFault@@@@@@@@@@@@@@@@@@@@@2");}}
?
?
?