atg.servlet
Class GenericFilterService

java.lang.Object
  extended by atg.servlet.GenericFilterService
All Implemented Interfaces:
javax.servlet.Filter

public class GenericFilterService
extends java.lang.Object
implements javax.servlet.Filter

Filter implementation with support for self-configuration, naming resolution, performance profiling and logging.

Derived class should override the following methods:

The filter may be configured from filter init parameters. specified in a web application deployment descriptor. Named init parameters are treated as properties of the filter. Parameters prefixed with cxt: are looked up using the filters name context.

The following example serves to demonstrate configuration of a generic filter service:

   <filter>
     <filter-name>MyFilterService</filter-name>
     <filter-class>com.acme.filter.MyFilterService</filter-class>
     <init-param>
       <param-name>loggingDebug</param-name>
       <param-value>false</param-value>
     </init-param>
     <init-param>
       <param-name>loggingWarning</param-name>
       <param-value>false</param-value>
     </init-param>
     <init-param>
       <param-name>loggingError</param-name>
       <param-value>true</param-value>
     </init-param>
     <init-param>
       <param-name>loggingInfo</param-name>
       <param-value>true</param-value>
     </init-param>
     <init-param>
       <param-name>MyString</param-name>
       <param-value>foobar</param-value>
     </init-param>
       <param-name>Object</param-name>
       <param-value>ctx:dynamo:/com/Acme/MyFooObject</param-value>
     </init-param>
   </filter>
  

Derived filters may use the lookup method to lookup objects in the filters name context. The objects name context is accessable via the context property.

The filter may log information using the logging facilities provided. Support for info, warning, error and debug levels are provided by the service.

If a performance monitor is enabled the filter collects performance metrics about the handleDoFilter method.


Field Summary
protected static java.lang.String ARRAY_DELIMITER
           
static java.lang.String CLASS_VERSION
          Class version string
protected static java.lang.String CONTEXT
           
protected static java.lang.String CONTEXT_DELIMITER
           
protected static java.lang.String ENVIRONMENT
           
protected static java.lang.String ENVIRONMENT_DELIMITER
           
protected  javax.naming.Context mContext
           
protected  javax.servlet.FilterConfig mFilterConfig
           
protected  boolean mLoggingDebug
           
protected  boolean mLoggingError
           
protected  boolean mLoggingInfo
           
protected  boolean mLoggingWarning
           
protected  java.lang.String mName
           
protected  javax.servlet.ServletContext mServletContext
           
protected static java.lang.String PERFOP_DOFILTERCHAIN
           
protected static java.lang.String PERFOP_FILTERREQUEST
           
protected static java.lang.String PERFOP_FILTERRESPONSE
           
protected static java.util.ResourceBundle sResourceBundle
           
protected static java.lang.String sResourceBundleName
           
 
Constructor Summary
GenericFilterService()
          Constructs an instanceof GenericFilterService
 
Method Summary
 void destroy()
          Called by the web container to indicate to a filter that it is being taken out of service
 void doFilter(javax.servlet.ServletRequest pServletRequest, javax.servlet.ServletResponse pServletResponse, javax.servlet.FilterChain pFilterChain)
          Called by the web container to indicate that a filter should filter a request/response
protected  void doFilterChain(javax.servlet.ServletRequest pServletRequest, javax.servlet.ServletResponse pServletResponse, javax.servlet.FilterChain pFilterChain)
          Called by the filter to indicate that a filter should process the remaining filter chain.
protected  boolean doFilterRequest(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, javax.servlet.FilterChain filterChain)
          Called by the filter to indicate that a filter should filter a request (before the filter chain is called).
protected  boolean doFilterRequest(javax.servlet.ServletRequest pServletRequest, javax.servlet.ServletResponse pServletResponse, javax.servlet.FilterChain pFilterChain)
          Called by the web continer to indicate that a filter should filter a request/response
protected  void doFilterResponse(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, javax.servlet.FilterChain filterChain)
           
