нαƒєєz
нαƒєєz

Reputation: 1249

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?

Upvotes: 6

Views: 1730

Answers (1)

Gvg
Gvg

Reputation: 318

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.

Upvotes: 2

Related Questions