How to get request's URI from WebRequest in Spring?

Found the solution. Casting WebRequest to ServletWebRequest solved the purpose.

((ServletWebRequest)request).getRequest().getRequestURI().toString()

returns the complete path - http://localhost:8080/signup


There are multiple solutions to this problem.

1) One can get request URI and client information from WebRequest using webRequest.getDescription(true).

true will show user's information such as client id and false will just print URI.

2) Instead of WebRequest of Use HttpServletRequest directly in method definition as

@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request, HttpServletRequest httpRequest) {
    logger.info(httpRequest.getRequestURI());
    return handleExceptionInternal(ex, errorMessage(HttpStatus.BAD_REQUEST, ex, request), headers, HttpStatus.BAD_REQUEST, request);
}