protected  void doFilterResponse(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)
          Called by the filter to indicate that a filter should filter a response (after the filter chain has been called).
 javax.naming.Context getContext()
          Returns property Context
 javax.servlet.FilterConfig getFilterConfig()
          Returns property FilterConfig
 java.lang.String getName()
          Returns property Name
 javax.servlet.ServletContext getServletContext()
          Returns property ServletContext
protected  void handleDoFilter(javax.servlet.ServletRequest pServletRequest, javax.servlet.ServletResponse pServletResponse, javax.servlet.FilterChain pFilterChain)
          Deprecated.  
 void init(javax.servlet.FilterConfig pFilterConfig)
          Called by the web container to indicate to a filter that it is being placed into server.
 boolean isLoggingDebug()
          Returns property LoggingDebug
 boolean isLoggingError()
          Returns property LoggingError
 boolean isLoggingInfo()
          Returns property LoggingInfo
 boolean isLoggingWarning()
          Returns property LoggingWarning
 void logDebug(java.lang.String pMessage)
          Logs an debug event with the specified message
 void logDebug(java.lang.String pMessage, java.lang.Throwable pThrowable)
          Logs an debug event with the specified message and Throwable
 void logDebug(java.lang.Throwable pThrowable)
          Logs an debug event with the specified Throwable
 void logError(java.lang.String pMessage)
          Logs an error event with the specified message
 void logError(java.lang.String pMessage, java.lang.Throwable pThrowable)
          Logs an error event with the specified message and Throwable
 void logError(java.lang.Throwable pThrowable)
          Logs an error event with the specified Throwable
 void logInfo(java.lang.String pMessage)
          Logs an info event with the specified message
 void logInfo(java.lang.String pMessage, java.lang.Throwable pThrowable)
          Logs an info event with the specified message and Throwable
 void logInfo(java.lang.Throwable pThrowable)
          Logs an info event with the specified Throwable
 void logWarning(java.lang.String pMessage)
          Logs an warning event with the specified message
 void logWarning(java.lang.String pMessage, java.lang.Throwable pThrowable)
          Logs an warning event with the specified message and Throwable
 void logWarning(java.lang.Throwable pThrowable)
          Logs an warning event with the specified Throwable
 java.lang.Object lookup(java.lang.String pName)
          Retreives the named object
protected  void setContext(javax.naming.Context pContext)
          Sets property Context
protected  void setFilterConfig(javax.servlet.FilterConfig pFilterConfig)
          Sets property FilterConfig
 void setLoggingDebug(boolean pLoggingDebug)
          Sets property LoggingDebug
 void setLoggingError(boolean pLoggingError)
          Sets property LoggingError
 void setLoggingInfo(boolean pLoggingInfo)
          Sets property LoggingInfo
 void setLoggingWarning(boolean pLoggingWarning)
          Sets property LoggingWarning
protected  void setName(java.lang.String pName)
          Sets property Name
protected  void setServletContext(javax.servlet.ServletContext pServletContext)
          Sets property ServletContext
 void startService(javax.servlet.FilterConfig pFilterConfig)
          Called by the filter service after it has been initialzed.
 void stopService()
          Called by the filter service after it has been destroyed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


sResourceBundleName

protected static final java.lang.String sResourceBundleName
See Also:
Constant Field Values

sResourceBundle

protected static final java.util.ResourceBundle sResourceBundle

ENVIRONMENT

protected static final java.lang.String ENVIRONMENT
See Also:
Constant Field Values

ENVIRONMENT_DELIMITER

protected static final java.lang.String ENVIRONMENT_DELIMITER
See Also:
Constant Field Values

CONTEXT

protected static final java.lang.String CONTEXT
See Also:
Constant Field Values

CONTEXT_DELIMITER

protected static final java.lang.String CONTEXT_DELIMITER
See Also:
Constant Field Values

ARRAY_DELIMITER

protected static final java.lang.String ARRAY_DELIMITER
See Also:
Constant Field Values

PERFOP_DOFILTERCHAIN

protected static final java.lang.String PERFOP_DOFILTERCHAIN
See Also:
Constant Field Values

PERFOP_FILTERREQUEST

protected static final java.lang.String PERFOP_FILTERREQUEST
See Also:
Constant Field Values

PERFOP_FILTERRESPONSE

protected static final java.lang.String PERFOP_FILTERRESPONSE
See Also:
Constant Field Values

mFilterConfig

protected javax.servlet.FilterConfig mFilterConfig

mName

protected java.lang.String mName

mServletContext

protected javax.servlet.ServletContext mServletContext

mContext

protected javax.naming.Context mContext

mLoggingInfo

protected boolean mLoggingInfo

mLoggingWarning

protected boolean mLoggingWarning

mLoggingError

protected boolean mLoggingError

mLoggingDebug

protected boolean mLoggingDebug
Constructor Detail

GenericFilterService

public GenericFilterService()
Constructs an instanceof GenericFilterService

Method Detail

setFilterConfig

protected void setFilterConfig(javax.servlet.FilterConfig pFilterConfig)
Sets property FilterConfig


getFilterConfig

public javax.servlet.FilterConfig getFilterConfig()
Returns property FilterConfig


setName

protected void setName(java.lang.String pName)
Sets property Name


getName

public java.lang.String getName()
Returns property Name


setServletContext

protected void setServletContext(javax.servlet.ServletContext pServletContext)
Sets property ServletContext


getServletContext

public javax.servlet.ServletContext getServletContext()
Returns property ServletContext


setContext

protected void setContext(javax.naming.Context pContext)
Sets property Context


getContext

public javax.naming.Context getContext()
Returns property Context


setLoggingInfo

public void setLoggingInfo(boolean pLoggingInfo)
Sets property LoggingInfo


isLoggingInfo

public boolean isLoggingInfo()
Returns property LoggingInfo


setLoggingWarning

public void setLoggingWarning(boolean pLoggingWarning)
Sets property LoggingWarning


isLoggingWarning

public boolean isLoggingWarning()
Returns property LoggingWarning


setLoggingError

public void setLoggingError(boolean pLoggingError)
Sets property LoggingError


isLoggingError

public boolean isLoggingError()
Returns property LoggingError


setLoggingDebug

public void setLoggingDebug(boolean pLoggingDebug)
Sets property LoggingDebug


isLoggingDebug

public boolean isLoggingDebug()
Returns property LoggingDebug


startService

public void startService(javax.servlet.FilterConfig pFilterConfig)
                  throws javax.servlet.ServletException
Called by the filter service after it has been initialzed. Derived classes should override this method

Parameters:
pFilterConfig - filter configuration information.
Throws:
javax.servlet.ServletException - if an exception occurs when starting this filter.

init

public void init(javax.servlet.FilterConfig pFilterConfig)
          throws javax.servlet.ServletException
Called by the web container to indicate to a filter that it is being placed into server.

Specified by:
init in interface javax.servlet.Filter
Parameters:
pFilterConfig - filter configuration information.
Throws:
ServletsException - if an exception occurs when initializing this filter.
javax.servlet.ServletException

doFilter

