Feb 12th, 2013, 01:25 PM
RestTemplate: Handling a service that returns varying response types
I'm hitting a RESTful service that returns XML in the normal case, but a text/plain response if there's an error. The current code calls the service like this:
DOMSource source = getRestTemplate().getForObject(url, DOMSource.class, upcOrSku);
As you can imagine, if the service returns an error in text/plain format, this blows up (even though both XML and String converters are registered - StringHttpMessageConverter can't make a DOMSource).
I have a couple ideas, but is there a best practice for handling this type of scenario?