Reputation: 12621
JSF-applications can throw ViewExpiredException
s when a session is expired. This event will be quite common when having guests on your system. Therefor the application will handle this event without any trouble for the guest, as follows:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/expired</location>
</error-page>
When a guest tries to send a request on an expired session, he will be redirected to /expired
. Since I don't consider this Exception
as a problem worth mentioning, I would like to prevent writing the stacktrace to the log of my applicationserver.
How can I accomplish this?
Upvotes: 7
Views: 4303
Reputation: 1108577
There are basically 2 options which each boil down to the same solution: catch, suppress and navigate to the error page all by yourself using either a servlet filter or a JSF exception handler. This way the exception won't reach the servletcontainer which would then handle and log it automatically.
Provided that the error page does really the job for you (this namely won't work with JSF ajax requests, unless you've a custom JSF ExceptionHandler
), then a servlet filter mapped on URL pattern matching JSF requests which does the following in its doFilter()
method should suffice:
try {
chain.doFilter(request, response);
} catch (ServletException e) {
if (e.getRootCause() instanceof ViewExpiredException) {
request.getRequestDispatcher("/expired").forward(request, response);
} else {
throw e;
}
}
If you would like to cover JSF ajax requests as well, then you can't go around a JSF exception handler. Head to the following related answers to see some concrete examples:
Upvotes: 7