类 InfraHandler

java.lang.Object
cn.taketoday.web.handler.InfraHandler
所有已实现的接口:
cn.taketoday.beans.factory.Aware, cn.taketoday.beans.factory.BeanNameAware, cn.taketoday.context.ApplicationContextAware, cn.taketoday.context.EnvironmentAware, cn.taketoday.core.env.EnvironmentCapable
直接已知子类:
DispatcherHandler

public abstract class InfraHandler extends Object implements cn.taketoday.context.ApplicationContextAware, cn.taketoday.core.env.EnvironmentCapable, cn.taketoday.context.EnvironmentAware, cn.taketoday.beans.factory.BeanNameAware
Infrastructure Handler
从以下版本开始:
4.0 2022/9/26 23:21
作者:
Harry Yang
  • 嵌套类概要

    嵌套类
    修饰符和类型
    说明
    private class 
    ApplicationListener endpoint that receives events from this handler's ApplicationContext only, delegating to onApplicationEvent on the DispatcherHandler instance.
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final String
    Prefix for ApplicationContext ids that refer to context path and/or servlet name.
    private cn.taketoday.context.ApplicationContext
     
    private boolean
    If the ApplicationContext was injected via setApplicationContext(cn.taketoday.context.ApplicationContext).
    protected String
     
    private Class<?>
    ApplicationContext implementation class to create.
    private String
    Explicit context config location.
    private String
    ApplicationContext id to assign.
    private String
    Comma-delimited ApplicationContextInitializer class names set through init param.
    private final ArrayList<cn.taketoday.context.ApplicationContextInitializer>
    Actual ApplicationContextInitializer instances to apply to the context.
    static final Class<?>
    Default context class for InfraHandler.
    private boolean
    Whether to log potentially sensitive info (request params at DEBUG + headers at TRACE).
    private cn.taketoday.core.env.ConfigurableEnvironment
     
    static final String
    Any number of these characters are considered delimiters between multiple values in a single init-param String value.
    protected final AtomicBoolean
     
    protected final cn.taketoday.logging.Logger
     
    private final Object
    Monitor for synchronized onRefresh execution.
    private boolean
    Flag used to detect whether onRefresh has already been called.
  • 构造器概要

    构造器
    限定符
    构造器
    说明
    protected
     
    protected
    InfraHandler(cn.taketoday.context.ApplicationContext applicationContext)
    Create a new InfraHandler with the given application context.
  • 方法概要

    修饰符和类型
    方法
    说明
    protected void
    This method will be invoked after any bean properties have been set and the ApplicationContext has been loaded.
    protected void
    applyDefaultContextId(cn.taketoday.context.ConfigurableApplicationContext context)
     
    protected void
    applyInitializers(cn.taketoday.context.ConfigurableApplicationContext context, List<cn.taketoday.context.ApplicationContextInitializer> initializers)
    Delegate the ApplicationContext before it is refreshed to any ApplicationContextInitializer instances specified by the "contextInitializerClasses" servlet init-param.
    protected void
    configureAndRefreshApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context)
     
    protected cn.taketoday.context.ApplicationContext
    createApplicationContext(cn.taketoday.context.ApplicationContext parent)
    Instantiate the ApplicationContext for this handler, either a default XmlWebApplicationContext or a custom context class, if set.
    protected cn.taketoday.core.env.ConfigurableEnvironment
    Create and return a new StandardEnvironment.
    void
    Destroy Application
    protected cn.taketoday.context.ApplicationContext
    Retrieve a ApplicationContext
    final cn.taketoday.context.ApplicationContext
    Return this handler's ApplicationContext.
    Return the custom context class.
    Return the explicit context config location, if any.
    Return the custom ApplicationContext id, if any.
    cn.taketoday.core.env.ConfigurableEnvironment
    Return the Environment associated with this handler.
    protected cn.taketoday.context.ApplicationContext
     
    void
     
    protected cn.taketoday.context.ApplicationContext
    Initialize and publish the ApplicationContext for this handler.
    boolean
    Whether logging of potentially sensitive, request details at DEBUG and TRACE level is allowed.
    protected final cn.taketoday.context.ApplicationContextInitializer
    loadInitializer(String className, cn.taketoday.context.ConfigurableApplicationContext context)
     
    protected void
    Log internal
    void
    onApplicationEvent(cn.taketoday.context.event.ContextRefreshedEvent event)
    Callback that receives refresh events from this handler's ApplicationContext.
    protected void
    onRefresh(cn.taketoday.context.ApplicationContext context)
    Template method which can be overridden to add servlet-specific refresh work.
    protected void
    postProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context)
    Post-process the given ApplicationContext before it is refreshed and activated as context for this handler.
    void
    Refresh this handler's application context, as well as the dependent state of the handler.
    void
    setApplicationContext(cn.taketoday.context.ApplicationContext applicationContext)
    Called by Infra via ApplicationContextAware to inject the current application context.
    void
     
    void
    setContextClass(Class<?> contextClass)
    Set a custom context class.
    void
    setContextConfigLocation(String contextConfigLocation)
    Set the context config location explicitly, instead of relying on the default location built from the namespace.
    void
    setContextId(String contextId)
    Specify a custom ApplicationContext id, to be used as serialization id for the underlying BeanFactory.
    void
    setContextInitializerClasses(String contextInitializerClasses)
    Specify the set of fully-qualified ApplicationContextInitializer class names, per the optional "contextInitializerClasses" servlet init-param.
    void
    setContextInitializers(cn.taketoday.context.ApplicationContextInitializer... initializers)
    Specify which ApplicationContextInitializer instances should be used to initialize the application context used by this InfraHandler.
    void
    Whether to log request params at DEBUG level, and headers at TRACE level.
    void
    setEnvironment(cn.taketoday.core.env.Environment environment)
    Set the Environment that this handler runs in.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • DEFAULT_CONTEXT_CLASS

      public static final Class<?> DEFAULT_CONTEXT_CLASS
      Default context class for InfraHandler.
      另请参阅:
      • ClassPathXmlApplicationContext
    • APPLICATION_CONTEXT_ID_PREFIX

      public static final String APPLICATION_CONTEXT_ID_PREFIX
      Prefix for ApplicationContext ids that refer to context path and/or servlet name.
    • INIT_PARAM_DELIMITERS

      public static final String INIT_PARAM_DELIMITERS
      Any number of these characters are considered delimiters between multiple values in a single init-param String value.
      另请参阅:
    • log

      protected final cn.taketoday.logging.Logger log
    • applicationContextInjected

      private boolean applicationContextInjected
      If the ApplicationContext was injected via setApplicationContext(cn.taketoday.context.ApplicationContext).
    • contextClass

      private Class<?> contextClass
      ApplicationContext implementation class to create.
    • contextId

      @Nullable private String contextId
      ApplicationContext id to assign.
    • contextConfigLocation

      @Nullable private String contextConfigLocation
      Explicit context config location.
    • contextInitializers

      private final ArrayList<cn.taketoday.context.ApplicationContextInitializer> contextInitializers
      Actual ApplicationContextInitializer instances to apply to the context.
    • contextInitializerClasses

      @Nullable private String contextInitializerClasses
      Comma-delimited ApplicationContextInitializer class names set through init param.
    • refreshEventReceived

      private volatile boolean refreshEventReceived
      Flag used to detect whether onRefresh has already been called.
    • onRefreshMonitor

      private final Object onRefreshMonitor
      Monitor for synchronized onRefresh execution.
    • beanName

      protected String beanName
    • environment

      @Nullable private cn.taketoday.core.env.ConfigurableEnvironment environment
    • applicationContext

      private cn.taketoday.context.ApplicationContext applicationContext
    • enableLoggingRequestDetails

      private boolean enableLoggingRequestDetails
      Whether to log potentially sensitive info (request params at DEBUG + headers at TRACE).
    • initialized

      protected final AtomicBoolean initialized
  • 构造器详细资料

    • InfraHandler

      protected InfraHandler()
    • InfraHandler

      protected InfraHandler(cn.taketoday.context.ApplicationContext applicationContext)
      Create a new InfraHandler with the given application context.

      Using this constructor indicates that the following properties / init-params will be ignored:

      The given application context may or may not yet be refreshed. If it (a) is an implementation of ConfigurableApplicationContext and (b) has not already been refreshed (the recommended approach), then the following will occur:

      If the context has already been refreshed or does not implement ConfigurableApplicationContext, none of the above will occur under the assumption that the user has performed these actions (or not) per his or her specific needs.
      参数:
      applicationContext - the context to use
      另请参阅:
  • 方法详细资料

    • setBeanName

      public void setBeanName(String name)
      指定者:
      setBeanName 在接口中 cn.taketoday.beans.factory.BeanNameAware
    • setEnvironment

      public void setEnvironment(cn.taketoday.core.env.Environment environment)
      Set the Environment that this handler runs in.

      Any environment set here overrides the StandardEnvironment provided by default.

      指定者:
      setEnvironment 在接口中 cn.taketoday.context.EnvironmentAware
      抛出:
      IllegalArgumentException - if environment is not assignable to ConfigurableEnvironment
    • getEnvironment

      public cn.taketoday.core.env.ConfigurableEnvironment getEnvironment()
      Return the Environment associated with this handler.

      If none specified, a default environment will be initialized via createEnvironment().

      指定者:
      getEnvironment 在接口中 cn.taketoday.core.env.EnvironmentCapable
    • createEnvironment

      protected cn.taketoday.core.env.ConfigurableEnvironment createEnvironment()
      Create and return a new StandardEnvironment.

      Subclasses may override this in order to configure the environment or specialize the environment type returned.

    • init

      public void init()
    • afterApplicationContextInit

      protected void afterApplicationContextInit()
      This method will be invoked after any bean properties have been set and the ApplicationContext has been loaded. The default implementation is empty; subclasses may override this method to perform any initialization they require.
    • initApplicationContext

      protected cn.taketoday.context.ApplicationContext initApplicationContext()
      Initialize and publish the ApplicationContext for this handler.

      Delegates to createApplicationContext(cn.taketoday.context.ApplicationContext) for actual creation of the context. Can be overridden in subclasses.

      返回:
      the ApplicationContext instance
      另请参阅:
    • getRootApplicationContext

      @Nullable protected cn.taketoday.context.ApplicationContext getRootApplicationContext()
    • configureAndRefreshApplicationContext

      protected void configureAndRefreshApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context)
    • applyDefaultContextId

      protected void applyDefaultContextId(cn.taketoday.context.ConfigurableApplicationContext context)
    • findApplicationContext

      @Nullable protected cn.taketoday.context.ApplicationContext findApplicationContext()
      Retrieve a ApplicationContext
      返回:
      the ApplicationContext for this handler, or null if not found
    • createApplicationContext

      protected cn.taketoday.context.ApplicationContext createApplicationContext(@Nullable cn.taketoday.context.ApplicationContext parent)
      Instantiate the ApplicationContext for this handler, either a default XmlWebApplicationContext or a custom context class, if set.

      This implementation expects custom contexts to implement the ConfigurableApplicationContext interface. Can be overridden in subclasses.

      Do not forget to register this handler instance as application listener on the created context (for triggering its callback), and to call ConfigurableApplicationContext.refresh() before returning the context instance.

      参数:
      parent - the parent ApplicationContext to use, or null if none
      返回:
      the ApplicationContext for this handler
      另请参阅:
    • postProcessApplicationContext

      protected void postProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext context)
      Post-process the given ApplicationContext before it is refreshed and activated as context for this handler.

      The default implementation is empty. refresh() will be called automatically after this method returns.

      Note that this method is designed to allow subclasses to modify the application context, while initApplicationContext() is designed to allow end-users to modify the context through the use of ApplicationContextInitializers.

      参数:
      context - the configured ApplicationContext (not refreshed yet)
      另请参阅:
    • applyInitializers

      protected void applyInitializers(cn.taketoday.context.ConfigurableApplicationContext context, List<cn.taketoday.context.ApplicationContextInitializer> initializers)
      Delegate the ApplicationContext before it is refreshed to any ApplicationContextInitializer instances specified by the "contextInitializerClasses" servlet init-param.

      See also postProcessApplicationContext(cn.taketoday.context.ConfigurableApplicationContext), which is designed to allow subclasses (as opposed to end-users) to modify the application context, and is called immediately before this method.

      参数:
      context - the configured ApplicationContext (not refreshed yet)
      initializers - ApplicationContextInitializer list
      另请参阅:
    • loadInitializer

      protected final cn.taketoday.context.ApplicationContextInitializer loadInitializer(String className, cn.taketoday.context.ConfigurableApplicationContext context)
    • refresh

      public void refresh()
      Refresh this handler's application context, as well as the dependent state of the handler.
      另请参阅:
    • onRefresh

      protected void onRefresh(cn.taketoday.context.ApplicationContext context)
      Template method which can be overridden to add servlet-specific refresh work. Called after successful context refresh.

      This implementation is empty.

      参数:
      context - the current ApplicationContext
      另请参阅:
    • destroy

      public void destroy()
      Destroy Application
    • logInfo

      protected void logInfo(String msg)
      Log internal
      参数:
      msg - Log message
    • onApplicationEvent

      public void onApplicationEvent(cn.taketoday.context.event.ContextRefreshedEvent event)
      Callback that receives refresh events from this handler's ApplicationContext.

      The default implementation calls onRefresh(cn.taketoday.context.ApplicationContext), triggering a refresh of this handler's context-dependent state.

      参数:
      event - the incoming ApplicationContext event
    • setApplicationContext

      public void setApplicationContext(cn.taketoday.context.ApplicationContext applicationContext)
      Called by Infra via ApplicationContextAware to inject the current application context. This method allows DispatcherServlets to be registered as Infra beans inside an existing ApplicationContext rather than finding a bootstrapped context.

      Primarily added to support use in embedded handler containers.

      指定者:
      setApplicationContext 在接口中 cn.taketoday.context.ApplicationContextAware
    • getApplicationContext

      public final cn.taketoday.context.ApplicationContext getApplicationContext()
      Return this handler's ApplicationContext.
    • setContextClass

      public void setContextClass(Class<?> contextClass)
      Set a custom context class. This class must be of type ApplicationContext.

      When using the default DispatcherHandler implementation, the context class must also implement the ConfigurableApplicationContext interface.

      另请参阅:
    • getContextClass

      public Class<?> getContextClass()
      Return the custom context class.
    • setContextId

      public void setContextId(@Nullable String contextId)
      Specify a custom ApplicationContext id, to be used as serialization id for the underlying BeanFactory.
    • getContextId

      @Nullable public String getContextId()
      Return the custom ApplicationContext id, if any.
    • setContextConfigLocation

      public void setContextConfigLocation(@Nullable String contextConfigLocation)
      Set the context config location explicitly, instead of relying on the default location built from the namespace. This location string can consist of multiple locations separated by any number of commas and spaces.
    • getContextConfigLocation

      @Nullable public String getContextConfigLocation()
      Return the explicit context config location, if any.
    • setContextInitializers

      public void setContextInitializers(@Nullable cn.taketoday.context.ApplicationContextInitializer... initializers)
      Specify which ApplicationContextInitializer instances should be used to initialize the application context used by this InfraHandler.
      另请参阅:
    • setContextInitializerClasses

      public void setContextInitializerClasses(String contextInitializerClasses)
      Specify the set of fully-qualified ApplicationContextInitializer class names, per the optional "contextInitializerClasses" servlet init-param.
      另请参阅:
    • setEnableLoggingRequestDetails

      public void setEnableLoggingRequestDetails(boolean enable)
      Whether to log request params at DEBUG level, and headers at TRACE level. Both may contain sensitive information.

      By default set to false so that request details are not shown.

      参数:
      enable - whether to enable or not
    • isEnableLoggingRequestDetails

      public boolean isEnableLoggingRequestDetails()
      Whether logging of potentially sensitive, request details at DEBUG and TRACE level is allowed.