- java.lang.Object
-
- jakarta.faces.context.ExceptionHandler
-
- jakarta.faces.context.ExceptionHandlerWrapper
-
- org.omnifaces.exceptionhandler.ExceptionSuppressor
-
- All Implemented Interfaces:
FacesListener
,SystemEventListener
,FacesWrapper<ExceptionHandler>
,EventListener
- Direct Known Subclasses:
ViewExpiredExceptionHandler
public class ExceptionSuppressor extends ExceptionHandlerWrapper
The
ExceptionSuppressor
will suppress all exceptions which are an instance of the types as listed in context parameter "org.omnifaces.EXCEPTION_TYPES_TO_SUPPRESS" and refresh the current page by redirecting to the current URL with query string. The context parameter value must be a commaseparated string of fully qualified names of exception types. Note that this also covers subclasses of specified exception types.<context-param> <param-name>org.omnifaces.EXCEPTION_TYPES_TO_SUPPRESS</param-name> <param-value>java.nio.channels.ClosedByInterruptException,java.nio.channels.IllegalSelectorException</param-value> </context-param>
This is useful for exceptions which are technically unavoidable such as those which boil down to that the network connection is abruptly closed by the client by e.g. navigating away while the page is loading, or closing the browser window/tab while the page is loading, or having the physical network connection cut down, or the physical machine crashed, etcetera. All which are beyond control of the server and therefore not really interesting to have logged into server logs.
Installation
This handler must be registered by a factory as follows in
faces-config.xml
in order to get it to run:<factory> <exception-handler-factory>org.omnifaces.exceptionhandler.ExceptionSuppressorFactory</exception-handler-factory> </factory>
In case there are multiple exception handlers, best is to register this handler as last one in the chain. For example, when combined with
FullAjaxExceptionHandler
, this ordering will prevent theFullAjaxExceptionHandler
from taking over the handling of the to-be-suppressed exceptions.<factory> <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory> <exception-handler-factory>org.omnifaces.exceptionhandler.ExceptionSuppressorFactory</exception-handler-factory> </factory>
- Since:
- 3.9
- Author:
- Lenny Primak
- See Also:
ExceptionSuppressorFactory
-
-
Field Summary
Fields Modifier and Type Field Description static String
PARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
The context parameter name to specify exception types to suppress byExceptionSuppressor
.
-
Constructor Summary
Constructors Modifier Constructor Description ExceptionSuppressor(ExceptionHandler wrapped)
Construct a new exception suppressor around the given wrapped exception handler.protected
ExceptionSuppressor(ExceptionHandler wrapped, Class<? extends Throwable>... exceptionTypesToSuppress)
Construct a new exception suppressor around the given wrapped exception handler and using the given array of exception types to suppress.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Class<? extends Throwable>[]
getExceptionTypesToSuppress(ServletContext context)
Get the exception types to suppress.void
handle()
Inspect allExceptionHandlerWrapper.getUnhandledExceptionQueuedEvents()
if any of them is caused by one of the exception types listed inPARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
.protected void
handleSuppressedException(FacesContext context, Throwable suppressedException)
Subclasses can override this method to have finer grained control over what must happen when the given exception has been suppressed.-
Methods inherited from class jakarta.faces.context.ExceptionHandlerWrapper
getHandledExceptionQueuedEvent, getHandledExceptionQueuedEvents, getRootCause, getUnhandledExceptionQueuedEvents, getWrapped, isListenerForSource, processEvent
-
-
-
-
Field Detail
-
PARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
public static final String PARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
The context parameter name to specify exception types to suppress byExceptionSuppressor
. The context parameter value must be a commaseparated string of fully qualified names of exception types. Note that this also covers subclasses of specified exception types.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ExceptionSuppressor
public ExceptionSuppressor(ExceptionHandler wrapped)
Construct a new exception suppressor around the given wrapped exception handler.- Parameters:
wrapped
- The wrapped exception handler.
-
ExceptionSuppressor
@SafeVarargs protected ExceptionSuppressor(ExceptionHandler wrapped, Class<? extends Throwable>... exceptionTypesToSuppress)
Construct a new exception suppressor around the given wrapped exception handler and using the given array of exception types to suppress.- Parameters:
wrapped
- The wrapped exception handler.exceptionTypesToSuppress
- Array of exception types to suppress.
-
-
Method Detail
-
getExceptionTypesToSuppress
public static Class<? extends Throwable>[] getExceptionTypesToSuppress(ServletContext context)
Get the exception types to suppress. This can be specified via context parameter "org.omnifaces.EXCEPTION_TYPES_TO_SUPPRESS".- Parameters:
context
- The involved servlet context.- Returns:
- Exception types to suppress.
-
handle
public void handle()
Inspect allExceptionHandlerWrapper.getUnhandledExceptionQueuedEvents()
if any of them is caused by one of the exception types listed inPARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
. If so, then drain theExceptionHandlerWrapper.getUnhandledExceptionQueuedEvents()
, and refresh the current URL with query string.- Overrides:
handle
in classExceptionHandlerWrapper
-
handleSuppressedException
protected void handleSuppressedException(FacesContext context, Throwable suppressedException)
Subclasses can override this method to have finer grained control over what must happen when the given exception has been suppressed.- Parameters:
context
- The involved faces context.suppressedException
- The suppressed exception.
-
-