-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Wyatt Smith opened SPR-16380 and commented
When writing an application, I had to upload a large file (~600 MB) using the RestTemplate, as well as use an oAuth2 bearer header. To do this, I added a custom interceptor to write the oauth header:
restTemplate.getInterceptors().add(new OauthAuthorizationInterceptor(accessToken));Because the file is so large, I was getting an OutOfMemoryException, so I disabled buffering:
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setBufferRequestBody(false);
restTemplate = new RestTemplate(requestFactory);The application continued getting the memory exception. Upon investigation, it appears as though the ClientHttpRequestFactory is wrapped by an InterceptingClientHttpRequestFactory because of the interceptor (InterceptingHttpAccessor#getRequestFactory). InterceptingClientHttpRequestFactory.getRequestFactory() returns a InterceptingClientHttpRequest, which is a AbstractBufferingClientHttpRequest (InterceptingClientHttpRequestFactory#createRequest). Despite requestFactory.setBufferRequestBody(false), a buffered request is made.
My temporary solution is to manually add the Authorization header everywhere and eliminate the interceptor so InterceptingHttpAccessor#getRequestFactory returns my original HttpComponentsClientHttpRequestFactory with buffering disabled instead of a InterceptingClientHttpRequestFactory wrapping it.
The long term solution should be for the InterceptingClientHttpRequestFactory to be allowed to be streaming instead of buffered.
Affects: 4.3.9
Issue Links:
- HttpComponentsStreamingClientHttpRequest fails if restTemplate has interceptors [SPR-17113] #21650 HttpComponentsStreamingClientHttpRequest fails if restTemplate has interceptors