在Axis2中用Gzip压缩soap请求

为什么需要压缩?

如果你的soap请求太大,或者是你想到降低它对于网络带宽的占用。你就可以在http层面通过采用Gzip来对soap请求进行压缩。

如何在Axis2中实施

Axis2采用了Apache的 Apache Commons HttpClient project 来实现它的http层,你只需要在客户端将以下属性

org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST

属性设置为

Boolean.TRUE

如果你是用Axis2中的工具生成的代码,那你可以这样设置。

ServiceStub stub = new ServiceStub();<br /><br />stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);

设置正确之后,Axis2不仅能把请求压缩,还会在soap的消息头中加入相关的信息,比如:

Content-Encoding: gzip

有了这个消息头的属性,Axis2的服务端可以正确的处理Gzip的请求,无需做额外的配置。

VN:F [1.9.7_1111]
留下你的评价吧
Rating: 6.3/10 (3 votes cast)
在Axis2中用Gzip压缩soap请求, 6.3 out of 10 based on 3 ratings

相关文章

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*