Reputation: 103
I have a route , that is downloading a file from FTP. After that I just would like to send the filename to a jms:queue and not anything else. Ho to do that?
Actually I have this route
<from uri="ftp://ftp.x.com?username=x&password=x&binary=true&stepwise=false&delay=20000" />
<to uri="file://{{download_folder}}?fileName=${date:file:yyyyMMdd}_${file:name}&keepLastModified=true" />
<to uri="processFileNameToBody" />
<to uri="jms:queue:File.Process" />
with this in processFileNameToBody (org.apache.camel.Processor)
public void process(Exchange exchange) throws Exception {
try {
if (exchange.getIn() instanceof GenericFileMessage) {
log.info("Starting Processing FileName to body");
Map<String, String> map = new HashMap<String, String>();
String file = (String) exchange.getIn().getHeader("CamelFileNameProduced");
map.put("file", file);
XStream xs = new XStream();
String xml = xs.toXML(map);
exchange.getOut().setBody(xml);
log.info("Finished Processing FileName to body:" + file);
}
}
catch (Exception e) {
log.error("", e);
throw e;
}
}
but it does not work. I got a NPE in GenericFileConverter.convert.to
Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: RemoteFile[
Perhaps anybody has a solution for this. It can't be so complicated, but actually I fail. I think it has something to do when the file is written. It is writte at the end, but I already changed the body.
Help is appreciated. Thanks
Upvotes: 1
Views: 841
Reputation: 6925
I think you are looking for something like this:
<from uri="ftp://ftp.x.com?username=x&password=x&binary=true&stepwise=false&delay=20000" />
<to uri="file://{{download_folder}}?fileName=${date:file:yyyyMMdd}_${file:name}&keepLastModified=true" />
<setBody><simple>${header.CamelFileNameProduced}</simple></setBody>
<to uri="jms:queue:File.Process" />
Upvotes: 3