Krystian Sikora
Krystian Sikora

Reputation: 12268

Apache Camel's ${file:ext} picks up everything after the first dot, instead of extension only

As the title says, I am trying to get file extension using Camel's File Language to specify the correct route.

choice().
   when().simple("${file:ext} in 'xml'").
      unmarshal(coreIt("jaxb[Core]")).
      beanRef(connectorName()+coreIt("[Core]ImportConnector"), "processXml").
   when().simple("${file:ext} in 'zip,7z'").
      beanRef(connectorName()+coreIt("[Core]ImportConnector"), "extractZip").
endChoice();

Problem is, client provides us with xml file that has a date in filename, separated by dots. For some reason camel treats everything after the first dot as an extension. If I do:

when().simple("${file:ext} in '09.16.xml'").

it works...

Is there any solution or workaround apart from creating a separate folder to import xml files? Thanks for your time.

Upvotes: 0

Views: 1983

Answers (2)

Pines Tran
Pines Tran

Reputation: 679

Try to use:

${file:name.ext}

Ref: https://camel.apache.org/components/4.4.x/languages/file-language.html

Upvotes: 0

Claus Ibsen
Claus Ibsen

Reputation: 55525

Well its tough as some files may have dot in extension such as '.tar.gz' and so on. So they should ideally not use dot in the file name. To work around this you would need to use some other simple expression to check for this. You can use ends with

${file:name} ends with 'xml'

And then you can use or:

${file:name} ends with 'zip' || ${file:name} ends with '7z'

See more details at: http://camel.apache.org/simple

Upvotes: 2

Related Questions