RESTEasy – Enable Gzip Compression Content Encoding

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
	public Users getAllUsers() 
		//more code....
	//Input compression
	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/;version="1";charset=UTF-8
RESTEasy example without gzip compression
RESTEasy example without gzip compression

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/;version="1";charset=UTF-8
RESTEasy example with gzip compression
RESTEasy example with gzip compression

Drop me a comment, something is not clear from the post.

Happy Learning !!


Notify of
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.