use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.
the class TestResource method defaultTest.
@GET
@Path("default")
public void defaultTest(@Suspended final AsyncResponse response) {
Thread t = new Thread() {
@Override
public void run() {
try {
LOG.info("TestResource: async thread started");
// Jetty async timeout defaults to 30000.
Thread.sleep(35000);
Response jaxrs = Response.ok("test").type(MediaType.TEXT_PLAIN).build();
response.resume(jaxrs);
LOG.info("TestResource: async thread finished");
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
};
t.start();
}
use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.
the class TestResource method test.
@GET
@Path("test")
public void test(@Suspended final AsyncResponse response) {
response.setTimeout(5000, TimeUnit.MILLISECONDS);
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.resume(jaxrs);
LOG.info("TestResource: async thread finished");
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
};
t.start();
}
use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.
the class AsyncResource method get.
@GET
@Produces("text/plain")
public void get(@Suspended final AsyncResponse response) {
response.setTimeout(2000, TimeUnit.MILLISECONDS);
Thread t = new Thread() {
private Logger log = Logger.getLogger(AsyncResource.class);
@Override
public void run() {
try {
Thread.sleep(100);
Response jaxrs = Response.ok("hello").type(MediaType.TEXT_PLAIN).build();
response.resume(jaxrs);
} catch (Exception e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
log.error(errors.toString());
}
}
};
t.start();
}
use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.
the class JaxrsAsyncResource method zero.
@GET
@Path("zero")
@Produces("text/plain")
public void zero(@Suspended final AsyncResponse response) {
response.setTimeout(0, TimeUnit.MILLISECONDS);
Thread t = new Thread() {
private Logger logger = Logger.getLogger(JaxrsAsyncResource.class);
@Override
public void run() {
try {
logger.info("Started");
Thread.sleep(1000);
Response jaxrs = Response.ok("hello").type(MediaType.TEXT_PLAIN).build();
response.resume(jaxrs);
} catch (Exception e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
logger.error(errors.toString());
}
}
};
t.start();
}
use of jakarta.ws.rs.container.AsyncResponse in project resteasy by resteasy.
the class JaxrsAsyncResource method get.
@GET
@Produces("text/plain")
public void get(@Suspended final AsyncResponse response) {
response.setTimeout(10000, TimeUnit.MILLISECONDS);
Thread t = new Thread() {
private Logger logger = Logger.getLogger(JaxrsAsyncResource.class);
@Override
public void run() {
try {
logger.info("Get thread started.");
Thread.sleep(100);
Response jaxrs = Response.ok("hello").type(MediaType.TEXT_PLAIN).build();
response.resume(jaxrs);
} catch (Exception e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
logger.error(errors.toString());
}
}
};
t.start();
}
Aggregations