@Override public void doFilterInternal(HttpServletRequest baseRequest, HttpServletResponse baseResponse, FilterChain chain) throws IOException, ServletException { try { super.doFilterInternal(baseRequest, baseResponse, chain); } catch (ServletException e) { if (e.getCause() instanceof StaleStateServiceException) { LOG.debug("Stale state detected", e); baseResponse.setStatus(HttpServletResponse.SC_CONFLICT); baseResponse.getWriter().write("Stale State Detected\n"); baseResponse.getWriter().write(e.getMessage() + "\n"); } else if (e.getCause() instanceof ServiceException) { //if authentication is null and CSRF token is invalid, must be session time out if (SecurityContextHolder.getContext().getAuthentication() == null && failureHandler != null) { baseRequest.setAttribute("sessionTimeout", true); failureHandler.onAuthenticationFailure(baseRequest, baseResponse, new SessionAuthenticationException("Session Time Out")); } else { throw e; } } else { throw e; } } } }
private void addErrorDetails(Map<String, Object> errorAttributes, WebRequest webRequest, boolean includeStackTrace) { Throwable error = getError(webRequest); if (error != null) { while (error instanceof ServletException && error.getCause() != null) { error = ((ServletException) error).getCause(); } if (this.includeException) { errorAttributes.put("exception", error.getClass().getName()); } addErrorMessage(errorAttributes, error); if (includeStackTrace) { addStackTrace(errorAttributes, error); } } Object message = getAttribute(webRequest, "javax.servlet.error.message"); if ((!StringUtils.isEmpty(message) || errorAttributes.get("message") == null) && !(error instanceof BindingResult)) { errorAttributes.put("message", StringUtils.isEmpty(message) ? "No message available" : message); } }
@Override public void doFilter(ServletRequest baseRequest, ServletResponse baseResponse, FilterChain chain) throws IOException, ServletException { try { super.doFilter(baseRequest, baseResponse, chain); } catch (ServletException e) { if (e.getCause() instanceof ServiceException) { HttpServletRequest baseHttpRequest = (HttpServletRequest) baseRequest; //if authentication is null and CSRF token is invalid, must be session time out if (SecurityContextHolder.getContext().getAuthentication() == null) { baseHttpRequest.setAttribute("sessionTimeout", true); failureHandler.onAuthenticationFailure((HttpServletRequest) baseRequest, (HttpServletResponse) baseResponse, new SessionAuthenticationException("Session Time Out")); } else { throw e; } } else { throw e; } } } }
@Test public void controllerAdviceWithNestedExceptionWithinDispatcherServlet() throws Exception { StaticWebApplicationContext ctx = new StaticWebApplicationContext(); ctx.registerSingleton("controller", NestedExceptionThrowingController.class); ctx.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class); ctx.refresh(); DispatcherServlet servlet = new DispatcherServlet(ctx); servlet.init(new MockServletConfig()); try { servlet.service(this.servletRequest, this.servletResponse); } catch (ServletException ex) { assertTrue(ex.getCause() instanceof IllegalStateException); assertTrue(ex.getCause().getCause() instanceof ServletRequestBindingException); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> * that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> * that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> * that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> * that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
/** * Returns the exception that caused this servlet exception. * * @return the <code>Throwable</code> * that caused this servlet exception */ public Throwable getRootCause() { return getCause(); } }
public Throwable getRootCause() { return getCause(); } }
@Deprecated @SuppressWarnings("unused") private static <T extends Throwable> Throwable cause(final T exception) { Throwable cause = null; if (exception != null) { cause = exception; while (cause instanceof ServletException && cause.getCause() != null) { final ServletException servletException = ((ServletException) cause); cause = servletException.getCause(); } } return cause; }
@Deprecated @SuppressWarnings("unused") private static <T extends Throwable> Throwable cause(final T exception) { Throwable cause = null; if (exception != null) { cause = exception; while (cause instanceof ServletException && cause.getCause() != null) { final ServletException servletException = ((ServletException) cause); cause = servletException.getCause(); } } return cause; }
private ServletException wrapException(Exception e, String msg) { this.logger.error(msg, e); ServletException servletException = new ServletException(msg, e); if (servletException.getCause() == null) { servletException.initCause(e); } return servletException; } }
public void doRules(ServletRequest request, ServletResponse response) throws IOException, ServletException { try { process(request, response); handleRewrite(request, response); } catch (InvocationTargetException e) { handleExcep(request, response, e); } catch (ServletException e) { if ( e.getCause() instanceof InvocationTargetException ) { handleExcep(request, response, (InvocationTargetException) e.getCause()); } else { throw e; } } }
@Override public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { try { super.doGet(request, response); } catch (IOException e) { logFreemarkerException(e); } catch (ServletException e) { Throwable wrapped = e.getCause(); if (wrapped == null) { wrapped = e; } logFreemarkerException(wrapped); } }