类 AbstractHandlerExceptionHandler

java.lang.Object
cn.taketoday.core.OrderedSupport
cn.taketoday.web.handler.AbstractHandlerExceptionHandler
所有已实现的接口:
cn.taketoday.core.Ordered, HandlerExceptionHandler
直接已知子类:
AbstractActionMappingMethodExceptionHandler, ResponseStatusExceptionHandler, SimpleHandlerExceptionHandler, SimpleMappingExceptionHandler

public abstract class AbstractHandlerExceptionHandler extends cn.taketoday.core.OrderedSupport implements HandlerExceptionHandler
Abstract base class for 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
  • 字段详细资料

    • logger

      protected final cn.taketoday.logging.Logger logger
      Logger available to subclasses.
    • mappedHandlers

      @Nullable private Set<?> mappedHandlers
    • mappedHandlerClasses

      @Nullable private Class<?>[] mappedHandlerClasses
    • warnLogger

      @Nullable private cn.taketoday.logging.Logger warnLogger
    • preventResponseCaching

      private boolean preventResponseCaching
  • 构造器详细资料

    • AbstractHandlerExceptionHandler

      public AbstractHandlerExceptionHandler()
  • 方法详细资料

    • setMappedHandlers

      public void setMappedHandlers(@Nullable Set<?> mappedHandlers)
      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

      public void setMappedHandlerClasses(Class<?>... mappedHandlerClasses)
      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

      public void addMappedHandlerClass(Class<?> mappedHandlerClass)
      Add a mapped handler class.
    • getMappedHandlerClasses

      @Nullable protected Class<?>[] getMappedHandlerClasses()
      Return the configured mapped handler classes.
    • setWarnLogCategory

      public void setWarnLogCategory(String loggerName)
      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. If null or empty String is passed, warn logging is turned off.

      By default there is no warn logging although subclasses like SimpleHandlerExceptionHandler can change that default. Specify this setting to activate warn logging into a specific category. Alternatively, override the logException(java.lang.Throwable, cn.taketoday.web.RequestContext) method for custom logging.

      另请参阅:
    • 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 to true in 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 the handleInternal(cn.taketoday.web.RequestContext, java.lang.Object, java.lang.Throwable) template method.
      指定者:
      handleException 在接口中 HandlerExceptionHandler
      ex - The exception occurred
      handler - Current handler
      返回:
      a corresponding view result to write to, or null for default processing in the resolution chain
      抛出:
      Exception - error handle failed
    • shouldApplyTo

      protected boolean shouldApplyTo(RequestContext request, @Nullable Object handler)
      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 context
      handler - the executed handler, or null if 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 via setMappedHandlers(Set) or setMappedHandlerClasses(Class[]).
    • logException

      protected void logException(Throwable ex, RequestContext request)
      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 execution
      request - current HTTP request (useful for obtaining metadata)
      另请参阅:
    • buildLogMessage

      protected String buildLogMessage(Throwable ex, RequestContext request)
      Build a log message for the given exception, occurred during processing the given request.
      参数:
      ex - the exception that got thrown during handler execution
      request - current HTTP request (useful for obtaining metadata)
      返回:
      the log message to use
    • logResultedInException

      protected void logResultedInException(Throwable target, Throwable handlerException)
      record log when an exception occurred in this exception handler
      参数:
      target - Throwable that occurred in request handler
      handlerException - Throwable occurred in this exception handler
    • prepareResponse

      protected void prepareResponse(Throwable ex, RequestContext response)
      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 execution
      response - current HTTP response
      另请参阅:
    • preventCaching

      protected void preventCaching(RequestContext response)
      Prevents the response from being cached, through setting corresponding HTTP Cache-Control: no-store header.
      参数:
      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 a result that 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 context
      handler - the executed handler, or null if 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 view to forward to, or null for default processing in the resolution chain
      抛出:
      Exception