SlideShare a Scribd company logo
Mule Integration Workshop
Mule Expression Language
•Rapidly connect any application, anywhere
•Anypoint Platform helps companies prepare for the future
with a next-generation SOA platform that connects on-
premises systems and the cloud.
•Mule ESB, CloudHub, Mule Studio, Mule Enterprise
Management, Anypoint Connectors
Anypoint
Platform
for SOA
•Connect SaaS with any application, anywhere
•Anypoint Platform helps companies connect SaaS applications
to each other and the enterprise, in the cloud and on-
premises.
•CloudHub, Mule ESB, Mule Studio, CloudHub Insight,
Anypoint Connectors
Anypoint
Platform
for SaaS
•All you need to connect any app, any device and any API
•With the Anypoint Platform for APIs, you can build new APIs,
design new interfaces for existing APIs and more efficiently
manage all your APIs using a single platform.
•API Portal, API Manager, Mule Studio, Mule ESB, CloudHub
Anypoint
Platform
for API
MuleSoft Anypoint Platforms
1
Chapters
Schedule
Mule Expression Language(MEL) - Introduction
MEL - Syntax
MEL – Operand, Property
MEL – Arithmetic Operators
MEL – Comparison Operators
MEL – Logical Operators
MEL – Assignment, Literals
MEL – Literals
MEL – Maps, Lists and Arrays
MEL – Control Flow, Context Objects
MEL – Context Object – Server
MEL – Context Object – Mule, App
MEL – Context Object – Message
MEL – Variables
MEL – Data Extraction Function
Mule Expression Language(MEL) - Introduction
 Mule Expression Language (MEL) supports the work of message processors by
providing a means of accessing, manipulating, and using information from the
message and its environment.
 In most cases, Mule expressions work within message processors to modify the way
those processors do their main jobs (for example, routing, filtering). Following are
the principal use cases:
 Make a decision based on the contents, properties, or context of a message and its
attachments. For example, a flow controller can route purchase orders for different types
of products to different JMS queues.
 Select a value from the contents, properties, or context of a message and its attachments.
For example, a cloud connector might extract a specific piece of information from the
current message to use as an argument.
 Replace a token with an actual value. For example, a logger can extract information from
the payload contents and place it into a logging message.
 We can also use MEL to implement a program (script) for which we would
otherwise use a programming language like Ruby, JavaScript, or Groovy. Scripts in
those languages cannot access the message and its environment as conveniently as
MEL can. In this case, MEL is the programming language for a custom message
processor.
Mule Expression Language - Syntax
Mule Expression Language Syntax
 MEL expression combines one or more operands with zero or more operators in a Java-like
syntax and returns the resulting value.
 At the heart of MEL are property expressions of the form contextObject.property. These
provide easy access to properties of the Mule message and its environment. For example, the
expression “message.payload” represents the payload property of the message context
object. Its value is the message payload.
 Java method invocations and assignments are the other common MEL expressions.
 In most cases, a MEL expression stands alone as the value of a configuration property of a
message processor. Mule evaluates the expression at runtime, and the message processor
uses the result.
 The syntax of a MEL program largely follows Java, but MEL implements dynamic typing by
performing type coercion at runtime. Semicolons follow each statement except the last,
whether the statements are on one line or separate lines. Return statements are usually
unnecessary, because a MEL program returns the value of the last MEL statement executed.
 MEL operators and basic operands are conventional and predictable (for example, 2 + 2 == 4
returns true). Property expressions provide convenient access to information from the
message and its environment (for example, server.fileSeparator returns "/" if the application is
running on a Linux server, and "" on a Windows server.). The remainder of this section
summarizes the most important elements of MEL syntax.
Mule Expression Language – Operand, Property
MEL Operand
 An operand can be a literal, a variable, or a MEL expression.
 The MEL expressions that most commonly appear as operands are property expressions and
method invocations.
Property Expressions
 The syntax of a property expression is “contextObject.property”. This can appear as an
operand in most MEL expressions, including on the left side of an assignment if the property is
writable from MEL.
Method Invocations
 Mule Expression Language uses standard Java method invocation.
 We can provide a fully qualified class name or import a class and use the unqualified name.
MEL automatically imports a number of Java classes.
 Eg. message.payload.getName(). If payload is a Java object—for example, representing a
person—this code invokes its getName method. The value of the expression is the value that
getName returns—presumably a string representing the person’s name.
MEL Operators
 MEL operators follow standard Java syntax, but operands are always by value, not by
reference. For example, "A" == 'A' evaluates to true, whereas the same expression evaluates
to false in Java.
Arithmetic Operators
Mule Expression Language – Arithmetic Operators
Symbol Definition Example/Value
-
Minus. The value is the value of the first operand minus the
value of the second.
2 - 4
-2
%
Modulo. The value is the remainder after dividing the value
of the first operand by the value of the second.
9 % 4
1
/
Over. The value is the value of the first operand divided by
the value of the second.
2 / 4
0.5
+
Plus. For numbers, the value is the sum of the values of the
operands. For strings, the value is the string formed by
concatenating the values of the operands.
2 + 4
6
'fu' + 'bar'
The String "fubar"
*
Times. The value is the product of the values of the
operands.
2 * 4
8
Comparison Operators
Mule Expression Language – Comparison Operators
Symbol Definition Example/Value
==
Equal. True if and only if (iff) the values of the operands are
equal.
'A' == 'A'
true
!= Not equal. True iff the values of the operands are unequal.
'A' != 'B'
true
>
Greater than. True iff the value on the left is greater than the
value on the right.
7 > 5
true
<
Less than. True iff the value on the left is less than the value
on the right
5 < 5
false
>=
Greater than or equal. True iff the value on the left is greater
than or equal to the value on the right.
5 >= 7
false
<=
Less than or equal. True iff the value on the left is less than or
equal to the value on the right.
5 <= 5
true
contains
Contains. True iff the string on the right is a substring of the
string on the left.
'fubar' contains
'bar'
true
is,
instance
of
Is an instance of. True iff the object on the left is an instance
of the class on the right.
'fubar' is String
true
Comparison Operators - contd
Logical Operators
Mule Expression Language – Logical Operators
Symbol Definition Example/Value
strsim
Degree of similarity. The value of the expression is a
number between 0 and 1 representing the degree of
similarity between the two string arguments.
'foo' strsim 'foo'
1.0
‘foobar’ strsim ‘foo’
0.5
soundslike
Sounds like. True iff the two string arguments sound alike
according to a Soundex comparison.
'Robert' soundslike
'Rupert'
true
Symbol Definition Example/Value
and
Logical AND. True iff both operands are true. (Don’t use
&&)
(a == b) and (c != d)
true iff a =b and c ≠ d
|| Logical OR. True iff at least one operand is true.
true ||anything
Always true
or
Chained OR. Scans left to right and returns the value of
the first non-empty item
false or '' or ' ' or 'dog'
The String "dog"
Mule Expression Language – Assignment, Literals
MEL Assignment
 An assignment is a MEL expression consisting of an identifier representing a mutable object to
the left of an equal sign and a MEL expression to the right of the equal sign. Eg:
message.payload = 'fu‘ sets the payload of the current message to the string "fu".
 MEL determines types dynamically, so declaring the type of a variable is optional. For example
if, with no prior declarations, if we write number = 1; number == '1' MEL assigns the
expression the value true.
 We can cast values to specific types. For example if we write
number = (String)1; number is String
MEL returns the value true for this expression.
MEL Literals
 Literals in MEL can be strings, numbers, Boolean values, types, and nulls. Maps, Lists and
Arrays data structures as literals as well.
MEL Literals – Numeric Literals
 Numeric literals are integers and floating point numbers, with the same ranges of values as
the underlying Java system.
MEL Literals – String Literals
 String literals are sequences of characters enclosed in single quotes. We cannot use double
quotes to express String literals as we can in Java, because MEL expressions appear within
double quotes in configuration files.
Mule Expression Language – Literals
MEL Literals – Boolean Literals
 Boolean literals are the values true and false. These are case sensitive.
MEL Literals – Null Literals
 A null literal takes the form null or nil. These are case sensitive.
MEL Literals – Type Literals
 Refer to any Java class by its fully qualified name or if it is one of the classes in the below
classes, by its unqualified name. References use the same dot notation as in Java, except that
we must use $ rather than a dot to refer to a nested class.
 MEL automatically imports the following Java classes.
 java.lang.*
 java.io.*
 java.net.*
 java.util.*
 java.math.BigDecimal
 java.math.BigInteger
 javax.activation.DataHandler
 javax.activation.MimeType
 java.util.regex.Pattern
 org.mule.api.transformer.DataType
 org.mule.transformer.types.DataTypeFactory
