Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring-ws-test - IllegalArgumentException during request comparison #1193

Closed
MHajoha opened this issue Apr 19, 2021 · 13 comments
Closed

spring-ws-test - IllegalArgumentException during request comparison #1193

MHajoha opened this issue Apr 19, 2021 · 13 comments
Assignees
Milestone

Comments

@MHajoha
Copy link

MHajoha commented Apr 19, 2021

With com.sun.xml.messaging.saaj:saaj-impl:1.5.3 (which is included in spring-boot-starter-web-services:2.4.5), the comparison of expected and actual request throws an IllegalArgumentException for us:

java.lang.IllegalArgumentException: Cannot find SOAP wrapper for element [SOAP-ENV:Envelope: null]

	at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:590)
	at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:578)
	at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.lookForEnvelope(SOAPPartImpl.java:155)
	at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:135)
	at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getDocumentElement(SOAPPartImpl.java:430)
	at org.custommonkey.xmlunit.DifferenceEngine.compareNode(DifferenceEngine.java:191)
	at org.custommonkey.xmlunit.DifferenceEngine.compare(DifferenceEngine.java:130)
	at org.custommonkey.xmlunit.Diff.compare(Diff.java:241)
	at org.custommonkey.xmlunit.Diff.appendMessage(Diff.java:364)
	at org.custommonkey.xmlunit.Diff.toString(Diff.java:378)
	at org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher.match(SoapEnvelopeDiffMatcher.java:61)
	at org.springframework.ws.test.support.matcher.AbstractSoapMessageMatcher.match(AbstractSoapMessageMatcher.java:40)
	at org.springframework.ws.test.client.WebServiceMessageMatcherAdapter.match(WebServiceMessageMatcherAdapter.java:43)
	at org.springframework.ws.test.client.MockSenderConnection.send(MockSenderConnection.java:76)
	at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:658)
	at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:606)
	at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:383)
	at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:373)
	at org.example.SpringWsTestReproTest.Should_Work(SpringWsTestReproTest.java:37)

This does not occur with saaj-impl:1.5.2.
I've created a relatively minimal test to reproduce the issue: https://github.com/MHajoha/spring-ws-test-bug-repro

@MHajoha MHajoha changed the title IllegalArgumentException during request comparison: Cannot find SOAP wrapper for element [SOAP-ENV:Envelope: null] spring-ws-test - IllegalArgumentException during request comparison Apr 19, 2021
@sephiroth-j
Copy link

sephiroth-j commented Apr 26, 2021

changes between saaj-impl 1.5.2 and 1.5.3
eclipse-ee4j/metro-saaj@1.5.2...1.5.3

I think it is due to the new cloning behavior.

There are also notable differences with v1.5.2 and 1.5.3 in the type of test (the actual soap request) in DifferenceEngine.compare. With v1.5.2 it was of type DocumentImpl - the same type of control which is the expected soap request. With v1.5.3 it is of type SOAPPart1_1Impl.

Maybe it's time to switch to xmlunit 2?

@Kr0oked
Copy link

Kr0oked commented Jun 9, 2021

I ran into the exact same issue

@pchurzin
Copy link

same for me

@nicolasmafra
Copy link

Workaround:

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

@mlshnkv
Copy link

mlshnkv commented May 27, 2022

Is there a solution to this problem today other than using saaj-impl:jar:1.5.2

AlbericMartel added a commit to AlbericMartel/spring-ws that referenced this issue Dec 8, 2022
The SoapEnvelopeDiffMatcher was untested at the MockWebServiceServer level. Upgrading to xmlunit2 fixed the issue.

Related: spring-projects#1193
@gregturn gregturn self-assigned this Jan 10, 2023
@gregturn gregturn added this to the 4.0.1 milestone Jan 10, 2023
@gregturn
Copy link
Contributor

I've patched this issue so things should run properly. It's currently working for Spring WS 4.0.1-SNAPSHOT, which is picked up by Spring Boot 3.0.2-SNAPSHOT.

