Reputation: 851
How I can extract files (one or more than one) from a zip file with Apache Camel? Is it possible?
I'm trying this
from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error")
.split(new ZipSplitter())
.streaming().convertBodyTo(String.class)
.to("file:/home/myinputzip")
.end();
When I start the application, the file is extracted from zip, but camel throws an exception and the file is moved to error folder:
ERROR: org.apache.camel.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID-ubuntu-35217-1377806407437-0-5 on ExchangeId: ID-ubuntu-35217-1377806407437-0-7). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot write null body to file: /home/myinputzip/aVIII_crrpfp201304.cap org.apache.camel.component.file.GenericFileOperationFailedException: Cannot write null body to file: /home/myinputzip/aVIII_crrpfp201304.cap at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:194) at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:257) at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:159) at org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:80) at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122) at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
Can anyone help me?
Upvotes: 8
Views: 10173
Reputation: 851
I solved as follows
from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error")
.split(new ZipSplitter())
.streaming().convertBodyTo(String.class)
.choice()
.when(body().isNotNull())
.to("file:/home/myinputzip")
.end()
.end();
Upvotes: 4
Reputation: 6925
I agree that your route should work, however, have you tried something like this:
from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error")
.unmarshal().zip()
.split(body(Iterable.class))
.streaming().convertBodyTo(String.class)
.to("file:/home/myinputzip")
.end();
I have take this example from http://camel.465427.n5.nabble.com/zip-file-best-practices-td5713437.html
I hope this works for you!
Upvotes: 0