org.nanocontainer.nanowar
Class ServletContainerProxyFilter

java.lang.Object
  extended by org.nanocontainer.nanowar.ServletContainerProxyFilter
All Implemented Interfaces:
javax.servlet.Filter

public class ServletContainerProxyFilter
extends Object
implements javax.servlet.Filter

ServletContainerProxyFilter is a Filter which delegates to any Filter which is registered in a PicoContainer, in any of the web scopes: context, session or request. This form of delegation is particularly useful as it brings dependency injections to filters. In fact the delegate filter may be implemented via any form of dependency injection.

The delegate Filter must be registered via the delegate-key or delegate-class init-params of this Filter.

The initialization is done lazily, using the init-type init-param to control it. Allowed values are:

The default is "context".

The lookup in the PicoContainer is by default done for each request, but you can control that behaviour with the lookup-only-once init-param. If set to "true", ServletContainerProxyFilter will only lookup your delegate filter at the first request.

Note: Be aware that any dependency on your filter, in this setup, will stay referenced by your filter for its whole lifetime, even though this dependency might have been set up at request level in your composer!

Author:
Grégory Joseph, Mauro Talevi

Constructor Summary
ServletContainerProxyFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain filterChain)
           
 void init(javax.servlet.FilterConfig filterConfig)
           
protected  void initDelegate()
           
protected  void lookupDelegate(javax.servlet.http.HttpServletRequest request)
          Looks up delegate Filter in PicoContainer found in any of the web scopes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletContainerProxyFilter

public ServletContainerProxyFilter()
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

doFilter

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

destroy

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

initDelegate

protected void initDelegate()
                     throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException

lookupDelegate

protected void lookupDelegate(javax.servlet.http.HttpServletRequest request)
Looks up delegate Filter in PicoContainer found in any of the web scopes.

Parameters:
request - the HttpServletRequest used to find the PicoContainer
Throws:
org.picocontainer.PicoInitializationException - if the delegate Filter cannot be found


Copyright © 2003-2009 Codehaus. All Rights Reserved.