Skip to content

Inconsistent support for RequestCallback in HttpComponentsClientHttpRequestFactory [SPR-11981] #16597

Closed
@spring-projects-issues

Description

@spring-projects-issues

Stéphane Nicoll opened SPR-11981 and commented

HttpComponentsClientHttpRequestFactory is supposed to handle features in a similar manner as SimpleClientHttpRequestFactory but it does not support RequestCallback when the bufferRequestBody is disabled.

Consider the following code

// Create the HttpComponentsClientHttpRequestFactory
SimpleClientHttpRequestFactory preconfiguredHTTPInstance = new SimpleClientHttpRequestFactory();
 
// Set BufferRequestBody as false, default is true.
preconfiguredHTTPInstance.setBufferRequestBody(false);
 
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(preconfiguredHTTPInstance);
restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); 
RequestCallback requestCallback = new RequestCallback() {
    @Override
    public void doWithRequest(ClientHttpRequest request) throws IOException {
        IOUtils.copy(content.getInputStream(), request.getBody());
    }
}; 
HttpMessageConverterExtractor<String> responseExtractor =
        new HttpMessageConverterExtractor<String>(String.class, restTemplate.getMessageConverters());
return restTemplate.execute(url, HttpMethod.POST, requestCallback, responseExtractor)

Switching to HttpComponentsClientHttpRequestFactory leads to UnsupportedOperationException("getBody not supported")


Affects: 4.0.6

Issue Links:

2 votes, 5 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions