9 Replies Latest reply on Jun 11, 2009 10:55 AM by Stan Silvert

    JSF 1.2

    Matt Choate Newbie

      We are trying to move our application from a JSF 1.1 based AS to a JSF 1.2 AS. In our current implementation we have the pattern where a XMLHttp browser request is made to a servlet which will try to reference the FacesContext in the service() method. This all worked under 1.1 just fine but when we deploy this to a 1.2 based server we get stack traces like:

      java.lang.NullPointerException
      at org.apache.catalina.connector.Request.setAttribute(Request.java:1443)
      at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:503)
      at com.sun.faces.context.RequestMap.put(ExternalContextImpl.java:1087)
      at com.sun.faces.util.RequestStateManager.getStateMap(RequestStateManager.java:281)
      at com.sun.faces.util.RequestStateManager.set(RequestStateManager.java:223)
      at com.sun.faces.el.FacesCompositeELResolver.setChainType(FacesCompositeELResolver.java:159)
      at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:71)
      at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
      at com.sun.faces.application.ValueBindingValueExpressionAdapter.getValue(ValueBindingValueExpressionAdapter.java:113)
      at com.salesgene.servlets.tree.TreeNavigationServlet.service(TreeNavigationServlet.java:54)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at com.salesgene.common.filters.UserSessionFilter.doProcessing(UserSessionFilter.java:355)
      at com.salesgene.common.filters.UserSessionFilter.doFilter(UserSessionFilter.java:197)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)


      This happens in every instance where we try to reference managed beans in a servlet. Oh, and we are getting the FacesContext following this approach:

      LifecycleFactory lifecycleFactory = (LifecycleFactory)
      FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
      Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);

      // Create new FacesContext.
      FacesContextFactory contextFactory = (FacesContextFactory)
      FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
      facesContext = contextFactory.getFacesContext(
      request.getSession().getServletContext(), request, response, lifecycle);

      // Create new View.
      UIViewRoot view = facesContext.getApplication().getViewHandler().createView(
      facesContext, "");
      facesContext.setViewRoot(view);

      // Set current FacesContext.
      FacesContextWrapper.setCurrentInstance(facesContext);


      Any help or advice would be most appreciated!

      -matt

        • 1. Re: JSF 1.2
          Stan Silvert Master

          This looks like a bug. Which exact version of JBoss AS are you using?

          Stan

          • 2. Re: JSF 1.2
            Matt Choate Newbie

            Jboss 5.1.0 GA

            • 3. Re: JSF 1.2
              Stan Silvert Master

              I no longer think it's a bug (in AS or JSF). After looking at the Catalina code where you got the NPE, I think you have a stale ExternalContext reference. I'm guessing this error doesn't happen on every single request?

              Make sure you are properly releasing the FacesContext in your servlet's service() method and you do it in a finally block.

              public void service(ServletRequest req, ServletResponse res) {
              
               FacesContext facesContext = null;
              
               try {
               // assign facesContext
               // blah blah blah
               } finally {
               facesContext.release();
               }
              }


              Stan

              • 4. Re: JSF 1.2
                Matt Choate Newbie

                Correct, it does not happen on every request. I will give this a shot. Should I do this in the servlet requests only or even if I reference a managed bean in the context of a faces request?

                • 5. Re: JSF 1.2
                  Stan Silvert Master

                  If you ever get a FacesContext from the FacesContextFactory then you should release that FacesContext in a finally block at the end of the request. Always do that. Otherwise, the factory can serve up a FacesContext with stale references.

                  Stan

                  • 6. Re: JSF 1.2
                    Matt Choate Newbie

                    Thanks Stan. One more question. So we have that servlet I mentioned before and basically it gets a non JSF request and gets a FacesContext with the purpose of getting a managed session bean to set some values on it. At the end of the request it sends a redirect to a JSF page. That JSF page will use AJAX4JAVA tags (now richfaces I guess). We get this error on that JSF page:

                    09:37:56,031 WARN [JBossManagedConnectionPool] Unable to fill pool
                    org.jboss.resource.JBossResourceException: Could not create connection; - nested
                    throwable: (java.sql.SQLException: Io exception: The Network Adapter could not
                    establish the connection)
                    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.g
                    etLocalManagedConnection(LocalManagedConnectionFactory.java:225)
                    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.c
                    reateManagedConnection(LocalManagedConnectionFactory.java:195)
                    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.cr
                    eateConnectionEventListener(InternalManagedConnectionPool.java:633)
                    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.fi
                    llToMin(InternalManagedConnectionPool.java:541)
                    at org.jboss.resource.connectionmanager.PoolFiller.run(PoolFiller.java:7
                    4)
                    at java.lang.Thread.run(Thread.java:619)
                    Caused by: java.sql.SQLException: Io exception: The Network Adapter could not es
                    tablish the connection
                    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
                    :112)
                    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
                    :146)
                    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
                    :255)
                    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
                    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:
                    414)
                    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
                    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio
                    n.java:35)
                    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
                    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.g
                    etLocalManagedConnection(LocalManagedConnectionFactory.java:207)
                    ... 5 more
                    09:37:56,171 WARN [JBossManagedConnectionPool] Unable to fill pool
                    org.jboss.resource.JBossResourceException: Could not create connection; - nested
                    throwable: (java.sql.SQLException: Io exception: The Network Adapter could not
                    establish the connection)
                    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.g
                    etLocalManagedConnection(LocalManagedConnectionFactory.java:225)
                    at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.c
                    reateManagedConnection(LocalManagedConnectionFactory.java:195)
                    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.cr
                    eateConnectionEventListener(InternalManagedConnectionPool.java:633)
                    at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.fi
                    llToMin(InternalManagedConnectionPool.java:541)
                    at org.jboss.resource.connectionmanager.PoolFiller.run(PoolFiller.java:7
                    4)
                    at java.lang.Thread.run(Thread.java:619)


                    Any ideas? We must be doing something fundamentally wrong in JSF1.2 that worked with JSF1.1 and AJAX4JAVA.

                    -matt

                    • 7. Re: JSF 1.2
                      Stan Silvert Master

                      I don't know off the top of my head but if you google for "unable to fill pool" you should get lots of results.

                      Stan

                      • 8. Re: JSF 1.2
                        Matt Choate Newbie

                        Shoot, I put the wrong stack trace in. This is the stack trace I meant to put in:
                        java.lang.NullPointerException
                        at javax.faces.application.StateManager.saveView(StateManager.java:167)
                        at com.sun.faces.application.ViewHandlerImpl$WriteBehindStateWriter.flus
                        hToWriter(ViewHandlerImpl.java:930)
                        at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.
                        java:205)
                        at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWra
                        pper.java:108)
                        at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.j
                        ava:216)
                        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePha
                        se.java:110)
                        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                        icationFilterChain.java:290)
                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                        ilterChain.java:206)
                        at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(Extensions
                        Filter.java:301)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                        icationFilterChain.java:235)
                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                        ilterChain.java:206)
                        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)

                        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                        icationFilterChain.java:235)
                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                        ilterChain.java:206)
                        at com.salesgene.common.filters.UserSessionFilter.doProcessing(UserSessi
                        onFilter.java:353)
                        at com.salesgene.common.filters.UserSessionFilter.doFilter(UserSessionFi
                        lter.java:195)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                        icationFilterChain.java:235)
                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                        ilterChain.java:206)
                        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
                        lter.java:96)
                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
                        icationFilterChain.java:235)
                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
                        ilterChain.java:206)
                        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
                        alve.java:235)
                        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
                        alve.java:191)
                        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
                        yAssociationValve.java:190)
                        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
                        e.java:92)
                        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.proce
                        ss(SecurityContextEstablishmentValve.java:126)
                        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invok
                        e(SecurityContextEstablishmentValve.java:70)
                        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
                        ava:127)
                        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
                        ava:102)
                        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC
                        onnectionValve.java:158)
                        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
                        ve.java:109)
                        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
                        a:330)
                        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java

                        • 9. Re: JSF 1.2
                          Stan Silvert Master

                          I'm guessing that's the same problem. It's trying to write state out to a stale Writer reference.

                          Stan