axis2:ServiceClient增加GZIP压缩支持

32 篇文章 0 订阅

使用axis2的ServiceClient,以RPC或Stub方式实现webservice调用时,如果要对数据进行GZIP压缩,也挺简单,只要给ServiceClient设置 MC_GZIP_REQUEST和MC_ACCEPT_GZIP 属性就可以了。
示例代码如下:

                Options options = serviceClient.getOptions();
                options.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
                options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
                options.setProperty(HTTPConstants.CHUNKED, "true");
                // Request(请求)数据用GZIP压缩
                options.setProperty(HTTPConstants.MC_GZIP_REQUEST, Boolean.TRUE);
                // 向服务器声明接受GZIP压缩
                options.setProperty(HTTPConstants.MC_ACCEPT_GZIP , Boolean.TRUE);

关于MC_GZIP_REQUEST和MC_ACCEPT_GZIP 属性的说明参见org.apache.axis2.transport.http.HTTPConstants代码中的注释:

    /**
     * If you want the HTTP sender to indicate that it can accept a gziped
     * response, set this message context property to true. The sender will
     * automatically unzip the response if its gzipped.
     */
    public static final String MC_ACCEPT_GZIP = "transport.http.acceptGzip";

    /**
     * by default the HTTP request body is not compressed. set this message
     * context property to true to have the request body gzip compressed.
     */
    public static final String MC_GZIP_REQUEST = "transport.http.gzipRequest";

以及方法void org.apache.axis2.client.Options.setProperty(String propertyKey, Object property)的说明:

org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST
If set this will GZip your request and send over to the destination. Before doing this, you must make sure that the receiving end supports GZip compressed streams. 

Possible values are:

"true"/"false" or Boolean.TRUE/Boolean.FALSE

org.apache.axis2.transport.http.HTTPConstants.MC_ACCEPT_GZIP
Whether or not you send a gzip-ped request, you can choose to receive GZIP back from the server using this flag.

Possible values are:

"true"/"false" or Boolean.TRUE/Boolean.FALSE
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值