MEL Key/Value Maps, Lists, and Arrays
 Maps are important in Mule Expression Language because much of the context you can work
with comes in the form of maps.
Mule Expression Language – Maps, Lists and Arrays
MEL Key/Value Maps, Lists, and Arrays
 Mule Expression Language uses a convenient syntax for maps and other data structures. It
begins with map literals, and there is also a convenient way to access items in maps. MEL
provides a streamlined way to access map data. Rather than constructing a map with a new
statement, and then using its put method to populate it, we can simply write the following:
[key1 : value1, key2 : value2, . . .]
and use this literal form wherever we would otherwise use a map by name, including as a
method argument.
 similar literal forms for lists ([item1, item2, . . .]) and arrays ({item1, item2, . . .}).
 Arrays in Java must specify the type of their contents, but in MEL they are untyped. MEL
supplies the correct type when we use them – either by determining it at compile time or
coercing the array to the correct type at run time.
Accessing Map Data
 MEL provides a simpler way to access map items than java.util.Map provides. For example,
Mule associates a map containing properties set by the inbound endpoint processor with each
message. We can refer to this map as message.inboundProperties. To retrieve the inbound
property with key name foo, write 'message.inboundProperties[foo]'. If that property can be
set (never the case with inbound properties, but true of some properties in other maps), we
can write message.outboundProperties[foo]=message.payload on the left side of an
assignment. If we try to set a property that cannot be set,Mule indicates failure by throwing
org.mvel2.PropertyAccessException.
Mule Expression Language–Control Flow, Context Objects
Control Flow
 MEL provides a full range of Java control flow statements. The most useful for typical MEL
expressions are conditional operands (often called ternary statements).
 A conditional operand has the form condition ? true value : false value.
For example, x = (name == 'Smith' ? 'Smith' : 'Unknown') sets the variable x to the string
"Smith" if the value of name is "Smith" and to the string "Unknown" if the value of name
is not "Smith".
MEL Context Objects and Functions
 Property expressions facilitate the use of properties of the Mule message and its environment
as operands in MEL expressions. They take the form contextObject.property. Context objects
provide logical groupings of the properties of the message and its environment.
 Functions provide ways to extract information that doesn’t already exist as a single value that
can be embodied in a property.
MEL Context Objects
 Context objects model the message and its environment. They make MEL Mule-centric, not
just another expression language. Different context objects are
 Server: properties of the hardware, operating system, user, and network interface.
 Mule: properties of the Mule instance.
 App: properties of the Mule application.
 Message: properties of the Mule message - [DEFAULT]
Mule Expression Language – Context Object - Server
Server
 This object provides read-only access to the properties of the hardware, operating system, user, and
network interface listed in the table.
 For example, the value of 'server.userName' is a string representing the name of the user.
Name Description
fileSeparator
Character that separates components of a file path ( "/" on UNIX and ""
on Windows)
host Fully qualified domain name of the server
ip The IP address of the server
locale
Default locale (of type java.util.Locale) of the JRE (can access
server.locale.language and server.locale.country)
javaVersion JRE version
javaVendor JRE vendor name
osName Operating system name
osArch Operating system architecture
osVersion Operating system version
systemProperties Map of Java system properties
timeZone Default TimeZone (java.util.TimeZone) of the JRE
tmpDir Temporary directory for use by the JRE
userName User name
userHome User home directory
userDir
User working directory.For example, the value of 'server.userName' is a
string representing the name of the user.
Mule Expression Language – Context Object – Mule, App
Mule
 This object provides read-only access to the properties of the Mule instance listed in the table.
 For example, the value of 'mule.version' is a string representing the Mule version.
App
 This object provides access to the properties of the Mule application listed in the table
 For example, the value of 'app.name' is a string representing the application name.
 For example, 'app.registry['foo']' refers to the object named foo in the Mule registry map. You
can set or retrieve its value.
Name Description
clusterId Cluster ID
home File system path to the home directory of the mule server installation
nodeId Cluster node ID
version Mule Version
Name Description
encoding Application default encoding (read-only)
name Application name (read-only)
standalone True if Mule is running standalone (read-only)
workdir Application work directory (read-only)
registry
Map representing the Mule registry (read/write).For example, the value of 'app.name' is
a string representing the application name.For example, 'app.registry['foo']' refers to the
object named foo in the Mule registry map. You can set or retrieve its value.
Mule Expression Language – Context Object – Message
Message
 This object provides access to the properties of the Mule message listed in the table.
Name Description
id (read-only)
rootId (read-only)
correlationId (read-only)
correlationSequence (read-only)
correlationGroupSize (read-only)
replyTo (read/write)
dataType (read-only)
payload (read/write)
inboundProperties Map (read-only)
inboundAttachments Map (read-only)
outboundProperties Map (read/write)
outboundAttachments Map (read/write)
exception (read-only)
Mule Expression Language – Variables
Variables
 In addition to local MEL variables, whose scope is the current message processor, MEL gives
you access to Mule flow and session variables. The variables reside in the following maps,
which are available to use in MEL expressions:
 flowVars – contains variables that are global to the current flow. They retain their values as control passes from one
message processor to another. Thus, you can set them in one message processor and use them in another.
 SessionVars – is essentially the same as flowVars, except that when one flow calls another one via a Mule endpoint they
are propagated.
 For example, to access the value of the foo flow variable, write flowVars['foo']. This can
appear on either side of an assignment. For example, the following code gets the value of the
session variable bar and uses it to set the value of the flow variable bar.
flowVars['foo'] = sessionVars['bar']
 As a further shortcut, you can simply use foo as a variable name in a MEL expression. If there
is no local MEL variable called foo, the MEL processor looks for one in flowVars, then in
sessionVars, before failing. For example, if the MEL expression contains foo == 'cat' and there
is no local MEL variable named foo, but there is a foo key in flowVars, then the foo in the
expression is equivalent to flowVars['foo'].
 Note, however, that we can turn this method of resolution off by including a configuration
attribute in the xml configuration file:
<configuration>
<expression-language autoResolveVariables="false">
</configuration>
Mule Expression Language – Data Extraction Function
Data Extraction Function
 The functions xpath and regex provide ways of extracting context information extract
information that doesn’t already exist as a single value that can be embodied in a property. By
default they work on the payload, but we can pass them different arguments explicitly.
Thank you

More Related Content

PDF
Containerizing MuleSoft applications for hybrid deployment
PPTX
Power of Transformation with DataWeave 2.X Engine
PPTX
Clustering, Server setup and Hybrid deployment setup using Anypoint Runtime M...
PPTX
Mule Runtime: Performance Tuning
PPTX
Session on API auto scaling, monitoring and Log management
PDF
Observability For You and Me with OpenTelemetry
PPTX
Mulesoft Anypoint platform introduction
PDF
Frequently asked MuleSoft Interview Questions and Answers from Techlightning
Containerizing MuleSoft applications for hybrid deployment
Power of Transformation with DataWeave 2.X Engine
Clustering, Server setup and Hybrid deployment setup using Anypoint Runtime M...
Mule Runtime: Performance Tuning
Session on API auto scaling, monitoring and Log management
Observability For You and Me with OpenTelemetry
Mulesoft Anypoint platform introduction
Frequently asked MuleSoft Interview Questions and Answers from Techlightning

What's hot (20)

PPTX
Best Practices for API Security
PDF
Introduction to MuleSoft
PPT
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
PDF
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
PDF
OOW15 - Advanced Architectures for Oracle E-Business Suite
PDF
Oracle Cloud Reference Architecture
PDF
Code Coverage
PDF
The Service Mesh: It's about Traffic
PPTX
Benefits of integration with the Mulesoft Anypoint Platform
PDF
MuleSoft Anypoint Platform and Three Tier Architecture
PPTX
Data weave 2.0 advanced (recursion, pattern matching)
PPTX
Creating MuleSoft API Template Project Using Maven Archetype
PPTX
Testing soap UI
PPTX
Introduction to MuleSoft
PPTX
MuleSoft Architecture Presentation
PPTX
Managing APIs with MuleSoft
PDF
Istio Service Mesh
PPTX
Mendix learning by Sunil Kumar
PDF
API strategy with IBM API connect
PPTX
Uml Presentation
Best Practices for API Security
Introduction to MuleSoft
Showdown: Integration Framework (Spring Integration, Apache Camel) vs. Enterp...
MuleSoft Nashik Virtual Meetup#4 - Implementing CI/CD pipeline for deploying ...
OOW15 - Advanced Architectures for Oracle E-Business Suite
Oracle Cloud Reference Architecture
Code Coverage
The Service Mesh: It's about Traffic
Benefits of integration with the Mulesoft Anypoint Platform
MuleSoft Anypoint Platform and Three Tier Architecture
Data weave 2.0 advanced (recursion, pattern matching)
Creating MuleSoft API Template Project Using Maven Archetype
Testing soap UI
Introduction to MuleSoft
MuleSoft Architecture Presentation
Managing APIs with MuleSoft
Istio Service Mesh
Mendix learning by Sunil Kumar
API strategy with IBM API connect
Uml Presentation
Ad

