类 AbstractHandlerExceptionHandler
- 所有已实现的接口:
cn.taketoday.core.Ordered,HandlerExceptionHandler
- 直接已知子类:
AbstractActionMappingMethodExceptionHandler,ResponseStatusExceptionHandler,SimpleHandlerExceptionHandler,SimpleMappingExceptionHandler
HandlerExceptionHandler implementations.
Supports mapped handlers and
handler classes that the handler
should be applied to and implements the Ordered interface.
- 从以下版本开始:
- 4.0 2022/3/2 17:59
- 作者:
- Arjen Poutsma, Juergen Hoeller, Sam Brannen, Harry Yang
-
字段概要
字段修饰符和类型字段说明protected final cn.taketoday.logging.LoggerLogger available to subclasses.private Class<?>[]private Set<?>private booleanprivate cn.taketoday.logging.Logger从类继承的字段 cn.taketoday.core.OrderedSupport
order从接口继承的字段 cn.taketoday.web.HandlerExceptionHandler
BEAN_NAME, NONE_RETURN_VALUE从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidaddMappedHandlerClass(Class<?> mappedHandlerClass) Add a mapped handler class.protected StringbuildLogMessage(Throwable ex, RequestContext request) Build a log message for the given exception, occurred during processing the given request.protected Class<?>[]Return theconfiguredmapped handler classes.handleException(RequestContext context, Throwable ex, Object handler) Check whether this handler is supposed to apply (i.e. if the supplied handler matches any of the configured handlers or handler classes), and then delegate to thehandleInternal(cn.taketoday.web.RequestContext, java.lang.Object, java.lang.Throwable)template method.protected abstract ObjecthandleInternal(RequestContext request, Object handler, Throwable ex) Actually handle the given exception that got thrown during handler execution, returning aresultthat represents a specific error page if appropriate.protected booleanWhether there are any handler mappings registered viasetMappedHandlers(Set)orsetMappedHandlerClasses(Class[]).protected voidlogException(Throwable ex, RequestContext request) Log the given exception at warn level, provided that warn logging has been activated through the"warnLogCategory"property.protected voidlogResultedInException(Throwable target, Throwable handlerException) record log when an exception occurred in this exception handlerprotected voidprepareResponse(Throwable ex, RequestContext response) Prepare the response for the exceptional case.protected voidpreventCaching(RequestContext response) Prevents the response from being cached, through setting corresponding HTTPCache-Control: no-storeheader.voidsetMappedHandlerClasses(Class<?>... mappedHandlerClasses) Specify the set of classes that this exception handler should apply to.voidsetMappedHandlers(Set<?> mappedHandlers) Specify the set of handlers that this exception handler should apply to.voidsetPreventResponseCaching(boolean preventResponseCaching) Specify whether to prevent HTTP response caching for any view resolved by this exception handler.voidsetWarnLogCategory(String loggerName) Set the log category for warn logging.protected booleanshouldApplyTo(RequestContext request, Object handler) Check whether this handler is supposed to apply to the given handler.从类继承的方法 cn.taketoday.core.OrderedSupport
getOrder, setOrder
-
字段详细资料
-
logger
protected final cn.taketoday.logging.Logger loggerLogger available to subclasses. -
mappedHandlers
-
mappedHandlerClasses
-
warnLogger
@Nullable private cn.taketoday.logging.Logger warnLogger -
preventResponseCaching
private boolean preventResponseCaching
-
-
构造器详细资料
-
AbstractHandlerExceptionHandler
public AbstractHandlerExceptionHandler()
-
-
方法详细资料
-
setMappedHandlers
Specify the set of handlers that this exception handler should apply to.The exception mappings and the default error view will only apply to the specified handlers.
If no handlers or handler classes are set, the exception mappings and the default error view will apply to all handlers. This means that a specified default error view will be used as a fallback for all exceptions; any further HandlerExceptionHandlers in the chain will be ignored in this case.
-
setMappedHandlerClasses
Specify the set of classes that this exception handler should apply to.The exception mappings and the default error view will only apply to handlers of the specified types; the specified types may be interfaces or superclasses of handlers as well.
If no handlers or handler classes are set, the exception mappings and the default error view will apply to all handlers. This means that a specified default error view will be used as a fallback for all exceptions; any further HandlerExceptionHandlers in the chain will be ignored in this case.
-
addMappedHandlerClass
Add a mapped handler class. -
getMappedHandlerClasses
Return theconfiguredmapped handler classes. -
setWarnLogCategory
Set the log category for warn logging. The name will be passed to the underlying logger implementation through Commons Logging, getting interpreted as a log category according to the logger's configuration. Ifnullor empty String is passed, warn logging is turned off.By default there is no warn logging although subclasses like
SimpleHandlerExceptionHandlercan change that default. Specify this setting to activate warn logging into a specific category. Alternatively, override thelogException(java.lang.Throwable, cn.taketoday.web.RequestContext)method for custom logging.- 另请参阅:
-
LoggerFactory.getLogger(String)Logger.getLogger(String)
-
setPreventResponseCaching
public void setPreventResponseCaching(boolean preventResponseCaching) Specify whether to prevent HTTP response caching for any view resolved by this exception handler.Default is
false. Switch this totruein order to automatically generate HTTP response headers that suppress response caching. -
handleException
@Nullable public Object handleException(RequestContext context, Throwable ex, @Nullable Object handler) throws Exception Check whether this handler is supposed to apply (i.e. if the supplied handler matches any of the configured handlers or handler classes), and then delegate to thehandleInternal(cn.taketoday.web.RequestContext, java.lang.Object, java.lang.Throwable)template method.- 指定者:
handleException在接口中HandlerExceptionHandlerex- The exception occurredhandler- Current handler- 返回:
- a corresponding view result to write to,
or
nullfor default processing in the resolution chain - 抛出:
Exception- error handle failed
-
shouldApplyTo
Check whether this handler is supposed to apply to the given handler.The default implementation checks against the configured handlers and handler classes, if any.
- 参数:
request- current HTTP request contexthandler- the executed handler, ornullif none chosen at the time of the exception (for example, if multipart resolution failed)- 返回:
- whether this resolved should proceed with resolving the exception for the given request and handler
- 另请参阅:
-
hasHandlerMappings
protected boolean hasHandlerMappings()Whether there are any handler mappings registered viasetMappedHandlers(Set)orsetMappedHandlerClasses(Class[]). -
logException
Log the given exception at warn level, provided that warn logging has been activated through the"warnLogCategory"property.Calls
buildLogMessage(java.lang.Throwable, cn.taketoday.web.RequestContext)in order to determine the concrete message to log.- 参数:
ex- the exception that got thrown during handler executionrequest- current HTTP request (useful for obtaining metadata)- 另请参阅:
-
setWarnLogCategory(java.lang.String)buildLogMessage(java.lang.Throwable, cn.taketoday.web.RequestContext)Logger.warn(Object, Throwable)
-
buildLogMessage
Build a log message for the given exception, occurred during processing the given request.- 参数:
ex- the exception that got thrown during handler executionrequest- current HTTP request (useful for obtaining metadata)- 返回:
- the log message to use
-
logResultedInException
record log when an exception occurred in this exception handler- 参数:
target- Throwable that occurred in request handlerhandlerException- Throwable occurred in this exception handler
-
prepareResponse
Prepare the response for the exceptional case.The default implementation prevents the response from being cached, if the
"preventResponseCaching"property has been set to "true".- 参数:
ex- the exception that got thrown during handler executionresponse- current HTTP response- 另请参阅:
-
preventCaching
Prevents the response from being cached, through setting corresponding HTTPCache-Control: no-storeheader.- 参数:
response- current HTTP response
-
handleInternal
@Nullable protected abstract Object handleInternal(RequestContext request, @Nullable Object handler, Throwable ex) throws Exception Actually handle the given exception that got thrown during handler execution, returning aresultthat represents a specific error page if appropriate.May be overridden in subclasses, in order to apply specific exception checks. Note that this template method will be invoked after checking whether this resolved applies ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception handling.
- 参数:
request- current HTTP request contexthandler- the executed handler, ornullif none chosen at the time of the exception (for example, if lookup handler failed)ex- the exception that got thrown during handler execution- 返回:
- a corresponding
Object viewto forward to, ornullfor default processing in the resolution chain - 抛出:
Exception
-