Monday, January 12, 2015

How to configure a VFS transport within WSO2 ESB?

In this tutorial I will show you the variety of options to configure a VFS transport.

What is VFS? 
Virtual File System (VFS) is an abstraction layer on top of a more concrete file system. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a uniform way. 

1) Local file system
    a Windows
    b Linux 
2) FTP 
3) SFTP 
4) CIFS - SMB 

The most used VFS options are:

1a. Local file system - Windows
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ProxyWinFile" transports="vfs" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>         
         <log level="custom">            
            <property name="LOG" value="=====Win File=======Win File=====Win File====="/>         
         </log>      
      </inSequence>
      <outSequence>         
         <send>            
            <endpoint>               
               <address uri="vfs:file:///D:/SPs/tmp/out"/>            
            </endpoint>         
         </send>      
      </outSequence>
   </target>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.PollInterval">20</parameter>
   <parameter name="transport.vfs.FileURI">file:///D:/SPs/tmp/in</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///D:/SPs/tmp/process</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///D:/SPs/tmp/fail</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
   <parameter name="transport.vfs.ContentType">text/xml</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
   <parameter name="transport.vfs.MoveTimestampFormat">yyyyMMdd_HHmmss_</parameter>
   <description></description>
</proxy>  

1b. Local file system - Linux
<proxy xmlns="http://ws.apache.org/ns/synapse" name="ProxyFile" transports="vfs" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="custom">
            <property name="LOG" value="=====File=======File=====File====="/>
         </log>
      </inSequence>
      <outSequence>
         <send>
            <endpoint>
               <address uri="vfs:file:///home/user/file/out"/>
            </endpoint>
         </send>
      </outSequence>
   </target>
   <parameter name="transport.PollInterval">20</parameter>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///home/user/file/process</parameter>
   <parameter name="transport.vfs.FileURI">file:///home/user/file/in</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///home/user/file/fail</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
   <parameter name="transport.vfs.ContentType">text/xml</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
   <parameter name="transport.vfs.MoveTimestampFormat">yyyyMMdd_HHmmss_</parameter>
   <description></description>
</proxy> 
 

2. FTP Proxy configuration
<proxy name="ProxyFTP" transports="vfs" startOnLoad="true" trace="disable">
      <description/>
      <target>
         <inSequence>
            <log level="custom">
               <property name="LOG" value="=====FTP=====FTP=====FTP====="/>
            </log>
         </inSequence>
         <outSequence>
            <send>
               <endpoint>
                  <address uri="vfs:ftp://acb:abc123@10.100.0.5/esbtest/out"/>
               </endpoint>
            </send>
         </outSequence>
      </target>
      <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
      <parameter name="transport.PollInterval">5</parameter>
      <parameter name="transport.vfs.MoveAfterProcess">vfs:ftp://acb:abc123@10.100.0.5/esbtest/process</parameter>
      <parameter name="transport.vfs.FileURI">vfs:ftp://acb:abc123@10.100.0.5/esbtest/in?vfs.passive=true</parameter>
      <parameter name="transport.vfs.MoveAfterFailure">vfs:ftp://acb:abc123@10.100.0.5/esbtest/fail</parameter>
      <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
      <parameter name="transport.vfs.ContentType">text/xml</parameter>
      <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
      <parameter name="transport.vfs.MoveTimestampFormat">yyyyMMdd_HHmmss_</parameter>
</proxy>

3. SFTP Proxy configuration
<proxy name="ProxySFTP" transports="vfs" startOnLoad="true" trace="disable">
      <description/>
      <target>
         <inSequence>
            <log level="custom">
               <property name="LOG" value="=====FTPS=======FTPS=====FTPS====="/>
            </log>
         </inSequence>
         <outSequence>
            <send>
               <endpoint>
                  <address uri="vfs:sftp://abc:abc123@10.100.0.5/esbtest/out"/>
               </endpoint>
            </send>
         </outSequence>
      </target>
      <parameter name="transport.PollInterval">5</parameter>
      <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
      <parameter name="transport.vfs.MoveAfterProcess">vfs:sftp://abc:abc123@10.100.0.5/esbtest/process</parameter>
      <parameter name="transport.vfs.FileURI">vfs:sftp://abc:abc123@10.100.0.5/esbtest/in?vfs.passive=true</parameter>
      <parameter name="transport.vfs.MoveAfterFailure">vfs:sftp://abc:abc123@10.100.0.5/esbtest/fail</parameter>
      <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
      <parameter name="transport.vfs.ContentType">text/xml</parameter>
      <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
      <parameter name="transport.vfs.MoveTimestampFormat">yyyyMMdd_HHmmss_</parameter>
</proxy>

4. CIFS - SMB Proxy configuration (Windows with domain)
<proxy name="ProxySMB" transports="vfs" startOnLoad="true" trace="disable">
      <description/>
      <target>
         <inSequence>
            <log level="custom">
               <property name="LOG" value="====SMB====SMB====SMB===="/>
            </log>
         </inSequence>
         <outSequence>
            <send>
               <endpoint>
                  <address uri="vfs:smb://devlab\user1:user123@10.200.3.187/test/out"/>
               </endpoint>
            </send>
         </outSequence>
      </target>
      <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
      <parameter name="transport.PollInterval">10</parameter>
      <parameter name="transport.vfs.MoveAfterProcess">smb://devlab\user1:user123@10.200.3.187/test/process</parameter>
      <parameter name="transport.vfs.FileURI">smb://devlab\user1:user123@10.200.3.187/test/in</parameter>
      <parameter name="transport.vfs.MoveAfterFailure">smb://devlab\user1:user123@10.200.3.187/test/fail</parameter>
      <parameter name="transport.vfs.Locking">false</parameter>
      <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
      <parameter name="transport.vfs.ContentType">text/xml</parameter>
      <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
      <parameter name="transport.vfs.MoveTimestampFormat">yyyyMMdd_HHmmss_</parameter>
</proxy> 
 

1 comment:

  1. Unable to connect the windows server using the file connector in wso2 6.4
    "smb://domain\userName:***@10.200.3.187/InputFile/123.txt".
    Trying to check the file exit (123.txt)in windows server.
    Getting the below error .



















    {$ctx:SourceFile}
    {$ctx:setTimeout}
    {$ctx:setPassiveMode}
    {$ctx:setSoTimeout}
    {$ctx:setStrictHostKeyChecking}
    {$ctx:setUserDirIsRoot}




    2019-07-05 09:24:22 ERROR - Unable to transfer the valuation file. ERROR_DETAILS: org.apache.synapse.SynapseException: Error occured in the mediation of the class mediator

    at org.apache.synapse.mediators.ext.ClassMediator.mediate(ClassMediator.java:98)

    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:108)

    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:70)

    at org.apache.synapse.mediators.template.TemplateMediator.mediate(TemplateMediator.java:104)

    at org.apache.synapse.mediators.template.InvokeMediator.mediate(InvokeMediator.java:148)

    at org.apache.synapse.mediators.template.InvokeMediator.mediate(InvokeMediator.java:84)

    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:108)

    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:70)

    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:158)

    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:224)

    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)

    at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:415)

    at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:151)

    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

    at java.lang.Thread.run(Thread.java:748)

    Caused by: org.apache.synapse.SynapseException: Error while processing a file.

    at org.apache.synapse.mediators.AbstractMediator.handleException(AbstractMediator.java:367)


    ReplyDelete