I am sending XML over HTTP request through Spring RestTemplate to an external gateway and I'm receiving a XML response back.
The XSD which was given to validate the response has a target namespace but the actual response doesn't contain the namespace prefix. I have generated the Java resources using the XSD and due to this I'm getting below error when getting response from (during the unmarshalling process),
ResponseEntity<Response> responseEntity = restTemplate.exchange(endpointURL, HttpMethod.POST, requestEntity,
Response.class);
The exception is:-
Exception in thread "main" javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"Response"). Expected elements are <{http://securetransport.dw/rcservice/xml}Response>
Are there any ways to skip the namespace check from Spring ResponseEntity?
If you have generated your bindings with the jaxb-plugin there should be a 'package-info.java'.
For example:
@javax.xml.bind.annotation.XmlSchema( namespace = "someurl", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED )
If you remove the namespace from the annotation it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With