Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Objective: Using the file system as transport medium using VFS transport listener and sender.

Prerequisites

...

Table of Contents

Introduction

This sample demonstrates how to use the file system as an input medium via the inbound file listener.

Prerequisites

  • Create 3 new directories named inout and original in a test directory (e.g., /home/user/test. Open ESB_HOME) in the local file system. Then, open the <ESB_HOME>/repository/samples/synapse_sample_254.xml and edit the following values. Change 900.xml file in a text editor and change the transport.vfs.FileURI, transport.vfs.MoveAfterProcess, transport.vfs.MoveAfterFailure parameter  parameter values to the above the in, original,  and original directories  directory locations respectively. Change outSequence endpoint address URI to out directory with the prefix vfs:. Values you have to change are marked with <!--CHANGE-->.
  • Start the Synapse configuration numbered 254: wso2esb-samples.sh -sn 254
  • Copy ESB_HOME/repository/samples/resources/vfs/test.xml to the directory given in transport.vfs.FileURI above.

Building the sample

The XML configuration for this sample is as follows:

Code Block
languagehtml/xmllinenumberstrue
<definitions xmlns="http://ws.apache.org/ns/synapse">
 	<proxy name="StockQuoteProxy" transports="vfs  <registry provider="org.wso2.carbon.mediation.registry.WSO2Registry">
    	  <parameter name="transport.vfs.FileURI">file:///home/user/test/in</parameter> <!--CHANGE-->cachableDuration">15000</parameter>
   </registry>
   <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager">
      <parameter name="transport.vfs.ContentType">text/xml<cachableDuration">15000</parameter>
   </taskManager>
    <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter><inboundEndpoint xmlns="http://ws.apache.org/ns/synapse" name="file_inbound" sequence="request" onError="fault" protocol="file" suspend="false">
      <parameters>
         <parameter name="transport.PollIntervalinterval">15<>1000</parameter>
         <parameter name="transport.vfs.MoveAfterProcess">file:///home/user/test/original<sequential">true</parameter>
<!--CHANGE-->         <parameter name="transport.vfs.MoveAfterFailureFileURI">file:///home/user/test/original<in</parameter>
         <!--CHANGE-->
         <parameter name="transport.vfs.ActionAfterProcessContentType">MOVE<>text/xml</parameter>
         <parameter name="transport.vfs.ActionAfterFailure">MOVE<FileNamePattern">.*\.xml</parameter>
        <target> <parameter name="transport.vfs.MoveAfterProcess">file:///home/user/test/original</parameter>
      	<endpoint>   <!--CHANGE-->
         	<address<parameter formatname="soap12" uri="http://localhost:9000/services/SimpleStockQuoteService"/>transport.vfs.MoveAfterFailure">file:///home/user/test/original</parameter>
            </endpoint><!--CHANGE-->
            <outSequence>
            	<property<parameter name="transport.vfs.ReplyFileNameActionAfterProcess">MOVE</parameter>
                          expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')"
						  scope="transport"/><parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
      </parameters>
   </inboundEndpoint>
     <property action="set" <sequence name="OUT_ONLYrequest" valueonError="truefault"/>
                <send>
      <call>
         	<endpoint>
            <address        	<address format="soap12" uri="vfs:filehttp://localhost:9000/home/user/test/outservices/SimpleStockQuoteService"/>
<!--CHANGE-->
                    </endpoint>
      </call>
      <drop/>
  </send> 			</outSequence>sequence>
		</target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
	</proxy>
</definitions>

...

</definitions>

This configuration file synapse_sample_900.xml is available in the <ESB_HOME>/repository/samples directory.

To build the sample

  1. Start the ESB with the sample 900 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
    The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."

  2. Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.

  3. Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.

Executing the sample

To execute the sample client

  • Copy the ESB_HOME/repository/samples/resources/vfs/test.xml file to the location specified in transport.vfs.FileURI in the configuration (i.e., the in directory).

    The  test.xml file contains a simple stock quote request and is as follows: 

    Code Block
    languagehtml/xml
    <?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>
        	<m0:getQuote xmlns:m0="http://services.samples"> 
            	<m0:request>
                	<m0:symbol>IBM</m0:symbol>
                </m0:request>
            </m0:getQuote>
        </soapenv:Body>
    </soapenv:Envelope>

...

Analyzing the output

You will see that the inbound polling file listener picks the file from in directory and send sends it to the Axis2 service. The , and that the request XML file will be is moved to original the process directory. The response from the Axis2 server will be saved to out directory. 

Excerpt
hiddentrue

Example of using the file system as transport input medium in WSO2 ESB.