public class DelegatingExceptionHandler extends DefaultExceptionHandler
An alternative implementation of ExceptionHandler
that discovers and automatically
configures individual AutoExceptionHandler
classes to handle specific types of
exceptions. This implementation is most useful when ActionBeans may produce many different
types of exceptions and it is desirable to separate exception handling logic for different
groups or classes of exceptions. Using this approach multiple AutoExceptionHandlers can be
configured simultaneously but do not have to be co-located.
Searches for implementations of AutoExceptionHandler using the same mechanism as is used to discover ActionBean implementations - a search of the classpath for classes that implement the interface. The search requires one parameter, DelegatingExceptionHandler.Packages, which should contain a comma separated list of root packages to search for AutoExceptionHandler classes. If this parameter is not specified, the DelegatingExceptionHandler will use the configuration parameter that is used for discovering ActionBean instances (ActionResolver.Packages). The configuration parameter is usually specified as an init-param for the Stripes Filter, e.g.:
<init-param> <param-name>DelegatingExceptionHandler.Packages</param-name> <param-value>com.myco.web,com.myco.shared</param-value> </init-param>
When the DefaultExceptionHandler.handle(Throwable, HttpServletRequest, HttpServletResponse)
is invoked
the set of AutoExceptionHandlers is examined to find the handler with the most specific
signature that is capable of handling the exception. If no handler is available to handle the
exception type supplied then the exception will be rethrown; if the exception is not a
ServletException it will be wrapped in a StripesServletException before being rethrown.
If it is desirable to ensure that all exceptions are handled simply create an
AutoExceptionHandler that takes with Exception
(preferable) or
Throwable
(this may catch unhandlable errors like OutOfMemoryError).
DefaultExceptionHandler.HandlerProxy
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PACKAGE_FILTERS
Deprecated.
|
static java.lang.String |
PACKAGES
Configuration key used to lookup the list of packages to scan for auto handlers.
|
static java.lang.String |
URL_FILTERS
Deprecated.
|
Constructor and Description |
---|
DelegatingExceptionHandler() |
Modifier and Type | Method and Description |
---|---|
protected java.util.Set<java.lang.Class<? extends AutoExceptionHandler>> |
findClasses()
Helper method to find implementations of AutoExceptionHandler in the packages specified in
Configuration using the
ResolverUtil class. |
void |
init(Configuration configuration)
Looks up the filters as defined in the Configuration and then invokes the
ResolverUtil to find implementations of AutoExceptionHandler. |
addHandler, addHandler, getConfiguration, getFileUploadExceededExceptionPath, handle, handle, unwrap
@Deprecated public static final java.lang.String URL_FILTERS
@Deprecated public static final java.lang.String PACKAGE_FILTERS
public static final java.lang.String PACKAGES
public void init(Configuration configuration) throws java.lang.Exception
ResolverUtil
to find implementations of AutoExceptionHandler. Each
implementation found is then examined and cached by calling
DefaultExceptionHandler.addHandler(Class)
init
in interface ConfigurableComponent
init
in class DefaultExceptionHandler
configuration
- the Configuration for this Stripes applicationjava.lang.Exception
- thrown if any of the discovered handler types cannot be safely
instantiatedprotected java.util.Set<java.lang.Class<? extends AutoExceptionHandler>> findClasses()
ResolverUtil
class.? Copyright 2005-2006, Stripes Development Team.