users@jersey.java.net

[Jersey] ChunkedOutput with AsyncResponse

From: Christopher Ng <cng1067_at_gmail.com>
Date: Fri, 27 Jun 2014 11:02:45 +0100

It seems that it is currently possible to return a ChunkedOutput with an
AsyncResponse, but it causes Tomcat to log a warning as Jersey tries to
suspend the AsyncContext twice.

This might seem like a bit of an odd thing to do, but returning
ChunkedOutput synchronously always immediately returns a 200, whereas I
would like to be able to choose whether to return a ChunkedOutput or eg a
500 at a 'later' point, using AsyncResponse.

I get the following warning in Tomcat, but apart from that things seem to
work as expected:

WARNING: Attempt to put servlet request into asynchronous mode has failed.
Please check your servlet configuration - all Servlet instances and Servlet
filters involved in the request processing must explicitly declare support
for asynchronous request processing.
java.lang.IllegalStateException: Calling [asyncStart()] is not valid for a
request with Async state [STARTED]
at
org.apache.coyote.AsyncStateMachine.asyncStart(AsyncStateMachine.java:175)
at
org.apache.coyote.ajp.AbstractAjpProcessor.action(AbstractAjpProcessor.java:453)
at org.apache.coyote.Request.action(Request.java:346)
at
org.apache.catalina.core.AsyncContextImpl.setStarted(AsyncContextImpl.java:345)
at org.apache.catalina.connector.Request.startAsync(Request.java:1665)
at
org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1029)
at
javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379)
at
javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379)
at
org.glassfish.jersey.servlet.async.AsyncContextDelegateProviderImpl$ExtensionImpl.suspend(AsyncContextDelegateProviderImpl.java:87)
at
org.glassfish.jersey.servlet.internal.ResponseWriter.suspend(ResponseWriter.java:121)
at
org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:674)
at
org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:375)
at
org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:365)
at
org.glassfish.jersey.server.ServerRuntime$AsyncResponder$3.run(ServerRuntime.java:820)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
at
org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:850)
at
org.glassfish.jersey.server.ServerRuntime$AsyncResponder.resume(ServerRuntime.java:812)