public class ExceptionFilter extends Object implements Filter
A filter for handling exceptions that may occour during the action's execution. The filter catchs all the exceptions throwed by the action and call the method handleException. The default implementation of the handleException method put in the action's output the following attributes:
"message" - The message of the Exception (e.getMessage())
"stacktrace" - The Exception's stacktrace (e.getStackTrace())
"stackheader" - The Exception's first stacktrace (e.getStackTrace()[0])
Also, the method e.printStackTrace() is called if the attribute "trace" is setted to true.
After that, the filter return "exception" as the action's result. A Consequence must be mapped for this result.
The behavior of this filter can be changed by extending it's class and overriding the handleException method.
| Modifier and Type | Field and Description |
|---|---|
static String |
EXCEPTION
Attribute EXCEPTION of ExceptionFilter.
|
static String |
EXCEPTION_KEY
Attribute EXCEPTION_KEY of ExceptionFilter.
|
static String |
MESSAGE_KEY
Attribute MESSAGE_KEY of ExceptionFilter.
|
static String |
STACK_HEADER_KEY
Attribute STACK_HEADER_KEY of ExceptionFilter.
|
static String |
STACK_TRACE_KEY
Attribute STACK_TRACE_KEY of ExceptionFilter.
|
| Constructor and Description |
|---|
ExceptionFilter()
Default constructor.
|
ExceptionFilter(boolean trace)
Parametric constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Gives a chance to the filter to deallocalte any resources before it is destroyed.
|
String |
filter(InvocationChain chain)
Execute the chain and cacth any exception that occours, delegating to the
handleException() method the resposability to handle the exception
throwed by the chain's execution.
|
protected static Throwable |
getRootCause(Throwable throwable)
Gets the root cause of exception.
|
protected String |
handleException(Action a,
Throwable throwable)
Handle the exception, putting in the action's output the message of the
exception, all the StackTrace elements and the first StackTrace element.
|
protected String |
prepareForHtml(String s) |
protected String |
prepareStackTrace(StackTraceElement[] stacktrace) |
protected String |
prepareStackTrace(String[] stacktrace) |
public static String MESSAGE_KEY
public static String EXCEPTION_KEY
public static String STACK_TRACE_KEY
public static String STACK_HEADER_KEY
public static String EXCEPTION
public ExceptionFilter()
public ExceptionFilter(boolean trace)
trace - booleanpublic String filter(InvocationChain chain) throws Exception
protected static Throwable getRootCause(Throwable throwable)
throwable - Throwableprotected String handleException(Action a, Throwable throwable)
a - the action that has throwed the exception.throwable - the exception throwed by the action's execution.protected String prepareStackTrace(StackTraceElement[] stacktrace)
Copyright © 2015. All Rights Reserved.