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