CSV to XML transformation with WSO2 ESB Smooks Mediator

This post provides a sample CSV to XML transformation with WSO2 ESB. WSO2 ESB supports executing Smooks features through 'Smooks Mediator'. 

Latest ESB can be downloaded from here

We are going to transform the below CSV to an XML message.


This is the format of the XML output message.
 <person number="1">
 <person number="2">
First lets write the smooks configuration to transform above CSV to given XML message (smooks-csv.xml).


   <resource-config selector="org.xml.sax.driver">
  <param name="fields">firstname,lastname,gender,age,country</param>
  <param name="rootElementName">people
  <param name="recordElementName">person
Now let's write a simple proxy service to take the CSV file as the input message and process through the smooks mediator. For that first you need to enable VFS transport sender and reciever.

Below is the service synapse configuration. Make sure to change the following parameters according to your file system. You can find more information about the parameters from here.

  •   transport.vfs.FileURI
  •   transport.vfs.MoveAfterProcess
  •   transport.vfs.ActionAfterFailure

<proxy xmlns="http://ws.apache.org/ns/synapse"
         <smooks config-key="smooks-csv">
            <input type="text"/>
            <output type="xml"/>
         <log level="full"/>
   <parameter name="transport.PollInterval">5</parameter>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.vfs.FileURI">file:///home/lakmali/dev/test/smooks/in</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///home/lakmali/dev/test/smooks/original</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///home/lakmali/dev/test/smooks/original</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
   <parameter name="transport.vfs.ContentType">text/plain</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>

You have to make a ESB local entry with the key 'smooks-csv' and give path to smooks-csv.xml which we crated above. So in the smooks mediator above, we are loading the smooks config through the local entry key name (smooks-csv).

To perform the transformation what you need to do is drop the input message file to transport.vfs.FileURI location. In the log you can see the transformed message in XML!! Now you got the CSV message in XML in your synapse sequence. So you can perform any further mediation to this message such as send to some endpoint/database/file etc.


  1. can you please make this tutorial more elaborative. step by step approach to achieve the transformation.

  2. Hi Rahul,

    You can get some insight from the below sample:


  3. I tried sample 271 with ESB 4.9.0
    It gives error on execution
    INFO - LogMediator To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:247f4674-cd22-461e-88c2-6f12693a7d67, Direction: request, MESSAGE = Executing default 'fault' sequence, ERROR_CODE = 0, ERROR_MESSAGE = XML error occurred while creating the Smooks configuration from the config key: smooks Caused by Failed to locate XSD resource '/META-INF/ns/synapse' on classpath. Namespace: 'http://ws.apache.org/ns/synapse'., Envelope:

  4. This comment has been removed by a blog administrator.


Post a Comment

Popular posts from this blog

PHP-SOAP web service with out a WSDL

Boomi Mapping - Removing special chars from an input

How to add Maven dependency from a relative path referencing a local jar