Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-682

Async request could not find CDI injected bean with RequestScoped

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 2.3.1, 3.0.3.Final, 3.6.2.Final
    • CDI Integration
    • Hide
      @Path("/")
      @RequestScoped
      public class Res {
          @GET
          @Path("/get")
          public String get() throws Exception {
              Thread.sleep(10000);
              return "aaa";
          }
      }
      
      curl -v -X GET http://localhost:8080/jaxrs-wf/get?asynch=true
      curl -v -X GET ${LINK_FROM_HEADER_FROM_PREVIOUS_REQUEST
      
      Show
      @Path( "/" ) @RequestScoped public class Res { @GET @Path( "/get" ) public String get() throws Exception { Thread .sleep(10000); return "aaa" ; } } curl -v -X GET http://localhost:8080/jaxrs-wf/get?asynch=true curl -v -X GET ${LINK_FROM_HEADER_FROM_PREVIOUS_REQUEST

    Description

      I am working on a issue related to async job in Reasteasy (http://docs.jboss.org/resteasy/docs/2.3.1.GA/userguide/html_single/index.html#async_job_service).

      I post a request adding ?asynch=true to the url, and the job is then run asynchronously, but when it runs, it works fine with @ApplicationScoped or @Singleton annotated bean, but it cannot access bean of class declared with @RequestScoped annotation and I always run into this error :

          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:664)
              at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:77)
              at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:87)
              at com.examplecompany.exampleproject.multitenancy.org$jboss$weld$bean-flat-ManagedBean-class_com$examplecompany$exampleproject$multitenancy$PersistenceContext_$$WeldClientProxy.setDb(org$jboss$weld$bean-flat-ManagedBean-class_com$examplecompany$exampleproject$multitenancy$PersistenceContext$$_WeldClientProxy.java)
              at com.examplecompany.exampleproject.auth.oauth.secure.OAuthDelegate.filterHttp(OAuthDelegate.java:115)
              at com.examplecompany.exampleproject.auth.oauth.secure.AuthorizationInterceptor.preProcess(AuthorizationInterceptor.java:59)
              at com.examplecompany.exampleproject.auth.oauth.secure.org$jboss$weld$bean-flat-ManagedBean-com$examplecompany$exampleproject$auth$oauth$secure$AuthorizationInterceptor$@javax$enterprise$context$ApplicationScoped()@javax$ws$rs$ext$Provider()@org$jboss$resteasy$annotations$interception$SecurityPrecedence()@org$jboss$resteasy$annotations$interception$ServerInterceptor()${com$examplecompany$exampleproject$auth$oauth$secure$AuthorizationInterceptor$oauthDelegate$@javax$inject$Inject()$$}_$$_WeldClientProxy.preProcess(org$jboss$weld$bean-flat-ManagedBean-com$examplecompany$exampleproject$auth$oauth$secure$AuthorizationInterceptor$@javax$enterprise$context$ApplicationScoped()@javax$ws$rs$ext$Provider()@org$jboss$resteasy$annotations$interception$SecurityPrecedence()@org$jboss$resteasy$annotations$interception$ServerInterceptor()${com$examplecompany$exampleproject$auth$oauth$secure$AuthorizationInterceptor$oauthDelegate$@javax$inject$Inject()$$}_$$_WeldClientProxy.java)
              at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:247)
              at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
              at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
              at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
              at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
              at org.jboss.resteasy.core.AsynchronousDispatcher.invokeSuper(AsynchronousDispatcher.java:227)
              at org.jboss.resteasy.core.AsynchronousDispatcher$1.call(AsynchronousDispatcher.java:267)
              at org.jboss.resteasy.core.AsynchronousDispatcher$1.call(AsynchronousDispatcher.java:259)
              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
              at java.util.concurrent.FutureTask.run(FutureTask.java:138)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:680)
      

      This error does not occur if I post the same request not adding ?asynch=true.

      I further investigated the issue and wrote the following lines in my code

          try {
              Context context = beanManager.getContext(RequestScoped.class);
          } catch (ContextNotActiveException e) {
              logger.info("Oops the context does not exists, we are in bad sh*t",e);
          }
      

      If I'm in async mode, the `ContextNotActiveException`is always thrown, and the log have the same exception message `WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped`.

      So I guess that when the task is launched async mode, the two context Session and Request are not created, and thus my bean defined in these scope are inaccessible.

      Attachments

        Issue Links

          Activity

            People

              rsigal@redhat.com Ronald Sigal
              nicocube Nicolas Lochet (Inactive)
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated: