[Resteasy-users] AsyncResponse problems
Hi I have made some observations using AsyncResponse with a MessageBodyWriter that seems a little strange. 1) Calling AsyncResponse.resume() with a user-defined object (intended for MessageBodyWriter) on same thread as the running request cause an exception almost immediately after returning (see below). 2) Calling AsyncResponse.resume() by wrapping the object, Response.ok().entity(object).build(), works and MessageBodyWriter writes the response. 3) Calling AsyncResponse.resume() on a separate thread (with a user-defined object), exactly like the example in AsyncResponse javadoc, the response is written correctly by the MessageBodyWriter. However, if I simulate a pause AFTER putting the response on the queue and let postMessage steal the response BEFORE returning from readMessage method, I get the same exception as 1). Comments: 1) Seems like this should just work? Or must every resume() object be wrapped in a Response object, like comment 2? 3) Imagine posting AsyncResponse to an executor that finish before returning from the originating method call. That would result in the same error as 1). Seems like a race-condition. Maybe unlikely, but still. Cheers, -Kristoffer org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: Unknown media type for response entity at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) ~[javax.servlet-3.0.0.v201112011016.jar:na] at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) ~[jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505) [jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) [jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.Server.handle(Server.java:445) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:224) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) [jetty-io-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) [jetty-util-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) [jetty-util-9.0.4.v20130625.jar:9.0.4.v20130625] at java.lang.Thread.run(Thread.java:722) [na:1.7.0_17] Caused by: java.lang.IllegalStateException: Unknown media type for response entity at org.jboss.resteasy.core.AbstractAsynchronousResponse.internalResume(AbstractAsynchronousResponse.java:165) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.SynchronousExecutionContext$SynchronousAsynchronousResponse.resume(SynchronousExecutionContext.java:87)
Re: [Resteasy-users] AsyncResponse problems
Sure thing, https://issues.jboss.org/browse/RESTEASY-917. Btw, I also had some trouble with cookies a few weeks, where Jetty forcibly add Expires attribute to the Cookie cause NewCookieHeaderDelegate to fail. Set-Cookie: guid=1.8217531194121000960;Path=/;Domain=.test.com;Expires=Wed, 18-Apr-2018 10:42:52 GMT;Max-Age=15000 Would you like me to log a bug for that also? On Wed, Jul 31, 2013 at 3:16 PM, Bill Burke bbu...@redhat.com wrote: You are using it correctly. Its just bugged. Can you log a detailed JIRA (just cut and paste the email)? I need to do some work in this area anyways to fix some other bugs the Java EE 7 TCK picked up and need to do a release soon. http://issues.jboss.org/jira/browse/RESTEASY On 7/31/2013 9:04 AM, Kristoffer Sjögren wrote: Hi I have made some observations using AsyncResponse with a MessageBodyWriter that seems a little strange. 1) Calling AsyncResponse.resume() with a user-defined object (intended for MessageBodyWriter) on same thread as the running request cause an exception almost immediately after returning (see below). 2) Calling AsyncResponse.resume() by wrapping the object, Response.ok().entity(object).build(), works and MessageBodyWriter writes the response. 3) Calling AsyncResponse.resume() on a separate thread (with a user-defined object), exactly like the example in AsyncResponse javadoc, the response is written correctly by the MessageBodyWriter. However, if I simulate a pause AFTER putting the response on the queue and let postMessage steal the response BEFORE returning from readMessage method, I get the same exception as 1). Comments: 1) Seems like this should just work? Or must every resume() object be wrapped in a Response object, like comment 2? 3) Imagine posting AsyncResponse to an executor that finish before returning from the originating method call. That would result in the same error as 1). Seems like a race-condition. Maybe unlikely, but still. Cheers, -Kristoffer org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalStateException: Unknown media type for response entity at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) ~[resteasy-jaxrs-3.0.1.Final.jar:na] at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) ~[javax.servlet-3.0.0.v201112011016.jar:na] at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) ~[jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505) [jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1094) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) [jetty-servlet-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1028) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.Server.handle(Server.java:445) [jetty-server-9.0.4.v20130625.jar:9.0.4.v20130625] at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:267)