Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Jersey 2.0 equivalent of GZIPContentEncodingFilter

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());
like image 420
Frederick Roth Avatar asked Jul 24 '13 12:07

Frederick Roth


2 Answers

Use

WebTarget r = ...
r.register(GZIPEncoder.class);
like image 130
Loša Avatar answered Sep 30 '22 15:09

Loša


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

like image 24
Alfishe Avatar answered Sep 30 '22 17:09

Alfishe