1
votes

I am attempting to use camel to route some files from an FTP into HDFS. My routes in general seem to be working fine, however anytime there is a file that has a space in its name, the route fails. It fails trying to copy the file over to HDFS. The files are dynamic and nature and change daily, so I will not be able to do a specific include and change the file name through .setHeader, nor will I be able to rename the files on the FTP.

Is it possible to dynamically rename files that have a space in there names with camel, before routing them into HDFS?

1

1 Answers

0
votes

The file name being stored in the message header called "CamelFileName", you could go with something like this:

from("sftp:...")
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                Message in = exchange.getIn();
                String originalFilename = (String) in.getHeader(Exchange.FILE_NAME);
                String modifiedFilename = originalFilename.replaceAll("\\s+", "");
                in.setHeader(Exchange.FILE_NAME,  modifiedFilename);
        }})
.to("hdfs:...");

or more succinctly:

from("ftp:in")
     .setHeader(Exchange.FILE_NAME, header(Exchange.FILE_NAME).regexReplaceAll("\\s+", "_").getExpression())
     .to("hdfs:out");