Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] ContinuationListener does not seem to work after upgrading Jetty from 8.x to 9.x

Hi all,

 

FYI I fixed this issue as follows:

1.      Replaced the earlier approach of using Jetty's "ContinuationListener" with Servlet 3.0's "AsyncListener", since Jetty's "ContinuationListener" does not seem to work after upgrading to Jetty 9.3.14.v20161028. This may be a Jetty bug.

2.      The listener related code segment was located BEFORE the filter’s “chain.doFilter()” call. I moved this code segment to a position AFTER the filter’s "chain.doFilter()" call, so that I can retrieve the AsyncContext that is "already created" in the Jetty ProxyServlet's service() method. I can then add an AsyncListener to the retrieved AsyncContext.

3.      I changed the “request.startAsync()” call in my filter to “request.getAsyncContext()” so that I am not starting a new AsyncContext which leads to the IllegalStateException, but only retrieving the AsyncContext that is already created in Jetty’s ProxyServlet.

 

So the updated code segment looks like this:

 

                chain.doFilter(myRequestWrapper, response);

 

                AsyncContext asyncContext = myRequestWrapper.getAsyncContext();

                asyncContext.addListener(new AsyncListener() {

                                                           

                                                            @Override

                                                            public void onTimeout(AsyncEvent event) throws IOException

                                                            {

                                                                        logger.log(Level.WARNING, "Async timeout...");

                                                            }

                                                           

                                                            @Override

                                                            public void onStartAsync(AsyncEvent event) throws IOException

                                                            {

                                                                        logger.log(Level.INFO, "Async start...");

                                                            }

                                                           

                                                            @Override

                                                            public void onError(AsyncEvent event) throws IOException

                                                            {

                                                                        logger.log(Level.SEVERE, "Async error...");

                                                            }

                                                           

                                                            @Override

                                                            public void onComplete(AsyncEvent event) throws IOException

                                                            {

                                                                                      HttpServletResponse httpResponse = (HttpServletResponse) event.getSuppliedResponse();

                                                                                     //HttpServletResponse httpResponse = (HttpServletResponse) event.getAsyncContext().getResponse();

                                                                                    if (httpResponse.getStatus() == HttpServletResponse.SC_OK || httpResponse.getStatus() == HttpServletResponse.SC_CREATED ) {

                                                                                                //some business logic

                                                                                    }

                                                            }

                                                }, myRequestWrapper, httpServletResponse);

 

Regards,
Sanjay

 

From: Sanjay Bhat
Sent: Tuesday, February 21, 2017 10:43 PM
To: 'jetty-dev@xxxxxxxxxxx' <jetty-dev@xxxxxxxxxxx>
Subject: ContinuationListener does not seem to work after upgrading Jetty from 8.x to 9.x

 

Hi all,

 

Environment:

 

·       In my environment, Kibana 4.5.2 is running behind a "reverse proxy servlet" which is created by extending Jetty's "ProxyServlet" class.

·       This is done so that the Kibana web interface can be accessed using the URL https://Jetty_Server_IP:8443/visual-analytics/proxy/... Requests for this URL are intercepted by the reverse proxy running in the Jetty Server and redirected to https://localhost:5601/... i.e., to the Kibana Server that is running in the same machine as the Jetty Server.

·       The Kibana Server then processes the request forwarded by the Jetty Server and returns the response back to the web browser.

·       NOTE: Jetty is running in "embedded mode" within my application.

 

Issue:

 

The "reverse proxy servlet" is mapped to the URL "/visual-analytics/proxy/*". There is another "filter" that is mapped to the URL "/visual-analytics/proxy/elasticsearch/.kibana/search/*" in which a “ContinuationListener” is being used as indicated by the following code snippet:

 

              ContinuationSupport.getContinuation(myRequestWrapper).addContinuationListener(new ContinuationListener() {

                   

                    @Override

                    public void onTimeout(Continuation continuation) {

                        logger.log(Level.WARNING, "Request timeout...");

                    }

                   

                    @Override

                    public void onComplete(Continuation continuation) {

                       

                        HttpServletResponse httpResponse = (HttpServletResponse)continuation.getServletResponse();

                        if (httpResponse.getStatus() == HttpServletResponse.SC_OK || httpResponse.getStatus() == HttpServletResponse.SC_CREATED ) {

                                                                                    //some business logic

                        }

                       

                    }

                });

                                               

The above ContinuationListener was working fine with Jetty version 8.1.15.v20140411 and the listener's onComplete() method was being called. But after upgrading the Jetty version to 9.3.14.v20161028, the ContinuationListener is no longer working i.e., neither the listener's onComplete() method nor the onTimeout() method is being called.

 

Any pointers on what could have gone wrong or how to debug this issue further would be greatly appreciated. Looking forward for any response...

 

Regards,

Sanjay

 


Back to the top