Java Wildfly中REST响应的GZip压缩
我正在编写一个REST服务来发送xml格式的数据列表。我该如何压缩响应 我看到了从文件系统发送zip文件的示例代码,但我想动态构建zip部分。首先查询我的数据库并构建要发送到客户机的xml数据。必须对这些xml数据进行压缩 请告知Java Wildfly中REST响应的GZip压缩,java,rest,jax-rs,gzip,wildfly-8,Java,Rest,Jax Rs,Gzip,Wildfly 8,我正在编写一个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 =
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{
}
如果客户端支持,RESTEasy将自动gzip响应。请看:gzip和zip是不同的东西。gzip是纯压缩,而zip是压缩和归档。这是哪一个?如果你能在代码中添加一些解释,那就更好了。