You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Java 17, Spring Boot 3 and logbook-spring-boot-starter:3.9.0
I have a Spring interceptor where I have to read the request body in my application. I also use Logbook to log the request and the response in custom format.
I was previously using the 1.13.0 version of Logbook. After migrating to the latest version, I can read the request body in my Spring interceptor but it is failing at @RequestBody annotation in the Spring Controller class with an error saying Required request body is missing
Possible Fix
After going through the code, I can see that previously with logbook 1.x, the underlying logic of httpServletRequest.getInputStream method was creating a ByteArrayInputStream object every time it gets called. So If I were to call getInputStream 2 times, it returns 2 different ByteArrayInputStream objects.
But now It is getting created once per request. Because of that, the first time getInputStream is called, the stream is closed and the second time we get an empty response body.
@mutyasaisrikar Afaik, it's a default behavior that reading from request stream drains it making controllers fail, and it requires manual handling of that unfortunately. It seems that if Logbook in previous versions handled it for us silently, it was only a fortunate coincidence.
I am using Java 17, Spring Boot 3 and logbook-spring-boot-starter:3.9.0
I have a Spring interceptor where I have to read the request body in my application. I also use Logbook to log the request and the response in custom format.
I was previously using the
1.13.0
version of Logbook. After migrating to the latest version, I can read the request body in my Spring interceptor but it is failing at@RequestBody
annotation in the Spring Controller class with an error sayingRequired request body is missing
Possible Fix
After going through the code, I can see that previously with logbook 1.x, the underlying logic of
httpServletRequest.getInputStream
method was creating aByteArrayInputStream
object every time it gets called. So If I were to call getInputStream 2 times, it returns 2 differentByteArrayInputStream
objects.But now It is getting created once per request. Because of that, the first time getInputStream is called, the stream is closed and the second time we get an empty response body.
Steps to Reproduce
https://github.com/mutyasaisrikar/logbook-error
RestApiTest
test fails because the Controller class is not able to read the request bodyThe text was updated successfully, but these errors were encountered: