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.
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 the FullAjaxExceptionHandler
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>
ExceptionSuppressorFactory
Modifier and Type | Field and Description |
---|---|
static String |
PARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
The context parameter name to specify exception types to suppress by
ExceptionSuppressor . |
Modifier | Constructor and 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.
|
Modifier and Type | Method and Description |
---|---|
static Class<? extends Throwable>[] |
getExceptionTypesToSuppress(ServletContext context)
Get the exception types to suppress.
|
void |
handle()
Inspect all
ExceptionHandlerWrapper.getUnhandledExceptionQueuedEvents() if any of them is caused by one of the exception types
listed in PARAM_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.
|
getHandledExceptionQueuedEvent, getHandledExceptionQueuedEvents, getRootCause, getUnhandledExceptionQueuedEvents, getWrapped, isListenerForSource, processEvent
public static final String PARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
ExceptionSuppressor
. 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.public ExceptionSuppressor(ExceptionHandler wrapped)
wrapped
- The wrapped exception handler.@SafeVarargs protected ExceptionSuppressor(ExceptionHandler wrapped, Class<? extends Throwable>... exceptionTypesToSuppress)
wrapped
- The wrapped exception handler.exceptionTypesToSuppress
- Array of exception types to suppress.public static Class<? extends Throwable>[] getExceptionTypesToSuppress(ServletContext context)
context
- The involved servlet context.public void handle()
ExceptionHandlerWrapper.getUnhandledExceptionQueuedEvents()
if any of them is caused by one of the exception types
listed in PARAM_NAME_EXCEPTION_TYPES_TO_SUPPRESS
.
If so, then drain the ExceptionHandlerWrapper.getUnhandledExceptionQueuedEvents()
, and refresh the current URL with query string.handle
in class ExceptionHandlerWrapper
protected void handleSuppressedException(FacesContext context, Throwable suppressedException)
context
- The involved faces context.suppressedException
- The suppressed exception.Copyright © 2012–2021 OmniFaces. All rights reserved.