I can't activate gzip-encoding in my Jersey service. This is what I've tried:
Started out with the
jersey-quickstart-grizzly2
archetype from the Getting Started Guide.Added
rc.register(org.glassfish.grizzly.http.GZipContentEncoding.class);
(have also tried
rc.register(org.glassfish.jersey.message.GZipEncoder.class);
)Started with
mvn exec:java
Tested with
curl --compressed -v -o - http://localhost:8080/myapp/myresource
The result is the following:
> GET /myapp/myresource HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 zlib/1.2.3.4 ...
> Host: localhost:8080
> Accept: */*
> Accept-Encoding: deflate, gzip
>
< HTTP/1.1 200 OK
< Content-Type: text/plain
< Date: Sun, 03 Nov 2013 08:07:10 GMT
< Content-Length: 7
<
* Connection #0 to host localhost left intact
* Closing connection #0
Got it!
That is, despite Accept-Encoding: deflate, gzip
in the request, there is no Content-Encoding: gzip
in the response.
What am I missing here??
You have to register the
org.glassfish.jersey.server.filter.EncodingFilter
as well. This example enablesdeflate
andgzip
compression:This solution is jersey specific and works not only with Grizzly, but with the JDK Http server as well.
Try the code like: