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 String |
PACKAGE_FILTERS
Deprecated.
|
static String |
PACKAGES
Configuration key used to lookup the list of packages to scan for auto handlers.
|
static String |
URL_FILTERS
Deprecated.
|
| Constructor and Description |
|---|
DelegatingExceptionHandler() |
| Modifier and Type | Method and Description |
|---|---|
protected Set<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, handle, unwrap@Deprecated public static final String URL_FILTERS
@Deprecated public static final String PACKAGE_FILTERS
public static final String PACKAGES
public void init(Configuration configuration) throws Exception
ResolverUtil to find implementations of AutoExceptionHandler. Each
implementation found is then examined and cached by calling
DefaultExceptionHandler.addHandler(Class)init in interface ConfigurableComponentinit in class DefaultExceptionHandlerconfiguration - the Configuration for this Stripes applicationException - thrown if any of the discovered handler types cannot be safely
instantiatedprotected Set<Class<? extends AutoExceptionHandler>> findClasses()
ResolverUtil class.© Copyright 2005-2006, Stripes Development Team.