首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

CXF 2.0 学习札记-3 SOAP Header (转)

2012-07-16 
CXF 2.0 学习笔记-3 SOAP Header (转)CXF 2.0 学习笔记-3 SOAP Header 基于CXF2.0前2个学习笔记,对原先服

CXF 2.0 学习笔记-3 SOAP Header (转)
CXF 2.0 学习笔记-3 SOAP Header

基于CXF2.0前2个学习笔记,对原先服务端与客户端进行修改,实现在SOAP Header里面添加自定义的数据进行认证

在做之前,先要理解如下的信息
拦截器(Interceptor)简单说明
????? Interceptor是CXF架构中一个很有特色的模式。你可以在不对核心模块进行修改的情况下,动态添加很多功能。这对于CXF这个以处理消息为中心的服务框架来说是非常有用的,CXF通过在Interceptor中对消息进行特殊处理,实现了很多重要功能模块,例如:日志记录,Soap消息处理,消息的压缩处。简单的说,可以在收到请求后,还未进行业务处理前,进行处理。或者在请求包发送前,进行报文的处理。
几个的API的介绍
Interceptor

定义两个方法,一个处理消息 handleMessage, 一个是处理错误 handleFault。

InterceptorChain
? 单个的Interceptor功能有限,CXF要实现一个SOAP消息处理,需要将许许多多的Interceptor组合在一起使用。因此设计了 InterceptorChain,在我看了InterceptorChain就像是一个Interceptor的小队长。 小队长有调配安置Interceptor的权力(add,remove),也有控制消息处理的权力(doInterceptor,pause,resume,reset,abort),同时也有交付错误处理的权力( {get|set}FaultObserver)。更有意思的是为灵活控制Interceptor的处理消息顺序(doInterceptStartingAt,doInterceptorStartingAfter),这也是InterceptorChain比较难理解的地方。
Fault
? 定义了CXF中的错误消息。
InterceptorProvider
  这里定义了Interceptor的后备保障部队。我们可以在InterceptorProvider中设置In,Out,InFault,OutFault 后备小分队,添加我们所希望添加的Interceptor。而InterceptorChain会根据这些后备小分队,组建自己的小分队实例,完成具体的作战功能任务。
AbstractAttributedInterceptorProvider
?? InterceptorProvider实现的抽象类,由于这个类来继承了HashMap,我们可以像这个类中存储一些属性信息。
AbstractBasicInterceptorProvider
?? 与AbstractAttributedInterceptorProvider不同,这个Interceptor只是简单实现了InterceptorProvider的功能,并不提供对其属性存储的扩展。
Message
?? 由于Interceptor是针对Message来进行处理的,当你打开Message这个类文件时,你会发现在Message中定义了很多常量,同时你还可以从Message中获取到很多与Message操作相关的信息。可以获取设置的对象有InterceptorChain Exchange Destination,还有获取设置Content的泛型接口,是不是感觉Message和Bus差不多,都成了大杂货铺,一切与消息处理相关的信息都可以放在Message中。

理解了Interceptor功能,下面的修改就很简单了


服务端修改

1.新建一个拦截器(Interceptor)

CXF 2.0 学习札记-3 SOAP Header (转)package?hs.cxf.soapHeader;
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)import?javax.xml.soap.SOAPException;
CXF 2.0 学习札记-3 SOAP Header (转)import?javax.xml.soap.SOAPHeader;
CXF 2.0 学习札记-3 SOAP Header (转)import?javax.xml.soap.SOAPMessage;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.binding.soap.SoapMessage;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.interceptor.Fault;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.phase.AbstractPhaseInterceptor;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.phase.Phase;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.w3c.dom.NodeList;
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)/**?*//**
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Title:获取soap头信息
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Description:
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Copyright:
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@author?zz
CXF 2.0 学习札记-3 SOAP Header (转)?*?@version?1.00.000
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*/
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)public?class?ReadSoapHeader?extends?AbstractPhaseInterceptor<SoapMessage>?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????private?SAAJInInterceptor?saa?=?new?SAAJInInterceptor();
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????public?ReadSoapHeader()?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????super(Phase.PRE_PROTOCOL);
CXF 2.0 学习札记-3 SOAP Header (转)????????getAfter().add(SAAJInInterceptor.class.getName());
CXF 2.0 学习札记-3 SOAP Header (转)????}
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????public?void?handleMessage(SoapMessage?message)?throws?Fault?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????SOAPMessage?mess?=?message.getContent(SOAPMessage.class);
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????if?(mess?==?null)?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????saa.handleMessage(message);
CXF 2.0 学习札记-3 SOAP Header (转)????????????mess?=?message.getContent(SOAPMessage.class);
CXF 2.0 学习札记-3 SOAP Header (转)????????}
CXF 2.0 学习札记-3 SOAP Header (转)????????SOAPHeader?head?=?null;
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????try?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????head?=?mess.getSOAPHeader();
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????}?catch?(SOAPException?e)?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????e.printStackTrace();
CXF 2.0 学习札记-3 SOAP Header (转)????????}
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????if?(head?==?null)?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????return;
CXF 2.0 学习札记-3 SOAP Header (转)????????}
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????try?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????//读取自定义的节点
CXF 2.0 学习札记-3 SOAP Header (转)????????????NodeList?nodes?=?head.getElementsByTagName("tns:spId");
CXF 2.0 学习札记-3 SOAP Header (转)????????????NodeList?nodepass?=?head.getElementsByTagName("tns:spPassword");
CXF 2.0 学习札记-3 SOAP Header (转)????????????//获取节点值,简单认证
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????????if?(nodes.item(0).getTextContent().equals("wdw"))?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????????????if?(nodepass.item(0).getTextContent().equals("wdwsb"))?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????????????System.out.println("认证成功");
CXF 2.0 学习札记-3 SOAP Header (转)????????????????}
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????????}?else?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????????SOAPException?soapExc?=?new?SOAPException("认证错误");
CXF 2.0 学习札记-3 SOAP Header (转)????????????????throw?new?Fault(soapExc);
CXF 2.0 学习札记-3 SOAP Header (转)????????????}
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????}?catch?(Exception?e)?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????SOAPException?soapExc?=?new?SOAPException("认证错误");
CXF 2.0 学习札记-3 SOAP Header (转)????????????throw?new?Fault(soapExc);
CXF 2.0 学习札记-3 SOAP Header (转)????????}
CXF 2.0 学习札记-3 SOAP Header (转)????}
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)}


2.配置文件中新增拦截器配置

CXF 2.0 学习札记-3 SOAP Header (转)<beans?xmlns="http://www.springframework.org/schema/beans"??
CXF 2.0 学习札记-3 SOAP Header (转)????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
CXF 2.0 学习札记-3 SOAP Header (转)????xmlns:jaxws="http://cxf.apache.org/jaxws"??
CXF 2.0 学习札记-3 SOAP Header (转)????xsi:schemaLocation="???
CXF 2.0 学习札记-3 SOAP Header (转)http://www.springframework.org/schema/beans?http://www.springframework.org/schema/beans/spring-beans.xsd???
CXF 2.0 学习札记-3 SOAP Header (转)http://cxf.apache.org/jaxws?http://cxf.apache.org/schemas/jaxws.xsd">???
CXF 2.0 学习札记-3 SOAP Header (转)??
CXF 2.0 学习札记-3 SOAP Header (转)????<import?resource="classpath:META-INF/cxf/cxf.xml"?/>???
CXF 2.0 学习札记-3 SOAP Header (转)????<import?resource="classpath:META-INF/cxf/cxf-extension-soap.xml"?/>???
CXF 2.0 学习札记-3 SOAP Header (转)????<import?resource="classpath:META-INF/cxf/cxf-servlet.xml"?/>???
CXF 2.0 学习札记-3 SOAP Header (转)??
CXF 2.0 学习札记-3 SOAP Header (转)????<bean?id="jaxWsServiceFactoryBean"??
CXF 2.0 学习札记-3 SOAP Header (转)????????class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">???
CXF 2.0 学习札记-3 SOAP Header (转)????????<property?name="wrapped"?value="true"?/>???
CXF 2.0 学习札记-3 SOAP Header (转)????????<property?name="dataBinding"?ref="aegisBean"?/>???
CXF 2.0 学习札记-3 SOAP Header (转)????</bean>???
CXF 2.0 学习札记-3 SOAP Header (转)??
CXF 2.0 学习札记-3 SOAP Header (转)????<bean?id="aegisBean"??
CXF 2.0 学习札记-3 SOAP Header (转)????????class="org.apache.cxf.aegis.databinding.AegisDatabinding"?/>???
CXF 2.0 学习札记-3 SOAP Header (转)??
CXF 2.0 学习札记-3 SOAP Header (转)????<jaxws:endpoint?id="CollectiveServices"??
CXF 2.0 学习札记-3 SOAP Header (转)????????implementor="hs.cxf.server.WebServiceSampleImpl"?address="/HelloWorld">???
CXF 2.0 学习札记-3 SOAP Header (转)????????<jaxws:inInterceptors>???
CXF 2.0 学习札记-3 SOAP Header (转)??????????<!--?日志拦截器?-->??????
CXF 2.0 学习札记-3 SOAP Header (转)??????????<bean?src="//img.reader8.com/uploadfile/jiaocheng/2014015/1438/201401140038527562.gif">??????????<!--?自定义拦截器?-->?
CXF 2.0 学习札记-3 SOAP Header (转)??????????<bean?src="//img.reader8.com/uploadfile/jiaocheng/2014015/1438/201401140038527562.gif">??????????</jaxws:inInterceptors>????
CXF 2.0 学习札记-3 SOAP Header (转)????????<jaxws:serviceFactory>???
CXF 2.0 学习札记-3 SOAP Header (转)????????????<ref?bean="jaxWsServiceFactoryBean"/>???
CXF 2.0 学习札记-3 SOAP Header (转)????????</jaxws:serviceFactory>???
CXF 2.0 学习札记-3 SOAP Header (转)????</jaxws:endpoint>???
CXF 2.0 学习札记-3 SOAP Header (转)</beans>??
CXF 2.0 学习札记-3 SOAP Header (转)


服务端的配置就告一段落了,接下来是客户端的修改
客户端
1.同样新增一个Interceptor

CXF 2.0 学习札记-3 SOAP Header (转)package?hs.cxf.client.SoapHeader;
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)import?java.util.List;
CXF 2.0 学习札记-3 SOAP Header (转)import?javax.xml.namespace.QName;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.binding.soap.SoapHeader;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.binding.soap.SoapMessage;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.headers.Header;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.helpers.DOMUtils;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.interceptor.Fault;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.phase.Phase;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.w3c.dom.Document;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.w3c.dom.Element;
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)/**?*//**
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Title:在发送消息前,封装Soap?Header?信息
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Description:
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Copyright:?
CXF 2.0 学习札记-3 SOAP Header (转)?*
CXF 2.0 学习札记-3 SOAP Header (转)?*?@author?zz
CXF 2.0 学习札记-3 SOAP Header (转)?*?@version?1.00.000
CXF 2.0 学习札记-3 SOAP Header (转)?*
CXF 2.0 学习札记-3 SOAP Header (转)?*/
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)public?class?AddSoapHeader?extends?AbstractSoapInterceptor?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)??????private?static?String?nameURI="http://127.0.0.1:8080/cxfTest/ws/HelloWorld";???
CXF 2.0 学习札记-3 SOAP Header (转)??????
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????public?AddSoapHeader()CXF 2.0 学习札记-3 SOAP Header (转){???
CXF 2.0 学习札记-3 SOAP Header (转)????????????super(Phase.WRITE);???
CXF 2.0 学习札记-3 SOAP Header (转)????????}???
CXF 2.0 学习札记-3 SOAP Header (转)????????
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????public?void?handleMessage(SoapMessage?message)?throws?Fault?CXF 2.0 学习札记-3 SOAP Header (转){???
CXF 2.0 学习札记-3 SOAP Header (转)????????????String?spPassword="wdwsb";???
CXF 2.0 学习札记-3 SOAP Header (转)????????????String?spName="wdw";???
CXF 2.0 学习札记-3 SOAP Header (转)???????????????
CXF 2.0 学习札记-3 SOAP Header (转)????????????QName?qname=new?QName("RequestSOAPHeader");???
CXF 2.0 学习札记-3 SOAP Header (转)????????????Document?doc=DOMUtils.createDocument();???
CXF 2.0 学习札记-3 SOAP Header (转)????????????//自定义节点
CXF 2.0 学习札记-3 SOAP Header (转)????????????Element?spId=doc.createElement("tns:spId");???
CXF 2.0 学习札记-3 SOAP Header (转)????????????spId.setTextContent(spName);???
CXF 2.0 学习札记-3 SOAP Header (转)????????????//自定义节点
CXF 2.0 学习札记-3 SOAP Header (转)????????????Element?spPass=doc.createElement("tns:spPassword");???
CXF 2.0 学习札记-3 SOAP Header (转)????????????spPass.setTextContent(spPassword);???
CXF 2.0 学习札记-3 SOAP Header (转)???????????????
CXF 2.0 学习札记-3 SOAP Header (转)????????????Element?root=doc.createElementNS(nameURI,?"tns:RequestSOAPHeader");???
CXF 2.0 学习札记-3 SOAP Header (转)????????????root.appendChild(spId);???
CXF 2.0 学习札记-3 SOAP Header (转)????????????root.appendChild(spPass);???
CXF 2.0 学习札记-3 SOAP Header (转)???????????????
CXF 2.0 学习札记-3 SOAP Header (转)????????????SoapHeader?head=new?SoapHeader(qname,root);???
CXF 2.0 学习札记-3 SOAP Header (转)????????????List<Header>?headers=message.getHeaders();???
CXF 2.0 学习札记-3 SOAP Header (转)????????????headers.add(head);???
CXF 2.0 学习札记-3 SOAP Header (转)????????????System.out.println(">>>>>添加header<<<<<<<");
CXF 2.0 学习札记-3 SOAP Header (转)????????}???
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)}
CXF 2.0 学习札记-3 SOAP Header (转)


