WSO2 is now Choreo LabsLearn more

Trusted AI Governance
Build

Create agents and AI apps with the tools and languages your teams already use.

Connect

Link agents securely to your APIs, data, models and business systems.

Run

Deploy, observe and operate agents and AI apps reliably at any scale.

Govern

Control identity, access, cost and policy for every agent in production.

Agent Management

Developer Platform

  • API Management Cloud

    Design, secure and publish APIs with governance and analytics built in.

    Sign Up Now
  • Integration Cloud

    Connect apps, data and AI agents with low-code and pro-code integration.

    Sign Up Now
  • Identity & Access Management Cloud

    Secure sign-in and access for customers, partners, workforce and agents.

    Sign Up Now
  • Agent Management Cloud

    Build, run and govern AI agents with full visibility and control.

    Sign Up Now
  • Developer Platform Cloud

    Ship cloud-native apps faster on an internal developer platform.

    Sign Up Now

Self-Hosted

Full control over your stack. Deploy directly to your own servers, bare metal, cloud, or Kubernetes environment. Your data never leaves your perimeter.

Product Downloads
Choreo Labs
AI Governance
Platform
Solutions
Resources
Article

[Blog post] CSV to XML transformation with WSO2 ESB smooks mediator

Latest ESB can be downloaded from here.

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

Lakmali,Erandi,Female,20,SriLanka
Lakmali,Baminiwatta,Female,20,SriLanka

This is the format of the XML output message.


 
  Lakmali
  Erandi
  Female
  20
  SriLanka
 
 
  Lakmali
  Baminiwatta
  Female
  20
  SriLanka
 

First lets write the smooks configuration to transform above CSV to given XML message (smooks-csv.xml).


 
   
  org.milyn.csv.CSVReader
  firstname,lastname,gender,age,country
  people
   
  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

   
   
      
         
            
            
         
         
      
   
   MOVE
   5
   file:///home/lakmali/dev/test/smooks/original
   file:///home/lakmali/dev/test/smooks/in
   file:///home/lakmali/dev/test/smooks/original
   .*.csv
   text/plain
   MOVE

You have to make an 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.

Source: https://blog.lakmali.com/2013/08/csv-to-xml-transformation-with-wso2-esb.html.