Java JAX-WS客户端:gzip响应的UnsupportedMediaException

Java JAX-WS客户端:gzip响应的UnsupportedMediaException,java,jax-ws,gzip,Java,Jax Ws,Gzip,我编写了JAX-WS(来自Sun)客户端,它进行服务调用,期望服务器响应被gzip: Map<String, List<String>> theHeaders = new HashMap<String, List<String>>(); theHeaders.put("Content-Encoding", Collections.singletonList("gzip")); theHeaders.put("Accept", Collections

我编写了JAX-WS(来自Sun)客户端,它进行服务调用,期望服务器响应被gzip:

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);
我认为JAX-WS应该支持现成的gzip Web服务响应,但它似乎不支持。它尝试使用默认的编解码器,用于application/soap+xml,尽管响应包含内容类型:application/x-gzip header


有没有办法让它使用另一个编解码器,用于gzip?有这样的编解码器吗?

您提到的链接告诉我们,当响应与一起发送时,它支持gzip

Content-encoding: gzip
标题,除标准内容类型标题外。如果服务器响应
内容类型:application/x-gzip
,则它是一个不同的头,即使gzip本身受支持,它似乎也不受支持。我认为你不应该设置这个:

theHeaders.put("Accept", Collections.singletonList("application/x-gzip"));
相反,只需设置accept encoding,包括gzip:

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"));

因此,为了确保我没有弄错:服务器端应该准确地响应gzip内容编码头,而不是application/x-gzip,以便在客户端将其视为gzip?@MikhailBerastau application/gzip是一个内容类型头值,gzip是应用编码头值。所以,对于所有的实现,服务器都应该使用内容编码gzip来响应,这样才能工作。对于某些web服务客户机库,也可以使用application/gzip内容类型,而对于某些web服务客户机库,则不可以。根据错误消息,我猜测在本例中不是这样。检查jaxws rt的源代码后,它会进行如下比较:if(contentEncoding!=null&&contentEncoding.contains(“gzip”){in=new GZIPInputStream(in);}因此在内容编码中提及gzip是可以接受的;re content type-我认为您是对的,它应该是application/soap+xml。在我的例子中,问题是contentEncoding变量为null(通过调试检查),即使在respond中正确设置了内容编码。是的,任何提及都应该可以接受。我把它作为唯一一个,因为您指出gzip是您想要使用的。
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"));