10 Replies Latest reply on Mar 7, 2012 1:06 AM by lszymik

    CDI request scope is not active during EJB method invocation

    maxsilva

      Hi,

       

      I have installed jboss 7.1.0-snapshot today because I need request scope context in ejb.

      That issue was resolved conform https://issues.jboss.org/browse/AS7-3129. However

      I make tests and this issue there is yet:

       

      16:30:10,813 INFO  [org.jboss.ejb.client] (http-localhost-127.0.0.1-8080-1) JBoss EJB Client version 1.0.0.Beta12

      16:30:10,906 ERROR [org.jboss.ejb3.invocation] (http-localhost-127.0.0.1-8080-1) JBAS014134: EJB Invocation failed on component BaseProvider for method public abstract java.lang.Integer br.gov.mg.mp.mpmg.container.IEntityProvider.getEntityCount(br.gov.mg.mp.mpmg.container.QueryProperty,java.lang.Class): javax.ejb.EJBException: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped

                at org.jboss.as.ejb3.tx.BMTInterceptor.handleException(BMTInterceptor.java:78) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

      Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped

                at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:598) [weld-core-1.1.5.Final.jar:2012-01-06 11:59]

       

      Below, my source:

       

      @RequestScoped

      public class EntityManagerProducer implements Serializable {

           ...

                @Inject

                private EntityManagerFactoryProducer factory;

           ...

                @Default

                @Produces

                public EntityManager create(InjectionPoint ip, EntityManagerConfig config) {

                          String persistenceUnit = getPersistenceUnit(ip, config);

                          return new EntityManagerProxy(persistenceUnit);

                }

           ...

       

      Please, the 7.1 snapshot version don´t have that issue resolved?

       

      Thanks in advanced,

       

      Maxwell

        • 1. Re: CDI request scope is not active during EJB method invocation
          jaikiran

          Can you please paste the entire exception stacktrace?

          • 2. Re: CDI request scope is not active during EJB method invocation
            alesj

            We had this issue in AS6:

            * https://github.com/weld/core/pull/123

            But it looks like it's still there for AS7?

            e.g. a proper interceptor needs to be added which takes care of associating EJB request with CDI request scope (and dissociate later)

            • 3. Re: CDI request scope is not active during EJB method invocation
              jaikiran

              As per https://issues.jboss.org/browse/AS7-3129 this should have been fixed in AS7 upstream. So not sure why the user is still seeing this issue.

              • 4. Re: CDI request scope is not active during EJB method invocation
                maxsilva

                Hi Jaikiran Pai,

                 

                Its should have been fixed, but it isn´t.

                 

                Please, Is possible to verify this issue? Or reopen it? Request scope is very important aspect.

                 

                Maxwell

                • 5. Re: CDI request scope is not active during EJB method invocation
                  swd847

                  Would you be able to provide more details about your application? In particular, is your ejb deployed in a jar with a beans.xml?

                  • 6. Re: CDI request scope is not active during EJB method invocation
                    maxsilva

                    Hi Stuart,

                     

                    My ejb is deployed in jar with beans.xml. Below my structure:

                     

                    --> my.ear

                         --> lib

                              --> my_entitymanager_producer.jar  (here, I have @RequestScoped public class EntityManagerProducer like first post message)

                         --> mycore_ejb.jar (here, my ejb stateless and remote, with @TransactionManagement(TransactionManagementType.BEAN), inject an entitymanager, so EntityManagerProducer should get in action)                   

                                   @Stateless

                                   @Remote(value = {IEntityProvider.class })

                                   @TransactionManagement(TransactionManagementType.BEAN)

                                   public class BaseProvider<T> implements IEntityProvider<T> {

                                        @inject

                                        EntityManager entityManager;

                                   ...

                     

                    It has beans.xml in my_entitymanager_producer.jar and in mycore_ejb.jar too (in META-INF).

                     

                    If I write a javax.enterprise.inject.spi.Extension file, declaring my.internal.CoreBootstrap and implement this CoreBootstrap (all in mycore_ejb.jar) like below, I don't get CDI request scope exception, but I don't think it is a good idea.

                         public class CoreBootstrap extends AbstractBootstrap {

                                          public void loadContext(@Observes final AfterBeanDiscovery event) {

                                                       addContext(new ThreadLocalContext(RequestScoped.class), event);

                                                       addContext(new ThreadLocalContext(SessionScoped.class), event);

                                        }

                          }

                     

                    Would you help? Would I do anything else?

                     

                    Thank you very much,

                    • 7. Re: CDI request scope is not active during EJB method invocation
                      maxsilva

                      Hi

                       

                      I have a more simple, very simple, example:

                       

                      @Stateless

                      @Remote(SRUNoticiaDeFato.class)

                      @TransactionManagement(TransactionManagementType.CONTAINER)

                      public class SRUNoticiaDeFatoBean implements  SRUNoticiaDeFato  {

                       

                                @Inject

                                private INoticiaFactory bean;

                       

                                public SRUNoticiaDeFatoBean() {

                                }

                       

                                @Override

                                public String instaura() {

                                               return bean.instaura();

                                }

                      }

                       

                      @RequestScoped

                      public class NoticiaFactory implements INoticiaFactory {

                       

                           private Integer test=0;

                       

                                @Override

                                public String instaura() { 

                                          test++;

                                          return test.toString();

                           }

                      }

                       

                      Below, a Servlet to execute ejb:

                       

                      public class TestServlet extends HttpServlet {

                       

                                private static final long serialVersionUID = 1L;

                       

                                @EJB(mappedName="java:global/SRU-EJBEAR/SRU-EJB/SRUNoticiaDeFatoBean")

                                private SRUNoticiaDeFato bean;

                            

                          public TestServlet() {

                                super();

                          }              

                       

                                 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                                response.setContentType("text/html;charset=UTF-8");

                                PrintWriter out = response.getWriter();

                       

                                out.println("<html>");

                                out.println("<head>");

                                out.println("<title>Ejb test</title>");

                                out.println("</head>");

                                out.println("<body>");

                       

                                out.println("<h1>"+bean.instaura()+"</h1>");

                                   

                                out.println("</body>");

                                out.println("</html>");

                       

                                out.close();

                                }

                      }

                       

                      The request scoped exception:

                      15:44:52,915 ERROR [org.jboss.ejb3.invocation] (http-localhost-127.0.0.1-8080-2) JBAS014134: EJB Invocation failed on component SRUNoticiaDeFatoBean for method public abstract java.lang.String br.mg.mp.sruejbclient.SRUNoticiaDeFato.instaura(): javax.ejb.EJBException: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped

                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:230) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropogatingInterceptor.processInvocation(EJBRemoteTransactionPropogatingInterceptor.java:80) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:57) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:175) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:173) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.java:43) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:92) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:122) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:107) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:90) [jboss-ejb-client-1.0.0.Beta12.jar:1.0.0.Beta12]

                                at $Proxy36.instaura(Unknown Source)          at br.gov.mg.mp.sruebjtest.TestServlet.doGet(TestServlet.java:85) [classes:]

                                at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

                                at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

                                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.9.Final.jar:]

                                at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.Final.jar:2012-01-06 11:59]

                                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.9.Final.jar:]

                                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:155) [jboss-as-web-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.9.Final.jar:]

                                at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2033) [jbossweb-7.0.9.Final.jar:]

                                at java.lang.Thread.run(Thread.java:662) [:1.6.0_26]

                      Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped

                                at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:598) [weld-core-1.1.5.Final.jar:2012-01-06 11:59]

                                at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71) [weld-core-1.1.5.Final.jar:2012-01-06 11:59]

                                at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79) [weld-core-1.1.5.Final.jar:2012-01-06 11:59]

                                at br.mg.mp.sruejb.NoticiaFactory$Proxy$_$$_WeldClientProxy.instaura(NoticiaFactory$Proxy$_$$_WeldClientProxy.java)

                                at br.mg.mp.sruejb.SRUNoticiaDeFatoBean.instaura(SRUNoticiaDeFatoBean.java:38)

                                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_26]

                                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_26]

                                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_26]

                                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_26]

                                at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:127) [jboss-as-weld-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:135) [jboss-as-weld-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:45)

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:84) [jboss-as-weld-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

                                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.0.Final-SNAPSHOT.jar:7.1.0.Final-SNAPSHOT]

                                ... 44 more

                       

                      I had used jboss 7.1 nightly build.

                      • 8. Re: CDI request scope is not active during EJB method invocation
                        swd847

                        Can you send me a test case that reproduces this?

                        • 9. Re: CDI request scope is not active during EJB method invocation
                          maxsilva

                          Hi Stuart,

                           

                          Here my tests cases.

                           

                          test1 is more simple, like last source in post.

                          https://docs.google.com/open?id=0B9jZG_HuBATiZjhlNzU5N2YtY2EyZC00ZGY1LWI0MDktNzQwZTQ2NDM5Y2Rh

                          (go File menu -> download)

                           

                          test2 is using producer with request scoped context.

                          https://docs.google.com/open?id=0B9jZG_HuBATiYWRlNjhkYzMtY2YzOC00ZDM2LWI1MDAtZGU3M2E4MGU3MmVi

                          (go File menu -> download)

                           

                          Please, I would like your help.

                           

                          Thanks

                          • 10. Re: CDI request scope is not active during EJB method invocation
                            lszymik

                            Hi,

                             

                            I have exactly the same issue. I have application splitted into two separated items: business logic server placed in EAR file and WAR file with web page which is accessing EAR with remote interface. The WAR module is using simple InitialContext to lookup remote bean and perform actions. As soon as remote bean is invoked the No active contexts for scope type javax.enterprise.context.RequestScoped exception oocurs.

                             

                            This is bloker for me now with porting from JBoss6 -> JBoss7.1

                             

                            Could you please help me with fixing it? Thanks in advance.