Spring Boot 2.4 (as mentioned above) hasn't been supported since November 2021, so it won't be visible there. I'll investigate whether this is a candidate for backporting to Spring WS 3.1, which is supported by Spring Boot 2.7. (All version of Spring Boot before 2.7 are no longer supported).

gregturn pushed a commit that referenced this issue Jan 10, 2023
Implement newer versions of PayloadDiffMatcher and SoapEnvelopematcher based on XMLUnit 2. Deprecate the prior versions of these supporting types so they can be removed in a future release. XMLUnit 2 eases the testing of MockWebServiceServer.

Resolves #1193.
@gregturn
Copy link
Contributor

Backported to 3.1.x.

gregturn added a commit that referenced this issue Jan 11, 2023
Related: #1193.
@sephiroth-j
Copy link

I am happy to confirm that the error is gone with Spring Boot 2.7.7, saaj-impl 1.5.3 and spring-ws 3.1.5-SNAPSHOT.

@kommpn
Copy link

kommpn commented Mar 12, 2023

I'm still facing this issue using encryption, while i run it on Intellij it works correctly, but when i dockerize it, returns:
java.lang.IllegalArgumentException: Cannot find SOAP wrapper for element [xenc:EncryptedData: null] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:590) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:578) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.impl.ElementImpl.getFirstChildElement(ElementImpl.java:660) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.impl.BodyImpl.getPayloadQName(BodyImpl.java:439) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.impl.BodyImpl.hasFault(BodyImpl.java:151) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at org.springframework.ws.soap.saaj.SaajSoapBody.hasFault(SaajSoapBody.java:55) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.soap.AbstractSoapMessage.hasFault(AbstractSoapMessage.java:62) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.soap.AbstractSoapMessage.getFaultCode(AbstractSoapMessage.java:68) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:94) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:60) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:288) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.24.jar!/:5.3.24] 2023-03-12 15:03:10 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.24.jar!/:5.3.24]

@BergChristopher
Copy link

I'm still facing this issue using encryption, while i run it on Intellij it works correctly, but when i dockerize it, returns: java.lang.IllegalArgumentException: Cannot find SOAP wrapper for element [xenc:EncryptedData: null] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:590) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:578) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.impl.ElementImpl.getFirstChildElement(ElementImpl.java:660) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.impl.BodyImpl.getPayloadQName(BodyImpl.java:439) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at com.sun.xml.messaging.saaj.soap.impl.BodyImpl.hasFault(BodyImpl.java:151) ~[saaj-impl-1.5.3.jar!/:1.5.3] 2023-03-12 15:03:10 at org.springframework.ws.soap.saaj.SaajSoapBody.hasFault(SaajSoapBody.java:55) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.soap.AbstractSoapMessage.hasFault(AbstractSoapMessage.java:62) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.soap.AbstractSoapMessage.getFaultCode(AbstractSoapMessage.java:68) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:94) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:60) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:288) ~[spring-ws-core-3.1.4.jar!/:na] 2023-03-12 15:03:10 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.24.jar!/:5.3.24] 2023-03-12 15:03:10 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.24.jar!/:5.3.24]

Your docker container is using spring-ws-core-3.1.4.jar not 3.1.5

@AntoineJT
Copy link
Contributor

I'm updating a Spring Boot 2.7 project to Spring Boot 3.1.2, and the issue was not present initially, but is there when updating Spring Boot

