Recently was working on a project where I had a to read an XML file from an FTP location, transform it and expose it as an API. Used WSO2 ESB 4.6.0 for this usecase; and I thought of documenting it for later reference. So here it goes
First the proxy that read the file from FTP and dump it to a defined location, (VFSProxy.xml)
<?xml version="1.0" encoding="UTF-8"?> | |
<proxy xmlns="http://ws.apache.org/ns/synapse" name="VFSProxy" transports="vfs" startOnLoad="true" trace="disable"> | |
<target> | |
<inSequence> | |
<log level="custom"> | |
<property name="STATUS" value="File received"/> | |
</log> | |
<property name="OUT_ONLY" value="true"/> | |
<send> | |
<endpoint> | |
<address uri="vfs:file:///home/nuwanbando/temp/files/out"/> | |
</endpoint> | |
</send> | |
</inSequence> | |
</target> | |
<parameter name="transport.PollInterval">10</parameter> | |
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter> | |
<parameter name="transport.vfs.FileURI">vfs:ftp://<ftpserver_url>/home/nuwanbando/temp/files/in?vfs.passive=true</parameter> | |
<parameter name="transport.vfs.MoveAfterProcess">file:///home/nuwanbando/temp/files/processed</parameter> | |
<parameter name="transport.vfs.MoveAfterFailure">file:///home/nuwanbando/temp/files/failed</parameter> | |
<parameter name="transport.vfs.FileNamePattern">.*.xml</parameter> | |
<parameter name="transport.vfs.ContentType">text/plain</parameter> | |
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter> | |
</proxy> |
This proxy will dump the file to "home/nuwanbando/temp/files/out"
location.
This file need to be read on-demand, once requested. ESB by default does not have a mediator to read XML files so that the mediation flow can manipulate the content, Continue reading Reading an XML file into WSO2 ESB; Transform it and expose it as an API