Apache Camel 的 ${file:ext} 获取第一个点之后的所有内容,而不是仅扩展名

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

正如标题所说,我正在尝试使用 Camel 的文件语言获取文件扩展名以指定正确的路径。

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();

问题是,客户向我们提供了 xml 文件,文件名中有日期,由点分隔。出于某种原因,camel 将第一个点之后的所有内容都视为扩展名。如果我这样做:

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

有效...

除了创建单独的文件夹来导入 xml 文件之外,是否有任何解决方案或变通方法?谢谢你的时间。

这很难,因为某些文件的扩展名可能带有点,例如“.tar.gz”等。所以他们最好不要在文件名中使用点。要解决此问题,您需要使用其他一些简单的表达式来检查这一点。您可以使用结尾

${file:name} ends with 'xml'

然后你可以使用或:

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

查看更多详细信息:http://camel.apache.org/simple