users@glassfish.java.net

Re: servlet 3.0 async, gfv3

From: emiddio-verizon <emiddio_at_verizon.net>
Date: Thu, 15 Apr 2010 11:40:06 -0700

my init() was not calling super;

i dont remember being required to call super.init(sc) before ? i will check my j2ee tutorial books to see if it has
always been a requirement?


i understand that calling AsyncContext.complete() is automatically done when the dispatched request servlet returns,
but i was looking for a way to call AsyncContext.complete(); you last 2 sentences -- i mostly understand -- but
i was thinking i wanted to "complete" the 1st dispatch and 1st AsyncContext -- not start another one???

and i had read what you explained somewhat --i have the servlet3.0 spec -- so the exception was not completely
un-expected -- but i was at a loss to see where one would want to call AsyncContext.complete();

the test servlet you provided does that at some point and when i get a chance i will study it --

today my dev computer tried to boot up with a dead hard disk -- so got to fix that 1st.


Actually, this is expected and conformant to the spec.

See javax.servlet.ServletRequest#isAsyncStarted:

     * <p>This method returns <tt>false</tt> if this request was
     * put into asynchronous mode, but has since been dispatched using
     * one of the {_at_link AsyncContext#dispatch} methods or released
     * from asynchronous mode via a call to {_at_link AsyncContext#complete}.

and javax.servlet.AsyncContext#dispatch:

     * <p>Control over the request and response is delegated
     * to the dispatch target, and the response will be closed when the
     * dispatch target has completed execution, unless
     * {_at_link ServletRequest#startAsync()} or
     * {_at_link ServletRequest#startAsync(ServletRequest, ServletResponse)}
     * are called.


Note that the target of an async dispatch need not call AsyncContext#complete in order to complete the response: The response will be completed and closed automatically when the async dispatch returns.

If you wanted to call AsyncContext#complete during an async dispatch, you must call ServletRequest#startAsync again, as was shown in the Servlet test code I sent a couple of days ago:

                // Second async dispatch
                req.startAsync().complete();


Thanks,

Jan




    Thanks,

    Jan



      gary

        Yes, only one init per Servlet, regardless of whether the Servlet is declared to support async operations. Shing Wai has confirmed in an earlier email that this is the case.



          i have not figured how i am suppose to use AsycnContext.complete(); if i async.dispach to another servlet -- that servlet cannot
          call AsyncContext.complete();


        Why not?