我正在尝试将 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/