如何为SOAP响应启用GZIP压缩?

4
我使用 SpringCXF 创建了一个简单的SOAP Web服务。现在我正在尝试为XML请求启用GZIP压缩。 以下代码可以接受压缩请求,但响应不会被压缩。为什么?
@Component
@WebService
public class SoapService {

}

@Autowired
private SpringBus bus;


EndpointImpl end = new EndpointImpl(bus, new SoapService());
end.getFeatures().add(config.gzipFeature());
ep.publish("/SoapService");

向此Soap服务发送请求:

Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml;charset=UTF-8
Headers: {accept-encoding=[gzip,deflate], content-encoding=[gzip], connection=[Keep-Alive], content-type=[text/xml;charset=UTF-8], ...}

响应(空标头!!):

Content-Type: text/xml
Headers:
Payload: ...

为什么响应没有使用gzip压缩?

我建议将XML消息作为压缩二进制数据的Base64编码字符串发送到SOAP正文中,客户端将解压缩此编码字符串。 - Naveen Ramawat
1个回答

4
你需要在接口中添加@GZIP注释。 这里是文档。 如果我没记错的话,你需要在spring配置中声明GZIPOutInterceptor
或者,您可以手动将GZIPOutInterceptor添加到您的端点中。

1
引用自己的话:“end.getFeatures().add(config.gzipFeature());” 这样手动将 GZIPOutInterceptor 添加到端点。 - membersound
我建议在GZIPOutInterceptor内设置一个断点,以查看它是否被调用?也许没有达到激活它所需的阈值大小。 - Andres Olarte

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接