How can I enable GZIP compression of the JSON response entity on Reslet?

纵饮孤独 提交于 2019-12-10 22:58:14

问题


I have a Restlet application already working that accepts JSON and returns JSON entity as response.

I'm trying to understand how I can compress the JSON entity that is returned in the response. I did not find any clear example on how to achieve it.

I think I have to put somewhere on the router chain the Encoder/EncoderService classes, but I really don't understand where and how to use them.

Could anybody help me?


回答1:


After some testing, I got the answer.

Creating a new filter like this

Filter encoder = new Encoder(getContext(), false, true, new EncoderService(true));

inside the createInboundRoot() method of my own Application class did the trick, the client requests were already containing the gzip header needed.



来源:https://stackoverflow.com/questions/19890645/how-can-i-enable-gzip-compression-of-the-json-response-entity-on-reslet

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