GZIP解压缩:ed响应(Grails/Groovy)

问题描述:

我正在使用RestBuilder插件使用REST api。我得到一个响应,其中身体被压缩:GZIP解压缩:ed响应(Grails/Groovy)

Content-Encoding=[gzip] 

Groovy/Grails提供任何简单的访问/原生方法来解码gzip压缩?我发现的唯一的东西是本地Java zip api(例如GZIPInputStream)。有人有更好的主意吗?

春HttpComponents会自动处理解码:

HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create().build()); 
RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory); 

ResponseEntity<String> response = restTemplate.exchange(
     "some/url/", HttpMethod.GET, new HttpEntity<Object>(requestHeaders), 
     String.class); 

基本上,你有两个选择在这里:

  • GZIPInputStream
  • 配置GZIP减压在Tomcat中,看到here
+0

我喜欢第二种选择,但这需要我配置嵌入式tomcat实例,以便测试环境有效。我会对此稍微考虑一下。 – john 2015-01-29 18:46:55