使用JBoss 5.1.0GA中的WSS拦截器调用CXF客户端时的WRONG_DOCUMENT_ERR

时间:2013-01-31 15:24:51

标签: xml jboss cxf wss

我有一个带有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 / endors中我有两个SAAJ实现:axis-saaj.jar和jboss-native-saaj.jar。我尝试将这些库结合起来,并发现在没有这两个库时,应用程序在使用WSS处理Web服务时应用程序(应用程序正常但没有发生任何事情:浏览器和日志中都没有错误),
  4. 我还尝试将axis-saaj和jboss-native-saaj(单独)添加到应用程序的WAR文件中。结果类似于第3点:申请手。

1 个答案:

答案 0 :(得分: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进程。希望这适用于所有人。