CXF配置和开发流程.docx
- 文档编号:10214317
- 上传时间:2023-05-24
- 格式:DOCX
- 页数:17
- 大小:52.46KB
CXF配置和开发流程.docx
《CXF配置和开发流程.docx》由会员分享,可在线阅读,更多相关《CXF配置和开发流程.docx(17页珍藏版)》请在冰点文库上搜索。
CXF配置和开发流程
CXF的配置和开发流程
第一种方式
配置信息如下
1、cxf用的jar包http:
//cxf.apache.org/download.html可以下载到。
2、web.xml
org.apache.cxf.transport.servlet.CXFServlet
3、配置文件applicationContext-service.xml(注意红色部分为配置文件新加配置)
//www.springframework.org/schema/beans" xmlns: xsi="http: //www.w3.org/2001/XMLSchema-instance" xmlns: jaxws="http: //cxf.apache.org/jaxws" xmlns: jaxrs="http: //cxf.apache.org/jaxrs" xsi: schemaLocation=" http: //www.springframework.org/schema/beanshttp: //www.springframework.org/schema/beans/spring-beans.xsd http: //cxf.apache.org/jaxwshttp: //cxf.apache.org/schemas/jaxws.xsd http: //cxf.apache.org/jaxwshttp: //cxf.apache.org/schemas/jaxws.xsd http: //cxf.apache.org/jaxrshttp: //cxf.apache.org/schemas/jaxrs.xsd http: //cxf.apache.org/transports/http/configuration http: //cxf.apache.org/schemas/configuration/http-conf.xsd "> META-INF/cxf/cxf.xml"/> META-INF/cxf/cxf-extension-soap.xml"/> META-INF/cxf/cxf-servlet.xml"/> endpointid="method2" implementor="com.fxb.webservice.service.impl.HelloServiceImpl" address="/HelloWorldTwo"> inInterceptors> inInterceptors> outInterceptors> outInterceptors> endpoint> 配置文件applicationContext-client.xml 注意applicationContext-service.xml配置文件中使用的是 endpoint> endpoint>标签 4、服务类HelloService.java @WebService publicinterfaceHelloService{ publicTestResponsehello(@WebParam(name="name")Stringname); } 实现类HelloServiceImpl.java TestResponse.java、TestList.java 5、客户端类HelloClient.java 6、拦截器MyInterceptor.java 各部分代码如下 Web.xml xmlversion="1.0"encoding="UTF-8"? > DOCTYPEweb-appPUBLIC"-//SunMicrosystems,Inc.//DTDWebApplication2.3//EN"" org.springframework.web.context.ContextLoaderListener org.apache.cxf.transport.servlet.CXFServlet applicationContext-service.xml xmlversion="1.0"encoding="UTF-8"? > --STARTSNIPPET: beans--> //www.springframework.org/schema/beans" xmlns: xsi="http: //www.w3.org/2001/XMLSchema-instance" xmlns: jaxws="http: //cxf.apache.org/jaxws" xmlns: jaxrs="http: //cxf.apache.org/jaxrs" xsi: schemaLocation=" http: //www.springframework.org/schema/beanshttp: //www.springframework.org/schema/beans/spring-beans.xsd http: //cxf.apache.org/jaxwshttp: //cxf.apache.org/schemas/jaxws.xsd http: //cxf.apache.org/jaxwshttp: //cxf.apache.org/schemas/jaxws.xsd http: //cxf.apache.org/jaxrshttp: //cxf.apache.org/schemas/jaxrs.xsd http: //cxf.apache.org/transports/http/configuration http: //cxf.apache.org/schemas/configuration/http-conf.xsd "> META-INF/cxf/cxf.xml"/> META-INF/cxf/cxf-extension-soap.xml"/> META-INF/cxf/cxf-servlet.xml"/> endpointid="method2" implementor="com.fxb.webservice.service.impl.HelloServiceImpl" address="/HelloWorldTwo"> inInterceptors> inInterceptors> outInterceptors> outInterceptors> endpoint> --ENDSNIPPET: beans--> applicationContext-client.xml xmlversion="1.0"encoding="UTF-8"? > --STARTSNIPPET: beans--> //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/beanshttp: //www.springframework.org/schema/beans/spring-beans.xsd http: //cxf.apache.org/jaxwshttp: //cxf.apache.org/schema/jaxws.xsd"> factory-bean="clientFactory"factory-method="create"/> //localhost: 8080/CXFSpring/services/HelloWorldTwo"/> --ENDSNIPPET: beans--> HelloService.java packagecom.fxb.webservice.service; importjavax.jws.WebParam; importjavax.jws.WebService; importjavax.jws.soap.SOAPBinding; importjavax.jws.soap.SOAPBinding.Style; importcom.fxb.webservice.bean.TestResponse; @WebService publicinterfaceHelloService{ publicTestResponsehello(@WebParam(name="name")Stringname); } HelloServiceImpl.java packagecom.fxb.webservice.service.impl; importcom.fxb.webservice.bean.TestList; importcom.fxb.webservice.bean.TestResponse; importcom.fxb.webservice.service.HelloService; publicclassHelloServiceImplimplementsHelloService{ publicTestResponsehello(Stringname){ System.out.println(name); TestResponsetestResponse=newTestResponse(); TestListtestList=newTestList(); testList.setName("HelloServiceImpl"); testResponse.setTestList(testList); returntestResponse; } } TestResponse.java类 packagecom.fxb.webservice.bean; importjavax.xml.bind.annotation.XmlAccessType; importjavax.xml.bind.annotation.XmlAccessorType; importjavax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name="TestResponse")//设置一级子节点 @XmlAccessorType(XmlAccessType.FIELD) publicclassTestResponse{ protectedTestListtestList; publicTestListgetTestList(){ returntestList; } publicvoidsetTestList(TestListtestList){ this.testList=testList; } } TestList.java类 packagecom.fxb.webservice.bean; importjavax.xml.bind.annotation.XmlAccessType; importjavax.xml.bind.annotation.XmlAccessorType; importjavax.xml.bind.annotation.XmlRootElement; @XmlRootElement(name="TestList")//设置二级子节点 @XmlAccessorType(XmlAccessType.FIELD) publicclassTestList{ //类的属性为三级子节点 protectedStringname; protectedStringage; publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } publicStringgetAge(){ returnage; } publicvoidsetAge(Stringage){ this.age=age; } } MyInterceptor.java packagecom.fxb.webservice.interceptor; importorg.apache.cxf.interceptor.Fault; importorg.apache.cxf.message.Message; importorg.apache.cxf.phase.AbstractPhaseInterceptor; importorg.apache.cxf.phase.Phase; importorg.apache.log4j.Logger; publicclassMyInterceptorextendsAbstractPhaseInterceptor privateLoggerlog=Logger.getLogger(MyInterceptor.class); publicMyInterceptor(Stringphase){ super(phase); } publicMyInterceptor(){ super(Phase.RECEIVE); } @SuppressWarnings("static-access") publicvoidhandleMessage(Messagemsg)throwsFault{ Stringuri=String.valueOf(msg.get(msg.REQUEST_URI)); StringBufferbf=newStringBuffer(uri+".xml"); msg.put(msg.REQUEST_URI,String.valueOf(bf)); System.out.println("inmyintercetptor11111111111111111111"); System.out.println(msg.get(msg.REQUEST_URI)); log.info("inmyinterceptor: "); } @Override publicvoidhandleFault(Messagemessage){ super.handleFault(message); System.out.println("handleFault@@@@@@@@@@@@@@@@@@@@@2"); } } HelloClient.java packagecom.fxb.webservice.client; importorg.apache.cxf.jaxws.JaxWsProxyFactoryBean; importorg.springframework.context.support.ClassPathXmlApplicationContext; importcom.fxb.webservice.bean.TestResponse; importcom.fxb.webservice.service.HelloService; publicclassHelloClient{ publicstaticvoidmain(String[]args){ ClassPathXmlApplicationContextcontext =newClassPathXmlApplicationContext(newString[]{"com/fxb/webservice/client/applicationContext-client.xml"}); HelloServiceclient=(HelloService)context.getBean("client"); TestResponseresponse=client.hello("Joe"); System.out.println("Response: "+response.getTestList().getName()); System.exit(0); } } 通过客户端测试输出为Response: HelloServiceImpl 通过http: //localhost: 8080/CXFSpring/services/HelloWorldTwo/hello输出为 第二种方式 配置信息如下 1、cxf用的jar包http: //cxf.apache.org/download.html可以下载到。 2、web.xml org.apache.cxf.transport.servlet.CXFServlet —路径根据需要自己定义--> 3、配置文件applicationContext-service.xml(注意红色部分为配置文件新加配置) //www.springframework.org/schema/beans" xmlns: xsi="http: //www.w3.org/2001/XMLSchema-instance" xmlns: jaxws="http: //cxf.apache.org
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CXF 配置 开发 流程
![提示](https://static.bingdoc.com/images/bang_tan.gif)