|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.web.filter.GenericFilterBean
public abstract class GenericFilterBean
Simple base implementation of javax.servlet.Filter
that treats
its config parameters as bean properties. Unknown parameters are ignored.
A very handy superclass for any type of filter. Type conversion of config parameters is automatic. It is also possible for subclasses to specify required properties.
This filter leaves actual filtering to subclasses, which have to
implement the Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
method.
This filter superclass has no dependency on a Spring application context. Filters usually don't load their own context but rather access beans from the root application context, accessible via the ServletContext.
addRequiredProperty(java.lang.String)
,
initFilterBean()
,
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
,
WebApplicationContextUtils.getWebApplicationContext(javax.servlet.ServletContext)
Field Summary | |
---|---|
protected Log |
logger
Logger available to subclasses |
Constructor Summary | |
---|---|
GenericFilterBean()
|
Method Summary | |
---|---|
protected void |
addRequiredProperty(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. |
void |
afterPropertiesSet()
Calls the initFilterBean() method that might
contain custom initialization of a subclass. |
void |
destroy()
Subclasses may override this to perform custom filter shutdown. |
FilterConfig |
getFilterConfig()
Make the FilterConfig of this filter available, if any. |
protected String |
getFilterName()
Make the name of this filter available to subclasses. |
protected ServletContext |
getServletContext()
Make the ServletContext of this filter available to subclasses. |
void |
init(FilterConfig filterConfig)
Standard way of initializing this filter. |
protected void |
initBeanWrapper(BeanWrapper bw)
Initialize the BeanWrapper for this GenericFilterBean, possibly with custom editors. |
protected void |
initFilterBean()
Subclasses may override this to perform custom initialization. |
void |
setBeanName(String beanName)
Stores the bean name as defined in the Spring bean factory. |
void |
setFilterConfig(FilterConfig filterConfig)
Alternative way of initializing this filter. |
void |
setServletContext(ServletContext servletContext)
Stores the ServletContext that the bean factory runs in. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.servlet.Filter |
---|
doFilter |
Field Detail |
---|
protected final Log logger
Constructor Detail |
---|
public GenericFilterBean()
Method Detail |
---|
public final void setBeanName(String beanName)
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
in interface BeanNameAware
beanName
- the name of the bean in the factoryBeanNameAware
,
getFilterName()
public final void setServletContext(ServletContext servletContext)
Only relevant in case of initialization as bean, to have a ServletContext as fallback to the context usually provided by a FilterConfig instance.
setServletContext
in interface ServletContextAware
servletContext
- ServletContext object to be used by this objectServletContextAware
,
getServletContext()
public void afterPropertiesSet() throws ServletException
initFilterBean()
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
in interface InitializingBean
ServletException
initFilterBean()
,
init(javax.servlet.FilterConfig)
protected final void addRequiredProperty(String property)
This method is only relevant in case of traditional initialization driven by a FilterConfig instance.
property
- name of the required propertypublic final void init(FilterConfig filterConfig) throws ServletException
init
in interface Filter
filterConfig
- the configuration for this filter
ServletException
- if bean properties are invalid (or required
properties are missing), or if subclass initialization fails.initFilterBean()
public final void setFilterConfig(FilterConfig filterConfig)
filterConfig
- the configuration for this filter
BeanInitializationException
- wrapping a ServletException
thrown by the init
methodinit(javax.servlet.FilterConfig)
protected void initBeanWrapper(BeanWrapper bw) throws BeansException
This default implementation is empty.
bw
- the BeanWrapper to initialize
BeansException
- if thrown by BeanWrapper methodsPropertyEditorRegistry.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor)
public final FilterConfig getFilterConfig()
getServletConfig()
.
Public to resemble the getFilterConfig()
method
of the Servlet Filter version that shipped with WebLogic 6.1.
null
if none availableGenericServlet.getServletConfig()
protected final String getFilterName()
getServletName()
.
Takes the FilterConfig's filter name by default. If initialized as bean in a Spring application context, it falls back to the bean name as defined in the bean factory.
null
if none availableGenericServlet.getServletName()
,
FilterConfig.getFilterName()
,
setBeanName(java.lang.String)
protected final ServletContext getServletContext()
getServletContext()
.
Takes the FilterConfig's ServletContext by default. If initialized as bean in a Spring application context, it falls back to the ServletContext that the bean factory runs in.
null
if none availableGenericServlet.getServletContext()
,
FilterConfig.getServletContext()
,
setServletContext(javax.servlet.ServletContext)
protected void initFilterBean() throws ServletException
Note: This method will be called from standard filter initialization as well as filter bean initialization in a Spring application context. Filter name and ServletContext will be available in both cases.
This default implementation is empty.
ServletException
- if subclass initialization failsgetFilterName()
,
getServletContext()
public void destroy()
Note: This method will be called from standard filter destruction as well as filter bean destruction in a Spring application context.
This default implementation is empty.
destroy
in interface Filter
destroy
in interface DisposableBean
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |