[SOLVED] org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR:

Here you can find the solution for a problem: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR exception

The problem

When you invoke a web service you got the exception like below:

org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.

The cause

There is a bug in the wss4j-ws-security-dom library in version 2.2.0 which might be delivered as dependency by SpringBoot freamework.

The solution

As as solution you can override the wss4j-ws-security-dom library dependency to higher version for the time it will be included in proper vesion as SpringBoot dependency. For do this – just open pom.xml file and add the following dependency.

<dependency>
    <groupId>org.apache.wss4j</groupId>
    <artifactId>wss4j-ws-security-dom</artifactId>
    <version>2.2.2</version>
</dependency>
0 0 vote
Article Rating
Subscribe
Notify of
guest
7 Comments
oldest
newest most voted
Inline Feedbacks
View all comments
Tomas Flekac
Tomas Flekac
1 year ago

Hello,

with your solutin i came with error org.apache.xml.security.utils.XMLUtils.encodeToString([B)Ljava/lang/String;

For me was solution to downgrade saaj lib to 1.3:

com.sun.xml.messaging.saaj
saaj-impl
1.3

Do you know when we can expect fix?

Thanks

Timothy Shouldice
Timothy Shouldice
1 year ago

Thanks for posting this, I hit the same issue and your solution got me back up running.

Srinivas HN
Srinivas HN
1 year ago

Hello,

It solved my problem too thanks much for the solution. Do you know for which version of spring boot version is this happening and from when ? It was working for me last week and suddenly started throwing this error. It would be helpful for me to get an answer.

Srinivas HN
Srinivas HN
1 year ago
Reply to  lukasz.ciesla

I see this is happening for the SOAP based calls it will happen for the rest based calls too ? Strange thing for me i was using the 2.1.3 and this issue started 2 or days back until that it was not having any issue. I dint upgrade i had 2.1.3 from beginnig

Hemadri Medida
Hemadri Medida
11 months ago

Thank you very much, the above solution helped me solve the problem quickly.

Baalu
Baalu
8 months ago

Thank You for the solution. I tried downgrading saaj-impl but I got different error. After adding wss4j-ws-security-dom 2.2.2 finally I am able to make the web service call successfully.