Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty response body when using Spring RestTemplate with LogbookClientHttpRequestInterceptor #948

Merged

Conversation

thowimmer
Copy link
Contributor

This PR fixes that null response bodies are returned for non-empty responses when using the new LogbookClientHttpRequestInterceptor with a Spring RestTemplate.

Description

The response extractor of the Spring RestTemplate considers the position of the response body stream.
This leads to a null response body, since the buffered RemoteResponse was not resetting the streams position after copying the response body bytes.

Motivation and Context

Currently RestTemplates without any special configuration are returning null response entities when using the new LogbookClientHttpRequestInterceptor.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@whiskeysierra
Copy link
Collaborator

👍

@whiskeysierra whiskeysierra merged commit 21b3736 into zalando:main Feb 8, 2021
@whiskeysierra
Copy link
Collaborator

Thank you for your contribution! 🎉
I'll release it asap.

@thowimmer
Copy link
Contributor Author

Cool thanks @whiskeysierra :-)

For you notice

This few lines of code changes how RestTemplate behaves when deserializing the response body in the end.

I had to change the response type of the first test to String so that it passes with my changes !
I'm unsure whether the intended behavior when calling getForObject(url, Void.class) is that it fails in case the server returns a response body of a certain content type.

Even though I think this behavior is the correct one, it might break some clients which have different assumptions in this respect - This might be a very limited side effect for clients which want to do the following thing:
Call getForObject(...) on an endpoint which returns a certain content type but do not want to interpret it further.

@whiskeysierra
Copy link
Collaborator

Understood. I'd rather fix the obvious issue here rather than staying compatible with a rather unusual behavior. Totally agree with your assessment there.

@whiskeysierra
Copy link
Collaborator

I released your fix as 2.4.2 to central.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants