Apache CXF-Web服务客户端在Tomcat中生成的SOAP消息不同于独立的JAR

时间:2019-06-11 11:54:38

标签: java tomcat soap cxf

我是Apache CXF的新手。我目前正在使用Apache CXF(版本3.3.2)开发一个Web服务客户端,该客户端旨在通过发送和接收SOAP消息连接到Web服务。然后,我开发的Web服务客户端将作为库集成到在Tomcat上运行的主要应用程序中。

Web服务客户端在我的开发环境中正常运行(我使用Eclipse),并且已成功从Web服务接收数据。同样,如果我将代码打包为独立的jar文件,则它可以正常工作。但是,当我将jar放置在Tomcat中并从主应用程序对其进行测试时,它会在以下情况下做出响应:

javax.xml.ws.soap.SOAPFaultException: Error reading XMLStreamReader.
        at org.apache.cxf.jaxws.JaxWsClientProxy.mapException(JaxWsClientProxy.java:195)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
        at com.sun.proxy.$Proxy103.searchEmployeeUsers(Unknown Source)
...
...
...
Caused by: org.apache.cxf.binding.soap.SoapFault: Error reading XMLStreamReader.
        at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:87)
        at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:53)
        at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:42)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:112)
        at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:70)
        at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:35)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:826)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1693)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1570)
        at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1371)
        at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
        at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:671)
        at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderIntercepto                   r.java:63)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:440)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:355)
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
        at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
        at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
        ... 79 more

我怀疑此异常来自Web服务端,这意味着我的Web Service客户端设法连接SOAP消息并将其发送到Web Service,但是Web Service无法以某种方式理解该消息。

我成功地从成功的案例(从Eclipse或独立的JAR执行客户端)和失败的案例(从Tomcat的客户端执行)中获取传出的SOAP消息,我发现了以下区别:

SOAP消息-成功

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soap:mustUnderstand="1">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-18d8d608-2918-4bce-833a-e36f38bcc2ef">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="soap"/>
...
...

SOAP消息-失败

<soapenv:Envelope xmlns://schemas.xmlsoap.org/soap/envelope/="xmlns:soapenv" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:mustUnderstand="1">
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-0cd3a846-c466-4393-a434-bab5f5d2ed5a">
<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:CanonicalizationMethod xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
<ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="//schemas.xmlsoap.org/soap/envelope/ soapenv" />
...
...

*我很抱歉没有提供完整的代码,因为某些部分是敏感的,但希望足以让您对问题有所了解。

我觉得很奇怪,因为我们没有在开发环境,独立JAR和Tomcat上更改任何代码。

我不明白是什么原因导致生成的SOAP消息有所不同。我怀疑它可能与依赖关系有关,因为以前我们还很难在tomcat应用程序中调整正确的依赖关系,以使此Web服务客户端正常工作。

我想知道的是:哪种依赖性导致了这种差异?另外,我应该怎么做才能解决此问题(确保Tomcat中生成的SOAP消息与开发环境/独立JAR中的消息相同)?有什么最佳实践吗?

谢谢。

0 个答案:

没有答案