Skip to content

Provide a way to read an InputStream with RestTemplate [SPR-7357] #12015

Closed

Description

@spring-projects-issues

Evgeny Goldin opened SPR-7357 and commented

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!


Affects: 3.0.3

Issue Links:

Activity

  1. spring-projects-issues commented on Jul 6, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Arjen Poutsma commented

    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.

  2. spring-projects-issues commented on Jul 7, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Evgeny Goldin commented

    Oh, that's good, thank you.

    But I'm using an exchange() call in order to set an HTTP header with HttpEntity before sending a request.
    Seems like I can't get to InputStream in this case, is that correct?

  3. spring-projects-issues commented on Jul 7, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Arjen Poutsma commented

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

  4. spring-projects-issues commented on Jul 18, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Evgeny Goldin commented

    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.

  5. spring-projects-issues commented on Aug 5, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Daniel Dacar commented

    Why is the InputStream closed? This forces the client to store the stream in memory or in I/O instead of passing it to other layers for processing.

  6. spring-projects-issues commented on Oct 26, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Andrey Beletsky commented

    Evgeny Goldin I also wonder why? Could you explain, please? Or send a link where it is already explained. It is very important not to fully read it in memory.

  7. added
    status: invalid
    type: enhancement
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: invalid

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions