External Functions Available In DataWeave
In addition to the built-in DataWeave functions, Mule Runtime and some modules, connectors, and components for Mule apps provide functions that you can use in DataWeave scripts. The functions are specific to the module, connector, and components.
These functions are always available since they are injected by the Mule Runtime.
p function provides access to properties, whether these are:
Mule property placeholders
You can read more on configuring properties and how they are handled here.
The following example will log the value of the property
1 2 3 <flow name="simple"> <logger message="#[p('some.property')]"/> </flow>
lookup function allows for executing a flow within your app and retrieves the resulting payload, taking the flow’s name and an input payload as parameters.
The specified flow is executed using the current attributes, variables, and error. It only replaces the payload for the first parameter, which must be a Java type.
Learn more about
causedBy function matches an error by its type, like an error handler does. This is useful when matching by a super type is required but specific sub-type logic also needed or when handling a
COMPOSITE_ROUTING error that contains child errors of different types.
The error to match against can be implicit, but the type is always a required parameter.
In the following example, a global error handler is set up to handle
SECURITY errors in a general way, while specific actions are set up for
1 2 3 4 5 6 7 8 9 10 11 12 13 <error-handler name="securityHandler"> <on-error-continue type="SECURITY"> <!-- general error handling for all SECURITY errors --> <choice> <when expression="#[error causedBy 'HTTP:UNAUTHORIZED']"> <!-- specific error handling only for HTTP:UNAUTHORIZED errors --> </when> <when expression="#[causedBy('HTTP:FORBIDDEN')]"> <!-- specific error handling only for HTTP:FORBIDDEN errors --> </when> </choice> </on-error-continue> </error-handler>
Notice that the error parameter is used both explicitly and implicitly.
When using connectors and components in a Mule app, you can inject functions. Unlike the Runtime functions, these functions require a namespace, which usually matches the component name.
For example, in an app using Batch you can use the following expression: