Skip to content

RestTemplate should support streaming download and upload [SPR-16885] #21424

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 May 31, 2018 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 31, 2018

Abhijit Sarkar opened SPR-16885 and commented

ResourceHttpMessageConverter has a boolean supportsReadStreaming, which if set, and the response type is InputStreamResource, returns InputStreamResource; otherwise it returns a ByteArrayResource. So clearly, the intent is supporting streaming download.

However, there is a problem: RestTemplate closes the response soon after the HttpMessageConverter runs. Thus, even if I asked for InputStreamResource, and got it, it's no good, because the response stream has been closed. I think it should be dependent on the response type.

On the writing side, implementations of ClientHttpRequestFactory has a boolean bufferRequestBody but SimpleClientHttpRequestFactory (JDK client) and HttpComponentsClientHttpRequestFactory (Apache HTTP client) support this feature, but not OkHttp3ClientHttpRequestFactory.


Affects: 5.0.2

Reference URL: https://stackoverflow.com/a/48041200/839733

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jun 5, 2018

Brian Clozel commented

As explained in #19448, RestTemplate is not meant to stream the response body; its contract doesn't allow it, and it's been around for so long that changing such a basic part of its behavior cannot be done without disrupting many applications. Please use WebClient instead for such use cases.

The second part of this issue seems unrelated. Is this about adding request body streaming support for okhttp3 in RestTemplate? If so, I think we can turn this issue into an enhancement request.

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: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants