Apache Camel (un)marshal 与“gzipDeflater”如何工作?

问题描述 投票:0回答:1

在此代码片段中,我想使用 Camel 解压缩 gzip 正文。根据Camel文档,除了camel-core之外不需要其他依赖项。

    public static void main(final String[] args) throws Exception {
    try (final CamelContext context = new DefaultCamelContext()) {
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() {
                this.from("direct:test").unmarshal().gzipDeflater().to("seda:test2");
            }
        });
        context.start();
        context.createProducerTemplate().sendBody("direct:test", "this is not gzip but it does not matter.");
        Thread.currentThread().join();
    }
}

当我运行代码时,出现此错误:

Caused by: java.lang.IllegalArgumentException: Data format 'gzipDeflater' could not be created. Ensure that the data format is valid and the associated Camel component is present on the classpath
at org.apache.camel.reifier.dataformat.DataFormatReifier.createDataFormat(DataFormatReifier.java:279)
at org.apache.camel.reifier.dataformat.DataFormatReifier.getDataFormat(DataFormatReifier.java:152)
at org.apache.camel.reifier.dataformat.DataFormatReifier.getDataFormat(DataFormatReifier.java:112)
at org.apache.camel.reifier.UnmarshalReifier.createProcessor(UnmarshalReifier.java:35)
at org.apache.camel.reifier.ProcessorReifier.makeProcessor(ProcessorReifier.java:870)
at org.apache.camel.reifier.ProcessorReifier.addRoutes(ProcessorReifier.java:610)
at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:213)
... 11 more

错误消息说我需要另一个依赖项,但 Camel 文档说我不需要一个。那么这应该如何运作?

java apache-camel gzip
1个回答
0
投票

好的,解决方案是添加camel-zip-deflater jar。 GZip Deflater 文档已过时。

© www.soinside.com 2019 - 2024. All rights reserved.