JAX-RS Resteasy has automatic GZIP decompression support. If the client framework or a JAX-RS service receives a message body with a Content-Encoding of “gzip”, it will automatically decompress it. The client framework automatically sets the Accept-Encoding header to be “gzip, deflate”. So you do not have to set this header yourself.
To use gzip compression, use @GZIP annotation in following manner.
//Output compression
@GET
@Path("/users")
@GZIP
@Produces("application/xml")
public Users getAllUsers()
{
//more code....
}
//OR
//Input compression
@POST
@Path("/users")
@Consumes("application/vnd.com.demo.user-management.user+xml;charset=UTF-8;version=1")
public Response createUser(@GZIP User user,
@DefaultValue("false") @QueryParam("allow-admin") boolean allowAdmin)
throws URISyntaxException
{
//More code...
}
Example Usages
Example API output without gzip compression, when calling above GET REST API, will be as follows:
Date: Sat, 03 Aug 2013 06:18:41 GMT Server: Apache-Coyote/1.1 Content-Length: 277 Content-Type: application/vnd.com.demo.user-management.users+xml;version="1";charset=UTF-8

Example API output with gzip compression using @GZIP annotation
Date: Sat, 03 Aug 2013 06:31:21 GMT Content-Encoding: gzip Server: Apache-Coyote/1.1 Content-Length: 165 Content-Type: application/vnd.com.demo.user-management.users+xml;version="1";charset=UTF-8

Drop me a comment, something is not clear from the post.
Happy Learning !!
Comments