ministry
ministry

Reputation: 113

HOW: Apache Camel, Regex match files

im experimenting in getting camel to do some file operations and pass them through the activeMQ broker, ive taken this project over from a guy who recently quit.

what ive got so far:

    <route id="SVLFTPCOPY">
  <from uri="sftp://*****:*******@********/srv/test/?fileName=*2280.xls&amp;noop=true&amp;idempotent=false"/>
    <to uri="file:/srv/data/test/destination/"/>
    <to uri="activemq:queue:svl.ftp.copy"/>
    </route>

it works to the point where it runs the route without throwing any errors, but still doesnt copy the file to the local file.

Any ideas? .

Upvotes: 7

Views: 28131

Answers (4)

Claus Ibsen
Claus Ibsen

Reputation: 55525

Yeah you need to use the include/exclude/filter option if you want to filter out files based on patterns. The fileName option is for a single file.

So in your case, remove fileName option and replace it with include=.*2280.xsl. Mind that the include is based on Java regular expressions, so we use dot star to indicate wildcard. More details here: https://camel.apache.org/components/latest/file-component.html. The ftp component inherits 99% of the options of the file component, so that is why I refer to the file wiki page.

Upvotes: 24

Devs love ZenUML
Devs love ZenUML

Reputation: 11862

In the implementation of name matching, the following code is used:

if (ObjectHelper.isNotEmpty(endpoint.getInclude())) {
    if (!name.matches(endpoint.getInclude())) {
        return false;
    }
}

So you can test which regular expression you should use. In you case, I think .*2280\\.xsl is what you should use.

Upvotes: 1

Peter Keller
Peter Keller

Reputation: 7636

Use the include option that uses Java regular expression:

include=.*2280\\.xsl

Please, mind the \\ before the dot .

Alternatively, use antInclude:

antInclude=*2280.xsl

Upvotes: 7

Olivier.Roger
Olivier.Roger

Reputation: 4249

For that kind of filtering I recommend to use the GenericFileFilter

Upvotes: 1

Related Questions