Apache camel 使用camel压缩和密码保护文件

Apache camel 使用camel压缩和密码保护文件,apache-camel,Apache Camel,我一直在尝试在我的路线压缩多个csv文件。我已经成功地做到了这一点 我用spring做同样的事情 现在新的要求是密码保护它们。下面是我使用的聚合策略。如何做到这一点 <route autoStartup="false" routePolicyRef="routeTwoTimer" startupOrder="2" id="zippingFileRoute"> <from uri="{{to.file.processed1}}"/> <choice i

我一直在尝试在我的路线压缩多个csv文件。我已经成功地做到了这一点

我用spring做同样的事情

现在新的要求是密码保护它们。下面是我使用的聚合策略。如何做到这一点

<route autoStartup="false" routePolicyRef="routeTwoTimer" startupOrder="2" id="zippingFileRoute">
    <from uri="{{to.file.processed1}}"/>
    <choice id="csvZipFile">
        <when>
            <simple>$simple{header.CamelFileName} regex '^.*(csv|CSV)$'</simple>
            <aggregate strategyRef="zipAggregationStrategy" completionFromBatchConsumer="true" eagerCheckCompletion="true">
                <correlationExpression>
                    <constant>true</constant>
                </correlationExpression>
                <to uri="{{to.file.processed2}}"/>
            </aggregate>
        </when>
    </choice>
</route>

$simple{header.CamelFileName}regex'^.*(csv | csv)$'
真的

正如评论中指出的,Java API在加密ZIP文件方面有点受限。ApacheCamel
ZipAggregationStrategy
正在使用
ZipoutStream
,因此也存在此限制。您可以使用任何其他库实现自定义
聚合器
,该库允许对Zip文件进行加密。比如说

添加Maven依赖项

<dependency>
    <groupId>net.lingala.zip4j</groupId>
    <artifactId>zip4j</artifactId>
    <version>1.3.2</version>
</dependency>
使用它

from("file://in")
    .to("log:in")
    .setHeader(PasswordZipAggregationStrategy.ZIP_PASSWORD_HEADER, constant("testPassword"))
    .aggregate().constant(true).completionFromBatchConsumer()
        .aggregationStrategy(new PasswordZipAggregationStrategy())
.to("log:out")
.to("file://out");

你一个问题也没问。你是说你不知道该怎么办?你有没有试过一些东西,但它不起作用?是的,雷,我不知道怎么做。你是对的,没有说任何关于zip选项(如密码)的内容。我想这是不支持的。一种选择是对所有文件进行加密,然后压缩(在zip中),或者在压缩后对zip文件进行压缩和加密。说Java OOB中没有密码加密。但是,可以集成到项目中的库很少。我个人会创建一个特定的Camel处理器来使用库来创建Zip文件。
from("file://in")
    .to("log:in")
    .setHeader(PasswordZipAggregationStrategy.ZIP_PASSWORD_HEADER, constant("testPassword"))
    .aggregate().constant(true).completionFromBatchConsumer()
        .aggregationStrategy(new PasswordZipAggregationStrategy())
.to("log:out")
.to("file://out");