|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectch.elca.el4j.services.exceptionhandler.AbstractExceptionHandlerInterceptor
ch.elca.el4j.services.exceptionhandler.ContextExceptionHandlerInterceptor
public class ContextExceptionHandlerInterceptor
This class allows to handle exceptions centrally. Realized as an interceptor, it can be added to an arbitrary bean using a proxy. The handler supports different contexts which allows to handle a particular exception in different fashions, depending on the current context.
This class is configured with different policies, one for each context.
A policy is an <context,
pair.
ExceptionConfiguration
>
Important: The context is stored in a ThreadLocal
, allowing to use this class in multi threading
environments. Since it's considered cumbersome to set the context before
each invocation it isn't reset. The programmer is responsible to set the
context appropriately.
Don't use this interceptor directly. Instead use the ContextExceptionHandlerFactoryBean
.
Example: Let's assume the exception configurations are initialized properly.
<bean id="contextExceptionHandlerInterceptor" class="ch.elca.el4j.services.exceptionhandler.ContextExceptionHandlerInterceptor"> <property name="policies"> <map> <entry key="gui"> <list> <ref local="guiExceptionConfiguration"/> </list> </entry> <entry key="batch"> <list> <ref local="batchExceptionConfiguration"/> </list> </entry> </map> </property> </bean>And the Java fragment:
ContextExceptionHandlerInterceptor.setContext("gui"); foo(); // an exception is handled by the gui policy ContextExceptionHandlerInterceptor.setContext("batch"); foo(); // an exception is handled by the batch policy foo(); // an exception is handled by the batch policy
ContextExceptionHandlerFactoryBean
Field Summary |
---|
Fields inherited from class ch.elca.el4j.services.exceptionhandler.AbstractExceptionHandlerInterceptor |
---|
s_retries |
Constructor Summary | |
---|---|
ContextExceptionHandlerInterceptor()
Default constructor. |
Method Summary | |
---|---|
protected Object |
handleException(Throwable t,
org.aopalliance.intercept.MethodInvocation invocation)
Handles the given exception that was thrown in the given method invocation's execution. |
static Object |
setContext(Object context)
Sets the current thread's context. |
void |
setPolicies(Map policies)
Sets the policies. |
Methods inherited from class ch.elca.el4j.services.exceptionhandler.AbstractExceptionHandlerInterceptor |
---|
doHandleException, doInvoke, getRetries, handleInterfaceExceptions, invoke, setDefaultBehaviourConsume, setForwardSignatureExceptions, setHandleRTSignatureExceptions, setRetries |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ContextExceptionHandlerInterceptor()
Method Detail |
---|
public static Object setContext(Object context)
context
- The context to set.
public void setPolicies(Map policies)
policies
- The policies to set.protected Object handleException(Throwable t, org.aopalliance.intercept.MethodInvocation invocation) throws Throwable
handleException
in class AbstractExceptionHandlerInterceptor
t
- The exception to handle.invocation
- The method invocation that threw the exception.
RetryException
- Signals that the complete invocation has to be rerun.
Throwable
- Any exception thrown by a exception handler.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |