0 Replies Latest reply on Dec 22, 2015 5:57 AM by yaroska

    Request Scope in async calls

    yaroska

      I have a problem to accessed request data from @Asynchronous methods.

       

      Here is the example:

       

      @RequestScoped
      public class CurrentUserService implements Serializable {

        public String token;

      }


      @Stateless
      public class Service {

         @Inject
         private RestClient client;


          @Resource
          private ManagedExecutorService executorService;


          @Resource
          private ContextService contextService;


          @Asynchronous
          private <T> Future<T> getFuture(Supplier<T> supplier) {

              Callable<T> task = supplier::get;

              Callable<T> callable = contextService.createContextualProxy(task, Callable.class);

              return executorService.submit(callable);

          }

       

         public String getToken() throws Exception {

            return getFuture(client::getToken).get();

         }

      }

       

      @ApplicationScoped
      public class RestClient {

          @Inject
          private CurrentUserService currentUserBean;

       

          public String getToken() {

              return currentUserBean.getToken();

          }

      }


      It's expected that request scoped data should be accessible within tasks executed within request scope. But it's not. Is it a bug? May be I'm doing something wrong? If yes - what it the correct way to propagate such data into async calls?

       

      Thanks in advance.