ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpSession session = httpRequest.getSession();
ExceptionBean exceptionBean = new ExceptionBean();
try {
chain.doFilter(request, response);
//Before rendering the response
} catch (ServletException e) {
Throwable rootCause = e.getRootCause();
while (rootCause.getCause() != null) {
rootCause = rootCause.getCause();
}
rootCause.printStackTrace();
exceptionBean.setThrowable(rootCause);
if (rootCause instanceof AccessDeniedException) {
//FIXME I18N
exceptionBean.setExplanation("//Vous n'avez pas les droits nécessaires pour effectuer cette opération");
} else {
// FIXME I18N
exceptionBean.setExplanation("//Une erreur générale s'est produite: ");
}
}
if (exceptionBean.getThrowable() != null) {
session.setAttribute(ExceptionBean.SESSION_REF, exceptionBean);
HttpServletResponse httpResponse = (HttpServletResponse) response;
String path = httpRequest.getContextPath() + "/pages/exception/general.xhtml";
httpResponse.sendRedirect(httpRequest.getContextPath() + "/pages/exception/general.jsf");
}