【发布时间】:2014-11-02 16:01:58
【问题描述】:
我正在编写一个 REST 服务以发送 xml 格式的数据列表。如何压缩响应。
我看到了从文件系统发送 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();
【问题讨论】:
-
如果客户端支持,RESTEasy 会自动压缩响应。见:docs.jboss.org/resteasy/docs/2.2.1.GA/userguide/html/gzip.html
-
gzip 和 zip 是不同的东西。 gzip 是纯压缩,而 zip 是压缩和归档。是哪一个?
标签: java rest jax-rs gzip wildfly-8