| 1 |
package org.jboss.resteasy.resteasy736; |
| 2 |
|
| 3 |
import org.jboss.resteasy.annotations.Suspend; |
| 4 |
import org.jboss.resteasy.spi.AsynchronousResponse; |
| 5 |
|
| 6 |
import javax.ws.rs.GET; |
| 7 |
import javax.ws.rs.Path; |
| 8 |
import javax.ws.rs.Produces; |
| 9 |
import javax.ws.rs.core.MediaType; |
| 10 |
import javax.ws.rs.core.Response; |
| 11 |
|
| 12 |
/** |
| 13 |
* |
| 14 |
* @author <a href="[email protected]">Ron Sigal</a> |
| 15 |
* @version $Revision: 1.1 $ |
| 16 |
* |
| 17 |
* Copyright Aug 15, 2012 |
| 18 |
*/ |
| 19 |
@Path("/") |
| 20 |
@Produces("text/plain") |
| 21 |
public class TestResource |
| 22 |
{ |
| 23 |
@GET |
| 24 |
@Path("test") |
| 25 |
public void test(final @Suspend(5000) AsynchronousResponse response) |
| 26 |
{ |
| 27 |
Thread t = new Thread() |
| 28 |
{ |
| 29 |
@Override |
| 30 |
public void run() |
| 31 |
{ |
| 32 |
try |
| 33 |
{ |
| 34 |
System.out.println("TestResource: async thread started"); |
| 35 |
Thread.sleep(10000); |
| 36 |
Response jaxrs = Response.ok("test").type(MediaType.TEXT_PLAIN).build(); |
| 37 |
response.setResponse(jaxrs); |
| 38 |
System.out.println("TestResource: async thread finished"); |
| 39 |
} |
| 40 |
catch (Exception e) |
| 41 |
{ |
| 42 |
e.printStackTrace(); |
| 43 |
} |
| 44 |
} |
| 45 |
}; |
| 46 |
t.start(); |
| 47 |
} |
| 48 |
|
| 49 |
@GET |
| 50 |
@Path("default") |
| 51 |
public void defaultTest(final @Suspend AsynchronousResponse response) |
| 52 |
{ |
| 53 |
Thread t = new Thread() |
| 54 |
{ |
| 55 |
@Override |
| 56 |
public void run() |
| 57 |
{ |
| 58 |
try |
| 59 |
{ |
| 60 |
System.out.println("TestResource: async thread started"); |
| 61 |
Thread.sleep(35000); // Jetty async timeout defaults to 30000. |
| 62 |
Response jaxrs = Response.ok("test").type(MediaType.TEXT_PLAIN).build(); |
| 63 |
response.setResponse(jaxrs); |
| 64 |
System.out.println("TestResource: async thread finished"); |
| 65 |
} |
| 66 |
catch (Exception e) |
| 67 |
{ |
| 68 |
e.printStackTrace(); |
| 69 |
} |
| 70 |
} |
| 71 |
}; |
| 72 |
t.start(); |
| 73 |
} |
| 74 |
} |