1 java rest tomcat maven jersey-2.0
我很好奇是否有人能够解决这个问题呢?我已经做了一些搜索,但看起来它仍然是Jersey 2异步REST实现的一个突出问题.我有以下代码:
@Path("myresource")
public class MyResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public void asyncGet(@Suspended final AsyncResponse asyncResponse) {
new Thread(new Runnable() {
@Override
public void run() {
String result = veryExpensiveOperation();
asyncResponse.resume(result);
}
private String veryExpensiveOperation() {
return "got it too";
}
}).start();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Servlet 3.0,所以没有web.xml ... Tomcat版本是7.0.54,我已经将以下行添加到server.xml
<Connector connectionTimeout="20000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
Run Code Online (Sandbox Code Playgroud)
这是Jersey Maven项目,所以我在下面评论过
<artifactId>jersey-container-servlet</artifactId>
Run Code Online (Sandbox Code Playgroud)
并评论出来
<artifactId>jersey-container-servlet-core</artifactId>
Run Code Online (Sandbox Code Playgroud)
我不知道我还能在这做什么,这就是堆栈跟踪
javax.servlet.ServletException: javax.ws.rs.ProcessingException: Attempt to suspend a connection of an asynchronous request failed in the underlying container.
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:391)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.ws.rs.ProcessingException: Attempt to suspend a connection of an asynchronous request failed in the underlying container.
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:312)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:103)
org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗???
确保您使用的是最新版本,截至发布之日,请使用v2.13
在web.xml中,确保将以下内容添加到servlet标记中
<async-supported>true</async-supported>
Run Code Online (Sandbox Code Playgroud)