I am logging the request body if some custom exception occurs. For this, I have added a filter which caches the HttpServletRequest
object using the ContentCachingRequestWrapper
. Here is the code sample for that:
@Component
public class RequestWrapperFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
filterChain.doFilter(new ContentCachingRequestWrapper(httpServletRequest), httpServletResponse);
}
}
And, my controller class looks something like this:
@PostMapping(Paths.INSPECTION_IMAGE_SUBMIT_REQUEST_V1)
public ResponseEntity<ResponseObject> processThisRequest(
@RequestBody RequestObject requestObject //how am I able to access this requestObject?
) throws Exception {
return someService.process(requestBody);
}
So, how am I able to use this requestObject
? Since, in the filter class, I have cached this, therefore, the getReader()
method must have already been called on this, right? So I should not be able to read the requestObject
, right?