webtier@glassfish.java.net

JSF2 Question on Filters/FacesContext/Request behavior

From: Lincoln Baxter, III <lincolnbaxter_at_gmail.com>
Date: Thu, 02 Apr 2009 23:37:26 -0400

When attempting to set an EL value from the Request (in a Servlet
Filter, manually initializing FacesContext) I seem to be getting
somewhat sporadic NullPointerExceptions. Most of the time this works,
but 1/10 times it does not. Any thoughts as to how this could be done
correctly? Should I be using Faces/EL to store/retrieve values from the
Request in a Filter? Should I just do it myself manually?

This is running on Tomcat and the 3/31 nightly snapshot.

Thanks,
Lincoln

Caused by: java.lang.NullPointerException
        at
org.apache.catalina.connector.Request.setAttribute(Request.java:1424)
        at
org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:503)
        at
javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:284)
        at com.sun.faces.context.RequestMap.put(RequestMap.java:97)
        at com.sun.faces.context.RequestMap.put(RequestMap.java:50)
        at com.sun.faces.mgbean.BeanManager$ScopeManager
$RequestScopeHandler.handle(BeanManager.java:457)
        at com.sun.faces.mgbean.BeanManager
$ScopeManager.pushToScope(BeanManager.java:442)
        at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:393)
        at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:254)
        at
com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
        at
com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
        at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
        at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
        at
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at com.ocpsoft.pretty.util.FacesElUtils.getValue(FacesElUtils.java:63)
        at
com.ocpsoft.pretty.PrettyContext.getCurrentInstance(PrettyContext.java:73)
        at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:65)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
com.ocpsoft.socialpm.jsf.filter.DataSetupFilter.doFilter(DataSetupFilter.java:255)
        at
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
        at
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
        at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
        at
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
        at
org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
        at
org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:173)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:271)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
        at
org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
        at org.springframework.security.util.FilterChainProxy
$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
        at
org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174)
        at
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
        at
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
com.ocpsoft.socialpm.jsf.filter.ExceptionFilter.doFilter(ExceptionFilter.java:39)
        ... 12 more