Spring Framework
  1. Spring Framework
  2. SPR-8016

RestTemplate - support response mapping to entity with potentially empty response body.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 3.1 M1
    • Fix Version/s: 4.1.5, 4.2 RC1
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      I am working with an API which returns an empty response body on http status 200 (OK) & a body which is populated on http status 400 (Bad Request).

      When using RestTemplate.getForEntity() this is fine for the case where the body is populated, however I get an exception for the 'null body' case.

      My understanding is one should provide a class implementing the ResponseBody interface & make the call via the execute() method on the RestTemplate.

      This task is a request to consider that the use case here is common & whether Spring should offer something out of the box for this situation.

      Also See: http://stackoverflow.com/questions/3322381/spring-resttemplate-behavior-when-handling-responses-with-a-status-of-no-content/3648447#3648447

        Issue Links

          Activity

          Hide
          Brian Clozel added a comment -

          Hi Koos Gadellaa
          The code you're referring to does not exist anymore and has been replaced by the latest fix, this will be released with 4.1.5.
          Do you still have concerns about that new fix?

          Show
          Brian Clozel added a comment - Hi Koos Gadellaa The code you're referring to does not exist anymore and has been replaced by the latest fix , this will be released with 4.1.5. Do you still have concerns about that new fix?
          Hide
          Koos Gadellaa added a comment -

          Ah! I was looking at the 4.1.x branch, and apparently the fix hasn't been merged to it yet...

          It'll probably work for me, but I currently can't see any checks if the body is valid as given in https://tools.ietf.org/html/rfc7230#section-3.4 (which was originaly referred).
          However, adhering to that part is a bit of a nuisance, as it effectively blocks users from getting a body, and I think that should be left to the user of the library (it's better to have the body as is, even if it turns out to be invalid, then no body at all)... so I'm all for it!
          (in the meantime, I'll work around it myself, as I can't wait for tomorrow )

          Show
          Koos Gadellaa added a comment - Ah! I was looking at the 4.1.x branch, and apparently the fix hasn't been merged to it yet... It'll probably work for me, but I currently can't see any checks if the body is valid as given in https://tools.ietf.org/html/rfc7230#section-3.4 (which was originaly referred). However, adhering to that part is a bit of a nuisance, as it effectively blocks users from getting a body, and I think that should be left to the user of the library (it's better to have the body as is, even if it turns out to be invalid, then no body at all)... so I'm all for it! (in the meantime, I'll work around it myself, as I can't wait for tomorrow )
          Hide
          Brian Clozel added a comment -

          I'll backport this right now.

          Show
          Brian Clozel added a comment - I'll backport this right now.
          Hide
          Satyapal Reddy added a comment -

          we are upgrading from Spring 3.2.2 to Spring 4.1.3/4.1.4 and what used to work earlier started failing due to the logic in hasMessageBody. I looked at 4.1.5 and that may work. But it may be a while before 4.1.5 is released. In our case, server is responding with a body, but with no Content-Length header and with Connection: close.

          Show
          Satyapal Reddy added a comment - we are upgrading from Spring 3.2.2 to Spring 4.1.3/4.1.4 and what used to work earlier started failing due to the logic in hasMessageBody. I looked at 4.1.5 and that may work. But it may be a while before 4.1.5 is released. In our case, server is responding with a body, but with no Content-Length header and with Connection: close.
          Hide
          Brian Clozel added a comment -

          Hi Satyapal Reddy
          Sorry for this inconvenience.
          4.1.5 is scheduled in a few days, you can check its status at any given time here.
          You can already test this by using 4.1.5-BUILD-SNAPSHOT builds; you just need to add https://repo.spring.io/libs-snapshot/ as a snapshot-enabled repository in your maven configuration.

          Thanks,

          Show
          Brian Clozel added a comment - Hi Satyapal Reddy Sorry for this inconvenience. 4.1.5 is scheduled in a few days, you can check its status at any given time here . You can already test this by using 4.1.5-BUILD-SNAPSHOT builds; you just need to add https://repo.spring.io/libs-snapshot/ as a snapshot-enabled repository in your maven configuration. Thanks,

            People

            • Assignee:
              Brian Clozel
              Reporter:
              David Victor
              Last updater:
              Stéphane Nicoll
            • Votes:
              9 Vote for this issue
              Watchers:
              19 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                6 weeks, 1 day ago