CXF配置和开发流程.docx

上传人:b****1 文档编号:10214317 上传时间:2023-05-24 格式:DOCX 页数:17 大小:52.46KB
下载 相关 举报
CXF配置和开发流程.docx_第1页
第1页 / 共17页
CXF配置和开发流程.docx_第2页
第2页 / 共17页
CXF配置和开发流程.docx_第3页
第3页 / 共17页
CXF配置和开发流程.docx_第4页
第4页 / 共17页
CXF配置和开发流程.docx_第5页
第5页 / 共17页
CXF配置和开发流程.docx_第6页
第6页 / 共17页
CXF配置和开发流程.docx_第7页
第7页 / 共17页
CXF配置和开发流程.docx_第8页
第8页 / 共17页
CXF配置和开发流程.docx_第9页
第9页 / 共17页
CXF配置和开发流程.docx_第10页
第10页 / 共17页
CXF配置和开发流程.docx_第11页
第11页 / 共17页
CXF配置和开发流程.docx_第12页
第12页 / 共17页
CXF配置和开发流程.docx_第13页
第13页 / 共17页
CXF配置和开发流程.docx_第14页
第14页 / 共17页
CXF配置和开发流程.docx_第15页
第15页 / 共17页
CXF配置和开发流程.docx_第16页
第16页 / 共17页
CXF配置和开发流程.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

CXF配置和开发流程.docx

《CXF配置和开发流程.docx》由会员分享,可在线阅读,更多相关《CXF配置和开发流程.docx(17页珍藏版)》请在冰点文库上搜索。

CXF配置和开发流程.docx

CXF配置和开发流程

CXF的配置和开发流程

第一种方式

配置信息如下

1、cxf用的jar包http:

//cxf.apache.org/download.html可以下载到。

2、web.xml

CXFServlet

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

1

CXFServlet

/services/*

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""

contextConfigLocation

WEB-INF/classes/applicationContext.xml

org.springframework.web.context.ContextLoaderListener

CXFServlet

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

1

CXFServlet

/services/*

xsd

text/xml

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

CXFServlet

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

1

CXFServlet

—路径根据需要自己定义-->

/service/*

3、配置文件applicationContext-service.xml(注意红色部分为配置文件新加配置)

//www.springframework.org/schema/beans"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

jaxws="http:

//cxf.apache.org

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2