What is the Jersey 2.0 equivalent of GZIPContentEncodingFilter

我的梦境 提交于 2019-12-05 03:03:29

Use

WebTarget r = ...
r.register(GZIPEncoder.class);

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

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

In Jersey 2.x (I use 2.26):

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

I did not have to include EncodingFilter/DeflateEncoder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!