users@jersey.java.net

Re: [Jersey] GZipContentEncodingFilter Sample

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 20 Apr 2010 10:00:20 +0200

On Apr 18, 2010, at 10:19 AM, Pavel Bucek wrote:

>
> Hello Marlon,
>
> all you need to do is
>
> server side:
>
> You have to set
> ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS and
> ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS. If you are
> configuring your application via ResourceConfig, it can be done like
> this:
>
> ResourceConfig rc = new
> DefaultResourceConfig(RootResource.class);
>
> rc
> .getProperties
> ().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
>
> com
> .sun
> .jersey
> .api.container.filter.GZIPContentEncodingFilter.class.getName());
>
> rc
> .getProperties
> ().put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS,
>
> com
> .sun
> .jersey
> .api.container.filter.GZIPContentEncodingFilter.class.getName());
>

Also in the 1.2-SNAPSHOT Pavel implemented programmatic filter
modification:

https://jersey.dev.java.net/nonav/apidocs/1.2-SNAPSHOT/jersey/com/sun/jersey/api/core/ResourceConfig.html
#getContainerRequestFilters%28%29

https://jersey.dev.java.net/nonav/apidocs/1.2-SNAPSHOT/jersey/com/sun/jersey/api/core/ResourceConfig.html
#getContainerResponseFilters%28%29

Paul.


> or if you use web.xml, add following to servlet element:
>
> <servlet>
> ...
> <init-param>
> <param-
> name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
> <param-
> value>com.sun.jersey.api.container.filter.GZIPContentEncodingFilter</
> param-value>
> </init-param>
> <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>
> </servlet>
>
> client side is simpler:
>
> Client c = Client.create();
> c.addFilter(new
> com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
>
> Regards,
> Pavel
>
> useful links:
>
> [1] ResourceConfig javadoc: https://jersey.dev.java.net/nonav/apidocs/1.1.5.1/jersey/com/sun/jersey/api/core/ResourceConfig.html
> [2] Constant field values: https://jersey.dev.java.net/nonav/apidocs/1.1.5.1/jersey/constant-values.html
> #com
> .sun.jersey.api.core.ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS
> [3] Deploying a RESTful Web Service: https://jersey.dev.java.net/nonav/documentation/latest/user-guide.html
> #d4e194
>
>
> Marlon Sayson wrote:
>>
>> I am new to java and come across Jersey. I have tried to analyze
>> the threads but I can't really comprehen how I could implement
>> GzipContentEncodingFilter.
>>
>> Could you please show/explain how I could used it both in client
>> and server side.
>>
>> Your help will be greatly appreciated.
>>
>> Thanks,
>>
>>
>> Marlon Sayson
>>
>>
>>
>> --
>> This message has been scanned for viruses and
>> dangerous content by MailScanner, and is
>> believed to be clean.
>
>