how to use data weave

8
How to use DataWeave component 14-05-2015

Upload: sivachandra-mandalapu

Post on 12-Jan-2017

117 views

Category:

Education


2 download

TRANSCRIPT

Page 1: How to use data weave

How to use DataWeave component

14-05-2015

Page 2: How to use data weave

Abstract

• The main motto of this PPT is How to use DataWeave in our applications.

Page 3: How to use data weave

Introduction

• The DataWeave language is a simple, powerful tool to query and transform data inside of Mule.

Page 4: How to use data weave

Example

Page 5: How to use data weave

.mflow• <?xml version="1.0" encoding="UTF-8"?>• <mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"

xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"• xmlns:spring="http://www.springframework.org/schema/beans" • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"• xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd• http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd• http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd• http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">• <flow name="dataweaveFlow">• <file:inbound-endpoint path="D:\csvcontact" responseTimeout="10000" doc:name="File"/>• <logger message="flow started" level="INFO" doc:name="Logger"/>• <dw:transform-message metadata:id="5e76ab87-23c8-4c36-9618-6620c53520f8" doc:name="Transform Message">• <dw:set-payload><![CDATA[%dw 1.0• %output application/json• ---• {• • • Address: {• • • • Country: payload.Address.Country,• • • State: payload.Address.State• ,• • City: payload.Address.City• }• }]]></dw:set-payload>• </dw:transform-message>• <logger message="--Output--#[message.payloadAs(java.lang.String)]--" level="INFO" doc:name="Logger"/>• </flow>• </mule>

Page 6: How to use data weave

• Output:• INFO 2016-05-06 12:38:07,038 [[dataweave].connector.file.mule.default.receiver.01]

org.mule.transport.file.FileMessageReceiver: Lock obtained on file: D:\csvcontact\sample.xml

• INFO 2016-05-06 12:38:07,038 [[dataweave].dataweaveFlow.stage1.05] org.mule.api.processor.LoggerMessageProcessor: flow started

• INFO 2016-05-06 12:38:07,038 [[dataweave].dataweaveFlow.stage1.05] org.mule.api.processor.LoggerMessageProcessor: --Output--{

• "Address": {• "Country": "India",• "State": "AP",• "City": "Dharmavaram"• }• }--•  •  •  

Page 7: How to use data weave

• Flow of execution:1. The above flow is used to convert xml to JSON

using DataWeave2. It will pick the .xml file from specific location and

will convert and display json response in console3. Sample xml:<Address><Country>India</Country><State>AP</State><City>Dharmavaram</City></Address>