Skip to content

RestTemplate with interceptor calling response getBody() throws IOException even if BufferingClientHttpRequestFactory is set #33662

Closed as not planned
@Hotvianskyi

Description

@Hotvianskyi

Affects: at least 3.2.1 to 3.3.4

The issue occurs when using RestTemplate to call another server as a client. There is a specific use case doesn't work as expected:

Steps to reproduce:
RestTemplate includes this line: restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); or an equivalent
Interceptor is created with a call getBody() on the result of ClientHttpRequestExecution.execute() inside of intercept() method override (for example, for logging purposes)
RestTemplate includes this interceptor
There is a call to restTemplate.exchange() with POST or PUT request, this request is expected to return an error (4xx or 5xx)

Expected result:
getBody() for the result of ClientHttpRequestExecution.execute() inside of the interceptor override is succesfully processed and the execution proceeds as usual, as BufferingClientHttpRequestFactory should provide the wrapped buffered response.

Actual result:
getBody() throws an IOException
Error demonstration:
https://github.com/Hotvianskyi/rest-remplate-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions