jp.terasoluna.fw.web.struts.action
Class DefaultExceptionHandler

java.lang.Object
  extended by org.apache.struts.action.ExceptionHandler
      extended by jp.terasoluna.fw.web.struts.action.DefaultExceptionHandler
Direct Known Subclasses:
SystemExceptionHandler

public class DefaultExceptionHandler
extends org.apache.struts.action.ExceptionHandler

General exception handler which outputs the log at a specified log level.

When exception occurs, it outputs the log and navigates to the error screen.

To use this function, specify DefaultExceptionHandler as a class of global exception or action level exception handler.

Specification of log level Following are the 6 types of log levels which can be specified in logLevel property.

  1. trace
  2. debug
  3. info
  4. warn
  5. error
  6. fatal

*When no log level is specified, error is set as default.
*At the time of specifying the logLevel, specify ExceptionConfigEx in the "className" attribute of <exception> tag.

Configuration example of global exception handling Provide the following description in the Struts configuration file(struts-config.xml).

 <struts-config>
   ...
   <global-exceptions>
     <exception key="some.key"
                path="/system-error"
                type="org.springframework.dao.DataAccessException"
                className="jp.terasoluna.fw.web.struts.action.ExceptionConfigEx"
                handler="jp.terasoluna.fw.web.struts.action.DefaultExceptionHandler">
       <set-property property="module" value="/exp"/>
     </exception>
     <exception key="some.key"
                path="/system-error"
                type="jp.terasoluna.fw.exception.SystemException"
                className="jp.terasoluna.fw.web.struts.action.ExceptionConfigEx"
                handler="jp.terasoluna.fw.web.struts.action.SystemExceptionHandler">
       <set-property property="module" value="/exp"/>
     </exception>
     <exception key="some.key"
                path="/system-error"
                type="java.lang.Exception"
                className="jp.terasoluna.fw.web.struts.action.ExceptionConfigEx"
                handler="jp.terasoluna.fw.web.struts.action.DefaultExceptionHandler">
       <set-property property="module" value="/exp"/>
       <set-property property="logLevel" value="fatal"/>
     </exception>
   </global-exceptions>
   ...
 <struts-config>
 

Configuration example of action level exception handling Provide the following description in the Struts configuration file (struts-config.xml)

 <struts-config>
   ...
   <action path="/start"
           type="jp.terasoluna.sample.xxx.SampleAction"
           name="_sampleForm"
           scope="session">
     <exception key="some.key"
                type="jp.terasoluna.sample.xxx.exception.XxxException"
                className="jp.terasoluna.fw.web.struts.action.ExceptionConfigEx"
                handler="jp.terasoluna.fw.web.struts.action.DefaultExceptionHandler"
                path="/sub-forward.do">
       <set-property property="module" value="/sub"/>
     </exception>
     <forward name="success" path="/business-error"/>
   </action>
   ...
 <struts-config>
 

When the transition path is not specified in the "path" attribute of <exception> element, "input" attribute of action mapping is considered as a forward resource.

Exception instance which is occurred, is stored in the request under Globals.EXCEPTION_KEY key.

See Also:
ExceptionHandler, ExceptionConfigEx, SystemExceptionHandler, Globals

Field Summary
protected static java.lang.String LOG_LEVEL_DEBUG
          Log level(DEBUG)
protected static java.lang.String LOG_LEVEL_ERROR
          Log level(ERROR)
protected static java.lang.String LOG_LEVEL_FATAL
          Log level(FATAL)
protected static java.lang.String LOG_LEVEL_INFO
          Log level(INFO)
protected static java.lang.String LOG_LEVEL_TRACE
          Log level(TRACE)
protected static java.lang.String LOG_LEVEL_WARN
          Log level(WARN)
private static org.apache.commons.logging.Log logger
          Log instance
private static org.apache.struts.util.MessageResources messages
          Message resource
 
Constructor Summary
DefaultExceptionHandler()
           
 
Method Summary
 org.apache.struts.action.ActionForward execute(java.lang.Exception ex, org.apache.struts.config.ExceptionConfig eConfig, org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm formInstance, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           Performs exception handling.
protected  org.apache.commons.logging.Log getLogger()
          Fetches logger of handler.
protected  void logException(java.lang.Exception e)
          Outputs the log exception.
protected  void logException(java.lang.Exception e, java.lang.String logLevel)
          Outputs the log exception.
protected  void logException(java.lang.Exception e, java.lang.String logLevel, java.lang.String message)
          Outputs the log exception.
protected  void logException(java.lang.String logLevel, java.lang.String message)
          Outputs the log exception.
 
Methods inherited from class org.apache.struts.action.ExceptionHandler
storeException, storeException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final org.apache.commons.logging.Log logger
Log instance


LOG_LEVEL_TRACE

protected static final java.lang.String LOG_LEVEL_TRACE
Log level(TRACE)

See Also:
Constant Field Values

LOG_LEVEL_DEBUG

protected static final java.lang.String LOG_LEVEL_DEBUG
Log level(DEBUG)

See Also:
Constant Field Values

LOG_LEVEL_INFO

protected static final java.lang.String LOG_LEVEL_INFO
Log level(INFO)

See Also:
Constant Field Values

LOG_LEVEL_WARN

protected static final java.lang.String LOG_LEVEL_WARN
Log level(WARN)

See Also:
Constant Field Values

LOG_LEVEL_ERROR

protected static final java.lang.String LOG_LEVEL_ERROR
Log level(ERROR)

See Also:
Constant Field Values

LOG_LEVEL_FATAL

protected static final java.lang.String LOG_LEVEL_FATAL
Log level(FATAL)

See Also:
Constant Field Values

messages

private static org.apache.struts.util.MessageResources messages
Message resource

Constructor Detail

DefaultExceptionHandler

public DefaultExceptionHandler()
Method Detail

execute

public org.apache.struts.action.ActionForward execute(java.lang.Exception ex,
                                                      org.apache.struts.config.ExceptionConfig eConfig,
                                                      org.apache.struts.action.ActionMapping mapping,
                                                      org.apache.struts.action.ActionForm formInstance,
                                                      javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response)
                                               throws javax.servlet.ServletException

Performs exception handling.

Overrides:
execute in class org.apache.struts.action.ExceptionHandler
Parameters:
ex - Exception
eConfig - Exception configuration
mapping - Action mapping
formInstance - Action form
request - HTTP request
response - HTTP response
Returns:
Transition information
Throws:
javax.servlet.ServletException - Servlet exception
See Also:
ExceptionHandler.execute( java.lang.Exception, org.apache.struts.config.ExceptionConfig, org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse )

logException

protected void logException(java.lang.Exception e,
                            java.lang.String logLevel)
Outputs the log exception.

Parameters:
e - Exception which is occurred
logLevel - Log level

logException

protected void logException(java.lang.String logLevel,
                            java.lang.String message)
Outputs the log exception.

Parameters:
logLevel - Log level
message - Message to be output

logException

protected void logException(java.lang.Exception e,
                            java.lang.String logLevel,
                            java.lang.String message)
Outputs the log exception.

Parameters:
e - Exception which is occurred
logLevel - Log level
message - Message to be output

logException

protected void logException(java.lang.Exception e)
Outputs the log exception.

*It is not output here

Overrides:
logException in class org.apache.struts.action.ExceptionHandler
Parameters:
e - Exception which is occurred
See Also:
ExceptionHandler.logException( java.lang.Exception)

getLogger

protected org.apache.commons.logging.Log getLogger()
Fetches the logger of handler.

For implementing own exception handler by extending this class, override this method in subclass and return the logger.

Returns:
Logger