title: Guice throwing OutOfScopeException when executing CompletableFuture
body: <p>From a request scoped thread, <code>CompletableFuture</code>s have to be completed by a task running in an executor. The provided Supplier uses a domain specific service <code>MessageService</code> which is session scoped. That service is injected by Guice.</p>
  
  <pre><code>public class MessageProcessingPage {
      private MessageService messageService;
  
      @Inject
      public MessagProcessingPage (MessageService messageService) {
          this.messageService = messageService;
      }
  
      // Called by request scoped thread.
      public void onProcessMessagesButton () {
          ExecutorService executorService = Executors.newFixedThreadPool(3);
          CompletableFuture.supplyAsync(
          // Called from a thread from the threadpool.
          () -&gt; {return messageService.retrieveMessageMetadataSet(x, y);}
          , executorService);
  
          ...
  
      }
  
      ...
  }
  </code></pre>
  
  <p>The <code>MessageService</code> has a (session scoped) <code>MessageRestClient</code> which is injected.</p>
  
  <pre><code>@SessionScoped
  public class MessageService {
      private MessageRestClient messageRestClient;
  
      @Inject
      public MessageRestClient (MessageRestClient messageRestClient) {
          this.messageRestClient = messageRestClient;
      }
  
      public MessageMetaDataSet retrieveMessageMetadataSet(x, y) {
          List&lt;MessageMetaData&gt; listOfMetaData = messageRestClient.retrieve(x, y, z);
          ...
      }
  
      ...
  }
  
  @SessionScoped
  public class MessageRestClient {
      ...
  }
  </code></pre>
  
  <p>Guice is getting into trouble when it tries to inject the <code>MessageRestClient</code>.</p>
  
  <pre><code>java.util.concurrent.CompletionException: com.google.inject.ProvisionException: Unable to provision, see the following errors:
  
  1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped [MessageRestClient]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
  </code></pre>
  
  <p>I read about a method in <code>ServletScopes</code>: <a href="https://google.github.io/guice/api-docs/latest/javadoc/com/google/inject/servlet/ServletScopes.html#transferRequest-java.util.concurrent.Callable-" rel="nofollow"><code>public static &lt;T&gt; Callable&lt;T&gt; transferRequest(Callable&lt;T&gt; callable)</code></a>
  But I don't see a way to use this, since no Callables come in to play. Can you help me with a solution?</p>