-
Notifications
You must be signed in to change notification settings - Fork 38.5k
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
Comments
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. |
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. |
Arjen Poutsma commented That is correct, but you can, however, get to the HTTP headers from the execute method. |
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 Many thanks for your help, Arjen. |
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. |
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. |
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:
The text was updated successfully, but these errors were encountered: