org.jasig.springframework.web.portlet.filter
Class DelegatingPortletFilterProxy

java.lang.Object
  extended by org.jasig.springframework.web.portlet.filter.GenericPortletFilterBean
      extended by org.jasig.springframework.web.portlet.filter.DelegatingPortletFilterProxy
All Implemented Interfaces:
javax.portlet.filter.ActionFilter, javax.portlet.filter.EventFilter, javax.portlet.filter.PortletFilter, javax.portlet.filter.RenderFilter, javax.portlet.filter.ResourceFilter, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.EnvironmentAware, org.springframework.web.portlet.context.PortletContextAware

public class DelegatingPortletFilterProxy
extends GenericPortletFilterBean

Proxy for a standard Portlet 2.0 Filter, delegating to a Spring-managed bean that implements the Filter interface. Supports a "targetBeanName" filter init-param in portlet.xml, specifying the name of the target bean in the Spring application context.

portlet.xml will usually contain a DelegatingPortletFilterProxy definition, with the specified filter-name corresponding to a bean name in Spring's root portlet application context. All calls to the filter proxy will then be delegated to that bean in the Spring context, which is required to implement the standard Portlet 2.0 Filter interface.

This approach is particularly useful for Filter implementation with complex setup needs, allowing to apply the full Spring bean definition machinery to Filter instances. Alternatively, consider standard Filter setup in combination with looking up service beans from the Spring root application context.

NOTE: The lifecycle methods defined by the Portlet Filter interface will by default not be delegated to the target bean, relying on the Spring application context to manage the lifecycle of that bean. Specifying the "targetFilterLifecycle" filter init-param as "true" will enforce invocation of the PortletFilter.init and PortletFilter.destroy lifecycle methods on the target bean, letting the portlet container manage the filter lifecycle.

This class was originally inspired by Spring's DelegatingFilterProxy

Author:
Eric Dalquist
See Also:
setTargetBeanName(java.lang.String), setTargetFilterLifecycle(boolean), ActionFilter.doFilter(javax.portlet.ActionRequest, javax.portlet.ActionResponse, javax.portlet.filter.FilterChain), EventFilter.doFilter(javax.portlet.EventRequest, javax.portlet.EventResponse, javax.portlet.filter.FilterChain), RenderFilter.doFilter(javax.portlet.RenderRequest, javax.portlet.RenderResponse, javax.portlet.filter.FilterChain), ResourceFilter.doFilter(javax.portlet.ResourceRequest, javax.portlet.ResourceResponse, javax.portlet.filter.FilterChain), PortletFilter.init(javax.portlet.filter.FilterConfig), PortletFilter.destroy(), #DelegatingFilterProxy(Filter), #DelegatingFilterProxy(String), #DelegatingFilterProxy(String, WebApplicationContext), WebApplicationInitializer

Field Summary
 
Fields inherited from class org.jasig.springframework.web.portlet.filter.GenericPortletFilterBean
logger
 
Constructor Summary
DelegatingPortletFilterProxy()
           
 
Method Summary
 void destroy()
          Subclasses may override this to perform custom filter shutdown.
protected  void destroyDelegate(javax.portlet.filter.PortletFilter delegate)
          Destroy the PortletFilter delegate.
 void doFilter(javax.portlet.ActionRequest request, javax.portlet.ActionResponse response, javax.portlet.filter.FilterChain chain)
          Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)
 void doFilter(javax.portlet.EventRequest request, javax.portlet.EventResponse response, javax.portlet.filter.FilterChain chain)
          Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)
 void doFilter(javax.portlet.RenderRequest request, javax.portlet.RenderResponse response, javax.portlet.filter.FilterChain chain)
          Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)
 void doFilter(javax.portlet.ResourceRequest request, javax.portlet.ResourceResponse response, javax.portlet.filter.FilterChain chain)
          Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)
protected  org.springframework.context.ApplicationContext findWebApplicationContext()
          Retrieve a WebApplicationContext from the PortletContext.
 String getContextAttribute()
          Return the name of the ServletContext attribute which should be used to retrieve the PortletApplicationContext from which to load the delegate PortletFilter bean.
protected  String getTargetBeanName()
          Return the name of the target bean in the Spring application context.
protected  void initDelegate(boolean require)
          Initialize the PortletFilter delegate, defined as bean the given Spring application context.
protected  void initFilterBean()
          Subclasses may override this to perform custom initialization.
protected  void invokeDelegate(javax.portlet.filter.ActionFilter delegate, javax.portlet.ActionRequest request, javax.portlet.ActionResponse response, javax.portlet.filter.FilterChain filterChain)
          Actually invoke the delegate ActionFilter with the given request and response.
