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.
Interceptor parameters:
- disabledChangeResult
- If true, does not change result and rethrows exception without logging it. Defaults to false.
- disabledErrorMessage
- If true, does not write error message to user. Defaults to false.
- applicationErrorMessage
- Error message to write for application rejection with the exception object replacing '${e}'. Defaults to "The action was rejected: ${e}".
- systemFailureErrorMessage
- Error message to write for system failures'. Defaults to "A system failure occurred, which was logged".
- 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckLogger(com.opensymphony.xwork2.ActionInvocation invocation) Ensures the logger for this instance has been initialised.Returns error message for application exceptions.booleanReturns whether changing result and logging when an exception is caught is disabled.booleanReturns whether writing error message is disabled.protected org.apache.logging.log4j.LoggerReturns logger to be used for this instance;Returns error message for system failure exceptions.intercept(com.opensymphony.xwork2.ActionInvocation invocation) protected booleanReturns whether exception indicates a system failure, rather than rejection due to business rules.protected voidlogException(com.opensymphony.xwork2.ActionInvocation invocation, boolean isSystemFailure, Exception e) Called to log exception before diverting to new result.protected org.apache.logging.log4j.LoggermakeLogger(com.opensymphony.xwork2.ActionInvocation invocation) Returns a new logger to be used by this interceptor instance.voidsetApplicationErrorMessage(String applicationErrorMessage) voidsetDisabledChangeResult(boolean disabledChangeResult) voidsetDisabledErrorMessage(boolean disabledErrorMessage) voidsetSystemFailureErrorMessage(String systemFailureErrorMessage) Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor
intercept, shouldIntercept, shouldInterceptMethods inherited from class org.apache.struts2.interceptor.AbstractInterceptor
destroy, init, setDisabledMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
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
- Specified by:
interceptin interfacecom.opensymphony.xwork2.interceptor.Interceptor- Specified by:
interceptin classcom.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
Returns error message for application exceptions. May contain '${e}' as substitution field for exception's message. Defaults to "The action was rejected: ${e}". -
setApplicationErrorMessage
-
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
-