Friday, April 12, 2013

Creating CSV Files from a Proxy Service

If you want to write a CSV file from a proxy service in WSO2 ESB, then following sample would help you to understand how it works.

  1. Uncomment the following lines in wso2esb-4.x.x/repository/conf/axis2/axis2.xml.
    <transportreceiver class="org.apache.synapse.transport.vfs.VFSTransportListener" name="vfs"/>
    <transportsender class="org.apache.synapse.transport.vfs.VFSTransportSender" name="vfs"/>
  2. Add below content into the resource called /_system/governance/xml2csv.xslt
    <xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:output method="text" encoding="iso-8859-1"/>
    <xsl:strip-space elements="*" />
    <xsl:template match="/*/child::*">
     <xsl:for-each select="child::*">
      <xsl:if test="position() != last()"><xsl:value-of select="normalize-space(.)"/>,</xsl:if>
      <xsl:if test="position()  = last()"><xsl:value-of select="normalize-space(.)"/><xsl:text>
  3. Create a proxy service named CSVProxy with the following content.
    <proxy xmlns="" name="CSVProxy" transports="https,http" 
        statistics="disable" trace="disable" startOnLoad="true">
             <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
                         <street>Flower Road</street>
                         <country>Sri Lanka</country>
             <xslt key="gov:/xml2csv.xslt"/>
             <property name="transport.vfs.ReplyFileName" expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.csv')" scope="transport"/>
             <property name="OUT_ONLY" value="true"/>
                   <address uri="vfs:file:///home/ruchira/csv"/>
    Note : vfs:file:///home/ruchira/csv is the path where generated csv files are stored. Hence replace it with a valid path in your machine.
  4. Invoke the CSVProxy service by issuing an HTTP GET to http://localhost:8280/services/CSVProxy
  5. CSV files will be created in the above specified path.


  1. Thanks for posting this. Exactly i was looking for.

  2. I have been trying to work on but this only works on a fixed number of addresses. I have some accounts that have more proxy addresses than others. What would be the best way of extracting these into a csv file. I need these in one column, proxyAddresses, with each address separated by a semicolon.
    Youtube Proxy

  3. Thanks a lot for making this available. I really appreciate that.
    access Bee MP3 in UK