Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring xml namespace during unmarshalling in RestTemplate

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?

like image 809
нαƒєєz Avatar asked Mar 10 '16 06:03

нαƒєєz


1 Answers

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.

like image 170
Gvg Avatar answered Oct 31 '22 02:10

Gvg