- java.lang.Object
-
- org.omnifaces.filter.HttpFilter
-
- org.omnifaces.filter.FacesExceptionFilter
-
- All Implemented Interfaces:
Filter
public class FacesExceptionFilter extends HttpFilter
The
FacesExceptionFilter
will solve 2 problems with exceptions thrown in Faces methods.- Mojarra's
FacesFileNotFoundException
needs to be interpreted as 404. - Root cause needs to be unwrapped from
FacesException
andELException
to utilize standard Servlet API error page handling.
Noted should be that this filter won't run on exceptions thrown during ajax requests. To handle them using
web.xml
configured error pages, useFullAjaxExceptionHandler
.Since version 3.2, the
FacesExceptionFilter
also logs exceptions with an UUID and IP via thelogException(HttpServletRequest, Throwable, String, String, Object...)
method. The UUID is in turn available in EL by#{requestScope['org.omnifaces.exception_uuid']}
.Installation
To get it to run, map this filter on an
<url-pattern>
of/*
inweb.xml
.<filter> <filter-name>facesExceptionFilter</filter-name> <filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class> </filter> <filter-mapping> <filter-name>facesExceptionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Error pages
Please refer the "Error pages" section of the
FullAjaxExceptionHandler
javadoc for recommended error page configuration.Configuration
Please refer the "Configuration" section of the
FullAjaxExceptionHandler
javadoc for available context parameters.Customizing
FacesExceptionFilter
If more fine grained control is desired for logging the exception, then the developer can opt to extend this
FacesExceptionFilter
and override one or more of the following protected methods:- Author:
- Bauke Scholtz
- See Also:
FullAjaxExceptionHandler
,HttpFilter
-
-
Constructor Summary
Constructors Constructor Description FacesExceptionFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doFilter(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain chain)
Filter the HTTP request.void
init()
Convenience init() method without FilterConfig parameter which will be called by init(FilterConfig).protected void
logException(HttpServletRequest request, Throwable exception, String location, String message, Object... parameters)
Log the thrown exception and determined error page location with the given message, optionally parameterized with the given parameters.-
Methods inherited from class org.omnifaces.filter.HttpFilter
destroy, doFilter, getFilterConfig, getInitParameter, getServletContext, init
-
-
-
-
Method Detail
-
init
public void init() throws ServletException
Description copied from class:HttpFilter
Convenience init() method without FilterConfig parameter which will be called by init(FilterConfig).- Overrides:
init
in classHttpFilter
- Throws:
ServletException
- When filter's initialization failed.
-
doFilter
public void doFilter(HttpServletRequest request, HttpServletResponse response, HttpSession session, FilterChain chain) throws ServletException, IOException
Description copied from class:HttpFilter
Filter the HTTP request. The session argument isnull
if there is no session.- Specified by:
doFilter
in classHttpFilter
- Parameters:
request
- The HTTP request.response
- The HTTP response.session
- The HTTP session, if any, elsenull
.chain
- The filter chain to continue.- Throws:
ServletException
- As wrapper exception when something fails in the request processing.IOException
- Whenever something fails at I/O level.- See Also:
Filter.doFilter(ServletRequest, ServletResponse, FilterChain)
-
logException
protected void logException(HttpServletRequest request, Throwable exception, String location, String message, Object... parameters)
Log the thrown exception and determined error page location with the given message, optionally parameterized with the given parameters. The default implementation logs throughjava.util.logging
as SEVERE when the thrown exception is not an instance of any type specified in context parameter "org.omnifaces.EXCEPTION_TYPES_TO_IGNORE_IN_LOGGING". The log message will be prepended with the UUID and IP address. The UUID is available in EL by#{requestScope['org.omnifaces.exception_uuid']}
.- Parameters:
request
- The involved servlet request.exception
- The exception to log.location
- The error page location.message
- The log message.parameters
- The log message parameters, if any. They are formatted usingFormatter
.- Since:
- 3.2
-
-