Apache Camel Mail Folder
I am trying to zip a folder using Camel. I have Processor
one that created folders with files inside them:
public class CreateDirProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
File d = new File("myDir/hi");
d.mkdirs();
File f = new File(d, "hello.txt");
f.createNewFile();
in.setBody(f);
}
}
It works correctly.
In my route, I am trying to zip a folder hi
so that I can do this:
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
ProducerTemplate template = context.createProducerTemplate();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:source")
.process(new CreateDirProcessor())
.marshal().zipFile().to("file:zipped");
}
});
context.start();
template.sendBody("direct:source", "test");
Thread.sleep(3000);
context.stop();
}
And it doesn't work. I got:
TypeConversionException: Error during type conversion from type: java.io.File to the required type... `myDir/hi` is a directory
Is the directory not a file? Can't you pin an entire folder and its contents with Camel?
Thanks everyone.
source to share
Caveat - I'm not a Camel expert, but I could contribute to give you some direction.
In Java, at least when you are zipping multiple files, you add each file as a "zip record" to your zip file. Here's an example. So no, you never loop a directory directly - while a directory is a file, the file only contains pointers to other files, so writing to the file "file" will not produce the desired results.
Now for the second question - I can see that this link makes the zip multiple files in one. Check the link. Note the use of wild-card (* .txt) to reference files on zip and not use a directory. Hope this helps.
source to share