错误的文档调用web服务Java-SOAP/CXF时出错

错误的文档调用web服务Java-SOAP/CXF时出错,java,spring,soap,cxf,Java,Spring,Soap,Cxf,我正在将一个运行java 1.7和jboss-eap-6.1的应用程序迁移到java 1.8和wildfly-18.0.0.Final 一切都运行得很好,但在使用SOAP调用特定的外部web服务时,我遇到了一个问题 我调用服务时出现以下错误: Caused by: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.

我正在将一个运行java 1.7和jboss-eap-6.1的应用程序迁移到java 1.8和wildfly-18.0.0.Final

一切都运行得很好,但在使用SOAP调用特定的外部web服务时,我遇到了一个问题

我调用服务时出现以下错误:

Caused by: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than 
the one that created it.
    at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:357)
    at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(ParentNode.java:288)
    at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:237)
    at org.apache.wss4j.dom.util.WSSecurityUtil.prependChildElement(WSSecurityUtil.java:375)
    at org.apache.wss4j.dom.util.WSSecurityUtil.findWsseSecurityHeaderBlock(WSSecurityUtil.java:497)
    at org.apache.wss4j.dom.message.WSSecHeader.insertSecurityHeader(WSSecHeader.java:167)
    at org.apache.wss4j.dom.handler.WSHandler.doSenderAction(WSHandler.java:117)
    at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor.access$100(WSS4JOutInterceptor.java:57)
    at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessageInternal(WSS4JOutInterceptor.java:275)
    at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:147)
    at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:132)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:441)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:356)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:314)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:140)
    ... 112 more
除此之外,所有其他服务都在工作。 当我查看spring上下文xml文件时,我看到这个服务有一个额外的配置,它是一个WSS4JOutInterceptorbean

<bean id="outInterceptorWSS" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
    <property name="properties">
        <map>
            <entry key="action" value="UsernameToken"/>
            <entry key="mustUnderstand" value="false"/>
            <entry key="user" value="username here"/>
            <entry key="passwordType" value="PasswordNone"/>
            <entry key="passwordCallbackClass"
                   value="PasswordHandler package here"/>
        </map>
    </property>
    </bean>

    <bean id="myServiceFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="serviceClass"
                  value="service package here"/>
        <property name="address"
                  value="endpointUrl here"/>
        <property name="username"
                  value="username here"/>
        <property name="password"
                  value="password here"/>
        <property name="outInterceptors" ref="outInterceptorWSS"/>
        <property name="bus" ref="cxf"/>
    </bean>

outiterceptorwssbean用于在调用外部web服务之前在soap消息中添加安全头。 该服务在迁移之前(java 1.7和jboss-eap-6-1)运行良好,但在迁移之后(java 1.8和wildfly-18.0.0.Final)不起作用

我不是100%确定,但我对这个问题的理解是wildfly创建了soap消息,spring上下文xml文件中定义的OutiterCeptorwsbean试图修改它,因此消息是:一个节点在与创建它的文档不同的文档中使用

感谢您的帮助。
谢谢。

将新版本的saaj impl添加到您的项目中

        <dependency>
            <groupId>com.sun.xml.messaging.saaj</groupId>
            <artifactId>saaj-impl</artifactId>
            <version>1.5.2</version>
        </dependency>

com.sun.xml.messaging.saaj
saaj impl
1.5.2

我们终于找到了这个问题的解决方案。 我们必须在我们的wildfly模块目录中手动添加saaj jar。为此,我们在这个目录中创建一个文件夹:${YOUR_WILDFLY_HOME}/modules/system/layers/base/com/sun/xml/messaging/saaj/main

在这个文件夹中,我们有两个文件:saaj-impl-1.3.16-jbossorg-1.jar(从Maven下载)和saaj-jar的module.xml文件。 这是module.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2011, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<module name="com.sun.xml.messaging.saaj" xmlns="urn:jboss:module:1.5">
<properties>
    <property name="jboss.api" value="private"/>
</properties>
<resources>
    <resource-root path="saaj-impl-1.3.16-jbossorg-1.jar"/>
</resources>

<dependencies>
    <module name="javax.api"/>
    <module name="javax.xml.soap.api"/>
    <module name="javax.xml.stream.api"/>
    <module name="javax.activation.api"/>
    <module name="org.apache.xerces" services="import"/>
</dependencies>

</module>


您解决过这个问题吗?我现在面临着同样的问题,运气也不太好。嗨@dracuella,这是我们wildfly中的库版本问题。我们必须在wildfly模块文件夹中手动添加jar的好版本。今天是星期六,我无法从家里获取我们的密码。星期一我会检查我们的代码,如果有的话,会给你更多的细节。你有没有发现你必须添加哪些JAR的细节?如果您升级或降级了?您好@dracuella。很抱歉我反应太晚了。有关详细信息,请参见下面我的答案。希望能有帮助。让我知道,谢谢。我们在JBoss(EAP 7.3.1)中已经有了提到的jar,但您给我们的方向是正确的。这确实是一个saaj问题,我们只是在应用程序中修复了它,而不是直接在JBoss中修复。