Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jul 6, 2010 · 6 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 6, 2010

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:

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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?

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants