类 GenericFilterBean
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.beans.factory.BeanNameAware,cn.taketoday.beans.factory.DisposableBean,cn.taketoday.beans.factory.InitializingBean,cn.taketoday.context.EnvironmentAware,cn.taketoday.core.env.EnvironmentCapable,ServletContextAware,Filter
Filter which treats
its config parameters (init-param entries within the
filter tag in web.xml) as bean properties.
A handy superclass for any type of filter. Type conversion of config parameters is automatic, with the corresponding setter method getting invoked with the converted value. It is also possible for subclasses to specify required properties. Parameters without matching bean property setter will simply be ignored.
This filter leaves actual filtering to subclasses, which have to
implement the Filter.doFilter(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse, jakarta.servlet.FilterChain) method.
This generic filter base class has no dependency on the Framework
ApplicationContext concept.
Filters usually don't load their own context but rather access service
beans from the Framework root application context, accessible via the
filter's ServletContext (see
WebApplicationContextUtils).
- 从以下版本开始:
- 4.0
- 作者:
- Harry Yang, Juergen Hoeller
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private Stringprivate cn.taketoday.core.env.Environmentprivate FilterConfigprotected final cn.taketoday.logging.LoggerLogger available to subclasses.private ServletContext -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected final voidaddRequiredProperty(String property) Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter.voidCalls theinitFilterBean()method that might contain custom initialization of a subclass.protected cn.taketoday.core.env.EnvironmentCreate and return a newStandardServletEnvironment.voiddestroy()Subclasses may override this to perform custom filter shutdown.cn.taketoday.core.env.EnvironmentReturn theEnvironmentassociated with this filter.Make the FilterConfig of this filter available, if any.private cn.taketoday.beans.PropertyValuesgetFilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties) protected StringMake the name of this filter available to subclasses.protected ServletContextMake the ServletContext of this filter available to subclasses.final voidinit(FilterConfig filterConfig) Standard way of initializing this filter.protected voidinitBeanWrapper(cn.taketoday.beans.BeanWrapper bw) Initialize the BeanWrapper for this GenericFilterBean, possibly with custom editors.protected voidSubclasses may override this to perform custom initialization.voidsetBeanName(String beanName) Stores the bean name as defined in the Framework bean factory.voidsetEnvironment(cn.taketoday.core.env.Environment environment) Set theEnvironmentthat this filter runs in.voidsetServletContext(ServletContext servletContext) Stores the ServletContext that the bean factory runs in.
-
字段详细资料
-
logger
protected final cn.taketoday.logging.Logger loggerLogger available to subclasses. -
beanName
-
environment
@Nullable private cn.taketoday.core.env.Environment environment -
servletContext
-
filterConfig
-
requiredProperties
-
-
构造器详细资料
-
GenericFilterBean
public GenericFilterBean()
-
-
方法详细资料
-
setBeanName
Stores the bean name as defined in the Framework bean factory.Only relevant in case of initialization as bean, to have a name as fallback to the filter name usually provided by a FilterConfig instance.
- 指定者:
setBeanName在接口中cn.taketoday.beans.factory.BeanNameAware- 另请参阅:
-
BeanNameAwaregetFilterName()
-
setEnvironment
public void setEnvironment(cn.taketoday.core.env.Environment environment) Set theEnvironmentthat this filter runs in.Any environment set here overrides the
StandardServletEnvironmentprovided by default.This
Environmentobject is used only for resolving placeholders in resource paths passed into init-parameters for this filter. If no init-params are used, thisEnvironmentcan be essentially ignored.- 指定者:
setEnvironment在接口中cn.taketoday.context.EnvironmentAware
-
getEnvironment
public cn.taketoday.core.env.Environment getEnvironment()Return theEnvironmentassociated with this filter.If none specified, a default environment will be initialized via
createEnvironment().- 指定者:
getEnvironment在接口中cn.taketoday.core.env.EnvironmentCapable
-
createEnvironment
protected cn.taketoday.core.env.Environment createEnvironment()Create and return a newStandardServletEnvironment.Subclasses may override this in order to configure the environment or specialize the environment type returned.
-
setServletContext
Stores the ServletContext that the bean factory runs in.Only relevant in case of initialization as bean, to have a ServletContext as fallback to the context usually provided by a FilterConfig instance.
- 指定者:
setServletContext在接口中ServletContextAware- 参数:
servletContext- the ServletContext object to be used by this object- 另请参阅:
-
afterPropertiesSet
Calls theinitFilterBean()method that might contain custom initialization of a subclass.Only relevant in case of initialization as bean, where the standard
init(FilterConfig)method won't be called.- 指定者:
afterPropertiesSet在接口中cn.taketoday.beans.factory.InitializingBean- 抛出:
ServletException- 另请参阅:
-
destroy
public void destroy()Subclasses may override this to perform custom filter shutdown.Note: This method will be called from standard filter destruction as well as filter bean destruction in a Framework application context.
This default implementation is empty.
-
addRequiredProperty
Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter. This should be called from the constructor of a subclass.This method is only relevant in case of traditional initialization driven by a FilterConfig instance.
- 参数:
property- name of the required property
-
init
Standard way of initializing this filter. Map config parameters onto bean properties of this filter, and invoke subclass initialization.- 指定者:
init在接口中Filter- 参数:
filterConfig- the configuration for this filter- 抛出:
ServletException- if bean properties are invalid (or required properties are missing), or if subclass initialization fails.- 另请参阅:
-
initBeanWrapper
protected void initBeanWrapper(cn.taketoday.beans.BeanWrapper bw) throws cn.taketoday.beans.BeansException Initialize the BeanWrapper for this GenericFilterBean, possibly with custom editors.This default implementation is empty.
- 参数:
bw- the BeanWrapper to initialize- 抛出:
cn.taketoday.beans.BeansException- if thrown by BeanWrapper methods- 另请参阅:
-
PropertyEditorRegistry.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
-
initFilterBean
Subclasses may override this to perform custom initialization. All bean properties of this filter will have been set before this method is invoked.Note: This method will be called from standard filter initialization as well as filter bean initialization in a Framework application context. Filter name and ServletContext will be available in both cases.
This default implementation is empty.
- 抛出:
ServletException- if subclass initialization fails- 另请参阅:
-
getFilterConfig
Make the FilterConfig of this filter available, if any. Analogous to GenericServlet'sgetServletConfig().Public to resemble the
getFilterConfig()method of the Servlet Filter version that shipped with WebLogic 6.1.- 返回:
- the FilterConfig instance, or
nullif none available - 另请参阅:
-
getFilterName
Make the name of this filter available to subclasses. Analogous to GenericServlet'sgetServletName().Takes the FilterConfig's filter name by default. If initialized as bean in a Framework application context, it falls back to the bean name as defined in the bean factory.
- 返回:
- the filter name, or
nullif none available - 另请参阅:
-
getServletContext
Make the ServletContext of this filter available to subclasses. Analogous to GenericServlet'sgetServletContext().Takes the FilterConfig's ServletContext by default. If initialized as bean in a Framework application context, it falls back to the ServletContext that the bean factory runs in.
- 返回:
- the ServletContext instance
- 抛出:
IllegalStateException- if no ServletContext is available- 另请参阅:
-
getFilterConfigPropertyValues
private cn.taketoday.beans.PropertyValues getFilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties) throws ServletException - 参数:
config- the FilterConfig we'll use to take PropertyValues fromrequiredProperties- set of property names we need, where we can't accept default values- 返回:
- PropertyValues
- 抛出:
ServletException- if any required properties are missing
-