org.springframework.web.filter
Class GenericFilterBean

java.lang.Object
  extended by org.springframework.web.filter.GenericFilterBean
All Implemented Interfaces:
Filter
Direct Known Subclasses:
DelegatingFilterProxy, OncePerRequestFilter

public abstract class GenericFilterBean
extends Object
implements Filter

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 is automatic. It is also possible for subclasses to specify required properties.

This filter leaves actual filtering to subclasses, which have to implement Filter's doFilter 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.

Since:
06.12.2003
Author:
Juergen Hoeller
See Also:
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 destroy()
          Subclasses may override this to perform custom filter shutdown.
 FilterConfig getFilterConfig()
          Make the FilterConfig of this filter available.
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)
          Map config parameters onto bean properties of this filter, and invoke subclass initialization.
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 setFilterConfig(FilterConfig filterConfig)
          Alternative way of initializing this filter.
 
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

logger

protected final Log logger
Logger available to subclasses

Constructor Detail

GenericFilterBean

public GenericFilterBean()
Method Detail

addRequiredProperty

protected final 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. This should be called from the constructor of a subclass

Parameters:
property - name of the required property

setFilterConfig

public final void setFilterConfig(FilterConfig filterConfig)
Alternative way of initializing this filter. Used by Servlet Filter version that shipped with WebLogic 6.1.

Parameters:
filterConfig - the configuration for this filter
Throws:
FatalBeanException - wrapping a ServletException thrown by the init method
See Also:
init(javax.servlet.FilterConfig)

init

public final void init(FilterConfig filterConfig)
                throws ServletException
Map config parameters onto bean properties of this filter, and invoke subclass initialization.

Specified by:
init in interface Filter
Parameters:
filterConfig - the configuration for this filter
Throws:
ServletException - if bean properties are invalid (or required properties are missing), or if subclass initialization fails.
See Also:
initFilterBean()

initBeanWrapper

protected void initBeanWrapper(BeanWrapper bw)
                        throws BeansException
Initialize the BeanWrapper for this GenericFilterBean, possibly with custom editors.

Parameters:
bw - the BeanWrapper to initialize
Throws:
BeansException - if thrown by BeanWrapper methods
See Also:
BeanWrapper.registerCustomEditor(java.lang.Class, java.beans.PropertyEditor)

getFilterConfig

public final FilterConfig getFilterConfig()
Make the FilterConfig of this filter available. Analogous to GenericServlet's getServletConfig.

Public to resemble the getFilterConfig method of the Servlet Filter version that shipped with WebLogic 6.1.

See Also:
GenericServlet.getServletConfig()

getFilterName

protected final String getFilterName()
Make the name of this filter available to subclasses. Analogous to GenericServlet's getServletName.

See Also:
GenericServlet.getServletName()

getServletContext

protected final ServletContext getServletContext()
Make the ServletContext of this filter available to subclasses. Analogous to GenericServlet's getServletContext.

See Also:
GenericServlet.getServletContext()

initFilterBean

protected void initFilterBean()
                       throws ServletException
Subclasses may override this to perform custom initialization. All bean properties of this filter will have been set before this method is invoked. This default implementation does nothing.

Throws:
ServletException - if subclass initialization fails

destroy

public void destroy()
Subclasses may override this to perform custom filter shutdown. This default implementation does nothing.

Specified by:
destroy in interface Filter


Copyright (c) 2002-2005 The Spring Framework Project.