在CXF客户端中启用gzip压缩 [英] Enable gzip compression in CXF client

查看:105
本文介绍了在CXF客户端中启用gzip压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图让我的客户使用gzip。我在服务器中启用了GZip功能。似乎客户端未发送正确的标头:

I'm trying to make my client use gzip. I have the GZip Feature enabled in the server. It seems that the client it's not sending the correct header:

POST /api/v1/data HTTP/1.1
Content-Type: text/xml; charset=UTF-8
Accept: */*
SOAPAction: ""
User-Agent: Apache CXF 2.6.2
Cache-Control: no-cache
Pragma: no-cache
Host: localhost:8001
Connection: keep-alive
Content-Length: 539

以下是我创建客户端的代码:

Here's the code where I create the client:

 private static final QName SERVICE_NAME = new QName(
            "http://xxx/", "IData");
    private static final QName PORT_NAME = new QName(
            "http://xxx/", "IDataPort");
    IData port;

    public void initPort() {
        Service service = Service.create(SERVICE_NAME);
        // Endpoint Address
        String endpointAddress = ClientUtil.getUrl()
                + "data";

        // Add a port to the Service
        service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING,
                endpointAddress);

        port = service.getPort(IData.class);
    }

IData接口实现的GZip注释为:

The IData interface implements has the GZip Annotation:

@WebService
@GZIP
public interface IData ....


推荐答案

解决方案:

修改后,这就是您所需要的需要:

After a revision, this is what you need:

Client client = ClientProxy.getClient(port);
client.getInInterceptors().add(new GZIPInInterceptor());
client.getOutInterceptors().add(new GZIPOutInterceptor());

此后有效。

这篇关于在CXF客户端中启用gzip压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