If I understand it correctly, that means that asynContext.dispatch is
illegal and will throw ISE, when dispatched more than once within a
dispatch flow.
ExampleA:
ServletA (startAsync() and dispatch("/b")) -> FilterB (startAsync() and
dispatch("/c") -> FilterC (startAsync() and dispatch("/d")) -> ServletD
(startAsync() and dispatch("/e")) -> ServletE
Assuming this would be ok.
ExampleB:
ServletA (startAsync() and dispatch("/b")) -> FilterB (startAsync() and
dispatch("/c") -> FilterC (startAsync() and dispatch("/c")) -> ServletC
This will be ok as well.
ExampleC:
ServletA (startAsync() and dispatch("/b")) -> FilterB (getAsyncContext()
and dispatch("/c") -> ISE
This is not ok because dispatched is used twice in the same async context
** assuming all servlets and fitlers are async support capable.
If I'm wrong, can someone please correct me and give me an example of when
asyncContext.dispatch() will throw ISE
Thanks guys.
On Wed, Dec 11, 2013 at 4:11 AM, Shing Wai Chan
<shing.wai.chan_at_oracle.com>wrote:
> Yes, you can start async in Servlet B.
> The paragraph below prevents the async started twice within a
> servlet/filter, etc.
>
> Shing Wai Chan
>
>
> On 12/10/13, 4:50 AM, tm jee wrote:
>
> Hi guys,
>
>
> On SWChan's blog (
> https://weblogs.java.net/blog/swchan2/archive/2011/09/08/startasync-servlet-30) it
> says
>
> AsyncListener#onStartAsync(AsyncEvent) will be invoked when the
> AsyncContext is reinitialized, for instance, when AsyncContext#dispatch() is
> invoked.
>
> In the spec (3.1) it is mentioned that
>
> java.lang.IllegalStateException should be thrown
> if AsyncContext#startAsync() method is called again within the scope of the
> same dispatch
>
>
> When i have say servlet A and servlet B.
>
> In Servlet A I do
>
> AsyncContext ac = req.startAsync();
> ac.addListener(myAsyncListener1);
> ac.start(new Runnable() {
> public void run() {
> ac.dispatch("/b"); // /b is mapped to Servlet B
> }
> });
>
>
> In Servlet B can I start another AsyncContext ?
>
> I guess i am wondering what is the scope of "the same dispatch" in this
> context? Would be glad if someone could point out what i've missed in the
> spec.
>
> Thanks
> Toby
>
>
>
>
>
>
>
>