I want the request body content from WebRequest when I override the below method in my ExceptionHandler which extends ResponseEntityExceptionHandler.
protected org.springframework.http.ResponseEntity<java.lang.Object> handleMethodArgumentNotValid(
org.springframework.web.bind.MethodArgumentNotValidException ex,
org.springframework.http.HttpHeaders headers,
org.springframework.http.HttpStatus status,
org.springframework.web.context.request.WebRequest request) {
/* compiled code */ }
I was able to cast WebRequest to ServletWebRequest like this ((ServletWebRequest)request)
and calling getRequest()
method to return the HttpServletRequest
.
But I am not able to get the content from ContentCachingRequestWrapper
, its giving blank string or 0 bytes. Please help me on this.
ContentCachingRequestWrapper wrapperRequest =
new ContentCachingRequestWrapper(((ServletWebRequest)request).getRequest());