I have a REST method where I want to output gziped content. I have added
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</param-value>
</init-param>
To the servlet in web.xml
I can see that the code goes thru the GZIPContentEncodingFilter class by debugging but output does not get the .gzip prefix and content is not compressed, instead it is normal json. I am using Jersey 1.14.
Method looks like:
@GET
@Path("/fundlight")
@Produces(MediaType.APPLICATION_JSON)
public Response getFundLightList() {
StopWatch watch = new StopWatch();
watch.start();
Collection<Object> objectResults = null;
objectResults = getCacheMap("FundLight").values();
List<FundLight> fundLightList = new ArrayList(objectResults);
watch.stop();
GenericEntity<List<FundLight>> entity = new GenericEntity<List<FundLight>>(fundLightList) {
};
ResponseBuilder builder = Response.ok(entity);
return builder.build();
}
I think it depends on the client request header parameters.
If the request contains an Accept-Encoding header containing “gzip” then the response entity (if any) is compressed using gzip and a Content-Encoding header of “gzip” is added to the response.
See:
http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/GZIPContentEncodingFilter.html