SlideShare a Scribd company logo
DATAWEAVE IN MULE
By Ravi Mishra
Using the DataWeave Transformer
• In Anypoint Studio, you can place a Transform
Message element in a flow to create transformations
using the DataWeave language.
• The editor helps you do this by offering intelligent
autocomplete suggestions, an output preview that is
updated in real time as you make changes.
• This generates a .dwl transformation file (or several of
them) that stores your code and is packaged with your
Mule application.
• When adding a Transform Message element to a Mule
Flow, it takes the elements from the incoming Mule
Message as its inputs. It then performs the necessary
actions to produce a Mule message as output for the next
element in the flow
• The DataWeave Text Editor GUI
• The Transform Message element allows you to freely
write DataWeave code.
• If you click on an instance of the Transform Message
element in your flow, its properties editor will be displayed.
This editor is divided into three sections:
• Input
• Transform
• Output
Input Section
In the main tab, a tree view shows the known metadata
contents of the incoming Mule Message, allowing you to
explore it and know what data is available for using as an
input, and how to reference each part of it.
If the Mule flow doesn’t expose Metadata about the
elements you need from the incoming message, you can
manually specify it. To do so, select the element of the input
you desire to define, note that the pencil icon at the top
right is no longer grayed out. Click this icon to open a new
tab in your input section where you can define a sample
with the structure of this data.
When the input is of JSON or XML types, the sample input contains plain XML or
JSON code. When the input is of type POJO or DataWeave, the sample input is
written in DataWeave for more simplicity. In these cases the sample DataWeave code
is merely a way to display the sample data, not a transformation in itself.
Setting Reader Parameters
• Some input formats, like CSV, allow you to define
a reader with specific properties that make
DataWeave parse inputs differently. Select the
input element you wish to configure on the tree
view of the input section, then click the gear icon.
Transform Section
• you write the actual DataWeave code that carries out the
transform. Notice that changing the type of your output
directive changes the output section of the editor.
Although DataWeave as a language supports adding
input directives and naming these by any name you like,
in Studio the elements of the input message are implicitly
considered input directives and so they don’t need to be
defined in the header.
If Studio has any metadata about the components that are
upstream or downstream from your Transform Message
element at the time when you add the component to your
flow, a scaffolding for your DataWeave code is written out
automatically, with as much depth as Studio can
intelligently deduce. In some cases, this code may be
enough to carry out the transformation you need, and no
additional coding is needed. Sometimes, all you need to do
is fill in the blank spaces in the scaffolding with references
to the input fields, other times you may want to carry out
more complex operations that involve aggregation, filtering,
calculations, defining custom functions, etc and there you
must write this out in DataWeave code.
Re-scaffolding
• Once you’ve added the Transform Message element to
your flow, any further changes you make to the
surrounding message processors and their metadata
won’t affect your `.dw`l file. You may still click the
Scaffolding button on the top left of the DataWeave
properties editor any time you want and have a new
scaffolding built, note that this will erase anything you’ve
written in the DataWeave body. Doing this won’t affect
any directives you defined in your header (except for the
output directive). Use this button if you’ve made any
changes to elements that come after the Transform
Message element on the flow that expose metadata and
don’t mind loosing what you’ve already written into the
transform’s body.
Referencing Existing Transforms
Instead of defining a new .dwl file, you can reference an
existing one by clicking theData Source button,
selecting On File as the source and referencing the correct
file.
Handling Multiple Outputs
A single Transform Message element can give shape to
several different components of the output Mule message.
Each of these output components must be defined in a
separate .dwl file, written out in a separate tab of the
Transform section. For example in one tab you may be
defining the payload contents, in another those of an
outbound property, and these will both be parts of the same
output Mule message
To add a new output, click the Plus sign at the
bottom right of the section:new+output.png[image]
A new tab will then appear, there you can specify
where in the output Mule message to place the
output of this DataWeave transform. In case you’re
creating a new variable or property, you must also
set a name for it.
In the XML editor you can do the same by adding multiple
child elements inside thedw:transform-message component.
<dw:transform-message>
<dw:set-payload resource="classpath:path/transform.dwl"/> <dw:set-
variable variableName="myVariable"
resource="classpath:path/transform.dwl"/> <dw:set-session-variable
variableName="mySessionVariable"
resource="classpath:path/transform.dwl"/> </dw:transform-message>
Output Section
• This section has two tabs, one of them shows you a neat
expandable tree view of the output data structure, the other
shows you a preview of what the actual output looks like, built
from any sample data you provide in the input section. As you
make changes in the transport section, notice how the data
structure changes. The output of the transformer is made into
the selected component of the output mule message. If your
transformer has multiple outputs, the Preview tab will display
the one corresponding to the currently selected transform.
Using DataWeave Language Elsewhere
• All components in Mule that support Mule Expression
Language also support expressions written in DataWeave
Language. To invoke an expression written in DataWeave
language, simply invoke the dw() function, the expression will
return whatever the transform outputs.
• DataWeave expressions defined within this function work just
as those defined within a Transform Message element, the only
difference is that the output is returned into the expression’s
result, wherever it may be.
• For example, you can define a custom object and
populate it with elements from the payload:
• That same expression could be added inside a Logger,
• within a MEL expression, to print out its result:
dw(myobject:{id:payload.accountid, user:payload.user})
#[`dw(myobject:{id:payload.accountid, user:payload.user})`]

More Related Content

PPTX
Data weave
PPTX
Mule data weave
PPTX
mule salesforce
 
PPTX
Dataweave 160103180124
PPTX
Dataweave
PPTX
Automatic documentation with mule
 
PPTX
Mule data bases
PPTX
Mule esb file to-string flow
Data weave
Mule data weave
mule salesforce
 
Dataweave 160103180124
Dataweave
Automatic documentation with mule
 
Mule data bases
Mule esb file to-string flow

What's hot (18)

PPTX
Mulesoft salesforce connector to update Object.
PPTX
Introduction to dataweave
PPTX
Integration with Dropbox using Mule ESB
PDF
Processing files sequentially in mule
PPTX
Junit in mule demo
PPTX
Mule dataweave
PPTX
Creating restful api using mule esb
PPTX
Velocity in Mule
PPTX
Mule using Salesforce
PPTX
Mule Collection Aggregator
PPTX
Mule velocity
PPTX
Send email attachment using smtp in mule esb
PPTX
Xml to xml transformation in mule
PPTX
Mulesoft file connector
PPTX
Mule esb :Data Weave
PPT
Data weave reference documentation
PPTX
MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module
PPT
Anypoint connectorfor ibm as 400
Mulesoft salesforce connector to update Object.
Introduction to dataweave
Integration with Dropbox using Mule ESB
Processing files sequentially in mule
Junit in mule demo
Mule dataweave
Creating restful api using mule esb
Velocity in Mule
Mule using Salesforce
Mule Collection Aggregator
Mule velocity
Send email attachment using smtp in mule esb
Xml to xml transformation in mule
Mulesoft file connector
Mule esb :Data Weave
Data weave reference documentation
MuleSoft Consuming Soap Web Service - CXF jax-ws-client Module
Anypoint connectorfor ibm as 400
Ad

Viewers also liked (20)

PPTX
Drools rule Concepts
PPTX
Data weave documentation
PPTX
Caching and invalidating with managed store
PPTX
Filters in mule
PPT
Mule batch processing
PPTX
Mule property placeholder
PPTX
Mule flow and filter
PPTX
WebService with VM
PPTX
Mule fundamentals
PPTX
Mapping and listing with mule
PPTX
Scatter gather component - mule
PPTX
Handle exceptions in mule
PPTX
Simple groovy example in mule
PPTX
Mule securing
PPTX
Scatter gather flow in mule
PPTX
Scatter gather in mule
PPTX
Mule for each scope header collection
PPTX
Idempotent filter in mule
PPTX
Mule - error handling
PPTX
Splitting with mule
Drools rule Concepts
Data weave documentation
Caching and invalidating with managed store
Filters in mule
Mule batch processing
Mule property placeholder
Mule flow and filter
WebService with VM
Mule fundamentals
Mapping and listing with mule
Scatter gather component - mule
Handle exceptions in mule
Simple groovy example in mule
Mule securing
Scatter gather flow in mule
Scatter gather in mule
Mule for each scope header collection
Idempotent filter in mule
Mule - error handling
Splitting with mule
Ad

Similar to Data weave in Mule (20)

PPTX
Dataweave nagarjuna
PPTX
Dataweave Basic
PPTX
Data weave
PPTX
Data weave
PPTX
Data weave
PPTX
Data weave
PPTX
Dataweave by nagarjuna
PPTX
Data weave
PPTX
Dataweave in studio
PPTX
Data weave in mule
PPTX
Muledataweave10 161029032456-161119152200
PPTX
How to – data integrity checks in batch processing
PPTX
PPTX
Mule data weave_2
PPTX
Mule data weave_3
PPTX
Mule with data weave
PDF
2 designer
DOCX
OBIEE publisher with Report creation - Tutorial
PPTX
Data weave (MuleSoft)
Dataweave nagarjuna
Dataweave Basic
Data weave
Data weave
Data weave
Data weave
Dataweave by nagarjuna
Data weave
Dataweave in studio
Data weave in mule
Muledataweave10 161029032456-161119152200
How to – data integrity checks in batch processing
Mule data weave_2
Mule data weave_3
Mule with data weave
2 designer
OBIEE publisher with Report creation - Tutorial
Data weave (MuleSoft)

Recently uploaded (20)

PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Pharma ospi slides which help in ospi learning
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Business Ethics Teaching Materials for college
PDF
Pre independence Education in Inndia.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Institutional Correction lecture only . . .
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Pharma ospi slides which help in ospi learning
O7-L3 Supply Chain Operations - ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Business Ethics Teaching Materials for college
Pre independence Education in Inndia.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Week 4 Term 3 Study Techniques revisited.pptx
Institutional Correction lecture only . . .
102 student loan defaulters named and shamed – Is someone you know on the list?
Anesthesia in Laparoscopic Surgery in India
Microbial disease of the cardiovascular and lymphatic systems
RMMM.pdf make it easy to upload and study
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Supply Chain Operations Speaking Notes -ICLT Program

