SlideShare a Scribd company logo
1 of 10
DATAWEAVE
• Data transformation is an inevitable component of
connectivity, as most systems don’t speak the same
language. Even when the format is similar, as when
two RESTful Web APIs exchange JSON payloads, their
message structure typically differs, making translation
a necessity.
• Calling Global MEL Functions from DataWeave
Code :
• If you define a global Mule Expression Language (MEL) function
in your Mule project, you can then invoke it anywhere in your
DataWeave code, without need for any special syntax.
• To create one such global function, you must edit your Mule
project’s XML file and enclose any functions that you wish to
define in the following set of tags
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
</global-functions>
</expression-language>
DataWeave – Body
• Calling Global MEL Functions from DataWeave Code :
• This global MEL function must be placed in the global
section, before any of the flows are defined.
• In the empty space in the tags shown in previous slide, you can
use any MEL expression to define custom functions.
• Example :
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def newUser() {
return ["name" : "mariano"]
}
def upperName(user) {
return user.name.toUpperCase()
}
</global-functions>
</expression-language>
</configuration>
DataWeave – Body
• Calling Global MEL Functions from DataWeave Code :
• With the MEL global function in place, in the DataWeave code of
your Transform Message element you can just refer to these
functions.
• Note that the inputs and outputs of these functions can even be
objects and arrays.
• Example :
%dw 1.0
%output application/json
---
{
"foo" : newUser(),
"bar": upperName(newUser())
}
• Even with these external functions in place, you should be
to preview the output of this transform, updated in real time
you edit it.
DataWeave – Body
• Read :
• The read function returns the result of parsing the content parameter with
the specified mimeType reader.
• It accepts three parameters :
• The first argument points the content that must be read.
• The second is the format in which to write it.
• A third optional argument lists reader configuration properties.
• Example :
• In the example above, what was in the CDATA element isn’t parsed by the
DataWeave reader by default, that’s why the read operator must be used to
interpret it.
DataWeave – Body
Transform Input Output
%dw 1.0
%output application/xml
---
output:
read(payload.root.xmlblock,
"application/xml").foo
<?xml version='1.0'
encoding='UTF-8'?>
<root>
<xmlblock><![CDATA[<foo>bar</f
oo>]]></xmlblock>
</root>
<?xml version='1.0'
encoding='UTF-8'?>
<output>bar</outp
t>
• Write :
• The write function returns a string with the serialized
representation of the value in the specified mimeType.
• It accepts three parameters :
• The first argument points to the element that must be written.
• the second is the format in which to write it.
• A third optional argument lists writer configuration properties.
• Example :
DataWeave – Body
Transform Input Output
%dw 1.0
%output application/xml
---
{
output: write(payload,
"application/csv",
{"separator" : "|"})
}
"Name": "Mr White",
"Email": "white@mulesoft.com",
"Id": "1234",
"Title": "Chief Java Prophet"
},
{
"Name": "Mr Orange",
"Email": "orange@mulesoft.com",
"Id": "4567",
"Title": "Integration Ninja"
}
]
<?xml version='1.0' encoding='US-
ASCII'?>
<output>Name|Email|Id|Title
Mr
White|white@mulesoft.com|1234|Chie
f Java Prophet
Mr
Orange|orange@mulesoft.com|4567|
ntegration Ninja
</output>
• Log :
• Returns the specified value and also logs the value in the
DataWeave representation with the specified prefix.
• Example :
• Note that besides producing the expected output, it also logs it.
DataWeave – Body
Transform Output Output To Logger
%dw 1.0
%output
application/json
---
{
result: log("Logging
the array",[1,2,3,4])
}
{
"result": [1,2,3,4]
}
Logging the array [1,2,3,4]
• Calling External Flows
• you can trigger the calling of a different flow in your
Mule application from a DataWeave transform,
through the following expression:
lookup(“flowName”,$)
Which takes two parameters:
• The name of the flow that must be called
• The payload to send to this flow, as a map
DataWeave – Body –External Flows
• Calling External Flows
• Example :
• note that only the payload returned by the invoked flow
will be assigned (i.e. all other message’s properties such as
flowVars and sessionVars will not be overridden when
using the lookup function).
• The lookup function does not support calling subflows.
DataWeave – Body –External Flows
Transform Mule Flow Output
%dw 1.0
%output application/json
---
{
a:
lookup("mySecondFlow",{b:"Hello"})
}
<flow name="mySecondFlow">
<set-payload doc:name="Set
Payload" value="#[payload.b + '
world!' ]"/>
</flow>
{
"a": "Hello world!"
}

More Related Content

What's hot

What's hot (19)

Mule: Java Transformer
Mule: Java TransformerMule: Java Transformer
Mule: Java Transformer
 
Mule esb
Mule esbMule esb
Mule esb
 
Mule Microsoft Service Bus
Mule Microsoft Service BusMule Microsoft Service Bus
Mule Microsoft Service Bus
 
Mule any point studio
Mule any point studioMule any point studio
Mule any point studio
 
Propertiesinmule
PropertiesinmulePropertiesinmule
Propertiesinmule
 
Mule agent notifications
Mule agent notificationsMule agent notifications
Mule agent notifications
 
Mule LDAP Connector
Mule LDAP ConnectorMule LDAP Connector
Mule LDAP Connector
 
Mulesoft file connector
Mulesoft file connectorMulesoft file connector
Mulesoft file connector
 
Database component in mule
Database component in muleDatabase component in mule
Database component in mule
 
Mule properties
Mule propertiesMule properties
Mule properties
 
Mule java part-1
Mule java part-1Mule java part-1
Mule java part-1
 
Dynamic file attribute
Dynamic file attributeDynamic file attribute
Dynamic file attribute
 
Junit in mule demo
Junit in mule demo Junit in mule demo
Junit in mule demo
 
Mule advanced
Mule advancedMule advanced
Mule advanced
 
Enjoy Munit with Mule
Enjoy Munit with MuleEnjoy Munit with Mule
Enjoy Munit with Mule
 
Mule overview-ppt
Mule overview-pptMule overview-ppt
Mule overview-ppt
 
Mule rabbitmq
Mule rabbitmqMule rabbitmq
Mule rabbitmq
 
Mule rabbit mq
Mule rabbit mqMule rabbit mq
Mule rabbit mq
 
Mule system properties
Mule system propertiesMule system properties
Mule system properties
 

Viewers also liked

Yazmin Kuball 2016 Resume
Yazmin Kuball 2016 ResumeYazmin Kuball 2016 Resume
Yazmin Kuball 2016 ResumeYazmin Kuball
 
Final%20Analysis%20Code%20Displayed.html
Final%20Analysis%20Code%20Displayed.htmlFinal%20Analysis%20Code%20Displayed.html
Final%20Analysis%20Code%20Displayed.htmlRyan Haeri
 
Suspensão de divulgação pesquisa eleitoral
Suspensão de divulgação pesquisa eleitoralSuspensão de divulgação pesquisa eleitoral
Suspensão de divulgação pesquisa eleitoralAkibas De Freitas Souza
 
Adobe Digital Economy Project – October 2016
Adobe Digital Economy Project – October 2016Adobe Digital Economy Project – October 2016
Adobe Digital Economy Project – October 2016Adobe
 
Operators in mule dataweave
Operators in mule dataweaveOperators in mule dataweave
Operators in mule dataweaveRamakrishna kapa
 
Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...
Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...
Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...Philippe Villette
 
Mule with data weave
Mule with data weaveMule with data weave
Mule with data weaveSon Nguyen
 
Introduction to dataweave
Introduction to dataweaveIntroduction to dataweave
Introduction to dataweaveSwati Deshpande
 
La actividad financiera del estado venezolano
La actividad financiera del estado venezolanoLa actividad financiera del estado venezolano
La actividad financiera del estado venezolanoMelvismar Garcia
 

Viewers also liked (18)

Dataweave types operators
Dataweave types operatorsDataweave types operators
Dataweave types operators
 
Yazmin Kuball 2016 Resume
Yazmin Kuball 2016 ResumeYazmin Kuball 2016 Resume
Yazmin Kuball 2016 Resume
 
Final%20Analysis%20Code%20Displayed.html
Final%20Analysis%20Code%20Displayed.htmlFinal%20Analysis%20Code%20Displayed.html
Final%20Analysis%20Code%20Displayed.html
 
Mule Cloud-Conceptos
Mule Cloud-ConceptosMule Cloud-Conceptos
Mule Cloud-Conceptos
 
niki1 (2)
niki1 (2)niki1 (2)
niki1 (2)
 
Report 2017
Report 2017Report 2017
Report 2017
 
완성23
완성23완성23
완성23
 
Concursal.
Concursal.Concursal.
Concursal.
 
Suspensão de divulgação pesquisa eleitoral
Suspensão de divulgação pesquisa eleitoralSuspensão de divulgação pesquisa eleitoral
Suspensão de divulgação pesquisa eleitoral
 
Adobe Digital Economy Project – October 2016
Adobe Digital Economy Project – October 2016Adobe Digital Economy Project – October 2016
Adobe Digital Economy Project – October 2016
 
design principles
design principlesdesign principles
design principles
 
Dataweave
DataweaveDataweave
Dataweave
 
Operators in mule dataweave
Operators in mule dataweaveOperators in mule dataweave
Operators in mule dataweave
 
Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...
Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...
Alerte a la pollution aux particules fines PM10 pour les Hautes Pyrenees pour...
 
Edital Completo
Edital CompletoEdital Completo
Edital Completo
 
Mule with data weave
Mule with data weaveMule with data weave
Mule with data weave
 
Introduction to dataweave
Introduction to dataweaveIntroduction to dataweave
Introduction to dataweave
 
La actividad financiera del estado venezolano
La actividad financiera del estado venezolanoLa actividad financiera del estado venezolano
La actividad financiera del estado venezolano
 

Similar to Mule dataweave

Similar to Mule dataweave (20)

Mule data weave_10
Mule data weave_10Mule data weave_10
Mule data weave_10
 
Mule data weave_2
Mule data weave_2Mule data weave_2
Mule data weave_2
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
SSIS : Ftp and script task
SSIS : Ftp and script taskSSIS : Ftp and script task
SSIS : Ftp and script task
 
Linq to sql
Linq to sqlLinq to sql
Linq to sql
 
Mule connectors-session1
Mule connectors-session1Mule connectors-session1
Mule connectors-session1
 
Mule ESB Components
Mule ESB Components Mule ESB Components
Mule ESB Components
 
Intro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data IntegrationIntro to Talend Open Studio for Data Integration
Intro to Talend Open Studio for Data Integration
 
Data weave
Data weaveData weave
Data weave
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Mule connectors-part 1
Mule connectors-part 1Mule connectors-part 1
Mule connectors-part 1
 
Data weave in Mule
Data weave in MuleData weave in Mule
Data weave in Mule
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Data weave
Data weave Data weave
Data weave
 
Dataweave
Dataweave Dataweave
Dataweave
 
Muleesbcomponents1 160625154208
Muleesbcomponents1 160625154208Muleesbcomponents1 160625154208
Muleesbcomponents1 160625154208
 
Introduction of ssis
Introduction of ssisIntroduction of ssis
Introduction of ssis
 

More from Son Nguyen

Wsdl connector introduction
Wsdl connector introductionWsdl connector introduction
Wsdl connector introductionSon Nguyen
 
Android intergrate with mule
Android intergrate with muleAndroid intergrate with mule
Android intergrate with muleSon Nguyen
 
Mule flow overview
Mule flow overviewMule flow overview
Mule flow overviewSon Nguyen
 
Mule flow and filter
Mule flow and filterMule flow and filter
Mule flow and filterSon Nguyen
 
Handle exceptions in mule
Handle exceptions in muleHandle exceptions in mule
Handle exceptions in muleSon Nguyen
 
Spring security integrate with mule
Spring security integrate with muleSpring security integrate with mule
Spring security integrate with muleSon Nguyen
 
Message processor in mule
Message processor in muleMessage processor in mule
Message processor in muleSon Nguyen
 
Expression language in mule
Expression language in muleExpression language in mule
Expression language in muleSon Nguyen
 
Using spring scheduler mule
Using spring scheduler muleUsing spring scheduler mule
Using spring scheduler muleSon Nguyen
 
Composite source in bound and out-bound
Composite source in bound and out-boundComposite source in bound and out-bound
Composite source in bound and out-boundSon Nguyen
 
Batch job processing
Batch job processingBatch job processing
Batch job processingSon Nguyen
 
Using message enricher
Using message enricherUsing message enricher
Using message enricherSon Nguyen
 
Finance connectors with mule
Finance connectors with muleFinance connectors with mule
Finance connectors with muleSon Nguyen
 
Google drive connection
Google drive connectionGoogle drive connection
Google drive connectionSon Nguyen
 
Using properties in mule
Using properties in muleUsing properties in mule
Using properties in muleSon Nguyen
 
Mule integrate with microsoft
Mule integrate with microsoftMule integrate with microsoft
Mule integrate with microsoftSon Nguyen
 
Anypoint connectors
Anypoint connectorsAnypoint connectors
Anypoint connectorsSon Nguyen
 
Mule esb basic introduction
Mule esb basic introductionMule esb basic introduction
Mule esb basic introductionSon Nguyen
 
Runing batch job in mule
Runing batch job in muleRuning batch job in mule
Runing batch job in muleSon Nguyen
 

More from Son Nguyen (20)

Wsdl connector introduction
Wsdl connector introductionWsdl connector introduction
Wsdl connector introduction
 
Android intergrate with mule
Android intergrate with muleAndroid intergrate with mule
Android intergrate with mule
 
Mule flow overview
Mule flow overviewMule flow overview
Mule flow overview
 
Mule flow and filter
Mule flow and filterMule flow and filter
Mule flow and filter
 
Handle exceptions in mule
Handle exceptions in muleHandle exceptions in mule
Handle exceptions in mule
 
Spring security integrate with mule
Spring security integrate with muleSpring security integrate with mule
Spring security integrate with mule
 
Message processor in mule
Message processor in muleMessage processor in mule
Message processor in mule
 
Expression language in mule
Expression language in muleExpression language in mule
Expression language in mule
 
Using spring scheduler mule
Using spring scheduler muleUsing spring scheduler mule
Using spring scheduler mule
 
Composite source in bound and out-bound
Composite source in bound and out-boundComposite source in bound and out-bound
Composite source in bound and out-bound
 
Batch job processing
Batch job processingBatch job processing
Batch job processing
 
Using message enricher
Using message enricherUsing message enricher
Using message enricher
 
Finance connectors with mule
Finance connectors with muleFinance connectors with mule
Finance connectors with mule
 
Google drive connection
Google drive connectionGoogle drive connection
Google drive connection
 
Using properties in mule
Using properties in muleUsing properties in mule
Using properties in mule
 
Mule integrate with microsoft
Mule integrate with microsoftMule integrate with microsoft
Mule integrate with microsoft
 
Jms queue
Jms queueJms queue
Jms queue
 
Anypoint connectors
Anypoint connectorsAnypoint connectors
Anypoint connectors
 
Mule esb basic introduction
Mule esb basic introductionMule esb basic introduction
Mule esb basic introduction
 
Runing batch job in mule
Runing batch job in muleRuning batch job in mule
Runing batch job in mule
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Mule dataweave

  • 2. • Data transformation is an inevitable component of connectivity, as most systems don’t speak the same language. Even when the format is similar, as when two RESTful Web APIs exchange JSON payloads, their message structure typically differs, making translation a necessity.
  • 3. • Calling Global MEL Functions from DataWeave Code : • If you define a global Mule Expression Language (MEL) function in your Mule project, you can then invoke it anywhere in your DataWeave code, without need for any special syntax. • To create one such global function, you must edit your Mule project’s XML file and enclose any functions that you wish to define in the following set of tags <configuration doc:name="Configuration"> <expression-language> <global-functions> </global-functions> </expression-language> DataWeave – Body
  • 4. • Calling Global MEL Functions from DataWeave Code : • This global MEL function must be placed in the global section, before any of the flows are defined. • In the empty space in the tags shown in previous slide, you can use any MEL expression to define custom functions. • Example : <configuration doc:name="Configuration"> <expression-language> <global-functions> def newUser() { return ["name" : "mariano"] } def upperName(user) { return user.name.toUpperCase() } </global-functions> </expression-language> </configuration> DataWeave – Body
  • 5. • Calling Global MEL Functions from DataWeave Code : • With the MEL global function in place, in the DataWeave code of your Transform Message element you can just refer to these functions. • Note that the inputs and outputs of these functions can even be objects and arrays. • Example : %dw 1.0 %output application/json --- { "foo" : newUser(), "bar": upperName(newUser()) } • Even with these external functions in place, you should be to preview the output of this transform, updated in real time you edit it. DataWeave – Body
  • 6. • Read : • The read function returns the result of parsing the content parameter with the specified mimeType reader. • It accepts three parameters : • The first argument points the content that must be read. • The second is the format in which to write it. • A third optional argument lists reader configuration properties. • Example : • In the example above, what was in the CDATA element isn’t parsed by the DataWeave reader by default, that’s why the read operator must be used to interpret it. DataWeave – Body Transform Input Output %dw 1.0 %output application/xml --- output: read(payload.root.xmlblock, "application/xml").foo <?xml version='1.0' encoding='UTF-8'?> <root> <xmlblock><![CDATA[<foo>bar</f oo>]]></xmlblock> </root> <?xml version='1.0' encoding='UTF-8'?> <output>bar</outp t>
  • 7. • Write : • The write function returns a string with the serialized representation of the value in the specified mimeType. • It accepts three parameters : • The first argument points to the element that must be written. • the second is the format in which to write it. • A third optional argument lists writer configuration properties. • Example : DataWeave – Body Transform Input Output %dw 1.0 %output application/xml --- { output: write(payload, "application/csv", {"separator" : "|"}) } "Name": "Mr White", "Email": "white@mulesoft.com", "Id": "1234", "Title": "Chief Java Prophet" }, { "Name": "Mr Orange", "Email": "orange@mulesoft.com", "Id": "4567", "Title": "Integration Ninja" } ] <?xml version='1.0' encoding='US- ASCII'?> <output>Name|Email|Id|Title Mr White|white@mulesoft.com|1234|Chie f Java Prophet Mr Orange|orange@mulesoft.com|4567| ntegration Ninja </output>
  • 8. • Log : • Returns the specified value and also logs the value in the DataWeave representation with the specified prefix. • Example : • Note that besides producing the expected output, it also logs it. DataWeave – Body Transform Output Output To Logger %dw 1.0 %output application/json --- { result: log("Logging the array",[1,2,3,4]) } { "result": [1,2,3,4] } Logging the array [1,2,3,4]
  • 9. • Calling External Flows • you can trigger the calling of a different flow in your Mule application from a DataWeave transform, through the following expression: lookup(“flowName”,$) Which takes two parameters: • The name of the flow that must be called • The payload to send to this flow, as a map DataWeave – Body –External Flows
  • 10. • Calling External Flows • Example : • note that only the payload returned by the invoked flow will be assigned (i.e. all other message’s properties such as flowVars and sessionVars will not be overridden when using the lookup function). • The lookup function does not support calling subflows. DataWeave – Body –External Flows Transform Mule Flow Output %dw 1.0 %output application/json --- { a: lookup("mySecondFlow",{b:"Hello"}) } <flow name="mySecondFlow"> <set-payload doc:name="Set Payload" value="#[payload.b + ' world!' ]"/> </flow> { "a": "Hello world!" }