Wildfly中REST响应的GZip压缩
问题描述:
我正在编写一个REST服务以xml格式发送数据列表。我如何压缩响应。Wildfly中REST响应的GZip压缩
我看到从文件系统发送zip文件的示例代码,但我想动态构建zip部分。首先查询我的数据库并构建要发送给客户端的xml数据。这个XML数据必须被压缩。
请指教。
File file = new File("Test.zip"); // Build this zip dynamically from the xml data and not from sile system
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition", "attachment; filename = Test.zip");
return response.build();
答
只是把这个注释
@GZIP
public class SomeController{
}
+0
如果您可以在代码中添加一些解释,那会更好。 – YoungHobbit 2015-12-11 03:31:56
的RESTEasy如果客户端支持它会自动gzip压缩的响应。请参阅:http://docs.jboss.org/resteasy/docs/2.2.1.GA/userguide/html/gzip.html – 2014-11-02 20:11:47
gzip和zip是不同的东西。 gzip是纯压缩,而zip是压缩和存档。哪一个? – 2014-11-03 01:26:32