Similar to Mule expression language (20)

PPTX
Expression language
PPTX
Expression language in mule
PPTX
Mule Expression language
PPTX
Mule mel 1
PPTX
Mule expression language
PPTX
A short introduction on mule expression language
PPTX
Mule mel 5_tips
PPTX
Mule mel 3
PPTX
Mule expression language - Part 1
PPTX
Mule mel 4_tips
PPTX
Mule mel 2
PPTX
Mule slides
PPTX
PPTX
Sai mule esb batch
PPTX
Mule esb
PPTX
Mule esb
PPTX
Mule esb kranthi
PPTX
Esb process
PPTX
Mule esb kranthi
PPTX
Expression language
Expression language in mule
Mule Expression language
Mule mel 1
Mule expression language
A short introduction on mule expression language
Mule mel 5_tips
Mule mel 3
Mule expression language - Part 1
Mule mel 4_tips
Mule mel 2
Mule slides
Sai mule esb batch
Mule esb
Mule esb
Mule esb kranthi
Esb process
Mule esb kranthi
Ad

More from sathyaraj Anand (7)

PPTX
Mule message processor or routers
PPT
Mule cloudhubconsoleoverview-sathyaraj
PPT
Security authorizationusingspringsecurity-sathyaraj
PPT
Security springsecuritymanager-sathyaraj
PPTX
Rest web services
PPTX
Mule esb mule message
PPTX
Mule filters
Mule message processor or routers
Mule cloudhubconsoleoverview-sathyaraj
Security authorizationusingspringsecurity-sathyaraj
Security springsecuritymanager-sathyaraj
Rest web services
Mule esb mule message
Mule filters

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
Programs and apps: productivity, graphics, security and other tools
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
Mobile App Security Testing_ A Comprehensive Guide.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Mule expression language

  • 1. Mule Integration Workshop Mule Expression Language
  • 2. •Rapidly connect any application, anywhere •Anypoint Platform helps companies prepare for the future with a next-generation SOA platform that connects on- premises systems and the cloud. •Mule ESB, CloudHub, Mule Studio, Mule Enterprise Management, Anypoint Connectors Anypoint Platform for SOA •Connect SaaS with any application, anywhere •Anypoint Platform helps companies connect SaaS applications to each other and the enterprise, in the cloud and on- premises. •CloudHub, Mule ESB, Mule Studio, CloudHub Insight, Anypoint Connectors Anypoint Platform for SaaS •All you need to connect any app, any device and any API •With the Anypoint Platform for APIs, you can build new APIs, design new interfaces for existing APIs and more efficiently manage all your APIs using a single platform. •API Portal, API Manager, Mule Studio, Mule ESB, CloudHub Anypoint Platform for API MuleSoft Anypoint Platforms 1
  • 3. Chapters Schedule Mule Expression Language(MEL) - Introduction MEL - Syntax MEL – Operand, Property MEL – Arithmetic Operators MEL – Comparison Operators MEL – Logical Operators MEL – Assignment, Literals MEL – Literals MEL – Maps, Lists and Arrays MEL – Control Flow, Context Objects MEL – Context Object – Server MEL – Context Object – Mule, App MEL – Context Object – Message MEL – Variables MEL – Data Extraction Function
  • 4. Mule Expression Language(MEL) - Introduction  Mule Expression Language (MEL) supports the work of message processors by providing a means of accessing, manipulating, and using information from the message and its environment.  In most cases, Mule expressions work within message processors to modify the way those processors do their main jobs (for example, routing, filtering). Following are the principal use cases:  Make a decision based on the contents, properties, or context of a message and its attachments. For example, a flow controller can route purchase orders for different types of products to different JMS queues.  Select a value from the contents, properties, or context of a message and its attachments. For example, a cloud connector might extract a specific piece of information from the current message to use as an argument.  Replace a token with an actual value. For example, a logger can extract information from the payload contents and place it into a logging message.  We can also use MEL to implement a program (script) for which we would otherwise use a programming language like Ruby, JavaScript, or Groovy. Scripts in those languages cannot access the message and its environment as conveniently as MEL can. In this case, MEL is the programming language for a custom message processor.
  • 5. Mule Expression Language - Syntax Mule Expression Language Syntax  MEL expression combines one or more operands with zero or more operators in a Java-like syntax and returns the resulting value.  At the heart of MEL are property expressions of the form contextObject.property. These provide easy access to properties of the Mule message and its environment. For example, the expression “message.payload” represents the payload property of the message context object. Its value is the message payload.  Java method invocations and assignments are the other common MEL expressions.  In most cases, a MEL expression stands alone as the value of a configuration property of a message processor. Mule evaluates the expression at runtime, and the message processor uses the result.  The syntax of a MEL program largely follows Java, but MEL implements dynamic typing by performing type coercion at runtime. Semicolons follow each statement except the last, whether the statements are on one line or separate lines. Return statements are usually unnecessary, because a MEL program returns the value of the last MEL statement executed.  MEL operators and basic operands are conventional and predictable (for example, 2 + 2 == 4 returns true). Property expressions provide convenient access to information from the message and its environment (for example, server.fileSeparator returns "/" if the application is running on a Linux server, and "" on a Windows server.). The remainder of this section summarizes the most important elements of MEL syntax.
  • 6. Mule Expression Language – Operand, Property MEL Operand  An operand can be a literal, a variable, or a MEL expression.  The MEL expressions that most commonly appear as operands are property expressions and method invocations. Property Expressions  The syntax of a property expression is “contextObject.property”. This can appear as an operand in most MEL expressions, including on the left side of an assignment if the property is writable from MEL. Method Invocations  Mule Expression Language uses standard Java method invocation.  We can provide a fully qualified class name or import a class and use the unqualified name. MEL automatically imports a number of Java classes.  Eg. message.payload.getName(). If payload is a Java object—for example, representing a person—this code invokes its getName method. The value of the expression is the value that getName returns—presumably a string representing the person’s name. MEL Operators  MEL operators follow standard Java syntax, but operands are always by value, not by reference. For example, "A" == 'A' evaluates to true, whereas the same expression evaluates to false in Java.
  • 7. Arithmetic Operators Mule Expression Language – Arithmetic Operators Symbol Definition Example/Value - Minus. The value is the value of the first operand minus the value of the second. 2 - 4 -2 % Modulo. The value is the remainder after dividing the value of the first operand by the value of the second. 9 % 4 1 / Over. The value is the value of the first operand divided by the value of the second. 2 / 4 0.5 + Plus. For numbers, the value is the sum of the values of the operands. For strings, the value is the string formed by concatenating the values of the operands. 2 + 4 6 'fu' + 'bar' The String "fubar" * Times. The value is the product of the values of the operands. 2 * 4 8
  • 8. Comparison Operators Mule Expression Language – Comparison Operators Symbol Definition Example/Value == Equal. True if and only if (iff) the values of the operands are equal. 'A' == 'A' true != Not equal. True iff the values of the operands are unequal. 'A' != 'B' true > Greater than. True iff the value on the left is greater than the value on the right. 7 > 5 true < Less than. True iff the value on the left is less than the value on the right 5 < 5 false >= Greater than or equal. True iff the value on the left is greater than or equal to the value on the right. 5 >= 7 false <= Less than or equal. True iff the value on the left is less than or equal to the value on the right. 5 <= 5 true contains Contains. True iff the string on the right is a substring of the string on the left. 'fubar' contains 'bar' true is, instance of Is an instance of. True iff the object on the left is an instance of the class on the right. 'fubar' is String true
  • 9. Comparison Operators - contd Logical Operators Mule Expression Language – Logical Operators Symbol Definition Example/Value strsim Degree of similarity. The value of the expression is a number between 0 and 1 representing the degree of similarity between the two string arguments. 'foo' strsim 'foo' 1.0 ‘foobar’ strsim ‘foo’ 0.5 soundslike Sounds like. True iff the two string arguments sound alike according to a Soundex comparison. 'Robert' soundslike 'Rupert' true Symbol Definition Example/Value and Logical AND. True iff both operands are true. (Don’t use &&) (a == b) and (c != d) true iff a =b and c ≠ d || Logical OR. True iff at least one operand is true. true ||anything Always true or Chained OR. Scans left to right and returns the value of the first non-empty item false or '' or ' ' or 'dog' The String "dog"
  • 10. Mule Expression Language – Assignment, Literals MEL Assignment  An assignment is a MEL expression consisting of an identifier representing a mutable object to the left of an equal sign and a MEL expression to the right of the equal sign. Eg: message.payload = 'fu‘ sets the payload of the current message to the string "fu".  MEL determines types dynamically, so declaring the type of a variable is optional. For example if, with no prior declarations, if we write number = 1; number == '1' MEL assigns the expression the value true.  We can cast values to specific types. For example if we write number = (String)1; number is String MEL returns the value true for this expression. MEL Literals  Literals in MEL can be strings, numbers, Boolean values, types, and nulls. Maps, Lists and Arrays data structures as literals as well. MEL Literals – Numeric Literals  Numeric literals are integers and floating point numbers, with the same ranges of values as the underlying Java system. MEL Literals – String Literals  String literals are sequences of characters enclosed in single quotes. We cannot use double quotes to express String literals as we can in Java, because MEL expressions appear within double quotes in configuration files.
  • 11. Mule Expression Language – Literals MEL Literals – Boolean Literals  Boolean literals are the values true and false. These are case sensitive. MEL Literals – Null Literals  A null literal takes the form null or nil. These are case sensitive. MEL Literals – Type Literals  Refer to any Java class by its fully qualified name or if it is one of the classes in the below classes, by its unqualified name. References use the same dot notation as in Java, except that we must use $ rather than a dot to refer to a nested class.  MEL automatically imports the following Java classes.  java.lang.*  java.io.*  java.net.*  java.util.*  java.math.BigDecimal  java.math.BigInteger  javax.activation.DataHandler  javax.activation.MimeType  java.util.regex.Pattern  org.mule.api.transformer.DataType  org.mule.transformer.types.DataTypeFactory MEL Key/Value Maps, Lists, and Arrays  Maps are important in Mule Expression Language because much of the context you can work with comes in the form of maps.
  • 12. Mule Expression Language – Maps, Lists and Arrays MEL Key/Value Maps, Lists, and Arrays  Mule Expression Language uses a convenient syntax for maps and other data structures. It begins with map literals, and there is also a convenient way to access items in maps. MEL provides a streamlined way to access map data. Rather than constructing a map with a new statement, and then using its put method to populate it, we can simply write the following: [key1 : value1, key2 : value2, . . .] and use this literal form wherever we would otherwise use a map by name, including as a method argument.  similar literal forms for lists ([item1, item2, . . .]) and arrays ({item1, item2, . . .}).  Arrays in Java must specify the type of their contents, but in MEL they are untyped. MEL supplies the correct type when we use them – either by determining it at compile time or coercing the array to the correct type at run time. Accessing Map Data  MEL provides a simpler way to access map items than java.util.Map provides. For example, Mule associates a map containing properties set by the inbound endpoint processor with each message. We can refer to this map as message.inboundProperties. To retrieve the inbound property with key name foo, write 'message.inboundProperties[foo]'. If that property can be set (never the case with inbound properties, but true of some properties in other maps), we can write message.outboundProperties[foo]=message.payload on the left side of an assignment. If we try to set a property that cannot be set,Mule indicates failure by throwing org.mvel2.PropertyAccessException.
  • 13. Mule Expression Language–Control Flow, Context Objects Control Flow  MEL provides a full range of Java control flow statements. The most useful for typical MEL expressions are conditional operands (often called ternary statements).  A conditional operand has the form condition ? true value : false value. For example, x = (name == 'Smith' ? 'Smith' : 'Unknown') sets the variable x to the string "Smith" if the value of name is "Smith" and to the string "Unknown" if the value of name is not "Smith". MEL Context Objects and Functions  Property expressions facilitate the use of properties of the Mule message and its environment as operands in MEL expressions. They take the form contextObject.property. Context objects provide logical groupings of the properties of the message and its environment.  Functions provide ways to extract information that doesn’t already exist as a single value that can be embodied in a property. MEL Context Objects  Context objects model the message and its environment. They make MEL Mule-centric, not just another expression language. Different context objects are  Server: properties of the hardware, operating system, user, and network interface.  Mule: properties of the Mule instance.  App: properties of the Mule application.  Message: properties of the Mule message - [DEFAULT]
  • 14. Mule Expression Language – Context Object - Server Server  This object provides read-only access to the properties of the hardware, operating system, user, and network interface listed in the table.  For example, the value of 'server.userName' is a string representing the name of the user. Name Description fileSeparator Character that separates components of a file path ( "/" on UNIX and "" on Windows) host Fully qualified domain name of the server ip The IP address of the server locale Default locale (of type java.util.Locale) of the JRE (can access server.locale.language and server.locale.country) javaVersion JRE version javaVendor JRE vendor name osName Operating system name osArch Operating system architecture osVersion Operating system version systemProperties Map of Java system properties timeZone Default TimeZone (java.util.TimeZone) of the JRE tmpDir Temporary directory for use by the JRE userName User name userHome User home directory userDir User working directory.For example, the value of 'server.userName' is a string representing the name of the user.
  • 15. Mule Expression Language – Context Object – Mule, App Mule  This object provides read-only access to the properties of the Mule instance listed in the table.  For example, the value of 'mule.version' is a string representing the Mule version. App  This object provides access to the properties of the Mule application listed in the table  For example, the value of 'app.name' is a string representing the application name.  For example, 'app.registry['foo']' refers to the object named foo in the Mule registry map. You can set or retrieve its value. Name Description clusterId Cluster ID home File system path to the home directory of the mule server installation nodeId Cluster node ID version Mule Version Name Description encoding Application default encoding (read-only) name Application name (read-only) standalone True if Mule is running standalone (read-only) workdir Application work directory (read-only) registry Map representing the Mule registry (read/write).For example, the value of 'app.name' is a string representing the application name.For example, 'app.registry['foo']' refers to the object named foo in the Mule registry map. You can set or retrieve its value.
  • 16. Mule Expression Language – Context Object – Message Message  This object provides access to the properties of the Mule message listed in the table. Name Description id (read-only) rootId (read-only) correlationId (read-only) correlationSequence (read-only) correlationGroupSize (read-only) replyTo (read/write) dataType (read-only) payload (read/write) inboundProperties Map (read-only) inboundAttachments Map (read-only) outboundProperties Map (read/write) outboundAttachments Map (read/write) exception (read-only)
  • 17. Mule Expression Language – Variables Variables  In addition to local MEL variables, whose scope is the current message processor, MEL gives you access to Mule flow and session variables. The variables reside in the following maps, which are available to use in MEL expressions:  flowVars – contains variables that are global to the current flow. They retain their values as control passes from one message processor to another. Thus, you can set them in one message processor and use them in another.  SessionVars – is essentially the same as flowVars, except that when one flow calls another one via a Mule endpoint they are propagated.  For example, to access the value of the foo flow variable, write flowVars['foo']. This can appear on either side of an assignment. For example, the following code gets the value of the session variable bar and uses it to set the value of the flow variable bar. flowVars['foo'] = sessionVars['bar']  As a further shortcut, you can simply use foo as a variable name in a MEL expression. If there is no local MEL variable called foo, the MEL processor looks for one in flowVars, then in sessionVars, before failing. For example, if the MEL expression contains foo == 'cat' and there is no local MEL variable named foo, but there is a foo key in flowVars, then the foo in the expression is equivalent to flowVars['foo'].  Note, however, that we can turn this method of resolution off by including a configuration attribute in the xml configuration file: <configuration> <expression-language autoResolveVariables="false"> </configuration>
  • 18. Mule Expression Language – Data Extraction Function Data Extraction Function  The functions xpath and regex provide ways of extracting context information extract information that doesn’t already exist as a single value that can be embodied in a property. By default they work on the payload, but we can pass them different arguments explicitly.