Results 1 to 2 of 2

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

  1. #1
    Join Date
    Aug 2007
    Posts
    1

    Default 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. #2
    Join Date
    Feb 2013
    Location
    China
    Posts
    1

    Default

    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....

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •