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()