【问题标题】:Spring Integration GZIP HTTP requestsSpring 集成 GZIP HTTP 请求
【发布时间】:2017-09-15 00:20:07
【问题描述】:

我需要通过出站网关压缩 HTTP 请求。是否有用于 Spring Integration 的 GZIPInterceptor 或其他东西?

【问题讨论】:

    标签: java spring spring-integration gzip spring-ws


    【解决方案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 评论中的链接。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    相关资源
    最近更新 更多