Cheat-Sheet-Mel-4 Page 2

ADVERTISEMENT

XPath support
XPath helper functions return DOM4J nodes. By default the XPath expression is evaluated on
xpath(xPathExpression [, xmlElement])
message.payload unless an xmlElement is specified:
To get the text content of an element or an attribute:
#[xpath(‘//title’).text]
#[xpath(‘//title/@id’).value]
JSON processing
MEL has no direct support for JSON. The json-to-object-transformer can turn a JSON payload into a hierarchy of simple data structures that are
easily parsed with MEL. For example, the following uses a filtered projection to build the equivalent of the $..[?(@.title==’Moby Dick’)].price JSON path
expression:
<json:json-to-object-transformer returnClass=”java.lang.Object” />
<expression-transformer
expression=”#[($.price in message.payload if $.title == ‘Moby Dick’)[0]]” />
More MVEL Goodness
Quick access to the MVEL 2.0 Documentation:
Java interoperability, for example to create a
<mulexml:context-property key=”transactionId”
random UUID and use it as an XSL-T parameter:
value=”#[java.util.UUID.randomUUID().toString()]” />
Safe bean property navigation, for example to
<set-variable variableName=”fullName” value=”#[message.payload.?name.
retrieve fullName only if the name object is not
fullName]” />
null:
Local variable assignment, as in this splitter
<splitter expression=”#[rows=StringUtils.split(message.payload,’\n\r’);
expression that splits a multi-line payload in rows
ArrayUtils.subarray(rows,1,rows.size())]” />
and drops the first row:
“Elvis” operator, to return the first non-null value
#[message.payload.userName or message.payload.userId]
of a list of values:
Global Configuration
<configuration>
<expression-language autoResolveVariables=”false”>
Define global imports, aliases and global functions
<import class=”org.mule.util.StringUtils” />
<import name=”rsu” class=”org.apache.commons.lang.RandomStringUtils” />
in the global configuration element. Global functions
<alias name=”appName” expression=”app.name” />
can be loaded from the file system, a URL, or a
<global-functions file=”extraFunctions.mvel”>
classpath resource (see extraFunctions.mvel below).
def reversePayload() { StringUtils.reverse(payload) }
Flow variables auto-binding can be turned off via the
def randomString(size) { rsu.randomAlphanumeric(size) }
autoResolveVariables attribute.
</global-functions>
</expression-language>
</configuration>
About MuleSoft
MuleSoft provides the most widely used integration platform for connecting SaaS and enterprise applications in the cloud and on-premise. With the rise of cloud and
mobile, enterprises face a choice: get overwhelmed by the resulting explosion of end points or seize the opportunity to gain competitive advantage. Founded on the idea
that connecting applications should not be hard, MuleSoft lets organizations harness the power of their applications through integration. MuleSoft’s Anypoint™ technology
eliminates costly, time-intensive point-to-point integration, enabling business agility. Delivered as a packaged integration experience, CloudHub™ (formerly Mule iON) and
Mule ESB™ are built on proven open source technology for the fastest, most reliable integration without vendor lock-in. Supporting billions of transactions per day, MuleSoft
is used in production by thousands of enterprises, including Walmart, MasterCard, Nokia, Nestlé and Honeywell, and powers integrations with leading SaaS vendors such as
, NetSuite, Workday, Intuit and Zuora.
For more information: Follow us on Twitter: @mulesoft.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2