Data weave in Mule

  • 1. DATAWEAVE IN MULE By Ravi Mishra
  • 2. Using the DataWeave Transformer • In Anypoint Studio, you can place a Transform Message element in a flow to create transformations using the DataWeave language. • The editor helps you do this by offering intelligent autocomplete suggestions, an output preview that is updated in real time as you make changes. • This generates a .dwl transformation file (or several of them) that stores your code and is packaged with your Mule application.
  • 3. • When adding a Transform Message element to a Mule Flow, it takes the elements from the incoming Mule Message as its inputs. It then performs the necessary actions to produce a Mule message as output for the next element in the flow
  • 4. • The DataWeave Text Editor GUI • The Transform Message element allows you to freely write DataWeave code. • If you click on an instance of the Transform Message element in your flow, its properties editor will be displayed. This editor is divided into three sections: • Input • Transform • Output
  • 5. Input Section In the main tab, a tree view shows the known metadata contents of the incoming Mule Message, allowing you to explore it and know what data is available for using as an input, and how to reference each part of it. If the Mule flow doesn’t expose Metadata about the elements you need from the incoming message, you can manually specify it. To do so, select the element of the input you desire to define, note that the pencil icon at the top right is no longer grayed out. Click this icon to open a new tab in your input section where you can define a sample with the structure of this data.
  • 6. When the input is of JSON or XML types, the sample input contains plain XML or JSON code. When the input is of type POJO or DataWeave, the sample input is written in DataWeave for more simplicity. In these cases the sample DataWeave code is merely a way to display the sample data, not a transformation in itself.
  • 7. Setting Reader Parameters • Some input formats, like CSV, allow you to define a reader with specific properties that make DataWeave parse inputs differently. Select the input element you wish to configure on the tree view of the input section, then click the gear icon.
  • 8. Transform Section • you write the actual DataWeave code that carries out the transform. Notice that changing the type of your output directive changes the output section of the editor. Although DataWeave as a language supports adding input directives and naming these by any name you like, in Studio the elements of the input message are implicitly considered input directives and so they don’t need to be defined in the header.
  • 9. If Studio has any metadata about the components that are upstream or downstream from your Transform Message element at the time when you add the component to your flow, a scaffolding for your DataWeave code is written out automatically, with as much depth as Studio can intelligently deduce. In some cases, this code may be enough to carry out the transformation you need, and no additional coding is needed. Sometimes, all you need to do is fill in the blank spaces in the scaffolding with references to the input fields, other times you may want to carry out more complex operations that involve aggregation, filtering, calculations, defining custom functions, etc and there you must write this out in DataWeave code.
  • 10. Re-scaffolding • Once you’ve added the Transform Message element to your flow, any further changes you make to the surrounding message processors and their metadata won’t affect your `.dw`l file. You may still click the Scaffolding button on the top left of the DataWeave properties editor any time you want and have a new scaffolding built, note that this will erase anything you’ve written in the DataWeave body. Doing this won’t affect any directives you defined in your header (except for the output directive). Use this button if you’ve made any changes to elements that come after the Transform Message element on the flow that expose metadata and don’t mind loosing what you’ve already written into the transform’s body.
  • 11. Referencing Existing Transforms Instead of defining a new .dwl file, you can reference an existing one by clicking theData Source button, selecting On File as the source and referencing the correct file.
  • 12. Handling Multiple Outputs A single Transform Message element can give shape to several different components of the output Mule message. Each of these output components must be defined in a separate .dwl file, written out in a separate tab of the Transform section. For example in one tab you may be defining the payload contents, in another those of an outbound property, and these will both be parts of the same output Mule message
  • 13. To add a new output, click the Plus sign at the bottom right of the section:new+output.png[image] A new tab will then appear, there you can specify where in the output Mule message to place the output of this DataWeave transform. In case you’re creating a new variable or property, you must also set a name for it.
  • 14. In the XML editor you can do the same by adding multiple child elements inside thedw:transform-message component. <dw:transform-message> <dw:set-payload resource="classpath:path/transform.dwl"/> <dw:set- variable variableName="myVariable" resource="classpath:path/transform.dwl"/> <dw:set-session-variable variableName="mySessionVariable" resource="classpath:path/transform.dwl"/> </dw:transform-message>
  • 15. Output Section • This section has two tabs, one of them shows you a neat expandable tree view of the output data structure, the other shows you a preview of what the actual output looks like, built from any sample data you provide in the input section. As you make changes in the transport section, notice how the data structure changes. The output of the transformer is made into the selected component of the output mule message. If your transformer has multiple outputs, the Preview tab will display the one corresponding to the currently selected transform.
  • 16. Using DataWeave Language Elsewhere • All components in Mule that support Mule Expression Language also support expressions written in DataWeave Language. To invoke an expression written in DataWeave language, simply invoke the dw() function, the expression will return whatever the transform outputs. • DataWeave expressions defined within this function work just as those defined within a Transform Message element, the only difference is that the output is returned into the expression’s result, wherever it may be.
  • 17. • For example, you can define a custom object and populate it with elements from the payload: • That same expression could be added inside a Logger, • within a MEL expression, to print out its result: dw(myobject:{id:payload.accountid, user:payload.user}) #[`dw(myobject:{id:payload.accountid, user:payload.user})`]