简体   繁体   中英

Camel ZipSplitter - How to get the file content of unzipped file?

I am calculating MD5 of each file before uploading to S3. When i am using with ZipSplitter, I want to calculate MD5 of each unzipped file seperately. Exchange.getIn() gives the entire zip file instead of single unzipped file.

from(source).choice().when(isZipFile)
                .split(new ZipSplitter())
                .streaming()
                .process(md5HeadersProcessor)
                .process(camelS3HeadersProcessor)
                .to(destination)
                .log("Uploading file ${file:name} completed...")
                .end()
                .endChoice()

MD5HeadersProcessor:

@Override
public void process(Exchange exchange) throws NoSuchAlgorithmException {
    byte[] bytes = exchange.getIn().getBody(byte[].class);
    exchange.getIn().setHeader(S3Constants.CONTENT_MD5, getMD5(bytes));
}

CamelS3HeadersProcessor:

@Override
public void process(Exchange exchange) throws Exception {
    SimpleBuilder simpleBuilder = new SimpleBuilder("${file:onlyname}");
    String fileName = simpleBuilder.evaluate(exchange, String.class);
     exchange.getIn().setHeader(S3Constants.KEY, fileName);
}

I am able to set the unzipped fileName in CamelS3HeadersProcessor . How can i get the content of unzipped file in MD5HeadersProcessor ?

Its working after i changed this from ZipSplitter to ZipFileDataFormat & Iterator .

ZipFileDataFormat zf = new ZipFileDataFormat();
zf.setUsingIterator(true);

from(source).choice().when(isZipFile)
            .unmarshal(zf)
            .split(bodyAs(Iterator.class))
            .streaming()
            .convertBodyTo(String.class)
            .process(md5HeadersProcessor)
            .process(camelS3HeadersProcessor)
            .to(destination)
            .log("Uploading file ${file:name} completed...")
            .end()
            .endChoice()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM