Search code examples
javajettyguicejetty-9

How to make _asyncSupported = true in Jetty 9.3 while servlet is loaded in code with Google guice ServletModule


I am trying to upgrade the Jetty from 8 to 9.3. As the default value of _asyncSupported become false so it will show the following error.

java.lang.IllegalStateException: !asyncSupported: stackDumperFilter at org.eclipse.jetty.server.Request.startAsync(Request.java:2248) at org.eclipse.jetty.continuation.Servlet3Continuation.suspend(Servlet3Continuation.java:188) at org.eclipse.jetty.servlets.ProxyServlet.service(ProxyServlet.java:659)

The servlet is loaded in the code through Google guice's ServletModule in the following way.

public class ProxyModule extends ServletModule {
    @Override
    protected void configureServlets() {
        serve("/someurl/*").with(ProxyServlet.class);
    }
}

@Singleton
public static class ProxyServlet extends SuperHttpProxyServlet {

    @Inject
    public ProxyServlet(@Named("something.proxy") Transparent proxy) {
            super(proxy);
        }
}

After Jetty 9 upgrade, it will take the default value of _asyncSupported which become false. So it will give exception for the following reason in the jetty library file (Package : org.eclipse.jetty.server).

public AsyncContext startAsync() throws IllegalStateException
    {
        if (!_asyncSupported)
            throw new IllegalStateException("!asyncSupported");
        _async.startAsync();
        return _async;
    }

So how do I make the ProxyServlet asyncSupported (true) when it is called by Google Guice's ServletModule ? I have tried with annotation but it won't work.

@WebServlet(urlPatterns={"/someurl/*"}, asyncSupported=true, loadOnStartup = 1)
@Singleton
public static class ProxyServlet extends SuperHttpProxyServlet {

    @Inject
    public ProxyServlet(@Named("something.proxy") Transparent proxy) {
                super(proxy);
            }
    }

But it got failed with the same error.


Solution

  • java.lang.IllegalStateException: !asyncSupported: stackDumperFilter at org.eclipse.jetty.server.Request.startAsync(Request.java:2248) at

    Set your stackDumpFilter to be asyncSupported=true

    The rule of thumb is, if anything in your filter chain (all filters + servlet) uses async, then all of those filters and servlet must be set to asyncSupported=true.