Skip to content

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

Closed

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

Activity

  1. spring-projects-issues commented on Jul 28, 2014

    @spring-projects-issues
    CollaboratorAuthor

    hangsub lim commented

    Is there any reason to throw Exception below?

    @Override
    protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
    throw new UnsupportedOperationException("getBody not supported");
    }

  2. spring-projects-issues commented on Jul 28, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Yes. That's the way HttpComponents work and this issue is about explaining that in the documentation.

  3. spring-projects-issues commented on Aug 26, 2014

    @spring-projects-issues
    CollaboratorAuthor

    hangsub lim commented

    I sended pull request about this issue.
    The problem is that Spring users don't know difference between HttpComponentsClientHttpRequestFactory and SimpleClientHttpRequestFactory.
    So I created testcase about HttpComponentsClientHttpRequestFactory test if bufferRequestBody is false.
    Here is the pull request : #603

  4. added
    type: bug
    status: waiting-for-triage
    in: web
    and removed
    type: bug
    on Jan 11, 2019
  5. added
    status: bulk-closed
    and removed
    status: waiting-for-triage
    on Jan 11, 2019
  6. spring-projects-issues commented on Jan 12, 2019

    @spring-projects-issues
    CollaboratorAuthor

    Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webstatus: bulk-closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions