0 Replies Latest reply on Jul 4, 2009 12:14 PM by Ravikumar Sundaram

    Asynchronous HTTP Request is not working as excepted  for Re

    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>