[英]JAX-WS client: UnsupportedMediaException for gzipped response
I wrote JAX-WS (from Sun) client which makes service calls which expect server responses to be gzipped: 我写了(来自Sun的)JAX-WS客户端,该客户端进行服务调用,期望服务器响应被压缩:
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);
According to the Fiddler, response is HTTP 200 (Ok) and soap response is gzipped. 根据Fiddler的说法,响应为HTTP 200(Ok),并且soap响应已压缩。 Still, I'm getting the following error:
不过,我收到以下错误:
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)
I read that JAX-WS should support gzipped webservice responses out of the box, but it looks like it doesn't. 我读到 JAX-WS应该开箱即用地支持gzip压缩的Web服务响应,但是看起来不支持。 It tries to use default codec which is for application/soap+xml despite the fact response contains Content-Type: application/x-gzip header.
尽管事实响应包含Content-Type:application / x-gzip标头,但它仍尝试使用针对application / soap + xml的默认编解码器。
Is there a way to make it use another codec, for gzip? 有没有办法让它对gzip使用另一个编解码器? Is there such a codec?
有这样的编解码器吗?
The link you referred to is telling that it supports gzip when the response is sent with 您所引用的链接告诉您,当发送响应时,它支持gzip。
Content-encoding: gzip
header, in addition to standard content-type header. 标头,以及标准的内容类型标头。 If the server responds with
Content-Type: application/x-gzip
, it's a different header, and it doesn't seem that would be supported even though gzip in itself is supported. 如果服务器以
Content-Type: application/x-gzip
响应,则它是一个不同的头,即使本身支持gzip,也似乎不支持该头。 I don't think you should be setting this: 我认为您不应该设置此设置:
theHeaders.put("Accept", Collections.singletonList("application/x-gzip"));
instead, just set accept-encoding including gzip: 相反,只需设置包含gzip的accept-encoding:
theHeaders.put("Accept", Collections.singletonList("application/soap+xml"));
theHeaders.put("Content-Type", Collections.singletonList("application/soap+xml"));
theHeaders.put("Accept-Encoding", Collections.singletonList("gzip"));
theHeaders.put("Content-Encoding", Collections.singletonList("gzip"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.