users@glassfish.java.net

Re: servlet 3.0 async, gfv3

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Thu, 15 Apr 2010 12:35:06 -0700

emiddio-verizon wrote:
> 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?
>

Yes, it has, as per the javadocs I quoted, which have been around from
day 1.

If you don't call super.init(config), your Servlet will be broken.

This is what GenericServlet#init(ServletConfig) does:

    public void init(ServletConfig config) throws ServletException {
        this.config = config;
        this.init();
    }

Note how the passed in "config" is saved, so it can be returned by a
call to getServletConfig():

    public ServletConfig getServletConfig() {
        return config;
    }

If you don't call super.init(config) from your GenericServlet subclass,
getServletConfig() will return null, which is a problem.
 
>
> 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();

You can call it if you want to complete the response without performing
any async dispatch.


>
> 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.
>
Good luck with that!

Jan

>
> 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?
>>>
>>>
>>
>