Wednesday, January 5, 2011

SFTP file transer with WSO2 ESB.

The VFS transport implementation is based on Apache Commons VFS implementation. VFS (Virtual File System) transport implementation is a module which belongs to the Apache Synapse project. It has a set of service level parameters that needs to be specified for each service.

VFS service level parameters and their descriptions can be found in [1] and the endpoint formats can be found in [2].

Following is a sftp sample for ESB 3.0.1. It copies a file from one sftp location to another sftp folder. SFTPVFSProxy is the proxy service which copies file from one sftp location to another.

If you need further information or need help troubleshooting this sample refer [5].

<proxy name="SFTPVFSProxy" transports="vfs" startOnLoad="true" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<log level="full"/>
<property name="File" expression="fn:concat('test-', get-property('transport', 'FILE_PATH'))" scope="default"/>
<property name="transport.vfs.ReplyFileName" expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<send>
<endpoint name="endpoint_urn_uuid_A1546EFFD75FC9CCED785986339425964585275">
<address uri="vfs:sftp://heshan:password@10.101.1.112/home/heshan/out"/>
</endpoint>
</send>
</inSequence>
</target>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.MoveAfterProcess">vfs:sftp://heshan:password@10.101.1.112/home/heshan/original</parameter>
<parameter name="transport.vfs.FileURI">vfs:sftp://heshan:password@10.101.1.112/home/heshan/in/test.xml</parameter>
<parameter name="transport.vfs.MoveAfterFailure">vfs:sftp://heshan:password@10.101.1.112/home/heshan/original</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</proxy>
Following is the XML file (test.xml) that is being moved.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soapenv:Body>
<getQuote xmlns="http://services.samples">
<request>
<symbol>IBM</symbol>
</request>
</getQuote>
</soapenv:Body>
</soapenv:Envelope>

If you are interested in trying out more VFS samples, refer [3] and [4].

No comments: