Announcement Announcement Module
Collapse
No announcement yet.
RestTemplate: Handling a service that returns varying response types Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?
Working...
X