0

我已经定义了一个全局函数如下

<configuration doc:name="Configuration">
    <expression-language autoResolveVariables="true">
        <import class="java.text.SimpleDateFormat" />
        <global-functions>
            def convertDate(shiftDate){
                dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                return dateFormat.format(shiftDate);
            }            
        </global-functions>         
    </expression-language>
</configuration>

但是当通过记录器调用时似乎什么都没有发生

<logger message="Convert Date #[convertDate(xpath://address/@timestamp)]" level="DEBUG" doc:name="Logger"/>

xpath 表达式 xpath://address/@timestamp 产生 2014-10-29T15:23:07

但在我看到的记录器之前

xpath-branch:/address/@timestamp 为:org.dom4j.tree.DefaultAttribute@6452310a [属性:名称时间戳值“2014-10-29T15:23:07”]

错误信息如下

org.mule.api.expression.InvalidExpressionException: [Error: unexpected end of statement]
[Near : {... convertDate(xpath://address/@payloadID) ....}]

我在这里做错了什么?非常感谢。

4

1 回答 1

0

您正在混合 MEL 和旧式的表达方式。

这是旧样式:xpath://address/@payloadID

这是梅尔:xpath('//address/@payloadID').value

所以你需要使用:

<logger
   message="Convert Date #[convertDate(xpath('//address/@payloadID').value)]"
   level="DEBUG" />

请参阅: http: //www.mulesoft.org/documentation/display/current/Mule+Expression+Language+Tips#MuleExpressionLanguageTips-XPathSupport

于 2014-11-03T06:08:43.880 回答