s.k
s.k

Reputation: 535

How do I process a zip file with Camel using the Spring DSL?

I want to monitor a directory for zip files and then individually process the files in the zip file using Camel and the Spring DSL. Is something like the following possible?

<camel:route>
  <camel:from uri="file:/src/Path/"/>
  <camel:split streaming="true">
    <zipSplit/>
    <camel:to uri="bean:fileProcessor?method=processStream"/>
  </camel:split>
</camel:route>

Ok so I found that the following works for a zip file containing one file but the question is how can a zip file containing more than one file be processed?

<bean id="zipFileDataFormat" class="org.apache.camel.dataformat.zipfile.ZipFileDataFormat"/>

<camel:camelContext>
    <camel:contextScan/>
    <camel:route>
        <camel:from uri="file:///C:/testSrc/?delay=6000&noop=true&idempotent=false"/>
        <camel:unmarshal ref="zipFileDataFormat"/>
        <camel:to uri="file:///C:/testDst"/>
    </camel:route>
</camel:camelContext>

Note that the file is not being sent to a bean for processing just unzipped into another directory.

Upvotes: 0

Views: 6339

Answers (1)

s.k
s.k

Reputation: 535

This works. Note the log element will give you the details.

<bean id="zipFileDataFormat" class="org.apache.camel.dataformat.zipfile.ZipFileDataFormat">
    <property name="usingIterator" value="true"/>
</bean>

<camel:camelContext>
    <camel:contextScan/>
    <camel:route id="unzipMultipleFiles">
        <camel:from uri="file:///C:/testSrc/?delay=30000&amp;noop=true&amp;idempotent=false"/>
        <camel:unmarshal ref="zipFileDataFormat"/>
        <camel:split streaming="true">
            <camel:simple>${body}</camel:simple>
            <camel:to uri="log:org.apache.camel?level=INFO&amp;showAll=true&amp;multiline=true"/>
            <camel:to uri="file:///C:/testDst"/>
        </camel:split>
    </camel:route>
</camel:camelContext>

Upvotes: 5

Related Questions