前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >axis2:ServiceClient增加GZIP压缩支持

axis2:ServiceClient增加GZIP压缩支持

作者头像
10km
发布2019-05-25 22:32:24
5650
发布2019-05-25 22:32:24
举报
文章被收录于专栏:10km的专栏10km的专栏

版权声明:本文为博主原创文章,转载请注明源地址。 https://cloud.tencent.com/developer/article/1433720

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

示例代码如下:

代码语言:javascript
复制
                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代码中的注释:

代码语言:javascript
复制
    /**
     * 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)的说明:

代码语言:javascript
复制
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
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年09月08日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档