Is it possible at runtime to decide whether to process a REST request to a resource endpoint synchronously or asynchronously? Take a simple example.
Synchronous version:
@Path("resource")
public class Resource {
@GET
@Produces({MediaType.TEXT_PLAIN})
public Response get() {
return Response.ok("Hello there!").build();
}
}
Asynchronous version:
@Path("resource")
public class Resource {
@GET
@Produces({MediaType.TEXT_PLAIN})
public void get(@Suspended final AsyncResponse r) {
r.resume(Response.ok("Hello there!").build());
}
}
Depending on certain parameters, at runtime I would like to decide whether to process the GET request synchronously or asynchronously. The resource endpoint URL ( http://server/resource) must be the same in both cases. Is it possible?
Of course, as you can see in the above example, the synchronous version can be faked asynchronously, just by calling AsyncResponse.resume(...). However, I would like to avoid the overhead of creating an asynchronous response.