2013-08-29 92 views
3

如何使用Apache Camel從zip文件中提取文件(一個或多個)?可能嗎?使用Apache Camel解壓縮文件?

我想這

from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error") 
    .split(new ZipSplitter()) 
    .streaming().convertBodyTo(String.class)  
    .to("file:/home/myinputzip") 
.end(); 

當我啓動應用程序,該文件是從解壓縮後,但駱駝拋出一個異常,並且文件被移動到文件夾錯誤:

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)

誰能幫我?

+0

這是與此相關的問題https://issues.apache.org/jira/browse/CAMEL-6679? – hveiga

回答

3

我解決了如下

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

我同意你的路線應該工作,但是,你有沒有嘗試過這樣的事情:

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

我不得不採取從http://camel.465427.n5.nabble.com/zip-file-best-practices-td5713437.html

我希望這個作品對你這個例子!

+1

謝謝,但它不工作...當我部署服務器拋出異常 錯誤:org.apache.camel.processor.DefaultErrorHandler - (MessageId:ID-ubuntu-48866-1377893653015-0- 1在ExchangeId上:ID-ubuntu-48866-1377893653015-0-2)。交付嘗試後耗盡:1抓到:java.util.zip.ZipException:不正確的標題檢查 java.util.zip.ZipException:不正確的標題檢查 \t at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164) ' – Hector

+0

從示例鏈接看起來像這條路線要求壓縮數據已經加載到路由中 - 它不處理處理文件。 –