12

I need the simplest filter by extension: f.e. file 20120523.173227.CustomerMaster05092012.QWERTY.xml route:

<from uri="file://{{fdr.folder.working.url}}&amp;include=*.xml"/>

doesn't work:

Dangling meta character '*' near index 0

WARN - file://root_folder/working/) [FileConsumer] Consumer Consumer[file://root_folder/working/?delay=1000&delete=true&idempotent=false&include=*.xml&initialDelay=1000&readLock=changed] failed polling endpoint: Endpoint[file://root_folder/working/?delay=1000&delete=true&idempotent=false&include=*.xml&initialDelay=1000&readLock=changed]. Will try again at next poll. Caused by: [java.util.regex.PatternSyntaxException - Dangling meta character '*' near index 0
*.xml
^]
java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
*.xml
^
    at java.util.regex.Pattern.error(Pattern.java:1713)
    at java.util.regex.Pattern.sequence(Pattern.java:1878)
    at java.util.regex.Pattern.expr(Pattern.java:1752)
    at java.util.regex.Pattern.compile(Pattern.java:1460)
    at java.util.regex.Pattern.<init>(Pattern.java:1133)
    at java.util.regex.Pattern.compile(Pattern.java:823)
    at java.util.regex.Pattern.matches(Pattern.java:928)
    at java.lang.String.matches(String.java:2090)
    at org.apache.camel.component.file.GenericFileConsumer.isMatched(GenericFileConsumer.java:458)
    at org.apache.camel.component.file.GenericFileConsumer.isValidFile(GenericFileConsumer.java:395)
    at org.apache.camel.component.file.FileConsumer.pollDirectory(FileConsumer.java:94)
    at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:107)
    at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:142)
    at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

ok maybe my bad. I put whole file to include:

<from uri="file://{{fdr.folder.working.url}}&amp;include=20120523.173227.CustomerMaster05092012.QWERTY.xml"/>

Whole file is OK. Let's try put * in the middle of file name

<from uri="file://{{fdr.folder.working.url}}&amp;include=20120523.*.xml"/>

and again it is OK. Let's put only one digit in file name

<from uri="file://{{fdr.folder.working.url}}&amp;include=2*.xml"/>

noup, camel didn't find such files I tried escaped asterisk but it did't help.

<from uri="file://{{fdr.folder.working.url}}&amp;include=\*.xml"/>
and
<from uri="file://{{fdr.folder.working.url}}&amp;include=\\*.xml"/>

File was just ignored. so question 1: how to use asterisk?

and question 2: how to use multimple file extensions, like include=.xml;.zip

thks

Dmitrii Borovoi
  • 2,814
  • 9
  • 32
  • 50

3 Answers3

17

damn, good thinking comes after, using brute force I found out correct value for include:

.*.xml|.*.zip
Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74
Dmitrii Borovoi
  • 2,814
  • 9
  • 32
  • 50
  • 5
    Yes its just a regular expression, so whatever you can do with the Java Regular Expression API is part of that filter. – Claus Ibsen Feb 25 '13 at 15:56
  • 5
    You should escape the last '.' character. Otherwise you'll match files like fooxml or barzip – Artur Sep 25 '15 at 18:37
5
(?i).*.xml|.*.zip

If you want case insensitive file extension matching.

Simon
  • 136
  • 2
  • 2
4

You have to properly escape the backslash in string and use end of string sign '$': include=.*\\.xml$

Adam Bogdan Boczek
  • 1,720
  • 6
  • 21
  • 34