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

UnsupportedOperationException in LogbookHttpRequestInterceptor with Spring Boot 3.2.2 and Apache Http Client 5 (how to fix test?) #1884

Closed
MrMasterZ opened this issue Sep 9, 2024 · 1 comment
Labels

Comments

@MrMasterZ
Copy link

Description

I Upgraded Spring Boot (was 3.1.9, became 3.2.2)
At the same time, the spring-web version increased (it was 6.0.17, became 6.1.3)
After that, the test works with errors
t1

This test calls method "customize":
t2

where
t3

MdcService - we have written an interface "MdcService" that defines the filling of MdcContext

Test throws an error (part of the stacktrace is given below):
t4

If you replace with restClient in the restTemplate test and make the call as to restClient, then the test will end with the same errors
(val restClient = RestClient.builder(restTemplate).build())

I found an explanation for these errors: #1693
This is because HttpComponentsClientHttpRequest has been reworked in Spring Framework 6.1.

There is also a link ( #1701) and says:
Use writeTo() to buffer HttpEntity in httpclient5
Use HttpEntity.writeTo() instead of relying on EntityUtils.toByteArray() to copy the OutputStream of the HttpEntity.

Thus, for test is necessary to replace EntityUtils.toByteArray() with HttpEntity.writeTo()
But how to do this if EntityUtils.toByteArray () is deep in stacktrace
How to fix the test?

Expected Behavior

Test passes without errors

Your Environment

  • Version used:
    • Logbook: 3.5.0
    • Spring Boot: 3.2.2
    • spring-web: 6.1.3
@MrMasterZ
Copy link
Author

I solved this problem by replacing the versions of the logbook libraries (it was: 3.5.0, it became: 3.8.0)

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

No branches or pull requests

1 participant