JAVA审核所有传入的Web请求

时间:2018-12-06 07:43:56

标签: java

我的ExceptionhandlingController类带有@ControllerAdvice注释,它们的方法带有@ExceptionHandler(ValidationException.class)注释。我需要审核afterCompletion类的HandlerInterceptorAdapter方法中的请求

我的任务是使用其响应对象从ExceptionhandlingController类获取异常,但是我在Exception方法的afterCompletion对象中获取空值。     我不确定如何继续进行此操作。

@ControllerAdvice
public class ExceptionHandlingController {


    /**
     * Resource not found.
     *
     * @param ex
     *            the ex
     * @return the response entity
     */
    @ExceptionHandler(ValidationException.class)
    public ResponseEntity<ExceptionResponse> resourceNotFound(
            ValidationException ex) {
        ExceptionResponse response = new ExceptionResponse();
        response.setErrorCode("Value not found");
        response.setErrorMessage(messageByLocaleService.getMessage(ex
                .getErrorCode()));
        Map<String, String> headers = new HashMap<>();
        return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
    }

这是我的Interceptor课     @零件     公共类AuditInterceptor扩展了HandlerInterceptorAdapter

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, 
            Object handler, ModelAndView modelAndView) throws Exception 

}

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
            Object handler, Exception ex) throws Exception {
        // here I need to audit the exception, but I am getting null in Exception ex
}

0 个答案:

没有答案