I need to compress HTTP requests over outbound-gateway. Is there a GZIPInterceptor
for Spring Integration or other thing for that?
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.