8 Replies Latest reply on Feb 22, 2010 11:35 AM by longbeach

    WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped

    longbeach

      Hi,
      I am running a Struts 2 web app on JBoss 6 M1
      A few months ago, I used JBoss 5.1 and the following worked.
      I think the error i get is similar to this one : My Link


      I have this simple JSP logout.jsp where i invalidate the session and redirect the user to another page :




      <%
      
      session.invalidate();
      response.sendRedirect(request.getContextPath() + "/index.jsp");
      
      %> 



      I get the following error :



      org.apache.jasper.JasperException: An exception occurred processing JSP page /login/logout.jsp at line 4
      
      1: <%
      2: 
      3: session.invalidate();
      4: response.sendRedirect(request.getContextPath() + "/index.jsp");
      5: 
      6: %> 
      
      
      Stacktrace:
           org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:498)
           org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
           org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
           org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
           javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
           org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:66)
           org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
           org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      cause m�re
      
      org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
           org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:757)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:139)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:99)
           org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:27)
           org.jboss.weld.conversation.NumericConversationIdGenerator_$$_javassist_37.nextId(NumericConversationIdGenerator_$$_javassist_37.java)
           org.jboss.weld.conversation.ConversationImpl.init(ConversationImpl.java:94)
           sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           java.lang.reflect.Method.invoke(Unknown Source)
           org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
           org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
           org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
           org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)
           org.jboss.weld.introspector.jlr.WeldMethodImpl.invoke(WeldMethodImpl.java:215)
           org.jboss.weld.injection.MethodInjectionPoint.invoke(MethodInjectionPoint.java:106)
           org.jboss.weld.util.Beans.callInitializers(Beans.java:797)
           org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:784)
           org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1$1.proceed(ManagedBean.java:172)
           org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:51)
           org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget$1.work(ManagedBean.java:166)
           org.jboss.weld.bean.ManagedBean$FixInjectionPoint.run(ManagedBean.java:137)
           org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.inject(ManagedBean.java:160)
           org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:324)
           org.jboss.weld.context.AbstractMapContext.get(AbstractMapContext.java:112)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:142)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:99)
           org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:27)
           org.jboss.weld.conversation.ConversationImpl_$$_javassist_36.isTransient(ConversationImpl_$$_javassist_36.java)
           org.jboss.weld.servlet.ConversationPropagationFilter$1.sendRedirect(ConversationPropagationFilter.java:81)
           org.apache.jsp.login.logout_jsp._jspService(logout_jsp.java:56)
           org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
           javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
           org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
           org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
           org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
           javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
           org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:66)
           org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
           org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      note La trace compl�te de la cause m�re de cette erreur est disponible dans les fichiers journaux de JBoss Web/2.1.6.GA.
      



      Any idea how to fix it ? Is it a bug ?
      Thanks.


        • 1. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
          nickarls

          Could you try 1.0.1.RC2 as I recall both context activation and session invalidation recovery has been improved since then?

          • 2. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
            dan.j.allen

            I just tried this against 1.0.1-CR2 and got the same result.


            13:19:21,472 INFO  [Version] WELD-000900 1.0.1 (CR2)



            One place this error shows up is in applications created by the Weld archetypes (I used the Java EE minimal).


            Here is the JSP code for the /index.jsp redirector page:


            <% response.sendRedirect("home.jsf"); %>



            Here is the resulting exception:


            13:21:02,165 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/widgets-jee].[jsp]] Servlet.service() for servlet jsp threw exception: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type @ConversationScoped
                 at org.jboss.weld.conversation.ConversationImpl.checkConversationActive(ConversationImpl.java:79)
                 at org.jboss.weld.conversation.ConversationImpl.isTransient(ConversationImpl.java:234)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:597)
                 at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
                 at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
                 at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
                 at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)
                 at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:112)
                 at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
                 at org.jboss.weld.conversation.ConversationImpl_$$_javassist_9.isTransient(ConversationImpl_$$_javassist_9.java)
                 at org.jboss.weld.servlet.ConversationPropagationFilter$1.sendRedirect(ConversationPropagationFilter.java:81)
                 at org.apache.jsp.index_jsp._jspService(index_jsp.java:53)
                    ...



            Looks like we might need an issue report. I'd say this is critical for 1.0.1.

            • 3. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
              dan.j.allen

              I'll explain the bug in the code.


              The ConversationPropagationFilter is wrapping all requests (not just JSF requests). The conversation scope is only active during JSF requests. The problem comes when ConversationPropagationFilter traps calls to sendRedirect(). It first checks whether the conversation is transient. But this check mandates that the conversation scope be active.


              @Override
              public void sendRedirect(String path) throws IOException
              {
                 ConversationImpl conversation = conversation(ctx);
                 if (!conversation.isTransient())
                 {
                    ...
                 }
                 super.sendRedirect(path);
              }



              public boolean isTransient()
              {
                 checkConversationActive();
                 return _transient;
              }



              I don't understand why isTransient() is enforcing that a conversation be active. If it's not active, then that should be considered transient (or there needs to be a portable way of checking if it's active.

              • 4. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
                nickarls

                Actually 6.7.4 says


                The conversation scope is active during all standard lifecycle phases of any JSF faces or non-faces request.
                



                So the conversation scope should actually be activated/deactivated in a requestlistener.


                6.7.5 says


                If any method of Conversation is called when the conversation scope is not active, a ContextNotActiveException is
                thrown.
                



                I have a bunch of conversation-related changed in my tree waiting to go in after my winter vacation (this week) and Pete's release. This should fix the above issue in the first place, methinks. It also includes proposal + implementation of the ConversationManager API which would allow for checking/activating/deactivating the conversation context in a portable way.


                A quick fix would be to have a non-portable exit-early check on non-active context in the filter until it is fixed properly if you want to fix it for 1.0.1 (and Pete thinks it's OK)

                • 5. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
                  pmuir

                  Dan Allen wrote on Feb 20, 2010 19:37:


                  I don't understand why isTransient() is enforcing that a conversation be active. If it's not active, then that should be considered transient (or there needs to be a portable way of checking if it's active.


                  As Nik says, this is specified. You can check if a context is active like:


                  boolean isContextActive(Class<?> scope) {
                     try {
                        beanManager.getContext(scope};
                     } catch (ContextNotActiveException e) {
                        return false;
                     }
                     return true;
                  }





                  A quick fix would be to have a non-portable exit-early check on non-active context in the filter until it is fixed properly if you want to fix it for 1.0.1 (and Pete thinks it's OK)


                  Right, this is a good suggestion, I'll apply to my tree locally. The filter isn't portable anyway.

                  • 6. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
                    pmuir

                    Fixed :-)

                    • 7. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
                      dan.j.allen

                      Pete Muir wrote on Feb 21, 2010 12:32:



                      Dan Allen wrote on Feb 20, 2010 19:37:


                      I don't understand why isTransient() is enforcing that a conversation be active. If it's not active, then that should be considered transient (or there needs to be a portable way of checking if it's active.


                      As Nik says, this is specified. You can check if a context is active like:

                      boolean isContextActive(Class<?> scope) {
                         try {
                            beanManager.getContext(scope};
                         } catch (ContextNotActiveException e) {
                            return false;
                         }
                         return true;
                      }





                      Ah. Of course. Duh. I couldn't think of the syntax off the top of my head.


                      Glad you got it fixed up. I wanted to avoid one of those minor, but damaging broken windows in the release :)

                      • 8. Re: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
                        longbeach

                        thanks for the update, i'll check it soon.