Description
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:
- Disable streaming when reading to Resources in RestTemplate [SPR-14882] #19448 Disable streaming when reading to Resources in RestTemplate ("duplicates")
- Update docs on RestTemplate to indicate it's superceded by WebClient [SPR-16993] #21531 Update docs on RestTemplate to indicate it's superceded by WebClient