Announcement Announcement Module
Collapse
No announcement yet.
How do I configure a RestTemplate to return null when 404 happens? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I configure a RestTemplate to return null when 404 happens?

    I am calling a REST URL that returns a 404 if data cannot be found, along with a body that contains some XML. A 404 is a valid case and an exception should not be thrown. (I am using Spring 3.0.5.)

    I am calling RestTemplate.getForObject() and want it to return null if the REST call results in a 404.

    Code:
    Foo foo = restTemplate.getForObject(url, Foo.class, vars);
    How can I configure the RestTemplate to return null when a 404 happens?

  • #2
    I have got the same problem few days ago. And I tried some idea. Only this one works.
    At the server side: set a aop around joinpoint, when your methods return null, then you put a flag in the cookies, and still return null.
    At the client side: Overrides the Spring RestTemplete, just Overrides one method called doExecute, there you can get the cookies you past.

    That's the way I did. Look forward to good idea....

    Comment

    Working...
    X