title: How to get request's URI from WebRequest in Spring?
body: <p>I am handling REST exceptions using <code>@ControllerAdvice</code> and <code>ResponseEntityExceptionHandler</code> in a spring Rest webservice. So far everything was working fine until I decided to add the <code>URI</code> path(for which exception has occurred) into the <strong>BAD_REQUEST</strong> response.</p>
  
  <pre><code>@ControllerAdvice
  public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
  
  @Override
  protected ResponseEntity&lt;Object&gt; handleHttpMessageNotReadable(HttpMessageNotReadableException ex,
          HttpHeaders headers, HttpStatus status, WebRequest request) {
      logger.info(request.toString());
      return handleExceptionInternal(ex, errorMessage(HttpStatus.BAD_REQUEST, ex, request), headers, HttpStatus.BAD_REQUEST, request);
  }
  
  private ApiError errorMessage(HttpStatus httpStatus, Exception ex, WebRequest request) {
      final String message = ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage();
      final String developerMessage = ex.getCause() == null ? ex.toString() : ex.getCause().getMessage();
      return new ApiError(httpStatus.value(), message, developerMessage, System.currentTimeMillis(), request.getDescription(false));
  }
  </code></pre>
  
  <p>ApiError is just a Pojo class:</p>
  
  <pre><code>public class ApiError {
  
      private Long timeStamp;
      private int status;
      private String message;
      private String developerMessage;
      private String path;
  }
  </code></pre>
  
  <p>But WebRequest has not given any api to get the path for which the request failed. I tried:
  <code>request.toString()</code> returns -> <em>ServletWebRequest: uri=/signup;client=0:0:0:0:0:0:0:1</em><br>
  <code>request.getDescription(false)</code> returns -> <em>uri=/signup</em><br>
  <code>getDescription</code> is pretty close to the requirement, but doesn't meet it. Is there any way to get only the uri part?</p>