GZIP compression/decompression

With a lot of mobile applications being used in the market, it becomes essential to enable faster transmission of large chunks of data over a network. RESTEasy provides the GZIP compression/decompression feature. When the response body is plain text, it can be easily compressed on the server side and then decompressed on the client side. RESTEasy accomplishes this with the @GZIP annotation applied at the method level, as shown ahead:

 /**
* Returns list of departments
*
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@GZIP
public List<Departments> findAllDepartments() {
//Find all departments from the data store and return compressed response
javax.persistence.criteria.CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery();
cq.select(cq.from(Departments.class));
List<Departments> departments = entityManager.createQuery(cq).getResultList();
return departments;
}

The @GZIP annotation of RESTEasy takes care of compressing the response message body and similarly when a server receives a request with content-encoding equal to GZIP then the request message body is decompressed automatically. 

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

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