org.mentawai.filter
Class ExceptionFilter

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

public class ExceptionFilter
extends java.lang.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 java.lang.String EXCEPTION
           
static java.lang.String EXCEPTION_KEY
           
static java.lang.String MESSAGE_KEY
           
static java.lang.String STACK_HEADER_KEY
           
static java.lang.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.
 java.lang.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  java.lang.String handleException(Action a, java.lang.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  java.lang.String prepareForHtml(java.lang.String s)
           
protected  java.lang.String prepareStackTrace(java.lang.StackTraceElement[] 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 java.lang.String MESSAGE_KEY

EXCEPTION_KEY

public static java.lang.String EXCEPTION_KEY

STACK_TRACE_KEY

public static java.lang.String STACK_TRACE_KEY

STACK_HEADER_KEY

public static java.lang.String STACK_HEADER_KEY

EXCEPTION

public static java.lang.String EXCEPTION
Constructor Detail

ExceptionFilter

public ExceptionFilter()

ExceptionFilter

public ExceptionFilter(boolean trace)
Method Detail

filter

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

handleException

protected java.lang.String handleException(Action a,
                                           java.lang.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 java.lang.String prepareStackTrace(java.lang.StackTraceElement[] stacktrace)

prepareForHtml

protected java.lang.String prepareForHtml(java.lang.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 © 2005 Mentawai Team. All Rights Reserved.