9

I am in the progress to migrate a Jerset 1.x client project to Jersey 2.0.

I found that GZIPContentEncodingFilter does not exist any longer. Is there something similar?

I stumbled over GZIPEncoder but am not sure how to plug it in.

In Jersey 1.17 I use:

WebResource r = ...
r.register(new GZIPContentEncodingFilter());

In Jersey 2.0 I search for somethink like:

WebTarget r = ...
r.register(new GZIPContentEncodingFilter());
Frederick Roth
  • 2,748
  • 4
  • 28
  • 42
  • Are you using jersey 2.0 on the server side as well? If so, may I ask how you got gzip-encoding to work? (I've posted a question regarding this [here](http://stackoverflow.com/questions/19751014/gzip-encoding-in-jersey-2).) – aioobe Nov 03 '13 at 10:17
  • Hi, unfortunately on the other side is a legacy system. – Frederick Roth Nov 11 '13 at 10:11

4 Answers4

9

Use

WebTarget r = ...
r.register(GZIPEncoder.class);
Loša
  • 2,621
  • 2
  • 14
  • 19
  • Hey, I have some more errors in my project. I will accept your answer when I'm finished and can try it. Thanks! – Frederick Roth Jul 25 '13 at 06:22
  • 1
    Works for me only if executed after r.register(EncodingFilter.class). The same calling sequence met in Jersey unit tests. See https://github.com/jersey/jersey/blob/master/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/EncodingTest.java – Alfishe May 05 '14 at 17:32
4

Most of details can be obtained from Jersey's own unit tests. So to allow responses to be compressed using GZip or Deflate algorighms (in cost of increased CPU load and latency) you should use:

WebResource r = ...
r.register(EncodingFilter.class); // Allow to process encodings
r.register(GZIPEncoder.class);
r.register(DeflateEncoder.class);

See configure method in Jersey v2.x encoding unit test: EncodingTest

Alfishe
  • 3,430
  • 1
  • 25
  • 19
1

In Jersey 2.x (I use 2.26):

WebTarget target = ...
target.register(GZipEncoder.class);

I did not have to include EncodingFilter/DeflateEncoder.

Vikas
  • 1,900
  • 1
  • 19
  • 20
0

Anotate method with @GZIP , It internally uses GZIP Encoder and remove GZIPContentEncodingFilter from web.xml that solves problem