protected  void invokeDelegate(javax.portlet.filter.EventFilter delegate, javax.portlet.EventRequest request, javax.portlet.EventResponse response, javax.portlet.filter.FilterChain filterChain)
          Actually invoke the delegate EventFilter with the given request and response.
protected  void invokeDelegate(javax.portlet.filter.RenderFilter delegate, javax.portlet.RenderRequest request, javax.portlet.RenderResponse response, javax.portlet.filter.FilterChain filterChain)
          Actually invoke the delegate RenderFilter with the given request and response.
protected  void invokeDelegate(javax.portlet.filter.ResourceFilter delegate, javax.portlet.ResourceRequest request, javax.portlet.ResourceResponse response, javax.portlet.filter.FilterChain filterChain)
          Actually invoke the delegate ResourceFilter with the given request and response.
protected  boolean isTargetFilterLifecycle()
          Return whether to invoke the PortletFilter.init and PortletFilter.destroy lifecycle methods on the target bean.
 void setContextAttribute(String contextAttribute)
          Set the name of the ServletContext attribute which should be used to retrieve the PortletApplicationContext from which to load the delegate PortletFilter bean.
 void setTargetBeanName(String targetBeanName)
          Set the name of the target bean in the Spring application context.
 void setTargetFilterLifecycle(boolean targetFilterLifecycle)
          Set whether to invoke the PortletFilter.init and PortletFilter.destroy lifecycle methods on the target bean.
 
Methods inherited from class org.jasig.springframework.web.portlet.filter.GenericPortletFilterBean
addRequiredProperty, afterPropertiesSet, doCommonFilter, getFilterConfig, getFilterName, getPortletContext, init, initBeanWrapper, setBeanName, setEnvironment, setPortletContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingPortletFilterProxy

public DelegatingPortletFilterProxy()
Method Detail

setContextAttribute

public void setContextAttribute(String contextAttribute)
Set the name of the ServletContext attribute which should be used to retrieve the PortletApplicationContext from which to load the delegate PortletFilter bean.


getContextAttribute

public String getContextAttribute()
Return the name of the ServletContext attribute which should be used to retrieve the PortletApplicationContext from which to load the delegate PortletFilter bean.


setTargetBeanName

public void setTargetBeanName(String targetBeanName)
Set the name of the target bean in the Spring application context. The target bean must implement the standard Portlet 2.0 PortletFilter interface.

By default, the filter-name as specified for the DelegatingPortletFilterProxy in portlet.xml will be used.


getTargetBeanName

protected String getTargetBeanName()
Return the name of the target bean in the Spring application context.


setTargetFilterLifecycle

public void setTargetFilterLifecycle(boolean targetFilterLifecycle)
Set whether to invoke the PortletFilter.init and PortletFilter.destroy lifecycle methods on the target bean.

Default is "false"; target beans usually rely on the Spring application context for managing their lifecycle. Setting this flag to "true" means that the portlet container will control the lifecycle of the target PortletFilter, with this proxy delegating the corresponding calls.


isTargetFilterLifecycle

protected boolean isTargetFilterLifecycle()
Return whether to invoke the PortletFilter.init and PortletFilter.destroy lifecycle methods on the target bean.


initFilterBean

protected void initFilterBean()
                       throws javax.portlet.PortletException
Description copied from class: GenericPortletFilterBean
Subclasses may override this to perform custom initialization. All bean properties of this filter will have been set before this method is invoked.

Note: This method will be called from standard filter initialization as well as filter bean initialization in a Spring application context. Filter name and PortletContext will be available in both cases.

This default implementation is empty.

Overrides:
initFilterBean in class GenericPortletFilterBean
Throws:
javax.portlet.PortletException - if subclass initialization fails
See Also:
GenericPortletFilterBean.getFilterName(), GenericPortletFilterBean.getPortletContext()

doFilter

