What is the Jersey 2.0 equivalent of GZIPContentEncodingFilter

我的未来我决定 提交于 2019-12-10 04:09:59

问题


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());

回答1:


Use

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



回答2:


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




回答3:


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




回答4:


In Jersey 2.x (I use 2.26):

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

I did not have to include EncodingFilter/DeflateEncoder.



来源:https://stackoverflow.com/questions/17834028/what-is-the-jersey-2-0-equivalent-of-gzipcontentencodingfilter

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