我有带有 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);
你知道这里发生了什么吗?
更新:
一些额外的提示。我希望这会有所帮助:
不确定这个问题是否仍然相关,但是当我在 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 进程。希望这对每个人都有效。