java.lang.IllegalArgumentException: Cannot find SOAP wrapper for element [SOAP-ENV:Envelope: null]

	at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:590)
	at com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl.find(SOAPDocumentImpl.java:578)
	at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.lookForEnvelope(SOAPPartImpl.java:155)
	at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:135)
	at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.getDocumentElement(SOAPPartImpl.java:430)
	at org.custommonkey.xmlunit.DifferenceEngine.compareNode(DifferenceEngine.java:191)
	at org.custommonkey.xmlunit.DifferenceEngine.compare(DifferenceEngine.java:130)
	at org.custommonkey.xmlunit.Diff.compare(Diff.java:241)
	at org.custommonkey.xmlunit.Diff.appendMessage(Diff.java:364)
	at org.custommonkey.xmlunit.Diff.toString(Diff.java:384)
	at org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher.match(SoapEnvelopeDiffMatcher.java:64)
	at org.springframework.ws.test.support.matcher.AbstractSoapMessageMatcher.match(AbstractSoapMessageMatcher.java:40)
	at org.springframework.ws.test.server.WebServiceMessageMatcherAdapter.match(WebServiceMessageMatcherAdapter.java:42)
	at org.springframework.ws.test.server.MockWebServiceClient$MockWebServiceClientResponseActions.andExpect(MockWebServiceClient.java:211)

The thing is that it's not fixable by using saaj-impl 1.5.2 as it's not compatible with 3.X: the following stacktrace occurs if I patch it to use 1.5.2 (the SAAJMetaFactory class is absent from this old version)

java.lang.NoClassDefFoundError: javax/xml/soap/SAAJMetaFactory
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	at jakarta.xml.soap.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:60)
	at jakarta.xml.soap.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:96)
	at jakarta.xml.soap.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:71)
	at jakarta.xml.soap.FactoryFinder.newInstance(FactoryFinder.java:136)
	at jakarta.xml.soap.FactoryFinder.find(FactoryFinder.java:132)
	at jakarta.xml.soap.SAAJMetaFactory.getInstance(SAAJMetaFactory.java:66)
	at jakarta.xml.soap.MessageFactory.newInstance(MessageFactory.java:126)
	at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.afterPropertiesSet(SaajSoapMessageFactory.java:139)
	at org.springframework.ws.support.DefaultStrategiesHelper.instantiateBean(DefaultStrategiesHelper.java:180)
	... 105 more
Caused by: java.lang.ClassNotFoundException: javax.xml.soap.SAAJMetaFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	... 123 more

I tried saaj-impl 3.0.2, 3.0.1 and 3.0.0 but the Cannot find SOAP wrapper for element issue is there everytime

@PhilippKemkes
Copy link

I'm updating a Spring Boot 2.7 project to Spring Boot 3.1.2, and the issue was not present initially, but is there when updating Spring Boot

I have exactly the same problem. Any ideas how to fix this issues?

saaj-impl 3.0.2
spring-boot-starter-web 3.1.2
spring-ws-test 4.0.5

AntoineJT added a commit to AntoineJT/spring-ws that referenced this issue Aug 15, 2023
When the XMLUnit2 upgrade was done (commit: c39d3d1) this import was
forgotten.

It causes the bug reported with XMLUnit1 (issue: spring-projects#1193) to still be
present when using `ResultMatchers#soapEnvelope(Source)`.
For more infos: spring-projects#1193 (comment)

Here comes the fix for it.
@AntoineJT
Copy link
Contributor

AntoineJT commented Aug 15, 2023

@PhilippKemkes Hey, I did have a fix now!

So, in fact, there are 2 possible fixes:

To apply the temporary workaround, just follow these steps:

  • Get the patch from this gist: https://gist.github.com/AntoineJT/8de3b08168803574b54cacfc5c425288
  • Put it wherever you want in your project tests
  • Replace all calls to ResponseMatchers.soapEnvelope by calls to PatchedSoapResponseMatchers.soapEnvelope (a search-and-replace in test files will do the thing, then add missing imports, and you're good to go)

Enjoy 😄

gregturn pushed a commit that referenced this issue Sep 5, 2023
When the XMLUnit2 upgrade was done (commit: c39d3d1) this import was forgotten.

It causes the bug reported with XMLUnit1 (issue: #1193) to still be present when using `ResultMatchers#soapEnvelope(Source)`.

For more infos: #1193 (comment)

See #1370.
Related: #1193.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.