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