0

I have to add WS-Security (UsernameToken) into the SOAP Request Header. As mentioned in the Apache CXF docs, used WSS4JOutInterceptor.

Apache CXF Version : 3.2.2

SOAP Request/Response exchange works if removed below maven dependency.

<dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.3.0</version>
</dependency>

and if above dependency is present then get below errors

        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(Unknown Source)
            at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(Unknown Source)
            at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown Source)
            at org.apache.wss4j.dom.util.WSSecurityUtil.prependChildElement(WSSecurityUtil.java:314)
            at org.apache.wss4j.dom.util.WSSecurityUtil.findWsseSecurityHeaderBlock(WSSecurityUtil.java:435)
            at org.apache.wss4j.dom.message.WSSecHeader.insertSecurityHeader(WSSecHeader.java:165)
            at org.apache.wss4j.dom.handler.WSHandler.doSenderAction(WSHandler.java:117)
            at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor.access$100(WSS4JOutInterceptor.java:56)
            at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessageInternal(WSS4JOutInterceptor.java:265)
            at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:137)
            at org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor$WSS4JOutInterceptorInternal.handleMessage(WSS4JOutInterceptor.java:124)
            at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
            at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
            at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:442)
            at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
            at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
            at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
            at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139)
            at com.sun.proxy.$Proxy127.getSubscriberPlus(Unknown Source)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
            at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
            at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
            at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:243)

Is there a way to make it work with the above mentioned dependency?

rawat
  • 165
  • 1
  • 2
  • 15
  • Hi Rawat did you manage to find a solution to this? – jdiaz4517 Jun 07 '18 at 10:37
  • [this worked](https://stackoverflow.com/questions/3184268/org-w3c-dom-domexception-wrong-document-err-a-node-is-used-in-a-different-docu/3184311) – rawat Jul 11 '18 at 23:34

0 Answers0