org.mentawai.filter
Class ExceptionFilter

java.lang.Object
  extended by org.mentawai.filter.ExceptionFilter
All Implemented Interfaces:
Filter

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.

Author:
Rubem Azenha (rubem.azenha@gmail.com)

Field Summary
static String EXCEPTION
           
static String EXCEPTION_KEY
           
static String MESSAGE_KEY
           
static String STACK_HEADER_KEY
           
static String STACK_TRACE_KEY
           
 
Constructor Summary
ExceptionFilter()
           
ExceptionFilter(boolean trace)
           
 
Method Summary
 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  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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_KEY

public static String MESSAGE_KEY

EXCEPTION_KEY

public static String EXCEPTION_KEY

STACK_TRACE_KEY

public static String STACK_TRACE_KEY

STACK_HEADER_KEY

public static String STACK_HEADER_KEY

EXCEPTION

public static String EXCEPTION
Constructor Detail

ExceptionFilter

public ExceptionFilter()

ExceptionFilter

public ExceptionFilter(boolean trace)
Method Detail

filter

public String filter(InvocationChain chain)
              throws Exception
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.

Specified by:
filter in interface Filter
Parameters:
chain - The InvocationChain for the action this filter is being applied to.
Returns:
the result of the action's execution.
Throws:
Exception

handleException

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.
This method can be overrided to change the behavior of the ExceptionFilter.

Parameters:
a - the action that has throwed the exception.
throwable - the exception throwed by the action's execution.
Returns:
the result of the action's execution.

prepareStackTrace

protected String prepareStackTrace(String[] stacktrace)

prepareStackTrace

protected String prepareStackTrace(StackTraceElement[] stacktrace)

prepareForHtml

protected String prepareForHtml(String s)

destroy

public void destroy()
Description copied from interface: Filter
Gives a chance to the filter to deallocalte any resources before it is destroyed. This is called when the web application is stopped, in other words, this has nothing to do with garbage collection.

Specified by:
destroy in interface Filter


Copyright © 2011. All Rights Reserved.