net.sourceforge.stripes.exception
Class DelegatingExceptionHandler

java.lang.Object
  extended by net.sourceforge.stripes.exception.DefaultExceptionHandler
      extended by net.sourceforge.stripes.exception.DelegatingExceptionHandler
All Implemented Interfaces:
ConfigurableComponent, ExceptionHandler

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).

Since:
Stripes 1.3
Author:
Jeppe Cramon, Tim Fennell

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

URL_FILTERS

@Deprecated
public static final String URL_FILTERS
Deprecated. 
Configuration key used to lookup the URL filters used when scanning for handlers.

See Also:
Constant Field Values

PACKAGE_FILTERS

@Deprecated
public static final String PACKAGE_FILTERS
Deprecated. 
Configuration key used to lookup the package filters used when scanning for handlers.

See Also:
Constant Field Values

PACKAGES

public static final String PACKAGES
Configuration key used to lookup the list of packages to scan for auto handlers.

Since:
Stripes 1.5
See Also:
Constant Field Values
Constructor Detail

DelegatingExceptionHandler

public DelegatingExceptionHandler()
Method Detail

init

public void init(Configuration configuration)
          throws Exception
Looks up the filters as defined in the Configuration and then invokes the ResolverUtil to find implementations of AutoExceptionHandler. Each implementation found is then examined and cached by calling DefaultExceptionHandler.addHandler(Class)

Specified by:
init in interface ConfigurableComponent
Overrides:
init in class DefaultExceptionHandler
Parameters:
configuration - the Configuration for this Stripes application
Throws:
Exception - thrown if any of the discovered handler types cannot be safely instantiated

findClasses

protected Set<Class<? extends AutoExceptionHandler>> findClasses()
Helper method to find implementations of AutoExceptionHandler in the packages specified in Configuration using the ResolverUtil class.

Returns:
a set of Class objects that represent subclasses of AutoExceptionHandler


? Copyright 2005-2006, Stripes Development Team.