public void doFilter(javax.servlet.ServletRequest pServletRequest,
                     javax.servlet.ServletResponse pServletResponse,
                     javax.servlet.FilterChain pFilterChain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Called by the web container to indicate that a filter should filter a request/response

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
pServletRequest - the servlet request
pServletResponse - the servlet response
pFilterChain - the filter chain
Throws:
java.io.IOException - when an i/o error occurs
javax.servlet.ServletException - when an error occurs when processing this filter

handleDoFilter

protected void handleDoFilter(javax.servlet.ServletRequest pServletRequest,
                              javax.servlet.ServletResponse pServletResponse,
                              javax.servlet.FilterChain pFilterChain)
                       throws java.io.IOException,
                              javax.servlet.ServletException
Deprecated. 

For backwards compatibility. The code in this method should all be in doFilter. Do not override this method in new classes!

Throws:
java.io.IOException
javax.servlet.ServletException

doFilterRequest

protected boolean doFilterRequest(javax.servlet.http.HttpServletRequest servletRequest,
                                  javax.servlet.http.HttpServletResponse servletResponse,
                                  javax.servlet.FilterChain filterChain)
                           throws java.io.IOException,
                                  javax.servlet.ServletException
Called by the filter to indicate that a filter should filter a request (before the filter chain is called). Derived classes should override this method.

Parameters:
servletRequest -
servletResponse -
Returns:
true if the filter chain should be called, false if the subclass handles calling the filter chain itself
Throws:
java.io.IOException
javax.servlet.ServletException

doFilterRequest

protected boolean doFilterRequest(javax.servlet.ServletRequest pServletRequest,
                                  javax.servlet.ServletResponse pServletResponse,
                                  javax.servlet.FilterChain pFilterChain)
                           throws java.io.IOException,
                                  javax.servlet.ServletException
Called by the web continer to indicate that a filter should filter a request/response

Parameters:
pServletRequest - the servlet request
pServletResponse - the servlet response
pFilterChain - the filter chain
Throws:
java.io.IOException - if an i/o error occurs
javax.servlet.ServletException - if an error occurs when processing this filter

doFilterResponse

protected void doFilterResponse(javax.servlet.ServletRequest servletRequest,
                                javax.servlet.ServletResponse servletResponse,
                                javax.servlet.FilterChain filterChain)
                         throws java.io.IOException,
                                javax.servlet.ServletException
Called by the filter to indicate that a filter should filter a response (after the filter chain has been called). Derived classes can override this method.

Parameters:
servletRequest -
servletResponse -
Throws:
java.io.IOException
javax.servlet.ServletException

doFilterResponse

protected void doFilterResponse(javax.servlet.http.HttpServletRequest servletRequest,
                                javax.servlet.http.HttpServletResponse servletResponse,
                                javax.servlet.FilterChain filterChain)
                         throws java.io.IOException,
                                javax.servlet.ServletException
Throws:
java.io.IOException
javax.servlet.ServletException

doFilterChain

protected void doFilterChain(javax.servlet.ServletRequest pServletRequest,
                             javax.servlet.ServletResponse pServletResponse,
                             javax.servlet.FilterChain pFilterChain)
                      throws java.io.IOException,
                             javax.servlet.ServletException
Called by the filter to indicate that a filter should process the remaining filter chain.

Parameters:
pServletRequest - the servlet request
pServletResponse - the servlet response
pFilterChain - the filter chain
Throws:
java.io.IOException - when an i/o error occurs
javax.servlet.ServletException - when an error occurs when processing this filter

stopService

public void stopService()
Called by the filter service after it has been destroyed. Derived classes should override this method.


destroy

public void destroy()
Called by the web container to indicate to a filter that it is being taken out of service

Specified by:
destroy in interface javax.servlet.Filter

lookup

public java.lang.Object lookup(java.lang.String pName)
                        throws javax.naming.NamingException
Retreives the named object

Parameters:
pName - the name of the object
Returns:
the named object
Throws:
javax.naming.NamingException - if an error occurs

logInfo

public void logInfo(java.lang.String pMessage)
Logs an info event with the specified message


logInfo

public void logInfo(java.lang.Throwable pThrowable)
Logs an info event with the specified Throwable


logInfo

public void logInfo(java.lang.String pMessage,
                    java.lang.Throwable pThrowable)
Logs an info event with the specified message and Throwable


logWarning

public void logWarning(java.lang.String pMessage)
Logs an warning event with the specified message


logWarning

public void logWarning(java.lang.Throwable pThrowable)
Logs an warning event with the specified Throwable


logWarning

public void logWarning(java.lang.String pMessage,
                       java.lang.Throwable pThrowable)
Logs an warning event with the specified message and Throwable


logError

public void logError(java.lang.String pMessage)
Logs an error event with the specified message


logError

public void logError(java.lang.Throwable pThrowable)
Logs an error event with the specified Throwable


logError

public void logError(java.lang.String pMessage,
                     java.lang.Throwable pThrowable)
Logs an error event with the specified message and Throwable


logDebug

public void logDebug(java.lang.String pMessage)
Logs an debug event with the specified message


logDebug

public void logDebug(java.lang.Throwable pThrowable)
Logs an debug event with the specified Throwable


logDebug

public void logDebug(java.lang.String pMessage,
                     java.lang.Throwable pThrowable)
Logs an debug event with the specified message and Throwable