org.omnifaces.filter
Class HttpFilter

java.lang.Object
  extended by org.omnifaces.filter.HttpFilter
All Implemented Interfaces:
javax.servlet.Filter
Direct Known Subclasses:
CharacterEncodingFilter, FacesExceptionFilter, FacesViewsForwardingFilter, GzipResponseFilter, OnDemandResponseBufferFilter

public abstract class HttpFilter
extends java.lang.Object
implements javax.servlet.Filter

An abstract filter for HTTP requests. It provides a convenient abstract doFilter() method providing the HTTP servlet request, response and session so that there's no need to cast them everytime. Also, default implementations of init(FilterConfig) and destroy() are provided, so that there's no need to implement them every time even when not really needed.

Author:
Arjan Tijms, Bauke Scholtz

Constructor Summary
HttpFilter()
           
 
Method Summary
 void destroy()
           
abstract  void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.FilterChain chain)
          Filter the HTTP request.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
           
protected  javax.servlet.FilterConfig getFilterConfig()
          Returns the filter config.
protected  java.lang.String getInitParameter(java.lang.String name)
          Returns the value of the filter init parameter associated with the given name.
protected  javax.servlet.ServletContext getServletContext()
          Returns the servlet context.
 void init()
          Convenience init() method without FilterConfig parameter which will be called by init(FilterConfig).
 void init(javax.servlet.FilterConfig filterConfig)
          Called by the servlet container when the filter is about to be placed into service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpFilter

public HttpFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Called by the servlet container when the filter is about to be placed into service. This implementation stores the FilterConfig object for later use by the getter methods. When overriding this method, call super.init(config), otherwise the getter methods will throw an illegal state exception.

Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

init

public void init()
          throws javax.servlet.ServletException
Convenience init() method without FilterConfig parameter which will be called by init(FilterConfig).

Throws:
javax.servlet.ServletException - When filter's initialization failed.

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws javax.servlet.ServletException,
                     java.io.IOException
Specified by:
doFilter in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException
java.io.IOException

doFilter

public abstract void doFilter(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response,
                              javax.servlet.http.HttpSession session,
                              javax.servlet.FilterChain chain)
                       throws javax.servlet.ServletException,
                              java.io.IOException
Filter the HTTP request. The session argument is null if there is no session.

Throws:
javax.servlet.ServletException
java.io.IOException
See Also:
Filter.doFilter(ServletRequest, ServletResponse, FilterChain)

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter

getFilterConfig

protected javax.servlet.FilterConfig getFilterConfig()
Returns the filter config.

Returns:
The filter config.

getInitParameter

protected java.lang.String getInitParameter(java.lang.String name)
Returns the value of the filter init parameter associated with the given name.

Parameters:
name - The filter init parameter name to return the associated value for.
Returns:
The value of the filter init parameter associated with the given name.

getServletContext

protected javax.servlet.ServletContext getServletContext()
Returns the servlet context.

Returns:
The servlet context.