1 Reply Latest reply on Jan 20, 2010 12:09 PM by Eric Blanchard

    Asynchronous HTTP Request is not working in Resteasy

    Ravikumar Sundaram Newbie

      Hi,
      I have written a simple Asynchronous HTTP Request RestEasy Application which contains two methods .

      1) asyncBasic() -- asynchronous method
      2) basic() --- normal RESTeasy http handler method i.e. synchronous

      I deployed this App in Jboss 5.0.0(native library enabled) and

      Case 1: when i send a request for both basic and asyncBasic , i am getting response back after 10 Seconds which i set as @suspend interval. but basic() should send response immediately which is not happening here.

      can someone help me to resolve this problem ? i followed the instruction
      given at
      http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0.2.GA/userguide/html/Asynchronous_HTTP_Request_Processing.html


      here is my code and web.xml

      @Path("/")
      public class SimpleResource
      {

      @GET
      @Path("basicasync")
      @Produces("text/plain")
      public void asyncBasic(final @Suspend(10000) AsynchronousResponse response) throws Exception
      {
      Thread t = new Thread()
      {
      @Override
      public void run()
      {
      try
      {
      Thread.sleep(5000);
      Response jaxrs = Response.ok("Async Date : "+(new Date())).type(MediaType.TEXT_PLAIN).build();
      response.setResponse(jaxrs);
      }
      catch (Exception e)
      {
      e.printStackTrace();
      }
      }
      };
      t.start();
      }


      @GET
      @Path("basic")
      @Produces("text/plain")
      public Response syncBasic() throws Exception
      {
      Response jaxrs = Response.ok("Sync Date "+(new Date())).type(MediaType.TEXT_PLAIN).build();
      response.setResponse(jaxrs);
      }
      }

      **********************************************************
      <?xml version="1.0"?>
      <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">

      <web-app>
      <display-name>Archetype Created Web Application</display-name>

      <context-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>com.test.BasicApplication</param-value>
      </context-param>

      <context-param>
      <param-name>resteasy.servlet.mapping.prefix</param-name>
      <param-value>/rest-services</param-value>
      </context-param>


      <listener-class>
      org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
      </listener-class>



      <servlet-name>Resteasy</servlet-name>
      <servlet-class>
      org.jboss.resteasy.plugins.server.servlet.JBossWebDispatcherServlet
      </servlet-class>


      <servlet-mapping>
      <servlet-name>Resteasy</servlet-name>
      <url-pattern>/rest-services/*</url-pattern>
      </servlet-mapping>

      </web-app>

        • 1. Re: Asynchronous HTTP Request is not working in Resteasy
          Eric Blanchard Newbie

          Hi,

          I have exactly the same problem as your when using Asynchronous support of RESTEasy for JBoss Web server (JBossWebDispatcherServlet).

           

          As RESTEasy content providers doesn't provide the size of the response content before bytes are written to output stream, then the servlet container uses the chunked Transfer-Encoding.

           

          In fact the first chunk (containing the whole content of response) is immediatly sent back to client, but not the 0 sized ending chunk.

          This last one is only sent when the connection is closed (tanks to timeout expiration or other action).

          Most of HTTP clients will not show any answer until the request is ended by this null chunk.

           

          With Synchronous RESTEasy dispatcher (HttpServletDispatcher), the null ending chunk is sent just after the first chunk and clients are happy with that.

           

          I susppect it is more a RESTEasy problem with the implementation of the Event Servlet API of JBoss Web (something related to async-http-jbossweb.jar ?)

           

           

          --

          Eric