title: Axon - How to get @QueryHandler handle method to return an Optional<MyType>
body: <p><strong>Note:</strong> </p>
  
  <p>The point of this question is not to just getting back a value that I ultimately want.<br>
  I can do that by simply not using <code>Optional</code>. 
  I would like an elegant solution so I could start returning Optional.</p>
  
  <p><strong>Explanation of what I tried to do:</strong></p>
  
  <p>I used the <code>QueryGateway</code> with a signature that will query my handler. 
  I broke out my code so you can see that on my <code>CompletableFuture</code> I will do a blocking get in order to retrieve the <code>Optional</code> that contains the object I really want. 
  <em>Note</em> that I am not looking for a class that holds my optional. 
  If this is not elegant then I may as well just do my null check.</p>
  
  <p>The call to the query works, but I get the following error:</p>
  
  <pre><code>org.axonframework.axonserver.connector.query.AxonServerQueryDispatchException: CANCELLED: HTTP/2 error code: CANCEL
      Received Rst Stream  
      AXONIQ-5002
      58484@DESKTOP-CK6HLMM
  </code></pre>
  
  <p>Example of code that initiates the query:</p>
  
  <pre><code>UserProfileOptionByUserQuery q = new UserProfileOptionByUserQuery(userId);    
  CompletableFuture&lt;Optional&lt;UserProfile&gt;&gt; query = 
    queryGateway.query(q,ResponseTypes.optionalInstanceOf(UserProfile.class));
  Optional&lt;UserProfile&gt; optional = query.get();
  </code></pre>
  
  <p>Error occurs on the <code>query.get()</code> invocation.</p>
  
  <p>Example of my Query Handler:</p>
  
  <pre><code>@QueryHandler
  Optional&lt;UserProfile&gt; handle(UserProfileOptionByUserQuery query, @MetaDataValue(USER_INFO) UserInfo userInfo) {
      assertUserCanQuery(query, userInfo);
      return userProfileRepository.findById(query.getUserId());
  }
  </code></pre>
  
  <p>The query handler works fine. 
  Other efforts such as using <code>OptionalResponseType</code> would not initiate my query as desired.</p>