Jersey client API for reading chunked input

To read the chunked input on the client, Jersey offers the org.glassfish.jersey.client.ChunkedInput<T> class. Here is a client example that reads the employee list in chunks, as returned by the server:

//Other imports omitted for brevity 
import org.glassfish.jersey.media.sse.EventInput; 
import javax.ws.rs.client.ClientBuilder; 
 
String BASE_URI = "http://localhost:8080/hr-app/api"; 
Client client = ClientBuilder.newClient(); 
Response response = client.target().path("employees") 
   .path("chunk").request().get(); 
ChunkedInput<List<Employee>> chunks = response 
    .readEntity(new GenericType<ChunkedInput<List<Employee>>>(){}); 
List<Employee> chunk; 
while ((chunk = chunks.read()) != null) { 
  //Code to process List<Employee> received in chunks goes here  
} 
//Close the client after use 
client.close(); 

Having discussed chunked output and input, we now will move on to another exciting feature offered by the Jersey framework, which allows the RESTful web APIs to push notifications to clients.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.4.179