/** * Factory for creating instances of this class. * * @param request * @return instance of request contains error attributes or {@code null} if it does not. */ public static ErrorAttributes of(HttpServletRequest request, String filterPrefix) { Args.notNull(request, "request"); Integer code = (Integer)request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); String message = (String)request.getAttribute(RequestDispatcher.ERROR_MESSAGE); String uri = DispatchedRequestUtils.getRequestUri(request, RequestDispatcher.ERROR_REQUEST_URI, filterPrefix); String servlet = (String)request.getAttribute(RequestDispatcher.ERROR_SERVLET_NAME); @SuppressWarnings("unchecked") Class<? extends Throwable> type = (Class<? extends Throwable>)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE); Throwable ex = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (!Strings.isEmpty(uri) || code != null || ex != null) { return new ErrorAttributes(code, message, uri, servlet, type, ex); } return null; }
/** * Factory for creating instances of this class. * * @param request * @return instance of request contains error attributes or {@code null} if it does not. */ public static ErrorAttributes of(HttpServletRequest request, String filterPrefix) { Args.notNull(request, "request"); Integer code = (Integer)request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); String message = (String)request.getAttribute(RequestDispatcher.ERROR_MESSAGE); String uri = DispatchedRequestUtils.getRequestUri(request, RequestDispatcher.ERROR_REQUEST_URI, filterPrefix); String servlet = (String)request.getAttribute(RequestDispatcher.ERROR_SERVLET_NAME); @SuppressWarnings("unchecked") Class<? extends Throwable> type = (Class<? extends Throwable>)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE); Throwable ex = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (!Strings.isEmpty(uri) || code != null || ex != null) { return new ErrorAttributes(code, message, uri, servlet, type, ex); } return null; }