I need to compress HTTP requests over outbound-gateway. Is there a GZIPInterceptor
for Spring Integration or other thing for that?
Asked
Active
Viewed 697 times
0

Gary Russell
- 166,535
- 14
- 146
- 179

alexsodev
- 489
- 5
- 12
1 Answers
3
There's nothing out of the box, but it's easy enough to add a pair of transformers to zip the payload before sending to the gateway...
@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();
}
and another to unzip...
@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();
}
You can also do it in a ClientHttpRequestInterceptor
.
Also see the link in Artem's comment below.

Gary Russell
- 166,535
- 14
- 146
- 179
-
The Apache HTTP Client supports that by default: http://stackoverflow.com/questions/2777076/does-apache-commons-httpclient-support-gzip and you can configure Spring Integration HTTP to use `HttpComponentsClientHttpRequestFactory` – Artem Bilan Apr 19 '17 at 01:44