2017-04-19 100 views

回答

1

沒有什麼現成的,但它是很容易添加一對變壓器發送到網關之前壓縮載荷...

@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評論中的鏈接。

+0

Apache HTTP Client默認支持:http://stackoverflow.com/questions/2777076/does-apache-commons-httpclient-support-gzip,你可以配置Spring集成HTTP使用'HttpComponentsClientHttpRequestFactory' –