骡表达正则表达式问题
Mule expression regex issue
我有一个 ftp 入站端点,其中存储了很多文件(不是全部给我)所以我添加了一个文件名正则表达式过滤器,其中包含我想从中获取的不同正则表达式FTP目录:
<file:filename-regex-filter pattern="
${environment}\.TEST.xml,
0\.${environment}\.REPD\.(.*).GZ,
${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
效果很好,但现在我想根据文件类型执行特定行为。
因此,我使用了一个具有不同 when 表达式的选择组件:
我的第一个想法是使用带有 when 表达式的选择组件,该表达式使用与文件名-正则表达式过滤器中使用的正则表达式相同的正则表达式:
<when expression="#[message.inboundProperties.originalFilename.matches('0\.${environment}\.REPD\.(.*).GZ')]">
// Specific behaviour for this type of files
</when>
这产生了以下错误消息:
Exception stack is:
1. [Error: illegal escape sequence: .]
[Near : {... age.inboundProperties.originalFilename.matches('0\.T\.REPD\.(.*).GZ') ....}]
^
[Line: 1, Column: 55] (org.mule.api.expression.InvalidExpressionException)
org.mule.el.mvel.MVELExpressionLanguage:238(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/InvalidExpressionException.html)
2. [Error: illegal escape sequence: .]
[Near : {... age.inboundProperties.originalFilename.matches('0\.T\.REPD(.*).GZ') ....}]
这意味着表达式属性不需要转义字符,所以我决定不转义它们
<when expression="#[message.inboundProperties['originalFilename'].matches('${environment}.TEST.xml')]">
//Specific behavior for this type of files...
</when>
<when expression="#[message.inboundProperties.originalFilename.matches('0.${environment}.REPD.*.GZ')]">
//Specific behavior for this type of files...
</when>
<otherwise>
<file:outbound-endpoint path="C:/test/result/other" responseTimeout="10000" outputPattern="#[message.inboundProperties.originalFilename]"/>
</otherwise>
这里的消息总是路由到 otherwise 子句,除了第一个不使用通配符的表达式...
使用 when 表达式是一种好的做法吗?放置表达式的正确方法是什么?
我找到了一个暂时可行的解决方案,但我认为一定有更好的使用正则表达式的解决方案:
<file:inbound-endpoint responseTimeout="10000" connector-ref="input" path="C:/test">
<file:filename-regex-filter pattern="
0\.${environment}\.REPD\.(.*).GZ,
${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
</file:inbound-endpoint>
<choice>
<when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('0.${environment}.REPD'.toLowerCase()) &&
(message.inboundProperties.originalFilename.toLowerCase()).endsWith('gz')]">
<gzip-uncompress-transformer/>
// Specific behaviour for this type of files
</when>
<when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &&
(message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &&
(message.inboundProperties.originalFilename.toLowerCase()).endsWith('.xml.gz')]">
// Specific behaviour for this type of files
</when>
<when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &&
(message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &&
(message.inboundProperties.originalFilename.toLowerCase()).endsWith('voucher.xml')]">
// Specific behaviour for this type of files
</when>
</choice>
我在互联网上搜索了几个小时,但没有找到解决我问题的有效方法。如果有人知道如何使用正则表达式或其他评估器解决这个问题,我很好奇...
我有一个 ftp 入站端点,其中存储了很多文件(不是全部给我)所以我添加了一个文件名正则表达式过滤器,其中包含我想从中获取的不同正则表达式FTP目录:
<file:filename-regex-filter pattern="
${environment}\.TEST.xml,
0\.${environment}\.REPD\.(.*).GZ,
${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
效果很好,但现在我想根据文件类型执行特定行为。 因此,我使用了一个具有不同 when 表达式的选择组件:
我的第一个想法是使用带有 when 表达式的选择组件,该表达式使用与文件名-正则表达式过滤器中使用的正则表达式相同的正则表达式:
<when expression="#[message.inboundProperties.originalFilename.matches('0\.${environment}\.REPD\.(.*).GZ')]">
// Specific behaviour for this type of files
</when>
这产生了以下错误消息:
Exception stack is:
1. [Error: illegal escape sequence: .]
[Near : {... age.inboundProperties.originalFilename.matches('0\.T\.REPD\.(.*).GZ') ....}]
^
[Line: 1, Column: 55] (org.mule.api.expression.InvalidExpressionException)
org.mule.el.mvel.MVELExpressionLanguage:238(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/InvalidExpressionException.html)
2. [Error: illegal escape sequence: .]
[Near : {... age.inboundProperties.originalFilename.matches('0\.T\.REPD(.*).GZ') ....}]
这意味着表达式属性不需要转义字符,所以我决定不转义它们
<when expression="#[message.inboundProperties['originalFilename'].matches('${environment}.TEST.xml')]">
//Specific behavior for this type of files...
</when>
<when expression="#[message.inboundProperties.originalFilename.matches('0.${environment}.REPD.*.GZ')]">
//Specific behavior for this type of files...
</when>
<otherwise>
<file:outbound-endpoint path="C:/test/result/other" responseTimeout="10000" outputPattern="#[message.inboundProperties.originalFilename]"/>
</otherwise>
这里的消息总是路由到 otherwise 子句,除了第一个不使用通配符的表达式...
使用 when 表达式是一种好的做法吗?放置表达式的正确方法是什么?
我找到了一个暂时可行的解决方案,但我认为一定有更好的使用正则表达式的解决方案:
<file:inbound-endpoint responseTimeout="10000" connector-ref="input" path="C:/test">
<file:filename-regex-filter pattern="
0\.${environment}\.REPD\.(.*).GZ,
${environment}(.*)PERSONNOTI(.*)\.xml\.gz,
${environment}(.*)PERSONNOTI(.*)voucher\.xml" caseSensitive="false" />
</file:inbound-endpoint>
<choice>
<when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('0.${environment}.REPD'.toLowerCase()) &&
(message.inboundProperties.originalFilename.toLowerCase()).endsWith('gz')]">
<gzip-uncompress-transformer/>
// Specific behaviour for this type of files
</when>
<when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &&
(message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &&
(message.inboundProperties.originalFilename.toLowerCase()).endsWith('.xml.gz')]">
// Specific behaviour for this type of files
</when>
<when expression="#[(message.inboundProperties.originalFilename.toLowerCase()).startsWith('${environment}'.toLowerCase()) &&
(message.inboundProperties.originalFilename.toLowerCase()).contains('personnoti') &&
(message.inboundProperties.originalFilename.toLowerCase()).endsWith('voucher.xml')]">
// Specific behaviour for this type of files
</when>
</choice>
我在互联网上搜索了几个小时,但没有找到解决我问题的有效方法。如果有人知道如何使用正则表达式或其他评估器解决这个问题,我很好奇...