Spring集成GZIP HTTP请求
答
没有什么现成的,但它是很容易添加一对变压器发送到网关之前压缩载荷...
@Bean
@Transformer(inputChannel = "gzipIt", outputChannel = "gzipped")
public byte[] gzip(byte[] in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzOut = new GZIPOutputStream(out);
FileCopyUtils.copy(in, gzOut);
return out.toByteArray();
}
,另一个解压...
@Bean
@Transformer(inputChannel = "gUnzipIt", outputChannel = "gUnzipped")
public byte[] gUnzip(byte[] in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPInputStream gzIn = new GZIPInputStream(new ByteArrayInputStream(in));
FileCopyUtils.copy(gzIn, out);
return out.toByteArray();
}
你也可以在ClientHttpRequestInterceptor
。
另请参阅下面的Artem评论中的链接。
Apache HTTP Client默认支持:http://*.com/questions/2777076/does-apache-commons-httpclient-support-gzip,你可以配置Spring集成HTTP使用'HttpComponentsClientHttpRequestFactory' –