Cheat-Sheet-Mel-4

ADVERTISEMENT

Mule Expression Language (MEL)
Cheat
Sheet
Server, Mule, Application and Message variables
Overview of the global contexts and the variables they give access to.
Server
Mule
App
Message
osArch
dataType
fileSeparator
clusterId
encoding
id
osVersion
payload
host
home
name
rootId
systemProperties
inboundProperties
ip
nodeId
standalone
correlationId
timeZone
inboundAttachments
locale
version
workdir
correlationSequence
tmpDir
outboundProperties
javaVersion
registry
correlationGroupSize
userName
outboundAttachments
javaVendor
replyTo
userHome
exception
osName
userDir
Create a directory named target in the system’s temporary directory and
<expression-component>
set it as the current payload:
targetDir = new java.io.File(server.tmpDir, ‘target’);
targetDir.mkdir();
payload = targetDir
</expression-component>
Set the username and password for an
<https:outbound-endpoint address=”https://#[message.inboundProperties.username]:
/>
HTTP endpoint at runtime based on inbound
message properties:
Flow and session variables
Flow variables are available in the flowVars context or directly as top level variables (unless autoResolveVariables is false or their name violates the
MVEL naming conventions). Session variables are available in the sessionVars context.
To create a session variable named sessionId whose value is the concatenation of the current message ID, “@” and the Mule instance node ID, use
either set-session-variable or MEL code, both shown hereafter:
<set-session-variable variableName=”sessionId” value=”#[message.id+’@’+mule.nodeId]” />
<expression-component>sessionVars.sessionId = message.id+’@’+mule.nodeId;</expression-component>
Payload and attachments
Copy the current payload in a flow variable named
<set-variable variableName=”originalPayload” value=”#[message.payload]” />
originalPayload then restore it:
<set-payload value=”#[originalPayload]” />
To retrieve the message payload in a particular format, using Mule’s auto-
<logger message=”#[message.payloadAs(java.lang.String)]” />
transformation capability, use payloadAs:
To extract all *.txt and *.xml attachments, use
<expression-transformer expression=”#[($.value in
a filtered projection:
message.inboundAttachments.entrySet() if $.key ~= ‘(.*\\.txt|.*\\.xml)’)]” />
The following shows how a bean can be dynamically retrieved from the registry, based on a name created by taking a value from a bean payload with a
getTargetService() accessor:
<set-variable variableName=”beanName” value=”#[message.payload.targetService+’Processor’]” />
<set-variable variableName=”bean” value=”#[app.registry[beanName]]” />

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2