public void doFilter(javax.portlet.ResourceRequest request,
                     javax.portlet.ResourceResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Description copied from class: GenericPortletFilterBean
Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.ResourceFilter
Overrides:
doFilter in class GenericPortletFilterBean
Throws:
IOException
javax.portlet.PortletException

doFilter

public void doFilter(javax.portlet.EventRequest request,
                     javax.portlet.EventResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Description copied from class: GenericPortletFilterBean
Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.EventFilter
Overrides:
doFilter in class GenericPortletFilterBean
Throws:
IOException
javax.portlet.PortletException

doFilter

public void doFilter(javax.portlet.RenderRequest request,
                     javax.portlet.RenderResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Description copied from class: GenericPortletFilterBean
Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.RenderFilter
Overrides:
doFilter in class GenericPortletFilterBean
Throws:
IOException
javax.portlet.PortletException

doFilter

public void doFilter(javax.portlet.ActionRequest request,
                     javax.portlet.ActionResponse response,
                     javax.portlet.filter.FilterChain chain)
              throws IOException,
                     javax.portlet.PortletException
Description copied from class: GenericPortletFilterBean
Calls GenericPortletFilterBean.doCommonFilter(PortletRequest, PortletResponse, FilterChain)

Specified by:
doFilter in interface javax.portlet.filter.ActionFilter
Overrides:
doFilter in class GenericPortletFilterBean
Throws:
IOException
javax.portlet.PortletException

destroy

public void destroy()
Description copied from class: GenericPortletFilterBean
Subclasses may override this to perform custom filter shutdown.

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.

Specified by:
destroy in interface javax.portlet.filter.PortletFilter
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Overrides:
destroy in class GenericPortletFilterBean

findWebApplicationContext

protected org.springframework.context.ApplicationContext findWebApplicationContext()
Retrieve a WebApplicationContext from the PortletContext. The WebApplicationContext must have already been loaded and stored in the PortletContext before this filter gets initialized (or invoked).

Subclasses may override this method to provide a different WebApplicationContext retrieval strategy.

Returns:
the WebApplicationContext for this proxy, or null if not found

initDelegate

protected void initDelegate(boolean require)
                     throws javax.portlet.PortletException
Initialize the PortletFilter delegate, defined as bean the given Spring application context.

The default implementation fetches the bean from the application context and calls the standard PortletFilter.init method on it, passing in the FilterConfig of this PortletFilter proxy.

Parameters:
wac - the root application context
Throws:
javax.portlet.PortletException - if thrown by the PortletFilter
See Also:
getTargetBeanName(), isTargetFilterLifecycle(), GenericPortletFilterBean.getFilterConfig(), PortletFilter.init(javax.portlet.filter.FilterConfig)

invokeDelegate

protected void invokeDelegate(javax.portlet.filter.ActionFilter delegate,
                              javax.portlet.ActionRequest request,
                              javax.portlet.ActionResponse response,
                              javax.portlet.filter.FilterChain filterChain)
                       throws javax.portlet.PortletException,
                              IOException
Actually invoke the delegate ActionFilter with the given request and response.

Parameters:
delegate - the delegate ActionFilter
request - the current action request
response - the current action response
filterChain - the current FilterChain
Throws:
javax.portlet.PortletException - if thrown by the PortletFilter
IOException - if thrown by the PortletFilter

invokeDelegate

protected void invokeDelegate(javax.portlet.filter.EventFilter delegate,
                              javax.portlet.EventRequest request,
                              javax.portlet.EventResponse response,
                              javax.portlet.filter.FilterChain filterChain)
                       throws javax.portlet.PortletException,
                              IOException
Actually invoke the delegate EventFilter with the given request and response.

Parameters:
delegate - the delegate EventFilter
request - the current Event request
response - the current Event response
filterChain - the current FilterChain
Throws:
javax.portlet.PortletException - if thrown by the PortletFilter
IOException - if thrown by the PortletFilter

invokeDelegate

protected void invokeDelegate(javax.portlet.filter.RenderFilter delegate,
                              javax.portlet.RenderRequest request,
                              javax.portlet.RenderResponse response,
                              javax.portlet.filter.FilterChain filterChain)
                       throws javax.portlet.PortletException,
                              IOException
Actually invoke the delegate RenderFilter with the given request and response.

Parameters:
delegate - the delegate RenderFilter
request - the current Render request
response - the current Render response
filterChain - the current FilterChain
Throws:
javax.portlet.PortletException - if thrown by the PortletFilter
IOException - if thrown by the PortletFilter

invokeDelegate

protected void invokeDelegate(javax.portlet.filter.ResourceFilter delegate,
                              javax.portlet.ResourceRequest request,
                              javax.portlet.ResourceResponse response,
                              javax.portlet.filter.FilterChain filterChain)
                       throws javax.portlet.PortletException,
                              IOException
Actually invoke the delegate ResourceFilter with the given request and response.

Parameters:
delegate - the delegate ResourceFilter
request - the current Resource request
response - the current Resource response
filterChain - the current FilterChain
Throws:
javax.portlet.PortletException - if thrown by the PortletFilter
IOException - if thrown by the PortletFilter

destroyDelegate

protected void destroyDelegate(javax.portlet.filter.PortletFilter delegate)
Destroy the PortletFilter delegate. Default implementation simply calls PortletFilter.destroy on it.

Parameters:
delegate - the PortletFilter delegate (never null)
See Also:
isTargetFilterLifecycle(), PortletFilter.destroy()


Copyright © 2013 Jasig. All Rights Reserved.