org.springframework.extensions.jcr.support
Class OpenSessionInViewFilter

java.lang.Object
  extended by org.springframework.web.filter.GenericFilterBean
      extended by org.springframework.web.filter.OncePerRequestFilter
          extended by org.springframework.extensions.jcr.support.OpenSessionInViewFilter
All Implemented Interfaces:
javax.servlet.Filter, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.web.context.ServletContextAware

public class OpenSessionInViewFilter
extends org.springframework.web.filter.OncePerRequestFilter

Servlet 2.3 Filter that binds a JCR Session to the thread for the entire processing of the request. Intended for the "Open Session in View" pattern, i.e. to allow for lazy loading in web views despite the original transactions already being completed.

This filter works similar to the AOP JcrInterceptor: It just makes JCR Sessions available via the thread. It is suitable for non-transactional execution but also for business layer transactions via JcrTransactionManager or JtaTransactionManager. In the latter case, Sessions pre-bound by this filter will automatically be used for the transactions.

Looks up the SessionFactory in Spring's root web application context. Supports a "SessionFactoryBeanName" filter init-param in web.xml ; the default bean name is "SessionFactory". Looks up the SessionFactory on each request, to avoid initialization order issues (when using ContextLoaderServlet, the root application context will get initialized after this filter).

Author:
Costin Leau, Sergio Bossa, Salvatore Incandela

Field Summary
static java.lang.String DEFAULT_JCR_SESSION_FACTORY_FACTORY_BEAN_NAME
           
 
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
 
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
 
Constructor Summary
OpenSessionInViewFilter()
           
 
Method Summary
protected  void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain)
           
protected  java.lang.String getSessionFactoryBeanName()
          Return the bean name of the SessionFactory to fetch from Spring's root application context.
protected  SessionFactory lookupSessionFactory()
          Look up the SessionFactory that this filter should use.
protected  SessionFactory lookupSessionFactory(javax.servlet.http.HttpServletRequest request)
          Look up the SessionFactory that this filter should use, taking the current HTTP request as argument.
 void setSessionFactoryBeanName(java.lang.String SessionFactoryBeanName)
          Set the bean name of the SessionFactory to fetch from Spring's root application context.
 
Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, shouldNotFilter
 
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setServletContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_JCR_SESSION_FACTORY_FACTORY_BEAN_NAME

public static final java.lang.String DEFAULT_JCR_SESSION_FACTORY_FACTORY_BEAN_NAME
See Also:
Constant Field Values
Constructor Detail

OpenSessionInViewFilter

public OpenSessionInViewFilter()
Method Detail

setSessionFactoryBeanName

public void setSessionFactoryBeanName(java.lang.String SessionFactoryBeanName)
Set the bean name of the SessionFactory to fetch from Spring's root application context. Default is "SessionFactory".

See Also:
DEFAULT_JCR_SESSION_FACTORY_FACTORY_BEAN_NAME

getSessionFactoryBeanName

protected java.lang.String getSessionFactoryBeanName()
Return the bean name of the SessionFactory to fetch from Spring's root application context.


doFilterInternal

protected void doFilterInternal(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response,
                                javax.servlet.FilterChain filterChain)
                         throws javax.servlet.ServletException,
                                java.io.IOException
Specified by:
doFilterInternal in class org.springframework.web.filter.OncePerRequestFilter
Throws:
javax.servlet.ServletException
java.io.IOException

lookupSessionFactory

protected SessionFactory lookupSessionFactory(javax.servlet.http.HttpServletRequest request)
Look up the SessionFactory that this filter should use, taking the current HTTP request as argument.

Default implementation delegates to the lookupSessionFactory without arguments.

Returns:
the SessionFactory to use
See Also:
lookupSessionFactory()

lookupSessionFactory

protected SessionFactory lookupSessionFactory()
Look up the SessionFactory that this filter should use. The default implementation looks for a bean with the specified name in Spring's root application context.

Returns:
the SessionFactory to use
See Also:
getSessionFactoryBeanName()


Copyright © 2009. All Rights Reserved.