hveiga
hveiga

Reputation: 6915

Using ZipSplitter in Apache Camel Spring DSL

I would like to know how to use ZipSplitter from camel-zipfile in Spring DSL. I have been trying different approaches based on this post Unzip a file using Apache Camel UnZippedMessageProcessor but I am not able to figure out how to do in Spring. Also, I have not found any examples about this.

I have something like this:

<bean id="zipSplitter" class="org.apache.camel.dataformat.zipfile.ZipSplitter" />

...

<split streaming="true" parallelProcessing="true">
    <?????>
    <convertBodyTo type="java.lang.String" />
    <to uri="file:foo" />
</split>

Thanks for the help!

Upvotes: 3

Views: 2740

Answers (2)

Emystein
Emystein

Reputation: 166

With Camel 2.13.0, using parallelProcessing="true" and unzipping a .zip file containing 10 xml files around 10Kb each, it throws a couple of exceptions:

Caused by: java.util.zip.ZipException: invalid distance too far back at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164) ~[na:1.7.0_55] at java.util.zip.ZipInputStream.read(ZipInputStream.java:193) ~[na:1.7.0_55] at java.io.BufferedInputStream.read1(BufferedInputStream.java:273) ~[na:1.7.0_55] at java.io.BufferedInputStream.read(BufferedInputStream.java:334) ~[na:1.7.0_55] at java.io.FilterInputStream.read(FilterInputStream.java:107) ~[na:1.7.0_55] at org.apache.camel.component.file.FileOperations.writeFileByStream(FileOperations.java:375) ~[camel-core-2.13.0.jar:2.13.0]

and on retry:

Caused by: java.io.IOException: Stream closed at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:66) ~[na:1.7.0_55] at java.util.zip.ZipInputStream.read(ZipInputStream.java:181) ~[na:1.7.0_55] at java.io.BufferedInputStream.read1(BufferedInputStream.java:273) ~[na:1.7.0_55] at java.io.BufferedInputStream.read(BufferedInputStream.java:334) ~[na:1.7.0_55] at java.io.FilterInputStream.read(FilterInputStream.java:107) ~[na:1.7.0_55] at org.apache.camel.component.file.FileOperations.writeFileByStream(FileOperations.java:375) ~[camel-core-2.13.0.jar:2.13.0]

I've found a workaround, removing the parallelProcessing="true" attribute:

<route id="ConsumeZipFiles">
    <from uri="file:src/test/resources/input/zip?noop=true&amp;delay=30000" />
    <split streaming="true">
        <ref>zipSplitter</ref> 
        <to uri="file:target/output" />
    </split>
</route>

Upvotes: 0

Willem Jiang
Willem Jiang

Reputation: 3291

You can use to hold the reference of expression just like this

<bean id="zipSplitter" class="org.apache.camel.dataformat.zipfile.ZipSplitter" />

...

<split streaming="true" parallelProcessing="true">
    <ref>zipSplitter</ref> 
    <convertBodyTo type="java.lang.String" />
    <to uri="file:foo" />
</split>

Upvotes: 5

Related Questions