【问题标题】:How to enable GZIP compression for SOAP responses?如何为 SOAP 响应启用 GZIP 压缩?
【发布时间】:2014-11-11 09:41:32
【问题描述】:

我使用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");

对此 SoapService 的请求:

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 压缩?

【问题讨论】:

  • 我会建议在soap body中发送xml消息作为压缩二进制数据的base64编码字符串,客户端客户端将解压这个编码字符串。

标签: java spring web-services soap cxf


【解决方案1】:

您需要将@GZIP 注解添加到您的界面。 Here's the documentation。如果我没记错的话,你需要在你的 spring 配置中声明 GZIPOutInterceptor

或者,您可以手动将GZIPOutInterceptor 添加到您的端点。

【讨论】:

  • 引用我自己的话:end.getFeatures().add(config.gzipFeature()); 这已经手动将 GZIPOutInterceptor 添加到端点。
  • 我建议在 GZIPOutInterceptor 中放置一个断点,看看它是否被调用?也许它没有达到激活它的阈值大小。
猜你喜欢
  • 2013-01-08
  • 1970-01-01
  • 1970-01-01
  • 2012-02-12
  • 2011-02-28
  • 2013-12-29
  • 2021-03-13
  • 2014-02-20
  • 1970-01-01
相关资源
最近更新 更多