Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unzip files with Apache Camel?

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?

like image 782
Hector Avatar asked Aug 29 '13 20:08

Hector


1 Answers

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();
like image 90
Hector Avatar answered Nov 13 '22 05:11

Hector