2.客户端调用程序修改

CXF 2.0 学习札记-3 SOAP Header (转)package?hs.cxf.client;
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)import?hs.cxf.client.SoapHeader.AddSoapHeader;
CXF 2.0 学习札记-3 SOAP Header (转)import?java.util.ArrayList;
CXF 2.0 学习札记-3 SOAP Header (转)import?javax.xml.bind.JAXBElement;
CXF 2.0 学习札记-3 SOAP Header (转)import?javax.xml.namespace.QName;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.endpoint.Client;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.frontend.ClientProxy;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.interceptor.Interceptor;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.transport.http.HTTPConduit;
CXF 2.0 学习札记-3 SOAP Header (转)import?org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)/**?*//**
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Title:
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Description:
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@Copyright:?
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*?@author?zz
CXF 2.0 学习札记-3 SOAP Header (转)?*?@version?1.00.000
CXF 2.0 学习札记-3 SOAP Header (转)?*?
CXF 2.0 学习札记-3 SOAP Header (转)?*/
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)public?class?TestClient?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????/**?*//**
CXF 2.0 学习札记-3 SOAP Header (转)?????*?测试1
CXF 2.0 学习札记-3 SOAP Header (转)?????*/
CXF 2.0 学习札记-3 SOAP Header (转)????@SuppressWarnings("unchecked")
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????public?void?testSend1()?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????try?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????JaxWsProxyFactoryBean?factory?=?new?JaxWsProxyFactoryBean();
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????????ArrayList<Interceptor>?list?=?new?ArrayList<Interceptor>();
CXF 2.0 学习札记-3 SOAP Header (转)????????????//?添加soap?header?
CXF 2.0 学习札记-3 SOAP Header (转)????????????list.add(new?AddSoapHeader());
CXF 2.0 学习札记-3 SOAP Header (转)????????????//?添加soap消息日志打印
CXF 2.0 学习札记-3 SOAP Header (转)????????????list.add(new?org.apache.cxf.interceptor.LoggingOutInterceptor());
CXF 2.0 学习札记-3 SOAP Header (转)????????????factory.setOutInterceptors(list);
CXF 2.0 学习札记-3 SOAP Header (转)????????????factory.setServiceClass(WebServiceSample.class);
CXF 2.0 学习札记-3 SOAP Header (转)????????????factory.setAddress("http://127.0.0.1:8080/cxfTest/ws/HelloWorld");
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????????Object?obj?=?factory.create();
CXF 2.0 学习札记-3 SOAP Header (转)????????????System.out.println(obj?==?null???"NULL"?:?obj.getClass().getName());
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????????if?(obj?!=?null)?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????????WebServiceSample?ws?=?(WebServiceSample)?obj;
CXF 2.0 学习札记-3 SOAP Header (转)????????????????String?str?=?ws.say("test");
CXF 2.0 学习札记-3 SOAP Header (转)????????????????System.out.println(str);
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????????????str?=?ws.say("1111");
CXF 2.0 学习札记-3 SOAP Header (转)????????????????System.out.println(str);
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????????????User?u?=?new?User();
CXF 2.0 学习札记-3 SOAP Header (转)????????????????JAXBElement<String>?je?=?new?JAXBElement<String>(new?QName(
CXF 2.0 学习札记-3 SOAP Header (转)????????????????????????"http://bean.cxf.hs",?"name"),?String.class,?"张三");
CXF 2.0 学习札记-3 SOAP Header (转)????????????????u.setName(je);
CXF 2.0 学习札记-3 SOAP Header (转)????????????????str?=?ws.sayUserName(u);
CXF 2.0 学习札记-3 SOAP Header (转)????????????????System.out.println(str);
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????????????//?通过对象来交互
CXF 2.0 学习札记-3 SOAP Header (转)????????????????ReqBean?req?=?new?ReqBean();
CXF 2.0 学习札记-3 SOAP Header (转)????????????????req.setExp(new?JAXBElement<String>(new?QName(
CXF 2.0 学习札记-3 SOAP Header (转)????????????????????????"http://bean.cxf.hs",?"exp"),?String.class,
CXF 2.0 学习札记-3 SOAP Header (转)????????????????????????"<exp>111<exp>"));
CXF 2.0 学习札记-3 SOAP Header (转)????????????????req.setSeqId(new?JAXBElement<String>(new?QName(
CXF 2.0 学习札记-3 SOAP Header (转)????????????????????????"http://bean.cxf.hs",?"seqId"),?String.class,
CXF 2.0 学习札记-3 SOAP Header (转)????????????????????????"12345678"));
CXF 2.0 学习札记-3 SOAP Header (转)????????????????RespBean?resp?=?ws.action(req);
CXF 2.0 学习札记-3 SOAP Header (转)????????????????System.out.println("resp_id:"?+?resp.getRespId().getValue());
CXF 2.0 学习札记-3 SOAP Header (转)????????????????System.out.println("resp_exp:"?+?resp.getExp().getValue());
CXF 2.0 学习札记-3 SOAP Header (转)????????????}
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????????}?catch?(Exception?ex)?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????????ex.printStackTrace();
CXF 2.0 学习札记-3 SOAP Header (转)????????}
CXF 2.0 学习札记-3 SOAP Header (转)????}
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????/**?*//**
CXF 2.0 学习札记-3 SOAP Header (转)?????*?测试2
CXF 2.0 学习札记-3 SOAP Header (转)?????*/
CXF 2.0 学习札记-3 SOAP Header (转)????@SuppressWarnings("unchecked")
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????public?void?testSend2()?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????String?webServiceUrl?=?"http://127.0.0.1:8080/cxfTest/ws/HelloWorld";
CXF 2.0 学习札记-3 SOAP Header (转)????????String?webServiceConTimeout?=?"60000";
CXF 2.0 学习札记-3 SOAP Header (转)????????String?webServiceRevTimeout?=?"60000";
CXF 2.0 学习札记-3 SOAP Header (转)????????JaxWsProxyFactoryBean?factory?=?new?JaxWsProxyFactoryBean();
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????ArrayList<Interceptor>?list?=?new?ArrayList<Interceptor>();
CXF 2.0 学习札记-3 SOAP Header (转)????????//?添加soap?header?信息
CXF 2.0 学习札记-3 SOAP Header (转)????????list.add(new?AddSoapHeader());
CXF 2.0 学习札记-3 SOAP Header (转)????????//?添加soap消息日志打印
CXF 2.0 学习札记-3 SOAP Header (转)????????list.add(new?org.apache.cxf.interceptor.LoggingOutInterceptor());
CXF 2.0 学习札记-3 SOAP Header (转)????????factory.setOutInterceptors(list);
CXF 2.0 学习札记-3 SOAP Header (转)????????factory.setServiceClass(WebServiceSample.class);
CXF 2.0 学习札记-3 SOAP Header (转)????????factory.setAddress(webServiceUrl);
CXF 2.0 学习札记-3 SOAP Header (转)????????WebServiceSample?service?=?(WebServiceSample)?factory.create();
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????????//超时时间设置
CXF 2.0 学习札记-3 SOAP Header (转)????????Client?clientP?=?ClientProxy.getClient(service);
CXF 2.0 学习札记-3 SOAP Header (转)????????HTTPConduit?http?=?(HTTPConduit)?clientP.getConduit();
CXF 2.0 学习札记-3 SOAP Header (转)????????HTTPClientPolicy?httpClientPolicy?=?new?HTTPClientPolicy();
CXF 2.0 学习札记-3 SOAP Header (转)????????httpClientPolicy.setConnectionTimeout(Integer
CXF 2.0 学习札记-3 SOAP Header (转)????????????????.valueOf(webServiceConTimeout));
CXF 2.0 学习札记-3 SOAP Header (转)????????httpClientPolicy.setReceiveTimeout(Integer
CXF 2.0 学习札记-3 SOAP Header (转)????????????????.valueOf(webServiceRevTimeout));
CXF 2.0 学习札记-3 SOAP Header (转)????????httpClientPolicy.setAllowChunking(false);
CXF 2.0 学习札记-3 SOAP Header (转)????????http.setClient(httpClientPolicy);
CXF 2.0 学习札记-3 SOAP Header (转)????????
CXF 2.0 学习札记-3 SOAP Header (转)????
CXF 2.0 学习札记-3 SOAP Header (转)????????//?通过对象来交互
CXF 2.0 学习札记-3 SOAP Header (转)????????ReqBean?req?=?new?ReqBean();
CXF 2.0 学习札记-3 SOAP Header (转)????????req.setExp(new?JAXBElement<String>(new?QName(
CXF 2.0 学习札记-3 SOAP Header (转)????????????????"http://bean.cxf.hs",?"exp"),?String.class,
CXF 2.0 学习札记-3 SOAP Header (转)????????????????"<exp>111<exp>"));
CXF 2.0 学习札记-3 SOAP Header (转)????????req.setSeqId(new?JAXBElement<String>(new?QName(
CXF 2.0 学习札记-3 SOAP Header (转)????????????????"http://bean.cxf.hs",?"seqId"),?String.class,
CXF 2.0 学习札记-3 SOAP Header (转)????????????????"12345678"));
CXF 2.0 学习札记-3 SOAP Header (转)????????System.out.println(">>>>>>发送消息<<<<<<<<<");
CXF 2.0 学习札记-3 SOAP Header (转)????????RespBean?resp?=?service.action(req);
CXF 2.0 学习札记-3 SOAP Header (转)????????System.out.println("resp_id:"?+?resp.getRespId().getValue());
CXF 2.0 学习札记-3 SOAP Header (转)????????System.out.println("resp_exp:"?+?resp.getExp().getValue());
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)????}
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????/**?*//**
CXF 2.0 学习札记-3 SOAP Header (转)?????*?@param?args
CXF 2.0 学习札记-3 SOAP Header (转)?????*/
CXF 2.0 学习札记-3 SOAP Header (转)CXF 2.0 学习札记-3 SOAP Header (转)????public?static?void?main(String[]?args)?CXF 2.0 学习札记-3 SOAP Header (转){
CXF 2.0 学习札记-3 SOAP Header (转)????????TestClient?tc?=?new?TestClient();
CXF 2.0 学习札记-3 SOAP Header (转)????????tc.testSend1();
CXF 2.0 学习札记-3 SOAP Header (转)????????System.out.println(">>>>>>>>>>>>2<<<<<<<<<<<<<");
CXF 2.0 学习札记-3 SOAP Header (转)????????tc.testSend2();
CXF 2.0 学习札记-3 SOAP Header (转)????????System.out.println(">>>>>>>>>>>>END<<<<<<<<<<<<<");
CXF 2.0 学习札记-3 SOAP Header (转)????}
CXF 2.0 学习札记-3 SOAP Header (转)
CXF 2.0 学习札记-3 SOAP Header (转)}

?

热点排行