【问题标题】:WRONG_DOCUMENT_ERR when invoking a web service Java - SOAP/CXF调用 Web 服务 Java - SOAP/CXF 时出现 WRONG_DOCUMENT_ERR
【发布时间】:2020-04-27 09:34:55
【问题描述】:

我正在将运行 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 文件时,我看到这个服务有一个额外的配置,它是一个 WSS4JOutInterceptor bean。

<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>

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

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

感谢任何帮助。 谢谢。

【问题讨论】:

  • 你解决过这个问题吗?我现在面临同样的问题,运气不好。
  • 嗨@dracuella 这是我们wildfly中库版本的问题。我们必须在 Wildfly 模块文件夹中手动添加良好版本的 jar。今天是星期六,我无法在家中访问我们的代码。星期一我会检查我们的代码,如果有的话,会给你更多的细节。
  • 您是否找到有关您必须添加哪些罐子的任何详细信息?如果您升级或降级?
  • 你好@dracuella。很抱歉,我答复晚了。您可以在下面查看我的答案以获取详细信息。希望能帮助到你。告诉我。

标签: java spring soap cxf


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    在这个文件夹中,我们有 2 个文件:saaj-impl-1.3.16-jbossorg-1.jar(从 Maven 下载)和一个 module.xml 文件对于 saaj jar。 这是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>
    

    【讨论】:

    • 谢谢。我们已经在 J​​Boss (EAP 7.3.1) 中有提到的 jar,但您向我们发送了正确的方向。这确实是一个 saaj 问题,我们只是在应用程序中而不是直接在 JBoss 中修复它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多