You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2016/05/17 10:24:18 UTC

8.5.2 async state?

Hi guys,

on 8.5.2 this code doesn't work anymore (in a valve):

if (!request.isAsync()) {

    getNext().invoke(request, response);

} else {
    request.getAsyncContext().addListener(...);
    getNext().invoke(request, response);
}

Issue is isAsync() = true but getAsyncContext() throws an exception since
isAsyncStarted() = false.

Was it intended?

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

Re: 8.5.2 async state?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I see, that's however a regression for tomcat users. could the async
listener wrapper impl this if a tomcat flag is switched on?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-05-17 13:03 GMT+02:00 Violeta Georgieva <mi...@gmail.com>:

> Hi,
>
> 2016-05-17 13:46 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:
> >
> > the real issue is adding a listener there trigger onStartAsync()*ONLY*
> (no
> > onCompleted(), onTimeout(), onError() etc... cause
> > org.apache.catalina.core.AsyncContextImpl#setStarted does
> listeners.clear();
> > )
> >
>
> That's behaviour is by spec:
>
> "public void addListener(AsyncListener) - Registers the given listener for
> notifications of onTimeout, onError, onComplete or onStartAsync. The first
> three are associated with the most recent asynchronous cycle started by
> calling
> one of the ServletRequest.startAsync methods. The onStartAsync is
> associated to a new asynchronous cycle via one of the
> ServletRequest.startAsync
> methods."
>
> so you can do the following:
>
>         public void onStartAsync(AsyncEvent event) throws IOException {
>             // Re-add this listener to the new AsyncContext
>             event.getAsyncContext().addListener(this);
>         }
>
> Regards,
> Violeta
>
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com> | JavaEE Factory
> > <https://javaeefactory-rmannibucau.rhcloud.com>
> >
> > 2016-05-17 12:43 GMT+02:00 Rémy Maucherat <re...@apache.org>:
> >
> > > 2016-05-17 12:37 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:
> > >
> > > > Only found https://bz.apache.org/bugzilla/show_bug.cgi?id=59261
> which
> > > > doesn't mean this code would be invalid
> > > >
> > > > Also if you add a listener eagerly you will have the start event and
> > > loose
> > > > all "end" (completed, timeout etc...) ones. This doesn't sound very
> > > > reliable.
> > > >
> > > > Can you point me out the related issue please?
> > > >
> > > > The bugzilla title says: "Request getAsyncContext should throw
> > > IllegalStateException if async is not started". So that's what happens
> now.
> > >
> > > Rémy
> > >
>

Re: 8.5.2 async state?

Posted by Violeta Georgieva <mi...@gmail.com>.
Hi,

2016-05-17 13:46 GMT+03:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> the real issue is adding a listener there trigger onStartAsync()*ONLY* (no
> onCompleted(), onTimeout(), onError() etc... cause
> org.apache.catalina.core.AsyncContextImpl#setStarted does
listeners.clear();
> )
>

That's behaviour is by spec:

"public void addListener(AsyncListener) - Registers the given listener for
notifications of onTimeout, onError, onComplete or onStartAsync. The first
three are associated with the most recent asynchronous cycle started by
calling
one of the ServletRequest.startAsync methods. The onStartAsync is
associated to a new asynchronous cycle via one of the
ServletRequest.startAsync
methods."

so you can do the following:

        public void onStartAsync(AsyncEvent event) throws IOException {
            // Re-add this listener to the new AsyncContext
            event.getAsyncContext().addListener(this);
        }

Regards,
Violeta

>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <http://rmannibucau.wordpress.com> | Github <
https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-05-17 12:43 GMT+02:00 Rémy Maucherat <re...@apache.org>:
>
> > 2016-05-17 12:37 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:
> >
> > > Only found https://bz.apache.org/bugzilla/show_bug.cgi?id=59261 which
> > > doesn't mean this code would be invalid
> > >
> > > Also if you add a listener eagerly you will have the start event and
> > loose
> > > all "end" (completed, timeout etc...) ones. This doesn't sound very
> > > reliable.
> > >
> > > Can you point me out the related issue please?
> > >
> > > The bugzilla title says: "Request getAsyncContext should throw
> > IllegalStateException if async is not started". So that's what happens
now.
> >
> > Rémy
> >

Re: 8.5.2 async state?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
the real issue is adding a listener there trigger onStartAsync()*ONLY* (no
onCompleted(), onTimeout(), onError() etc... cause
org.apache.catalina.core.AsyncContextImpl#setStarted does listeners.clear();
)


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-05-17 12:43 GMT+02:00 Rémy Maucherat <re...@apache.org>:

> 2016-05-17 12:37 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:
>
> > Only found https://bz.apache.org/bugzilla/show_bug.cgi?id=59261 which
> > doesn't mean this code would be invalid
> >
> > Also if you add a listener eagerly you will have the start event and
> loose
> > all "end" (completed, timeout etc...) ones. This doesn't sound very
> > reliable.
> >
> > Can you point me out the related issue please?
> >
> > The bugzilla title says: "Request getAsyncContext should throw
> IllegalStateException if async is not started". So that's what happens now.
>
> Rémy
>

Re: 8.5.2 async state?

Posted by Rémy Maucherat <re...@apache.org>.
2016-05-17 12:37 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:

> Only found https://bz.apache.org/bugzilla/show_bug.cgi?id=59261 which
> doesn't mean this code would be invalid
>
> Also if you add a listener eagerly you will have the start event and loose
> all "end" (completed, timeout etc...) ones. This doesn't sound very
> reliable.
>
> Can you point me out the related issue please?
>
> The bugzilla title says: "Request getAsyncContext should throw
IllegalStateException if async is not started". So that's what happens now.

Rémy

Re: 8.5.2 async state?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Only found https://bz.apache.org/bugzilla/show_bug.cgi?id=59261 which
doesn't mean this code would be invalid

Also if you add a listener eagerly you will have the start event and loose
all "end" (completed, timeout etc...) ones. This doesn't sound very
reliable.

Can you point me out the related issue please?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-05-17 12:26 GMT+02:00 Mark Thomas <ma...@apache.org>:

> On 17/05/2016 11:24, Romain Manni-Bucau wrote:
> > Hi guys,
> >
> > on 8.5.2 this code doesn't work anymore (in a valve):
> >
> > if (!request.isAsync()) {
> >
> >     getNext().invoke(request, response);
> >
> > } else {
> >     request.getAsyncContext().addListener(...);
> >     getNext().invoke(request, response);
> > }
> >
> > Issue is isAsync() = true but getAsyncContext() throws an exception since
> > isAsyncStarted() = false.
> >
> > Was it intended?
>
> Yes. It is in the change log.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

Re: 8.5.2 async state?

Posted by Mark Thomas <ma...@apache.org>.
On 17/05/2016 11:24, Romain Manni-Bucau wrote:
> Hi guys,
> 
> on 8.5.2 this code doesn't work anymore (in a valve):
> 
> if (!request.isAsync()) {
> 
>     getNext().invoke(request, response);
> 
> } else {
>     request.getAsyncContext().addListener(...);
>     getNext().invoke(request, response);
> }
> 
> Issue is isAsync() = true but getAsyncContext() throws an exception since
> isAsyncStarted() = false.
> 
> Was it intended?

Yes. It is in the change log.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org