我编写了 JAX-WS(来自 Sun)客户端,它进行服务调用,期望服务器响应被压缩:
Map<String, List<String>> theHeaders = new HashMap<String, List<String>>();
theHeaders.put("Content-Encoding", Collections.singletonList("gzip"));
theHeaders.put("Accept", Collections.singletonList("application/x-gzip"));
theHeaders.put("Accept-Encoding", Collections.singletonList("gzip, deflate"));
theHeaders.put("Content-Type", Collections.singletonList("application/x-gzip"));
((BindingProvider) client).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, theHeaders);
根据 Fiddler 的说法,响应是 HTTP 200 (Ok),soap 响应是 gzip 压缩的。不过,我收到以下错误:
com.sun.xml.ws.server.UnsupportedMediaException: Unsupported Content-Type: application/x-gzip Supported ones are: [application/soap+xml]
at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:322)
at com.sun.xml.ws.encoding.StreamSOAP12Codec.decode(StreamSOAP12Codec.java:107)
at com.sun.xml.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:156)
at com.sun.xml.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:312)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:295)
我读到JAX-WS 应该支持开箱即用的 gzipped webservice 响应,但看起来它不支持。尽管事实响应包含 Content-Type: application/x-gzip 标头,但它尝试使用适用于 application/soap+xml 的默认编解码器。
有没有办法让它使用另一个编解码器,用于gzip?有这样的编解码器吗?