title: Get request values from ExceptionHandler using Spring MVC
body: <p>I have a Spring MVC Controller and an Exception Handler. When an exception occurs, I want the Exception Handler to log all the GET/POST data that was sent in the request. How can this be achieved?</p>
  
  <p>Controller:</p>
  
  <pre><code>@Controller
  @RequestMapping("/foo")
  public class FooController {
      private final FooService fooService;
  
      @PostMapping("/bar")
      @ResponseBody
      public BarObject doSomething(@RequestBody final FooContext context) 
      {
          return fooService.doSomething(context);
      }
  }
  </code></pre>
  
  <p>Exception Handler:</p>
  
  <pre><code>@ControllerAdvice
  public class ExceptionController {
  
      private final Logger log = LoggerFactory.getLogger(ExceptionController.class);
  
      @ResponseStatus(HttpStatus.BAD_REQUEST)
      @ExceptionHandler(Exception.class)
      @ResponseBody
      public ErrorMessage handleException(final HttpServletRequest request, final Exception exception) {
          //Retrieve request data 
          //request.getQueryString() 
          // How to get POST data if we cannot access @RequestBody?)
          log.error(request.getRequestURI(), exception);
          return new ErrorMessage(request.getRequestURI(), exception.getLocalizedMessage());
  }
  </code></pre>