Sunday, July 24, 2016

WSO2 Data Mapper - Properties operator


Introduction


WSO2 Data Mapper supports using of ESB Properties(Synapse Properties) while data mapping.

Let's say we want to add a value of already defined ESB property into a resultant payload. In this use case we have two properties called "appID" and "time" defined previously and we want to use them while data mapping. See the below Proxy service which defines two properties before the Data mapper mediator



Proxy configuration

<proxy name="DataTransformerWithDataMapper" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <property name="appID" scope="default" type="STRING" value="APP0001"/>
            <property expression="get-property(&quot;SYSTEM_DATE&quot;, &quot;yyyy.MM.dd G 'at' HH:mm:ss z&quot;)" name="time" scope="default" type="STRING"/>
            <datamapper config="gov:datamapper/propertyOperator.dmc" inputSchema="gov:datamapper/propertyOperator_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/propertyOperator_outputSchema.json" outputType="XML"/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
</proxy>


How to add Property operator and configure.


Go to Data Mapper editor by double clicking on DataMapper mediator. In the tool palette you can see there is a operator called "Properties" under "Common" category. 

This operator can be used to retrieve already defined properties and use them in Data Mapping. 

Drag and drop "Properties" operator into canvas. Right click on this operator and select "Configure Property Operator". Use opened dialog box to provide property scope(synapse(default), transport, axis2, axis2-client, operation), property name values.



You can compose your Data Mapping diagram as shown below to retrieve already defined properties and append them to output payload.  




Try it by yourselves


I have attached sample input.xml, output.xml and proxy service configuration. Load input and output files into input and output of data mapper diagram and do the mapping as shown above using "Property" operator. Deploy all the required artifact into an ESB and invoke the proxy service with input.xml as the payload.

Furthermore I have attached Maven Multi Module project which contains all the required projects, input.xml and output.xml in following location. You can try it by yourself.

https://drive.google.com/folderview?id=0BzCWN6PPAojbOHV1dGZNSVdCMzQ&usp=sharing

Download the archive. Unzip and use steps mentioned in following link to import PropertyOperatorSample project into workspace.

https://docs.wso2.com/display/DVS380/Quick+Start+Guide#QuickStartGuide-Importingexistingprojects


No comments:

Post a Comment