java - 当使用 Google guice ServletModule 在代码中加载 servlet 时,如何在 Jetty 9.3 中使 _asyncSupported = true

标签 java jetty guice jetty-9

我正在尝试将 Jetty 从 8 升级到 9.3。由于 _asyncSupported 的默认值变为 false,因此会显示以下错误。

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)

servlet 通过 Google guice 的 ServletModule 按以下方式加载到代码中。

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);
        }
}

Jetty 9升级后,_asyncSupported将采用默认值,变为false。因此,由于以下原因,jetty库文件(包:org.eclipse.jetty.server)中会出现异常。

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

那么当 Google Guice 的 ServletModule 调用 ProxyServlet 时,如何使 ProxyServlet asyncSupported (true) 呢? 我尝试过使用注释,但它不起作用。

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

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

但它因同样的错误而失败。

最佳答案

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

将您的stackDumpFilter设置为asyncSupported=true

经验法则是,如果过滤器链中的任何内容(所有过滤器 + servlet)使用异步,那么所有这些过滤器和 servlet 都必须设置为 asyncSupported=true。

关于java - 当使用 Google guice ServletModule 在代码中加载 servlet 时,如何在 Jetty 9.3 中使 _asyncSupported = true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57090646/

相关文章:

java - 在Windows服务器上运行jetty+solr

java - 为 tls 握手指定密码套件

java - 如何使用通用界面配置 Google-Guice?

generics - 如何使用 Guice 注入(inject)通用参数?

java - 从 JFrame (linux) (eclipse) 运行可执行文件

java - Apache Commons Lang 类 "add"的时间复杂度为 'ArrayUtils'

intellij-idea - 在 IntelliJ 中,如何在内部 jetty 运行配置中设置服务器端口

guice - Guice 绑定(bind)是否也绑定(bind)子类?

java:while循环-在进入花括号之间的语句之前使用分号的语句?

java - 数组列表中的数组