VFS Transport Examples
Background
This example demonstrates sending and receiving a file message from an SFTP service, using the Mule VFS Transport Since FTP, File, and other services supported by the VFS Connector are available as separate connectors in Mule, SFTP will be the focus of this example.
This is a simple example that accepts text input from the console, then dispatches that text input as a file to an SFTP service. Then, the same file is received from the SFTP service and printed to the console. Please see the VFS Transport User Guide for more details.
Running the Example
Note: Please make sure you have completed all the steps of the VFS Connector Installation before proceeding.
The starting directory for this sample is the "examples" directory, found in either your Mule-SalesForce Connector zip directory if you installed from binary, or your Subversion workspace if you built from source.
1. Open conf/mule-vfs-examples-config.xml in a text editor. Change the sftp endpoint URIs to match your sftp service (there are 2 of them, so make sure to change them both). For this example, use the same directory for both the inbound and outbound sftp endpoints.
<endpoint address="vfs:sftp: connector="sftpConnector" />
 | For most Unix/Linux sftp services, /path/to/dir above would translate to the absolute path of /path/to/dir. Using FreeSSHd on Windows, you set the base path for all users, so /path/to/dir would be relative to that base. | |
 | Make sure the user has permissions to access the directory specified. |
3.Start your Mule 1.3.3 server with the configuration we edited in Step 1:
vfs.bat (Windows) or vfs (Linux/Unix)
4. After startup, you should see something like this in the console:
**********************************************************************
* Mule ESB and Integration Platform version Not Set *
* Not Set *
* For more information go to http://mule.mulesource.org *
* *
* Server started: Monday, March 19, 2007 1:17:21 AM PDT *
* Server ID: SFTP_TEST *
* JDK: 1.5.0_11 (mixed mode) *
* OS: Windows XP - Service Pack 2 (5.1, x86) *
* Host: QMULE (192.168.1.101) *
* *
* Agents Running: *
* Mule Admin: accepting connections on tcp://localhost:60504 *
**********************************************************************
INFO 2007-03-19 01:17:22,734 [WrapperSimpleAppMain] org.mule.MuleServer: Mule S
erver initialized.
=====VFS SFTP Demo. Enter file contents to be routed to SFTP service .=====
5. By entering text to the console at the prompt above, Mule will dispatch a file message to the SFTP service specifed in Step 1. You will then see the following (linebreaks added for readability):
=====VFS SFTP Demo. Enter file contents to be routed to SFTP service .=====
This is a mule message
INFO 2007-03-19 01:52:18,078 [SystemStreamConnector.endpoint.stream.System.in.r
eceiver.1] org.mule.providers.vfs.VFSMessageDispatcher: Successfully connected t
o: sftp://mule:test123@localhost/files/sftp-source
INFO 2007-03-19 01:52:18,078 [SystemStreamConnector.endpoint.stream.System.in.r
eceiver.1] org.mule.providers.vfs.VFSMessageDispatcher: Writing file to: sftp://
mule:test123@localhost/files/sftp-source/sftp-example-file.txt
The INFO logging tells you that Mule was able to connect and write to the resource sftp://
mule:test123@localhost/files/sftp-source/sftp-example-file.txt.
This behavior was configured in the following mule-descriptor from conf/mule-vfs-examples-config.xml:
<mule-descriptor name="sftpSend" implementation="org.mule.components.simple.BridgeComponent">
<inbound-router>
<endpoint address="stream://System.in" />
</inbound-router>
<outbound-router>
<router className="org.mule.routing.outbound.FilteringOutboundRouter">
<endpoint address="vfs:sftp://mule:test123@localhost/files/sftp-source" connector="sftpConnector" />
</router>
</outbound-router>
</mule-descriptor>
6. The VFS Connector uses a PollingMessageReceiver to retrieve files from an SFTP. Since we configured the polling frequency to be 10 seconds, you should see the following in the console in 10 s (linebreaks added for readability):
INFO 2007-03-19 01:52:21,187 \[sftpConnector.endpoint.sftp.mule.test123.localhos
t.files.sftp.source.receiver.1\] org.mule.providers.stream.StreamMessageDispatche
r: Successfully connected to: stream://System.out
This is a mule message
You should see the same message you entered in Step 5.
This behavior was configured in the following mule-descriptor from conf/mule-vfs-examples-config.xml:
<mule-descriptor name="sftpReceive" implementation="org.mule.components.simple.BridgeComponent">
<inbound-router>
<endpoint address="vfs:sftp://mule:test123@localhost/files/sftp-source" connector="sftpConnector" />
</inbound-router>
<outbound-router>
<router className="org.mule.routing.outbound.FilteringOutboundRouter">
<endpoint address="stream://System.out" />
</router>
</outbound-router>
</mule-descriptor>