Fix integration between Logbook and HttpClient5 #1368
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background information
I recently migrated a project I am working on from Spring Boot 2 to 3.
After it, I noticed that Logbook stopped logging formatted XML.
After debugging, the main issue I found is the integration between Apache HttpClient5, Zalando Logbook and Spring-WS.
Logbook works well with JSON (Spring-Web) and does not have this issue.
Root cause of the issue
Logbook expects to find a non-blank Content Type from
HttpEntity
during his execution oforg.zalando.logbook.BodyFilter
chain.Solution
I did, basically, the same what is already written for JSON in Spring-Web:
https://github.com/spring-projects/spring-framework/blob/v6.0.8/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java#L90
I copied the code from version 6.0.8 because that's what I had in my classpath. While I was creating this pull request I noticed that Spring team already refactored the above mentioned class: https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java#L141