|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.stripes.exception.DefaultExceptionHandler
net.sourceforge.stripes.exception.DelegatingExceptionHandler
public class DelegatingExceptionHandler
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).
Nested Class Summary |
---|
Nested classes/interfaces inherited from class net.sourceforge.stripes.exception.DefaultExceptionHandler |
---|
DefaultExceptionHandler.HandlerProxy |
Field Summary | |
---|---|
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 Summary | |
---|---|
DelegatingExceptionHandler()
|
Method Summary | |
---|---|
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. |
Methods inherited from class net.sourceforge.stripes.exception.DefaultExceptionHandler |
---|
addHandler, addHandler, getConfiguration, getFileUploadExceededExceptionPath, handle, handle, unwrap |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@Deprecated public static final String URL_FILTERS
@Deprecated public static final String PACKAGE_FILTERS
public static final String PACKAGES
Constructor Detail |
---|
public DelegatingExceptionHandler()
Method Detail |
---|
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 ConfigurableComponent
init
in class DefaultExceptionHandler
configuration
- the Configuration for this Stripes application
Exception
- thrown if any of the discovered handler types cannot be safely
instantiatedprotected Set<Class<? extends AutoExceptionHandler>> findClasses()
ResolverUtil
class.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |