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

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

public class SystemExceptionHandler
extends DefaultExceptionHandler

Exception process handler exclusively for SystemException.

When the system exception occurs, outputs the log and navigates to error screen.
If the system exeception occurs while the action is being executed, error information is output and navigated to the system error screen which is defined in the action mapping.
To use this function, specify the SystemExceptionHandler as the class of global exception or action level exception handler in Struts configuration file (struts-config.xml).
When the global exception and action level exception are in conflict, action level exception is given the priority over the global exception as per the Struts specifications.
When the replacement string is specified in SystemException, it is embedded in the error message.

Log level specification Following are the 6 types of log levels that can be specified in property logLevel.

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

*When it is not specified, default is error.
*At the time of specifying logLevel, specify ExceptionConfigEx in the className attribute of <exception> tag.

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

 <struts-config>
   ...
   <global-exceptions>
     <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"/>
       <set-property property="logLevel" value="fatal"/>
     </exception>
   </global-exceptions>
   ...
 <struts-config>
 

Action level exception handling configuration example Provide the following description in 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.fw.exception.SystemException"
                className="jp.terasoluna.fw.web.struts.action.ExceptionConfigEx"
                handler="jp.terasoluna.fw.web.struts.action.SystemExceptionHandler"
                path="/sub-forward.do">
       <set-property property="module" value="/sub"/>
     </exception>
     <forward name="success" path="/system-error"/>
   </action>
   ...
 <struts-config>
 

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

Occurred exception instance is stored in request with the PageContext.EXCEPTION key. Thus, in JSP, it can be fetched as the implicit exception object.

See Also:
SystemException, ExceptionConfigEx, DefaultExceptionHandler, PageContext

Field Summary
private static org.apache.commons.logging.Log log
          Log class.
 
Fields inherited from class jp.terasoluna.fw.web.struts.action.DefaultExceptionHandler
LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_FATAL, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_WARN
 
Constructor Summary
SystemExceptionHandler()
           
 
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)
          Entry point of SystemException exception handler.
private  java.lang.String getErrorMessage(javax.servlet.http.HttpServletRequest req, jp.terasoluna.fw.exception.SystemException se, org.apache.struts.util.MessageResources resources)
          Fetches the error mesage by specifying the message key for message resource.
protected  org.apache.commons.logging.Log getLogger()
          Fetches the logger of handler.
 
Methods inherited from class jp.terasoluna.fw.web.struts.action.DefaultExceptionHandler
logException, logException, logException, logException
 
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

log

private static org.apache.commons.logging.Log log
Log class.

Constructor Detail

SystemExceptionHandler

public SystemExceptionHandler()
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
Entry point of "SystemException" exception handler.

Overrides:
execute in class DefaultExceptionHandler
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:
DefaultExceptionHandler.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 )

getErrorMessage

private java.lang.String getErrorMessage(javax.servlet.http.HttpServletRequest req,
                                         jp.terasoluna.fw.exception.SystemException se,
                                         org.apache.struts.util.MessageResources resources)
Fetches error message by specifying the message key for the message resource.

Parameters:
req - HTTP request
se - SystemException
resources - Message resource
Returns:
Error message

getLogger

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

Overrides:
getLogger in class DefaultExceptionHandler
Returns:
Logger Logger