InputStream consumed by DispatcherServlet logRequest
See original GitHub issueAffects: 5.2.1
A few weeks ago I enabled debug logging for my application, today I had forgotten about but noticed that my injected InputStream
was empty. After a debugging session (first assuming it again was related to the HiddenHttpMethodFilter
) I ended up at
So every time I enable debug logging I cannot use my injected InputStream
:
@PostMapping
public ResponseEntity<String> doPost(InputStream input, HttpServletRequest request) {
...
I do now get this logging:
2019-12-10T10:27:46,305 [http-nio-8082-exec-7] DEBUG org.springframework.web.servlet.DispatcherServlet - POST "/communication", parameters={masked}
But maybe it would make sense to auto-wrap the request in DEBUG when that logging is active or give a warning when injecting the consumed InputStream
later and even report who did it 😄
Thanks!
Related to (but not covered by): #22985
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Spring Boot - How to log all requests and responses with ...
... Log request and response payload ("body") ======== // We CANNOT simply read the request payload here, because then the InputStream would be...
Read more >Spring - Log Incoming Requests - Baeldung
The main issue with the reading request is that, as soon as the input stream is read for the first time, it's marked...
Read more >Log Incoming Requests In Spring - Java Development Journal
You have to be careful while using such approach as input stream will be marked as consumed the moment it is read for...
Read more >Chapter 5. Creating a Web service with Spring-WS
The MessageDispatcherServlet is a standard Servlet which conveniently extends from the standard Spring Web DispatcherServlet , and wraps a MessageDispatcher .
Read more >Logging HttpRequest parameters and request body-Spring MVC
If the request body is huge I recommend putting the input stream into a ... HttpServletRequestWrapper { public LogRequest(HttpServletRequest request) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes this is expected, and besides the logging of request details, any other code could cause a similar issue by accessing a request parameter.
Note that you can inject the content reliably as
@RequestBody String
or@RequestBody ByteArrayResource
because we reconstruct the body from request parameters inServletServerHttpRequest#getBody
.Yes, just use the standard multipart support in the Servlet container.