Recently, I came across some Mule documentations and it seems like I can extend the MEL with more methods from java classes. Has anyone have any experience in doing this and how it works?
So MEL automatically imports the following java classes so that we can call their methods in MEL. Was hoping to extend this list of java classes.
MEL automatically imports the Java classes listed below. You can use these imported classes without using full-qualifier names. For example, because BigInteger is imported, you can write #[BigInteger.valueOf(payload.dueAmount)] instead of #[java.math.BigInteger.valueOf(payload.dueAmount)].
There is documentation on how to define a global configuration with additional java class imports, etc. But I'm not sure how to exactly use this.
<configuration>
<expression-language autoResolveVariables="false">
<import class="org.mule.util.StringUtils" />
<import name="rsu" class="org.apache.commons.lang.RandomStringUtils" />
<alias name="appName" expression="app.name" />
<global-functions file="extraFunctions.mvel">
def reversePayload() { StringUtils.reverse(payload) }
def randomString(size) { rsu.randomAlphanumeric(size) }
</global-functions>
</expression-language>
</configuration>
How would you access the methods in MEL with the above configuration? Would it be...
<set-variable value="#[appName.reversePayload()]" variableName="reversePayload" doc:name="Variable containing a reverse version of the Payload"/>
I think they are available without qualification.
<set-variable value="#[reversePayload()]" variableName="reversePayload" doc:name="Variable containing a reverse version of the Payload"/>