Class UnhandledExceptionWriterInterceptor

java.lang.Object
org.apache.struts2.interceptor.AbstractInterceptor
com.opensymphony.xwork2.interceptor.AbstractInterceptor
name.matthewgreet.strutscommons.interceptor.UnhandledExceptionWriterInterceptor
All Implemented Interfaces:
com.opensymphony.xwork2.interceptor.ConditionalInterceptor, com.opensymphony.xwork2.interceptor.Interceptor, Serializable, org.apache.struts2.interceptor.ConditionalInterceptor, org.apache.struts2.interceptor.Interceptor

public class UnhandledExceptionWriterInterceptor extends com.opensymphony.xwork2.interceptor.AbstractInterceptor
Detects an exception not handled by the form driven action, logs it, changes the result to 'input' or 'error' as needed and, if it implements ValidationAware, writes an action error for the user. Checked exceptions are regarded as an application rejection and use the 'input' result. Unchecked exceptions are regarded as system failures and use the 'error' result.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor

    com.opensymphony.xwork2.interceptor.ConditionalInterceptor.LegacyAdapter
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    checkLogger(com.opensymphony.xwork2.ActionInvocation invocation)
    Ensures the logger for this instance has been initialised.
    Returns error message for application exceptions.
    boolean
    Returns whether changing result and logging when an exception is caught is disabled.
    boolean
    Returns whether writing error message is disabled.
    protected org.apache.logging.log4j.Logger
    Returns logger to be used for this instance;
    Returns error message for system failure exceptions.
    intercept(com.opensymphony.xwork2.ActionInvocation invocation)
     
    protected boolean
    Returns whether exception indicates a system failure, rather than rejection due to business rules.
    protected void
    logException(com.opensymphony.xwork2.ActionInvocation invocation, boolean isSystemFailure, Exception e)
    Called to log exception before diverting to new result.
    protected org.apache.logging.log4j.Logger
    makeLogger(com.opensymphony.xwork2.ActionInvocation invocation)
    Returns a new logger to be used by this interceptor instance.
    void
    setApplicationErrorMessage(String applicationErrorMessage)
     
    void
    setDisabledChangeResult(boolean disabledChangeResult)
     
    void
    setDisabledErrorMessage(boolean disabledErrorMessage)
     
    void
    setSystemFailureErrorMessage(String systemFailureErrorMessage)
     

    Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor

    intercept, shouldIntercept, shouldIntercept

    Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptor

    destroy, init, setDisabled

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.struts2.interceptor.Interceptor

    destroy, init
  • Constructor Details

    • UnhandledExceptionWriterInterceptor

      public UnhandledExceptionWriterInterceptor()
  • Method Details

    • checkLogger

      protected void checkLogger(com.opensymphony.xwork2.ActionInvocation invocation)
      Ensures the logger for this instance has been initialised.
    • getLogger

      protected org.apache.logging.log4j.Logger getLogger()
      Returns logger to be used for this instance;
    • isSystemFailureException

      protected boolean isSystemFailureException(Exception e)
      Returns whether exception indicates a system failure, rather than rejection due to business rules.
    • logException

      protected void logException(com.opensymphony.xwork2.ActionInvocation invocation, boolean isSystemFailure, Exception e)
      Called to log exception before diverting to new result.
    • makeLogger

      protected org.apache.logging.log4j.Logger makeLogger(com.opensymphony.xwork2.ActionInvocation invocation)
      Returns a new logger to be used by this interceptor instance.
    • intercept

      public String intercept(com.opensymphony.xwork2.ActionInvocation invocation) throws Exception
      Specified by:
      intercept in interface com.opensymphony.xwork2.interceptor.Interceptor
      Specified by:
      intercept in class com.opensymphony.xwork2.interceptor.AbstractInterceptor
      Throws:
      Exception
    • getDisabledChangeResult

      public boolean getDisabledChangeResult()
      Returns whether changing result and logging when an exception is caught is disabled. Defaults to false;
    • setDisabledChangeResult

      public void setDisabledChangeResult(boolean disabledChangeResult)
    • getDisabledErrorMessage

      public boolean getDisabledErrorMessage()
      Returns whether writing error message is disabled. Defaults to false.
    • setDisabledErrorMessage

      public void setDisabledErrorMessage(boolean disabledErrorMessage)
    • getApplicationErrorMessage

      public String getApplicationErrorMessage()
      Returns error message for application exceptions. May contain '${e}' as substitution field for exception's message. Defaults to "The action was rejected: ${e}".
    • setApplicationErrorMessage

      public void setApplicationErrorMessage(String applicationErrorMessage)
    • getSystemFailureErrorMessage

      public String getSystemFailureErrorMessage()
      Returns error message for system failure exceptions. May contain '${e}' as substitution field for exception's message. Defaults to "A system failure occurred, which was logged".
    • setSystemFailureErrorMessage

      public void setSystemFailureErrorMessage(String systemFailureErrorMessage)