Thursday, April 13, 2017

How to read/write files using VFS transport in WSO2 ESB

To enable the VFS transport
Edit the <ESB_HOME>/repository/conf/axis2/axis2.xml file and uncomment the VFS listener and the VFS sender as follows:

<transportreceiver name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportListener"/>
<transportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender"/>

Create a folder structure as below:
├── Pass ├── Original ├── Failures ├── output
             ├── test.xml 

Configure the below proxy in WSO2 ESB.

<proxy name="testVFS" startonload="true" trace="disable" transports="https http vfs" xmlns="http://ws.apache.org/ns/synapse">
   <description>
   <target>
      <insequence>
         <property name="transport.vfs.ReplyFileName" scope="transport" value="myfile.xml">
         <property name="OUT_ONLY" value="true">
         <send>
            <endpoint>
               <address uri="vfs:file:///home/ubuntu/output">
            </address>
</endpoint>
         </send>
      </property></property></insequence>
   </target>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.PollInterval">5</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///home/ubuntu/Pass</parameter>
   <parameter name="transport.vfs.FileURI">file:///home/ubuntu/Original</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///home/ubuntu/Failures/</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
   <parameter name="transport.vfs.ContentType">application/xml</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</description>
</proxy>

Our proxy will automatically poll for files in the given location.

  • test.xml file will be located in file:///home/ubuntu/Pass
  • myfile.xml will get created in the file:///home/ubuntu/output folder

No comments:

Post a Comment