Reputation: 167
My proxy uses a vfs transport to read a csv file. Content of csv file 1,9,WSO2
I want to transform this csv content to as follows
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:xsd="http://services.samples">
<soapenv:Header/>
<soapenv:Body>
<xsd:placeOrder>
<xsd:order>
<xsd:price>1</xsd:price>
<xsd:quantity>9</xsd:quantity>
<xsd:symbol>WSO2</xsd:symbol>
</xsd:order>
</xsd:placeOrder>
</soapenv:Body>
</soapenv:Envelope>
using smook mediator.
The smook config file should use java binding(using HashMap and ArrayList) and freemarker to do the transform. (preferable approach)
Can anyone help me out ???? (If yes Please post the answer)
Upvotes: 0
Views: 1051
Reputation: 37
Please refer below article. It explains a similar scenario. https://medium.com/sa-team-blog/reading-files-and-sending-file-content-to-an-api-using-wso2-enterprise-integrator-4118db8e295c?source=friends_link&sk=5242b3c380f100b1bccaadf183f19836
In nutshell, you have to do the following.
First, Create an ESB solutions project Then, Create a file processer proxy service within that project, with transport type = "VFS". Define VFS parameters within the proxy service XML file as parameter attributes. Drag and drop a smooks mediator to your input message flow in your proxy service. Create a local entry in your ESB solution project, and define smooks properties in that local entry file. Then give that local entry file name as the smooks config key to the smooks mediator.
Upvotes: -1
Reputation: 11
I have created one proxy service and I am using the VFS to do the file process.For that enable the vfs.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CSVtoXMLSmooks" startOnLoad="true" statistics="disable" trace="disable" transports="vfs,http,https">
<target>
<inSequence>
<smooks config-key="CsvtoXml_Smooks">
<input type="text"/>
<output type="xml"/>
</smooks>
<property expression="$body/*" name="payload" scope="default" type="STRING"/>
<log level="custom">
<property expression="get-property('payload')" name="Response payload==="/>
</log>
</inSequence>
</target>
<parameter name="transport.PollInterval">1</parameter>
<parameter name="transport.vfs.FileURI">file:///Home/smooks/In</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///Home/smooks/Out</parameter>
<description/>
</proxy>
Inside the proxy service.Call the smooks mediator.
<smooks config-key="CsvtoXml_Smooks">
<input type="text"/>
<output type="xml"/>
</smooks>
Create one local entry to define the mapping and process of smooks mediator.
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">
<resource-config selector="org.xml.sax.driver">
<resource>org.milyn.csv.CSVReader</resource>
<param name="fields">CustID,CustName,CustAddress</param>
<param name="rootElementName">data</param>
<param name="recordElementName">csvRecord</param>
</resource-config>
Sample Input:
1,chris,india
2,sam,South india
Output will be like this:
<data><csvRecord number="1"><CustID>1</CustID><CustName>chris</CustName><CustAddress>india</CustAddress></csvRecord><csvRecord number="2"><CustID>2</CustID><CustName>sam</CustName><CustAddress>South india</CustAddress></csvRecord></data>
Try this.Thank you.
Upvotes: 1
Reputation: 9702
You need to use CSVParser for this.
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.0.xsd">
<resource-config selector="org.xml.sax.driver">
<resource>org.milyn.csv.CSVParser</resource>
<param name="fields" type="string-list">price, quantity,symbol</param>
</resource-config>
</smooks-resource-list>
You can find this post useful
Upvotes: 0