2

我有带有 WSS 拦截器的 CXF Web 服务客户端,可以从控制台运行,但是当从 JBoss 运行时会抛出这样的异常:

发生意外的异常

Unexpected exception occured 
javax.xml.ws.soap.SOAPFaultException: WRONG_DOCUMENT_ERR: A node is
used in a different document
than the one that created
it.    
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:156)   
at $Proxy1020.getAccountStatements(Unknown Source)  
at com.sru.statement.impl.cs.CSStatementGetter.getStatementFromBank(CSStatementGetter.java:164)   
at com.sru.statement.impl.cs.CSStatementGetter.getStatement(CSStatementGetter.java:90)   
at com.sru.hub.common.statement.CommonStatementImportExecutor.execute(CommonStatementImportExecutor.java:89)   
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)   
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)   
at java.lang.reflect.Method.invoke(Method.java:597)   
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)   
(...)
at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:260)   
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)   
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)   
at java.lang.Thread.run(Thread.java:662)   
Caused by: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A
node is used in a
different document than the one
that created it.  
at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknown Source)  
at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)  
at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)  
at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)  
at org.jboss.ws.core.soap.SOAPDocument.appendChild(SOAPDocument.java:222)   
at org.jboss.ws.core.soap.SOAPPartImpl.appendChild(SOAPPartImpl.java:297)   
at org.apache.cxf.staxutils.W3CDOMStreamWriter.setChild(W3CDOMStreamWriter.java:119)   
at org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:109)   
at org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:137)   
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:122)   
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:81)   
at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:61)   
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)   
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)   
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:462)   
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:365)   
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:318)   
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:95)   
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)   
... 80 more  

它适用于这些库:

/org/apache/cxf/cxf-rt-frontend-jaxws/2.4.2/cxf-rt-frontend-jaxws-2.4.2.jar
/org/apache/cxf/cxf-api/2.4.2/cxf-api-2.4.2.jar
/org/apache/cxf/cxf-common-utilities/2.4.2/cxf-common-utilities-2.4.2.jar
/org/apache/cxf/cxf-rt-core/2.4.2/cxf-rt-core-2.4.2.jar
/org/apache/cxf/cxf-rt-frontend-simple/2.4.2/cxf-rt-frontend-simple-2.4.2.jar
/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar
/org/apache/ws/xmlschema/xmlschema-core/2.0/xmlschema-core-2.0.jar
/org/apache/cxf/cxf-rt-bindings-soap/2.4.2/cxf-rt-bindings-soap-2.4.2.jar
/org/apache/cxf/cxf-tools-common/2.4.2/cxf-tools-common-2.4.2.jar
/org/apache/cxf/cxf-rt-databinding-jaxb/2.4.2/cxf-rt-databinding-jaxb-2.4.2.jar
/org/apache/cxf/cxf-rt-ws-addr/2.4.2/cxf-rt-ws-addr-2.4.2.jar
/org/apache/neethi/neethi/3.0.1/neethi-3.0.1.jar
/org/apache/cxf/cxf-rt-ws-security/2.4.2/cxf-rt-ws-security-2.4.2.jar
/org/apache/ws/security/wss4j/1.6.2/wss4j-1.6.2.jar
/commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar
/org/apache/cxf/cxf-rt-transports-http/2.4.2/cxf-rt-transports-http-2.4.2.jar
/org/apache/xmlsec/1.4.2/xmlsec-1.4.2.jar
/commons-io/commons-io/2.4/commons-io-2.4.jar

如果在没有 WSS 拦截器的情况下调用客户端,则一切正常。

WSS拦截器代码:

Client client = ClientProxy.getClient(port);
Endpoint cxfEndpoint = client.getEndpoint();
Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put(WSHandlerConstants.USER, "username_alex");
outProps.put(WSHandlerConstants.ADD_UT_ELEMENTS, WSConstants.NONCE_LN + " " +WSConstants.CREATED_LN);
outProps.put(WSHandlerConstants.PW_CALLBACK_REF, this);
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);

有什么想法吗?

更新:

一些额外的提示。我希望它会有所帮助:

  1. 我试图在 Tomcat 上运行该应用程序。有用,
  2. 因为这张票:https ://issues.apache.org/jira/browse/CXF-4612?page= com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel 我用另外两个版本的 CXF 测试了应用程序:2.5.7 和 2.5.8。它失败了。
  3. 在我的 JBoss 的 /lib/endorsed 中,我有两个 SAAJ 实现:axis-saaj.jar 和 jboss-native-saaj.jar。我尝试将这些库结合起来,发现如果没有它们,应用程序在使用 WSS 处理 Web 服务时会分发(应用程序可以工作,但什么也没发生:浏览器和日志中都没有错误),
  4. 我还尝试将axis-saaj 和jboss-native-saaj(分别)添加到应用程序的WAR 文件中。结果与第 3 点类似:应用手。
4

1 回答 1

1

不确定这个问题是否仍然相关,但是当我在 JBoss 6.1.0 上遇到这个问题时遇到了这个问题。所以我想我会发布一个解决方案。

JBoss 为创建和处理 SOAP 消息期间涉及的许多工厂设置默认值。在这里特别造成问题的一个是javax.xml.soap.MessageFactory.

Apache CXF 有一个名为SAAJOutInterceptor. 这是硬编码在org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.

我不确定,但我认为这里的想法是将 SOAP 消息从 CXF 特定对象更改为平台特定对象。这样做时,初始化的 MessageFactory 是org.jboss.ws.core.soap.MessageFactoryImpl. 这个类来自 jar common/lib/jbossws-native-core.jar

一种蛮力解决方案是摆脱这个罐子。它没有在我们的应用程序中产生任何问题。但更体面的解决方案是通过在META-INF/services/javax.xml.soap.MessageFactory应用程序的类路径上以这种精确结构定义文件来覆盖 JBoss MessageFactory。

对于 WAR 文件,它必须放在 WEB-INF/classes 下。该文件只有一行,如下所示:

com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl

进行此更改后重新启动 JBoss 进程。希望这对每个人都有效。

于 2016-01-12T17:54:01.997 回答