Java Reference
In-Depth Information
Client client = ClientBuilder.newClient();
WebTarget target ="/
GenericType<List<Student>> list = new
GenericType<List<Student>>() {};
List<Student> students
Asynchronous processing
In addition to the standardization of the client API, JAX-RS 2.0 has integrated a fea-
ture already present in many of the APIs of the Java EE platform, which is asyn-
chronous processing. It is now possible for a JAX-RS client to send requests or pro-
cess responses asynchronously.
The following code demonstrates how a JAX-RS client can perform a get request
asynchronously and wait for the response passively. As shown in the code, the exe-
cution of a JAX-RS request asynchronously requires a call to the async() method.
This method returns an object of type AsyncInvoker whose get, post, delete, and
put methods allow us to obtain the object type Future that will be used for further
processing of the response.
The following code is an example of the execution of a asynchronous process in a
JAX-RS client:
public class AppAsynchronousRestfulClient {
public static void main(String[] args) {
String baseURI ="http://localhost:8080/
String location = "/rs-resources";
String method = "/students/
Client client = ClientBuilder.newClient();
WebTarget target =
Search WWH ::

Custom Search