5 Replies Latest reply on Oct 29, 2013 5:41 AM by Martin Kouba

    Message driven bean calling EJB produces WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped

    Tim Pro Newbie

      Looking for help resolving the stated error.  I am running on JBoss AS 7.1.2, WELD 1.8, and receive the error WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped.  Since this is an unchecked exception it is being swallowed by the app server, but I am picking this error up in my app monitoring tool logs.  The code structure is a message driven bean making a call to an EJB.  The code is using annotations and CDI.  Any insight to how why this error is occurring is appreciated.   Code samples provided below.

       

      MessageConsumerBean.java

      public abstract class MessagingConsumerBean implements MessageListener {

          @EJB

          protected MessagingClient messagingClient;

          @Resource

          protected MessageDrivenContext ctx;

        @Inject ...

      ......

      public void onMessage(final Message message) {

           messagingClient.doSomething();

         .....

      }

       

      TestConsumerBean.java

      package com.test

       

      import javax.ejb.ActivationConfigProperty;

      import javax.ejb.MessageDriven;

      import javax.ejb.TransactionAttribute;

      import javax.ejb.TransactionAttributeType;

      import javax.ejb.TransactionManagement;

      import javax.ejb.TransactionManagementType;

       

       

      @MessageDriven(

                      name = "TestConsumerBean",

                      activationConfig = {

                                          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

                                          @ActivationConfigProperty(propertyName = "destination",

                                                          propertyValue = "Datacache"),

                                          @ActivationConfigProperty(propertyName = "connectorClassName",

                                                          propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),

                                          @ActivationConfigProperty(propertyName = "consumerMaxRate", propertyValue = "-1"),

                                          @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),

                                          @ActivationConfigProperty(propertyName = "reconnectAttempts", propertyValue = "-1"),

                                          @ActivationConfigProperty(propertyName = "setupAttempts", propertyValue = "-1"),

                                          @ActivationConfigProperty(propertyName = "consumerWindowSize", propertyValue = "65536") })

      @TransactionManagement(value = TransactionManagementType.CONTAINER)

      @TransactionAttribute(value = TransactionAttributeType.REQUIRED)

      public class TestConsumerBean extends MessagingConsumerBean {

      }

       

      MessagingClient.java

      public interface MessagingClient {

      ....

      }

       

      MessagingClientBean .java

      @Stateless

      @Remote(MessagingClient.class)

      public class MessagingClientBean implements MessagingClient {

      @Inject

      .....

      }

        • 1. Re: Message driven bean calling EJB produces WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
          Martin Kouba Master

          Hi Tim,

          this should work - request context is active during message delivery to any EJB message-driven bean. However I don't see any @RequestScoped bean in your code snippet. Also paste the full stack so that we have more info to identify the problem.

          • 2. Re: Message driven bean calling EJB produces WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
            Tim Pro Newbie

            Thanks for the response Martin.

             

            Here is the exception stack, taken from dynatrace monitoring tool.   I do not have any @RequestScoped annotations in this specific code.  This exception is regularly logged in our production system but I am unable to reproduce in my test system.  I did find some issues logged may be related.  CDI request scope is not active during EJB method invocation.

             

            Exception Details

            Throwing Class: org.jboss.weld.manager.BeanManagerImpl

            Throwing Method: getContext

            Count: 19019

            Exception Class: org.jboss.weld.context.ContextNotActiveException

            Message: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped

             

             

            Exception StackTrace

            Method Class Line File Name

            getContext org.jboss.weld.manager.BeanManagerImpl 619 <unknown>

            processInvocation org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor 73 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.invocation.InitialInterceptor 21 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.invocation.ChainedInterceptor 61 <unknown>

            processInvocation org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor 53 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor 51 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            invokeInCallerTx org.jboss.as.ejb3.tx.CMTTxInterceptor 201 <unknown>

            required org.jboss.as.ejb3.tx.CMTTxInterceptor 305 <unknown>

            processInvocation org.jboss.as.ejb3.tx.CMTTxInterceptor 189 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor 41 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1 42 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.as.ejb3.component.interceptors.LoggingInterceptor 59 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.as.ee.component.NamespaceContextInterceptor 50 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription$5$1 184 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.as.ee.component.TCCLInterceptor 45 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.invocation.ChainedInterceptor 61 <unknown>

            invoke org.jboss.as.ee.component.ViewService$View 165 <unknown>

            processInvocation org.jboss.as.ee.component.ViewDescription$1 176 <unknown>

            proceed org.jboss.invocation.InterceptorContext 288 <unknown>

            processInvocation org.jboss.invocation.ChainedInterceptor 61 <unknown>

            invoke org.jboss.as.ee.component.ProxyInvocationHandler 72 <unknown>

            • 3. Re: Message driven bean calling EJB produces WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
              Martin Kouba Master

              I think you can safely ignore this exception - it's used to detect wheter a request context is active or not (see http://grepcode.com/file/repo1.maven.org/maven2/org.jboss.as/jboss-as-weld/7.1.2.Final/org/jboss/as/weld/ejb/EjbRequestS…). If I'm not mistaken this is the only portable way of doing such a check. However portability is not necessary here. FYI this is not the case for WildFly8.

              • 4. Re: Message driven bean calling EJB produces WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
                Tim Pro Newbie

                this seems to indicate that the RequestScope is not active.  is that the case?  perhaps due to the ejb being declared as remote.  i could probably refactor the code so that the ejb is local.  anyways i need to eliminate this exception as it is occurring very often and appears on top of list being closely watched by my client.  any thoughts on how i can accomplish elimination?

                 

                thanks

                • 5. Re: Message driven bean calling EJB produces WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
                  Martin Kouba Master

                  Yes, this code is used to activate the request context (if not already active) during some special invocations of EJB components (MDB , timers, async, remote interface, etc.). Invocation of a session bean via local interface should not need this - so refactoring should help (but I'm afraid you will not be able to refactor your message-driven beans). Anyway you could also try to supress the logging in your monitoring tool (it's not logged on the AS level). AFAIK there will be no more JBoss AS7 community release and it's fixed in WildFly 8 master. If you're using JBoss EAP contact the support or file a ticket.

                  1 of 1 people found this helpful