0

I have defined a global function as below

<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>

But when calling via logger nothing seems to happen

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

The xpath expression xpath://address/@timestamp yields 2014-10-29T15:23:07

But before the logger I see

xpath-branch:/address/@timestamp is: org.dom4j.tree.DefaultAttribute@6452310a [Attribute: name timestamp value "2014-10-29T15:23:07"]

The error message is as below

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

What am I doing wrong here? Many Thanks.

hpandalai
  • 438
  • 2
  • 13
  • 31

1 Answers1

0

You're mixing MEL and the old style of expressions.

This is old style: xpath://address/@payloadID

This is MEL: xpath('//address/@payloadID').value

So you need to use:

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

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

David Dossot
  • 33,403
  • 4
  • 38
  • 72