Spring Framework
  1. Spring Framework
  2. SPR-7357

Provide a way to read an InputStream with RestTemplate

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 3.0.3
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Please, see http://forum.springsource.org/showthread.php?t=91713
      Today I need to "abandon" RestTemplate when I need to read a raw binary response as InputStream and not as in-memory byte[]

      Thank you!

        Activity

        Hide
        Arjen Poutsma added a comment -

        You can already read an InputStream by using the execute() method on the RestTemplate in combination with a ResponseExtractor implementation, see here.

        Note that you cannot simply return the InputStream from the extractor, because by the time the execute method returns, the underlying connection and stream are already closed.

        Show
        Arjen Poutsma added a comment - You can already read an InputStream by using the execute() method on the RestTemplate in combination with a ResponseExtractor implementation, see here . Note that you cannot simply return the InputStream from the extractor, because by the time the execute method returns, the underlying connection and stream are already closed.
        Hide
        Evgeny Goldin added a comment -

        Oh, that's good, thank you.

        But I'm using an exchange() call in order to <a href="http://forum.springsource.org/showthread.php?t=91471">set an HTTP header</a> with HttpEntity before sending a request.
        Seems like I can't get to InputStream in this case, is that correct?

        Show
        Evgeny Goldin added a comment - Oh, that's good, thank you. But I'm using an exchange() call in order to <a href="http://forum.springsource.org/showthread.php?t=91471">set an HTTP header</a> with HttpEntity before sending a request. Seems like I can't get to InputStream in this case, is that correct?
        Hide
        Arjen Poutsma added a comment -

        That is correct, but you can, however, get to the HTTP headers from the execute method.

        Show
        Arjen Poutsma added a comment - That is correct, but you can, however, get to the HTTP headers from the execute method.
        Hide
        Evgeny Goldin added a comment -

        Yes, it worked! I now use RestTemplate for all requests.

        Note that you cannot simply return the InputStream from the extractor, because by the time the execute method returns, the underlying connection and stream are already closed

        That was important. Indeed, I could only read an InputStream inside ResponseExtractor.extractData ( ClientHttpResponse )

        Many thanks for your help, Arjen.

        Show
        Evgeny Goldin added a comment - Yes, it worked! I now use RestTemplate for all requests. Note that you cannot simply return the InputStream from the extractor, because by the time the execute method returns, the underlying connection and stream are already closed That was important. Indeed, I could only read an InputStream inside ResponseExtractor.extractData ( ClientHttpResponse ) Many thanks for your help, Arjen.

          People

          • Assignee:
            Arjen Poutsma
            Reporter:
            Evgeny Goldin
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 39 weeks, 2 days ago