1 Reply Latest reply on Mar 5, 2018 3:01 AM by Martin Kouba

    Context lost when using StreamingOutput

    Tino B Newbie

      Hello,

       

       

      I would like to stream a Response using StreamingOutput but the context seems to be lost when doing so. In a @Stateless class with a logic @ApplicationScoped injected.

      So, in my case, this would work (simplified) :

      public String noStream(Filter filter) { 
           ...
           logic
      .getById(filter));
          
      ...
      }

      And this would fail when calling the logic:

      public StreamingOutput stream(Filter filter) { 
           return new StreamingOutput() { 
                @Override public void write(OutputStream os) throws IOException, WebApplicationException {
                     ...
                     logic
      .getById(filter));
                    
      ...
                }
           };
      }

      Error message :

      WELD-001303: No active contexts for scope type javax.transaction.TransactionScoped

      Obvioulsy, "logic" triggers plenty subcalls but is there something I can do on this level to keep the context somehow ?

      Thanks in advance.


        • 1. Re: Context lost when using StreamingOutput
          Martin Kouba Master

          Hi Tino,

          the problem is that normal scopes (such as @TransactionScoped) are associated with the current thread and usually don't propagate. In your case, it's JTA impl which provides the CDI context. So I would probably start with finding out when  StreamingOutput#write() is invoked and read the JTA spec to find details about when the transaction context is active (and whether it propagates, i.e. if it can be associated with more threads).