Running the Transport samples with WSO2 Enterprise Service Bus (ESB)

Sample 250: Introduction to switching transports - JMS to http/s

<definitions xmlns="http://ws.apache.org/ns/synapse">

    <proxy name="StockQuoteProxy" transports="jms">
        <target>
            <inSequence>
                <property action="set" name="OUT_ONLY" value="true"/>
            </inSequence>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
        <parameter name="transport.jms.ContentType">
            <rules>
                <jmsProperty>contentType</jmsProperty>
                <default>application/xml</default>
            </rules>
        </parameter>
    </proxy>

</definitions>

Objective: Introduction to switching transports with proxy services

Prerequisites:
Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps above)
Download, install and start a JMS server, and configure ESB to listen on JMS (refer notes below)
Start the Synapse configuration numbered 250: i.e. wso2esb-samples -sn 250
For this example we would use ActiveMQ as the JMS provider. Once ActiveMQ is installed and started you should get a message as follows:

INFO BrokerService - ActiveMQ JMS Message Broker (localhost) started

You will now need to configure the Axis2 instance used by ESB (not the sample Axis2 server) to enable JMS support using the above provider. Refer to the Axis2 documentation on setting up JMS for more details (http://ws.apache.org/axis2/1_1/jms-transport.html). You will also need to copy the ActiveMQ client jar files activemq-core-5.2.0.jar and geronimo-j2ee-management_1.0_spec-1.0.jar into the repository/components/lib directory to allow ESB to connect to the JMS provider.

For a default ActiveMQ v4.0 installation, you may uncomment the Axis2 transport listener configuration found at repository/conf/axis2.xml as

<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> ...

You need to enable the JMS transport sender for the ESB to be able to send messages over the JMS transport. To enable the JMS transport sender uncomment the Axis2 transport sender configuration found at repository/conf/axis2.xml as

<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender" />

Once you start the Synapse configuration and request for the WSDL of the proxy service (http://localhost:8280/services/StockQuoteProxy?wsdl) you will notice that its exposed only on the JMS transport. This is because the configuration specified this requirement in the proxy service definition.

Now lets send a place order request on JMS, using the dumb stock quote client as follows:

ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/StockQuoteProxy -Djms_payload=MSFT

On the ESB debug log you will notice that the JMS listener received the request message as:

[JMSWorker-1] DEBUG ProxyServiceMessageReceiver -Proxy Service StockQuoteProxy received a new message...

Now if you examine the console running the sample Axis2 server, you will see a message indicating that the server has accepted an order as follows:

Accepted order for : 16517 stocks of MSFT at $ 169.14622538721846

In this sample, client sends the request message to the proxy service exposed over JMS in Synapse. ESB forwards this message to the HTTP EPR of the simple stock quote service hosted on the sample Axis2 server, which sends a 202 Accepted response back to the ESB. Since the placeOrder operation is an in-only service operation the JMS client does not receive any response in this sample.

e.g.

<property name="transport.jms.Destination" value="dynamicTopics/something.TestTopic"/>

Sample 251: Switching from http/s to JMS

<definitions xmlns="http://ws.apache.org/ns/synapse">

    <proxy name="StockQuoteProxy" transports="http">
        <target>
            <endpoint>
                <address uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;
                   java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
            </endpoint>
            <inSequence>
                <property action="set" name="OUT_ONLY" value="true"/>
            </inSequence>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>

</definitions>

Objective: Demonstrate switching from HTTP to JMS

Prerequisites:
Download, install and start a JMS server

Configure sample Axis2 server for JMS (refer notes above)
Start the Axis2 server and deploy the SimpleStockQuoteService (see below)
Configure the Synapse JMS transport (refer notes above - sample 250)
Start the Synapse configuration numbered 251: i.e. wso2esb-samples -sn 251

To switch from HTTP to JMS, edit the samples/axis2Server/repository/conf/axis2.xml for the sample Axis2 server and enable JMS (refer notes above), and restart the server. Now you can see that the simple stock quote service is available in both JMS and HTTP in the sample Axis2 server. To see this, point your browser to the WSDL of the service at http://localhost:9000/services/SimpleStockQuoteService?wsdl. JMS URL for the service is mentioned as below:

jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=
QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&
java.naming.provider.url=tcp://localhost:61616

You may also notice that the simple stock quote proxy service exposed in ESB is now available only in HTTP as we have specified transport for that service as HTTP. To observe this, access the WSDL of stock quote proxy service at http://localhost:8280/services/StockQuoteProxy?wsdl.

This ESB configuration creates a proxy service over HTTP and forwards received messages to the above EPR using JMS. To test this, send a place order request to ESB using HTTP as follows:

ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=placeorder -Dsymbol=MSFT

The sample Axis2 server console will print a message indicating that it has accepted the order as follows:

Accepted order for : 18406 stocks of MSFT at $ 83.58806051152119

Sample 252: Pure text/binary and POX message support with JMS

<definitions xmlns="http://ws.apache.org/ns/synapse">

    <sequence name="text_proxy">
        <header name="Action" value="urn:placeOrder"/>
        <script language="js"><![CDATA[
            var args = mc.getPayloadXML().toString().split(" ");
            mc.setPayloadXML(
            <m:placeOrder xmlns:m="http://services.samples/xsd">
                <m:order>
                    <m:price>{args[0]}</m:price>
                    <m:quantity>{args[1]}</m:quantity>
                    <m:symbol>{args[2]}</m:symbol>
                </m:order>
            </m:placeOrder>);
        ]]></script>
        <property action="set" name="OUT_ONLY" value="true"/>
        <send>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
        </send>
    </sequence>

    <sequence name="mtom_proxy">
        <property action="set" name="OUT_ONLY" value="true"/>
        <header name="Action" value="urn:oneWayUploadUsingMTOM"/>
        <send>
            <endpoint>
                <address uri="http://localhost:9000/services/MTOMSwASampleService" optimize="mtom"/>
            </endpoint>
        </send>
    </sequence>

    <sequence name="pox_proxy">
        <property action="set" name="OUT_ONLY" value="true"/>
        <header name="Action" value="urn:placeOrder"/>
        <send>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
            </endpoint>
        </send>
    </sequence>

    <sequence name="out">
        <send/>
    </sequence>

    <proxy name="JMSFileUploadProxy" transports="jms">
        <target inSequence="mtom_proxy" outSequence="out"/>
        <parameter name="transport.jms.Wrapper">{http://services.samples/xsd}element</parameter>
    </proxy>
    <proxy name="JMSTextProxy" transports="jms">
        <target inSequence="text_proxy" outSequence="out"/>
        <parameter name="transport.jms.Wrapper">{http://services.samples/xsd}text</parameter>
    </proxy>
    <proxy name="JMSPoxProxy" transports="jms">
        <target inSequence="pox_proxy" outSequence="out"/>
        <parameter name="transport.jms.ContentType">application/xml</parameter>
    </proxy>
</definitions>

Objective: Pure POX/Text and Binary JMS Proxy services - including MTOM

Prerequisites:
Configure JMS for ESB (Refer notes)
Start the Synapse configuration numbered 252: i.e. wso2esb-samples -sn 252
Start the Axis2 server and deploy the SimpleStockQuoteService and the MTOMSwASampleService if not already done

This configuration creates three JMS proxy services named JMSFileUploadProxy, JMSTextProxy and JMSPoxProxy exposed over JMS queues with the same names as the services. The first part of this example demonstrates the pure text message support with JMS, where a user sends a space separated text JMS message of the form "<price> <qty> <symbol>". ESB converts this message into a SOAP message and sends this to the SimpleStockQuoteServices' placeOrder operation. ESB uses the script mediator to transform the text message into a XML payload using the Javascript support available to tokenize the string. The proxy service property named "transport.jms.Wrapper" defines a custom wrapper element QName, to be used when wrapping text/binary content into a SOAP envelope.

Execute JMS client as follows. This will post a pure text JMS message with the content defined (e.g. "12.33 1000 ACP") to the specified JMS destination - dynamicQueues/JMSTextProxy

ant jmsclient -Djms_type=text -Djms_payload="12.33 1000 ACP" -Djms_dest=dynamicQueues/JMSTextProxy

Following the debug logs, you could notice that ESB received the JMS text message and transformed it into a SOAP payload as follows. Notice that the wrapper element "{http://services.samples/xsd}text" has been used to hold the text message content.

[JMSWorker-1] DEBUG ProxyServiceMessageReceiver - Body :
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body><axis2ns1:text xmlns:axis2ns1="http://services.samples/xsd">12.33 1000 ACP</axis2ns1:text></soapenv:Body>
</soapenv:Envelope>

Now, you could see how the script mediator created a stock quote request by tokenizing the text as follows, and sent the message to the placeOrder operation of the SimpleStockQuoteService.

[JMSWorker-1] DEBUG AddressEndpoint - Sending message to endpoint :: name = AnonymousEndpoints resolved address = http://localhost:9000/services/SimpleStockQuoteService
[JMSWorker-1] DEBUG AddressEndpoint - SOAPAction: urn:placeOrder
[JMSWorker-1] DEBUG AddressEndpoint - WSA-Action: urn:placeOrder
[JMSWorker-1] DEBUG AddressEndpoint - Body :
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body>
  <m:placeOrder xmlns:m="http://services.samples/xsd"><m:order><m:price>12.33</m:price><m:quantity>1000</m:quantity><m:symbol>ACP</m:symbol></m:order>
</m:placeOrder></soapenv:Body></soapenv:Envelope>

The sample Axis2 server would now accept the one way message and issue the following message:

Wed Apr 25 19:50:56 LKT 2007 samples.services.SimpleStockQuoteService :: Accepted order for : 1000 stocks of ACP at $ 12.33

The next section of this example demonstrates how a pure binary JMS message could be received and processed through ESB. The configuration creates a proxy service named 'JMSFileUploadProxy' that accepts binary messages and wraps them into a custom element '{http://services.samples/xsd}element'. The received message is then forwarded to the MTOMSwASampleService using the SOAP action 'urn:oneWayUploadUsingMTOM' and optimizing binary conent using MTOM. To execute this sample, use the JMS client to publish a pure binary JMS message containing the file './../../repository/samples/resources/mtom/asf-logo.gif' to the JMS destination 'dynamicQueues/JMSFileUploadProxy' as follows:

ant jmsclient -Djms_type=binary -Djms_dest=dynamicQueues/JMSFileUploadProxy -Djms_payload=./../../repository/samples/resources/mtom/asf-logo.gif

Examining the ESB debug logs reveals that the binary content was received over JMS and wrapped with the specified element into a SOAP infoset as follows:

[JMSWorker-1] DEBUG ProxyServiceMessageReceiver - Proxy Service JMSFileUploadProxy received a new message...
...
[JMSWorker-1] DEBUG ProxyServiceMessageReceiver - Body :
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><axis2ns1:element xmlns:axis2ns1="http://services.samples/xsd">R0lGODlhgw...AAOw==</axis2ns1:element></soapenv:Body>
</soapenv:Envelope>

Thereafter the message was sent as a MTOM optimized message as specified by the 'format=mtom' attribute of the endpoint, to the MTOMSwASampleService using the SOAP action 'urn:oneWayUploadUsingMTOM'. Once received by the sample service, it is saved into a temporary file and could be verified for correctness.

Wrote to file : ./../../work/temp/sampleServer/mtom-29208.gif

The final section of this example shows how a POX JMS message received by ESB is sent to the SimpleStockQuoteService as a SOAP message. Use the JMS client as follows to create a POX (Plain Old XML) message with a stock quote request payload (without a SOAP envelope), and send it to the JMS destination 'dynamicQueues/JMSPoxProxy' as follows:

ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/JMSPoxProxy -Djms_payload=MSFT

You can see that ESB received the POX message and displays it as follows in the debug logs, and then converts it into a SOAP payload and sends to the SimpleStockQuoteService after setting the SOAP action as 'urn:placeOrder'.

[JMSWorker-1] DEBUG ProxyServiceMessageReceiver - Proxy Service JMSPoxProxy received a new message...
...
[JMSWorker-1] DEBUG ProxyServiceMessageReceiver - Body :
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><m:placeOrder xmlns:m="http://services.samples/xsd">
    <m:order>
        <m:price>172.39703010684752</m:price>
        <m:quantity>19211</m:quantity>
        <m:symbol>MSFT</m:symbol>
    </m:order>
</m:placeOrder></soapenv:Body></soapenv:Envelope>
[JMSWorker-1] DEBUG ProxyServiceMessageReceiver - Using the sequence named pox_proxy for message mediation
...
[JMSWorker-1] DEBUG HeaderMediator - Setting header : Action to : urn:placeOrder
...
[JMSWorker-1] DEBUG AddressEndpoint - Sending message to endpoint :: name = AnonymousEndpoints resolved address = http://localhost:9000/services/SimpleStockQuoteService
[JMSWorker-1] DEBUG AddressEndpoint - SOAPAction: urn:placeOrder
[JMSWorker-1] DEBUG AddressEndpoint - Body :
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><m:placeOrder xmlns:m="http://services.samples/xsd">
    <m:order>
        <m:price>172.39703010684752</m:price>
        <m:quantity>19211</m:quantity>
        <m:symbol>MSFT</m:symbol>
    </m:order>
</m:placeOrder></soapenv:Body></soapenv:Envelope>
[JMSWorker-1] DEBUG Axis2FlexibleMEPClient - sending [add = false] [sec = false] [rm = false] [ mtom = false] [ swa = false] [ force soap=true; pox=false] [ to null] 

The sample Axis2 server displays a successful message on the receipt of the message as:

Wed Apr 25 20:24:50 LKT 2007 samples.services.SimpleStockQuoteService :: Accepted order for : 19211 stocks of MSFT at $ 172.39703010684752

Sample 253: One way bridging from JMS to http and replying with a 202 Accepted response

<definitions xmlns="http://ws.apache.org/ns/synapse">

    <proxy name="JMStoHTTPStockQuoteProxy" transports="jms">
        <target>
            <inSequence>
                <property action="set" name="OUT_ONLY" value="true"/>
            </inSequence>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>

    <proxy name="OneWayProxy" transports="http">
        <target>
            <inSequence>
                <log level="full"/>
            </inSequence>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>

</definitions>

Objective: Demonstrate one way message bridging from JMS to http and replying with a http 202 Accepted response

Prerequisites:
Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

Start the Synapse configuration numbered 253: i.e. wso2esb-samples -sn 253

This example invokes the one-way 'placeOrder' operation on the SimpleStockQuoteService using the Axis2 ServiceClient.fireAndForget() API at the client. To test this, use 'ant -Dmode=placeorder...' and you will notice the one way JMS message flowing through ESB into the sample Axis2 server instance over http, and Axis2 acknowledging it with a http 202 Accepted response.

ant stockquote -Dmode=placeorder -Dtrpurl="jms:/JMStoHTTPStockQuoteProxy?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.ContentTypeProperty=Content-Type&transport.jms.DestinationType=queue"
SimpleStockQuoteService :: Accepted order for : 7482 stocks of IBM at $ 169.27205579038733

The second example shows how ESB could be made to respond with a http 202 Accepted response to a request received. The proxy service simply logs the message received and acknowledges it. On the ESB console you could see the logged message, and if TCPMon was used at the client, you would see the 202 Accepted response sent back to the client from ESB

ant stockquote -Dmode=placeorder -Dtrpurl=http://localhost:8280/services/OneWayProxy
HTTP/1.1 202 Accepted
Content-Type: text/xml; charset=UTF-8
Host: 127.0.0.1
SOAPAction: "urn:placeOrder"
Date: Sun, 06 May 2007 17:20:19 GMT
Server: Synapse-HttpComponents-NIO
Transfer-Encoding: chunked

0

Sample 254: Using the file system as transport medium using VFS transport listener and sender

<definitions xmlns="http://ws.apache.org/ns/synapse">
        <proxy name="StockQuoteProxy" transports="vfs">
                <parameter name="transport.vfs.FileURI">file:///home/user/test/in</parameter> <!--CHANGE-->
                <parameter name="transport.vfs.ContentType">text/xml</parameter>
                <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
                <parameter name="transport.PollInterval">15</parameter>
                <parameter name="transport.vfs.MoveAfterProcess">file:///home/user/test/original</parameter> <!--CHANGE-->
                <parameter name="transport.vfs.MoveAfterFailure">file:///home/user/test/original</parameter> <!--CHANGE-->
                <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
                <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>

                <target>
                        <endpoint>
                                <address format="soap12" uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                        </endpoint>
                        <outSequence>
                                <property name="transport.vfs.ReplyFileName"
                                          expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')" scope="transport"/>
                                <property action="set" name="OUT_ONLY" value="true"/> 
                                <send>
                                        <endpoint>
                                                <address uri="vfs:file:///home/user/test/out"/> <!--CHANGE-->
                                        </endpoint>
                                </send>
                        </outSequence>
                </target>
                <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
        </proxy>
</definitions> 

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

Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

Create three new directories in a test directory. e.g. in, out, original in /home/user/test. Open ESB_HOME/repository/samples/synapse_sample_254.xml and edit the following values. Change transport.vfs.FileURI, transport.vfs.MoveAfterProcess, transport.vfs.MoveAfterFailure parameter values to the above in, original, original directories respectively. Change outSequence endpoint address uri to out directory with the prefix vfs:. Values you have to change are marked with <!--CHANGE-->.

In the axis2.xml uncomment the VFS transport listener and sender.

Start the Synapse configuration numbered 254: i.e. wso2esb-samples -sn 254

Copy ESB_HOME/repository/samples/resources/vfs/test.xml to the directory given in transport.vfs.FileURI above.

test.xml file content is as follows

<?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>

VFS transport listener will pick the file from in directory and send it to the Axis2 service. The request XML file will be moved to original directory. The response from the Axis2 server will be saved to out directory.

Note: Please make sure to uncomment "VFSTransportListener" and "VFSTransportSender" in the axis2 configuration.(axis2.xml)

Sample 255: Switching from ftp transport listener to mail transport sender

<definitions xmlns="http://ws.apache.org/ns/synapse">
        <proxy name="StockQuoteProxy" transports="vfs">
                <parameter name="transport.vfs.FileURI">vfs:ftp://guest:guest@localhost/test?vfs.passive=true</parameter> <!--CHANGE-->
                <parameter name="transport.vfs.ContentType">text/xml</parameter>
                <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
                <parameter name="transport.PollInterval">15</parameter>

                <target>
                        <inSequence>
                                <header name="Action" value="urn:getQuote"/>
                        </inSequence>
                        <endpoint>
                                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                        </endpoint>
                        <outSequence>
                                <property action="set" name="OUT_ONLY" value="true"/>
                                <send>
                                        <endpoint>
                                                <address uri="mailto:user@host"/> <!--CHANGE-->
                                        </endpoint>
                                </send>
                        </outSequence>
                </target>
                <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
        </proxy>
</definitions> 

Objective: Switching from ftp transport listener to mail transport sender

Prerequisites:
You will need access to an FTP server and an SMTP server to try this sample.

Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

Enable mail transport sender in the ESB axis2.xml. See Setting up mail transport sender

Create a new test directory in the FTP server. Open ESB_HOME/repository/samples/synapse_sample_255.xml and edit the following values. Change transport.vfs.FileURI parameter value point to the test directory at the FTP server. Change outSequence endpoint address uri email address to a working email address. Values you have to change are marked with <!--CHANGE-->.

Start the Synapse configuration numbered 255: i.e. wso2esb-samples -sn 255

Copy ESB_HOME/repository/samples/resources/vfs/test.xml to the ftp directory given in transport.vfs.FileURI above.

VFS transport listener will pick the file from the directory in the ftp server and send it to the Axis2 service. The file in the ftp directory will be deleted. The response will be sent to the given email address.

Sample 256: Proxy services with the mail transport

<!-- Using the mail transport -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="StockQuoteProxy" transports="mailto">

        <parameter name="transport.mail.Address">synapse.demo.1@gmail.com</parameter>
        <parameter name="transport.mail.Protocol">pop3</parameter>
        <parameter name="transport.PollInterval">5</parameter>
        <parameter name="mail.pop3.host">pop.gmail.com</parameter>
        <parameter name="mail.pop3.port">995</parameter>
        <parameter name="mail.pop3.user">synapse.demo.1</parameter>
        <parameter name="mail.pop3.password">mailpassword</parameter>
        <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter>
        <parameter name="mail.pop3.socketFactory.fallback">false</parameter>
        <parameter name="mail.pop3.socketFactory.port">995</parameter>
        <parameter name="transport.mail.ContentType">application/xml</parameter>

        <target>
            <inSequence>
                <property name="senderAddress" expression="get-property('transport', 'From')"/>
                <log level="full">
                    <property name="Sender Address" expression="get-property('senderAddress')"/>
                </log>
                <send>
                    <endpoint>
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                    </endpoint>
                </send>
            </inSequence>
            <outSequence>
                <property name="Subject" value="Custom Subject for Response" scope="transport"/>
                <header name="To" expression="fn:concat('mailto:', get-property('senderAddress'))"/>
                <log level="full">
                    <property name="message" value="Response message"/>
                    <property name="Sender Address" expression="get-property('senderAddress')"/>
                </log>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
</definitions> 

Objective: Using the mail transport with Proxy services

Prerequisites:
You will need access to an email account

Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

Enable mail transport listener in the ESB axis2.xml. Simply uncomment the relevant transport receiver entry in the file.

Enable mail transport sender in the ESB axis2.xml. See Setting up mail transport sender

Enable mail transport receiver in the ESB axis2.xml. See Setting up mail transport listener

Start the Synapse configuration numbered 256: i.e. wso2esb-samples -sn 256

Send a plain/text email with the following body and any custom Subject from your mail account.

<m0:getQuote xmlns:m0="http://services.samples"><m0:request><m0:symbol>IBM</m0:symbol></m0:request></m0:getQuote> 

After a few seconds (e.g. 30s), you should receive a POX response in your email account with the stock quote reply.

Note that in this sample we used the transport.mail.ContentType property to make sure that the transport parses the request message as POX. If you remove this property, you may still be able to send requests using a standard mail client if instead of writing the XML in the body of the message, you add it as an attachment. In that case, you should use .xml as a suffix for the attachment and format the request as a SOAP 1.1 message. Indeed, for a file with suffix .xml the mail client will most likely use text/xml as the content type, exactly as required for SOAP 1.1. Sending a POX message using this approach will be a lot trickier, because most standard mail clients don't allow the user to explicitly set the content type.

Sample 257: Proxy services with the FIX transport

<!-- Using the FIX transport -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="FIXProxy" transports="fix">

        <parameter name="transport.fix.AcceptorConfigURL">file:/home/synapse_user/fix-config/fix-synapse.cfg</parameter>
        <parameter name="transport.fix.InitiatorConfigURL">file:/home/synapse_user/fix-config/synapse-sender.cfg</parameter>
        <parameter name="transport.fix.AcceptorMessageStore">file</parameter>
        <parameter name="transport.fix.InitiatorMessageStore">file</parameter>

        <target>
            <endpoint>
                <address uri="fix://localhost:19876?BeginString=FIX.4.0&amp;SenderCompID=SYNAPSE&amp;TargetCompID=EXEC"/>
            </endpoint>
	    <inSequence>
		<log level="full"/>
	    </inSequence>
            <outSequence>
                <log level="full"/>
		<send/>
            </outSequence>
        </target>
    </proxy>
</definitions> 

Objective: Demonstrate the usage of the FIX (Financial Information eXchange) transport with proxy services

Prerequisites:
You will need the two sample FIX applications that come with Quickfix/J (Banzai and Executor). Configure the two applications to establish sessions with the ESB. See Configuring Sample FIX Applications

Start Banzai and Executor

Enable FIX transport in the Synapse axis2.xml. See Setting up FIX transport

Configure Synapse for FIX samples. See Configuring WSO2 ESB for FIX Samples

Open up the ESB_HOME/repository/samples/synapse_sample_257.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created. Also make sure that transport.fix. InitiatorConfigURL property points to the synapse-sender.cfg file you created. Once done you can start the Synapse configuration numbered 257: i.e. wso2esb-samples -sn 257. Note that the ESB creates a new FIX session with Banzai at this point.

Send an order request from Banzai to the ESB.

WSO2 ESB will create a session with Executor and forward the order request. The responses coming from the Executor will be sent back to Banzai.

Sample 258: Switching from HTTP to FIX

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="FIXProxy">

        <parameter name="transport.fix.InitiatorConfigURL">file:/home/synapse_user/fix-config/synapse-sender.cfg</parameter>
        <parameter name="transport.fix.InitiatorMessageStore">file</parameter>
        <parameter name="transport.fix.SendAllToInSequence">false</parameter>
        <parameter name="transport.fix.DropExtraResponses">true</parameter>

        <target>
            <endpoint>
                <address uri="fix://localhost:19876?BeginString=FIX.4.0&amp;SenderCompID=SYNAPSE&amp;TargetCompID=EXEC"/>
            </endpoint>
	    <inSequence>
	    	<property name="transport.fix.ServiceName" value="FIXProxy" scope="axis2-client"/>
			<log level="full"/>
	    </inSequence>
        <outSequence>
            <log level="full"/>
			<send/>
        </outSequence>
        </target>
    </proxy>
</definitions> 

Objective: Demonstrate switching from HTTP to FIX

Prerequisites:
You will need the Executor sample application that comes with Quickfix/J. Configure Executor to establish a session with Synapse. See Configuring Sample FIX Applications

Start Executor.

Enable FIX transport sender in the Synapse axis2.xml. See Setting up FIX transport

Configure Synapse for FIX samples. See Configuring Synapse for FIX Samples. There is no need to create the fix-synapse.cfg file for this sample. Having only the synapse-sender.cfg file is sufficient.

Go to the ESB_HOME/repository/samples/synapse_sample_258.xml file and make sure that transport.fix.InitiatorConfigURL property points to the synapse-sender.cfg file you created. Once done you can start the Synapse configuration numbered 258: i.e. wso2esb-samples -sn 258

Invoke the FIX Client as follows. This command sends a FIX message embedded in a SOAP message over HTTP.

ant fixclient -Dsymbol=IBM -Dqty=5 -Dmode=buy -Daddurl=http://localhost:8280/services/FIXProxy

Synapse will create a session with Executor and forward the order request. The first response coming from the Executor will be sent back over HTTP. Executor generally sends two responses for each incoming order request. But since the response has to be forwarded over HTTP only one can be sent back to the client.

Sample 259: Switch from FIX to HTTP

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <localEntry key="xslt-key-req" src="file:repository/conf/sample/resources/transform/transform_fix_to_http.xslt" />
    <proxy name="FIXProxy" transports="fix">
        <target>
            <endpoint>
                <address
                    uri="http://localhost:9000/services/SimpleStockQuoteService" />
            </endpoint>
            <inSequence>
                <log level="full" />
                <xslt key="xslt-key-req" />
                <log level="full" />
            </inSequence>
            <outSequence>
                <log level="full" />
            </outSequence>
        </target>
    <parameter name="transport.fix.AcceptorConfigURL">
        file:repository/conf/sample/resources/fix/fix-synapse.cfg
    </parameter>
    <parameter name="transport.fix.AcceptorMessageStore">
        file
    </parameter>
   </proxy>
</definitions>
      

Objective: Demonstrate the capability of switching between FIX to HTTP

Prerequisites:

You will need the sample FIX blotter that come with Quickfix/J (Banzai). Configure the blotter to establish sessions with Synapse. See Configuring Sample FIX Applications

Start the Axis2 server and deploy the SimpleStockQuoteService if not already deployed

Start Banzai

Enable FIX transport in the Synapse axis2.xml. See Setting up FIX transport

Configure ESB for FIX samples. See Configuring the ESB for FIX Samples

Open up the ESB_HOME/repository/samples/synapse_sample_259.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created. Once done you can start the Synapse configuration numbered 259: i.e. wso2esb-samples -sn 259. Note that Synapse creates a new FIX session with Banzai at this point.

Send an order request from Banzai to Synapse. e.g. Buy DELL 1000 @ 100. User has to send a 'Limit' Order because price is a mandatory field for 'placeOrder' operation.

ESB will forward the order request to one-way 'placeOrder' operation on the SimpleStockQuoteService. ESB uses a simple XSLT mediator to transform the incoming FIX to a SOAP message.

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
  <xsl:template match="/">
    <m0:placeOrder xmlns:m0="http://services.samples">
        <m0:order>
            <m0:price><xsl:value-of select="//message/body/field[@id='44']"/></m0:price>
            <m0:quantity><xsl:value-of select="//message/body/field[@id='38']"/></m0:quantity>
            <m0:symbol><xsl:value-of select="//message/body/field[@id='55']"/></m0:symbol>
        </m0:order>
    </m0:placeOrder>
   </xsl:template>
</xsl:stylesheet>
      

To get an idea about the various transport parameters being used in this sample see FIX Transport Parameters.

Sample 260: Switch from FIX to AMQP

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="FIXProxy" transports="fix">
        <target>
            <endpoint>
                <address uri="jms:/QpidStockQuoteService?transport.jms.ConnectionFactoryJNDIName=qpidConnectionfactory&amp;java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory&amp;java.naming.provider.url=repository/conf/sample/resources/fix/con.properties&amp;transport.jms.ReplyDestination=replyQueue"/>
            </endpoint>
            <inSequence>
                <log level="full" />
            </inSequence>
            <outSequence>
                <property name="transport.fix.ServiceName"
                    value="FIXProxy" scope="axis2-client" />
                <log level="full" />
                        <send />
            </outSequence>
        </target>
        <parameter name="transport.fix.AcceptorConfigURL">
            file:repository/conf/sample/resources/fix/fix-synapse.cfg
        </parameter>
        <parameter name="transport.fix.AcceptorMessageStore">
            file
        </parameter>
    </proxy>
</definitions>

Objective: Demonstrate the capability of switching between FIX and AMQP protocols

Prerequisites:

You will need the sample FIX blotter that comes with Quickfix/J (Banzai). Configure the blotter to establish sessions with Synapse. See Configuring Sample FIX Applications

Configure the AMQP transport for WSO2 ESB. See Configure ESB for AMQP Transport

Start the AMQP consumer, by switching to samples/axis2Client directory and running the consumer using the following command. Consumer will listen to the queue 'QpidStockQuoteService', accept the orders and reply to the queue 'replyQueue'.

ant amqpconsumer -Dpropfile=$ESB_HOME/repository/samples/resources/fix/direct.properties

Start Banzai

Enable FIX transport in the Synapse axis2.xml. See Setting up FIX transport

Configure Synapse for FIX samples. See Configuring Synapse for FIX Samples

Open up the ESB_HOME/repository/samples/synapse_sample_260.xml file and make sure that the transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created. Once done you can start the Synapse configuration numbered 260: i.e. wso2esb-samples -sn 260. Note that Synapse creates a new FIX session with Banzai at this point.

Send an order request from Banzai to Synapse. e.g. Buy DELL 1000 @ MKT.

Synapse will forward the order request by binding it to a JMS message payload and sending it to the AMQP consumer. AMQP consumer will send a execution back to Banzai.

Sample 261: Switch between FIX versions

<definitions xmlns="http://ws.apache.org/ns/synapse">
     <proxy name="OrderProcesserProxy41" transports="fix">
        <target>
           <endpoint>
              <address uri="fix://localhost:19877?BeginString=FIX.4.1&amp;SenderCompID=SYNAPSE&amp;TargetCompID=EXEC"/>
           </endpoint>
           <inSequence><log level="full"/></inSequence>
           <outSequence><log level="full"/><send/></outSequence>
        </target>
        <parameter name="transport.fix.AcceptorConfigURL">file:repository/conf/sample/resources/fix/fix-synapse-m40.cfg</parameter>
        <parameter name="transport.fix.AcceptorMessageStore">file</parameter>
        <parameter name="transport.fix.InitiatorConfigURL">file:repository/conf/sample/resources/fix/synapse-sender-m.cfg</parameter>
        <parameter name="transport.fix.InitiatorMessageStore">file</parameter>
     </proxy>
</definitions>

Objective: Demonstrate the capability of switching between FIX versions e.g. FIX4.0 to FIX4.1

Prerequisites:

You will need the two sample FIX applications that come with Quickfix/J (Banzai and Executor). Configure the two applications to establish sessions with Synapse. See Configuring Sample FIX Applications.

Add the following lines to the Banzai configuration file (banzai.cfg).

DataDictionary=~/etc/spec/FIX40-synapse.xml

Note: FIX40-synapse.xml can be found at $ESB_HOME/repository/sampless/resources/fix. This is a custom FIX data dictionary file that has added tag 150,151 to the execution messages (35=8) of FIX4.0. Make sure the DataDictionary property of the banzai.cfg points to this data dictionary file.

Add the following lines to the Executor configuration file (executor.cfg).

[session]
BeginString=FIX.4.1
SocketAcceptPort=19877

Start Banzai and Executor using the custom configuration files.

Enable FIX transport in the Synapse axis2.xml. See Setting up FIX transport

Configure Synapse for FIX samples. We will be using two custom configuration files for Synapse in this sample. These two custom configuration files can be found at ESB_HOME/repository/conf/sample/resources/fix directory. The two files are called fix-synapse-m40.cfg and synapse-sender-m.cfg. You can point your Synapse configuration to these two files (this is already done in the supplied synapse_sample_261.xml file) or you may create copies of them and point the Synapse configuration to the copies. In either case make sure that the properties like FileStorePath and FileLogPath in the two files point to valid locations in your local file system.

Open up the $ESB_HOME/repository/samples/synapse_sample_261.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse-m40.cfg file described above and transport.fix.InitiatorConfigURL points to the synapse-sender-m.cfg file described above. Once done you can start the Synapse configuration numbered 261: i.e. wso2esb-samples -sn 261. Note that Synapse creates a new FIX session with Banzai at this point.

Send an order request from Banzai to Synapse. e.g. Buy DELL 1000 @ MKT.

Synapse will forward the order request from FIX4.0 to the Executor that accepts FIX4.1 messages. Executor will send an ack and an execution back to Banzai.

Sample 262: CBR of FIX messages

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <sequence name="CBR_SEQ">
        <in>
            <switch source="//message/body/field[@id='55']">
                <case regex="GOOG">
                    <send>
                        <endpoint>
                            <address
                                uri="fix://localhost:19876?BeginString=FIX.4.0&amp;SenderCompID=SYNAPSE&amp;TargetCompID=EXEC" />
                        </endpoint>
                    </send>
                </case>
                <case regex="MSFT">
                    <send>
                        <endpoint>
                            <address
                                uri="fix://localhost:19877?BeginString=FIX.4.1&amp;SenderCompID=SYNAPSE&amp;TargetCompID=EXEC" />
                        </endpoint>
                    </send>
                </case>
                <default></default>
            </switch>
        </in>
        <out>
            <send />
        </out>
    </sequence>
    <proxy name="FIXProxy" transports="fix">
        <target inSequence="CBR_SEQ" />
        <parameter name="transport.fix.AcceptorConfigURL">
            file:repository/conf/sample/resources/fix/fix-synapse.cfg
        </parameter>
        <parameter name="transport.fix.AcceptorMessageStore">
            file
        </parameter>
        <parameter name="transport.fix.InitiatorConfigURL">
            file:repository/conf/sample/resources/fix/synapse-sender.cfg
        </parameter>
        <parameter name="transport.fix.InitiatorMessageStore">
            file
        </parameter>
    </proxy>
</definitions>

Objective: Demonstrate the capability of CBR FIX messages

Prerequisites:

You will need the two sample FIX applications that come with Quickfix/J (Banzai and Executor). Configure the two applications to establish sessions with Synapse. See Configuring Sample FIX Applications

Add the following lines to banzai.cfg.

DataDictionary=~/etc/spec/FIX40-synapse.xml

Note: FIX40-synapse.xml can be found at $ESB_HOME/repository/samples/resources/fix. This is a custom FIX data dictionary file that has added tag 150,151 to the execution messages (35=8) of FIX4.0. Make sure the DataDictionary property of the banzai.cfg points to this data dictionary file.

Add the following lines to executor.cfg

[session]
BeginString=FIX.4.1
SocketAcceptPort=19877

Start Banzai and Executor using the custom config files.

Enable FIX transport in the Synapse axis2.xml. See Setting up FIX transport

Configure Synapse for FIX samples. See Configuring Synapse for FIX Samples

Open up the ESB_HOME/repository/samples/synapse_sample_262.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created and transport.fix.InitiatorConfigURL points to the synapse-sender.cfg file you created. Once done you can start the Synapse configuration numbered 262: i.e. wso2esb-samples -sn 262. Note that Synapse creates a new FIX session with Banzai at this point.

Send an order request from Banzai to Synapse. e.g. Buy GOOG 1000 @ MKT, Buy MSFT 3000 @ MKT, Buy SUNW 500 @ 100.20

Synapse will forward the order requests with symbol 'GOOG' to FIX endpoint FIX-4.0 @ localhost:19876.

Synapse will forward the order requests with symbol 'MSFT' to FIX endpoint FIX-4.1 @ localhost:19877.

Synapse will not forward the orders with other symbols to any endpoint. (default case has kept blank in the configuration)

Sample 263: Transport switching - JMS to http/s using JBoss Messaging(JBM)

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="StockQuoteProxy" transports="jms">
        <target>
            <inSequence>
                <property action="set" name="OUT_ONLY" value="true"/>
            </inSequence>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/>
        <parameter name="transport.jms.ContentType">
            <rules>
                <jmsProperty>contentType</jmsProperty>
                <default>application/xml</default>
            </rules>
        </parameter>
    </proxy>
</definitions>

Objective: Introduction to switching transports with proxy services. The JMS provider will be JBoss Messaging(JBM).

Prerequisites:

Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps above)

Download, install and start JBM server, and configure Synapse to listen on JBM (refer notes below)

Start the ESB configuration numbered 263: i.e. wso2esb-samples -sn 263

We need to configure the required queues in JBM. Add the following entry to JBM jms configuration inside file-config/stand-alone/non-clustered/jbm-jms.xml.

<queue name="StockQuoteProxy">
    <entry name="StockQuoteProxy"/>
</queue>

Once you started the JBM server with the above changes you'll be able to see the following on STDOUT.

10:18:02,673 INFO [org.jboss.messaging.core.server.impl.MessagingServerImpl]  JBoss Messaging Server version 2.0.0.BETA3 (maggot, 104) started 

You also need to copy the jbm-core-client.jar, jbm-jms-client.jar, jnp-client.jar(these jars are inside $JBOSS_MESSAGING/client folder) and jbm-transports.jar, netty.jar(these jars are from $JBOSS_MESSAGING/lib folder) jars from JBM into the $ESB_HOME/repository/components/lib directory. This was tested with JBM 2.0.0.BETA3

You need to add the following configuration for Axis2 JMS transport listener in axis2.xml found at repository/conf/axis2.xml.

<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
    <parameter name="default" locked="false">
        <parameter name="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</parameter>
        <parameter name="java.naming.provider.url">jnp://localhost:1099</parameter>
        <parameter name="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</parameter>
        <parameter name="transport.jms.ConnectionFactoryJNDIName">ConnectionFactory</parameter>
    </parameter>
</transportReceiver>

Once you start ESB configuration 263 and request for the WSDL of the proxy service (http://localhost:8280/services/StockQuoteProxy?wsdl) you will notice that its exposed only on the JMS transport. This is because the configuration specified this requirement in the proxy service definition.

Before running the JMS client you need to open the build.xml ant script and uncomment the following block under the jmsclient target.

<!--<sysproperty key="java.naming.provider.url" value="${java.naming.provider.url}"/> <sysproperty key="java.naming.factory.initial" value="${java.naming.factory.initial}"/> <sysproperty key="java.naming.factory.url.pkg" value="${java.naming.factory.url.pkg}"/>-->

Now lets send a stock quote request on JMS, using the dumb stock quote client as follows:

ant jmsclient -Djms_type=pox -Djms_dest=StockQuoteProxy -Djms_payload=MSFT -Djava.naming.provider.url=jnp://localhost:1099 -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

On the ESB debug(you'll need to enable debug log in ESB) log you will notice that the JMS listener received the request message as:

[JMSWorker-1] DEBUG ProxyServiceMessageReceiver -Proxy Service StockQuoteProxy received a new message...

Now if you examine the console running the sample Axis2 server, you will see a message indicating that the server has accepted an order as follows:

Accepted order for : 16517 stocks of MSFT at $ 169.14622538721846

In this sample, the client sends the request message to the proxy service exposed over JMS in Synsape. Synapse forwards this message to the HTTP EPR of the simple stock quote service hosted on the sample Axis2 server. Note that the operation is out-only and no response is sent back to the client. The transport.jms.ContentType property is necessary to allow the JMS transport to determine the content type of incoming messages. With the given configuration it will first try to read the content type from the 'contentType' message property and fall back to 'application/xml' (i.e. POX) if this property is not set. Note that the JMS client used in this example doesn't send any content type information.

Note: It is possible to instruct a JMS proxy service to listen to an already existing destination without creating a new one. To do this, use the parameter elements on the proxy service definition to specify the destination and connection factory etc.

e.g.

<parameter name="transport.jms.Destination">dynamicTopics/something.TestTopic</parameter>

Sample 264: Sending Two-Way Messages Using JMS transport

<definitions xmlns="http://ws.apache.org/ns/synapse">
   <proxy name="StockQuoteProxy" transports="http">
       <target>
           <endpoint>
                   <address uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&
                 java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue"/>
           </endpoint>
           <inSequence>
               <property action="set" name="transport.jms.ContentTypeProperty" value="Content-Type" scope="axis2"/>
           </inSequence>
           <outSequence>
               <property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/>
               <send/>
           </outSequence>
       <target>
       <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/>
   </proxy>
</definitions>

Objective: Demonstrate sending request response scenario with JMS transport

Prerequisites:

You need to set up ESB and axis2 server to use the JMS transport. See Sample 251 for more details.

This sample is similar to the Sample 251. Only difference is we are expecting a response from the server. JMS transport uses transport.jms.ContentTypeProperty to determine the content type of the response message. If this property is not set JMS transport treats the incoming message as plain text.

In the out path we remove the message context property TRANSPORT_HEADERS. If these property is not removed JMS headers will be passed to the client.

Start ESB using sample 264.

wso2esb-samples -sn 264

Start Axis2 server with SimpleStockService deployed

Invoke the stockquote client using the following command.

ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dsymbol=MSFT

The sample Axis2 server console will print a message indicating that it has received the request:

Generating quote for : MSFT

In the client side it shoud print a message indicating it has received the price.

 Standard :: Stock price = $154.31851804993238

Sample 265: Using vfs transport to access a windows share

<!-- Using the vfs transport to access a windows share -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="StockQuoteProxy" transports="vfs">
		<parameter name="transport.vfs.FileURI">smb://host/test/in</parameter> <!--CHANGE-->
        <parameter name="transport.vfs.ContentType">text/xml</parameter>
        <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
        <parameter name="transport.PollInterval">15</parameter>
		<parameter name="transport.vfs.MoveAfterProcess">smb://host/test/original</parameter> <!--CHANGE-->
		<parameter name="transport.vfs.MoveAfterFailure">smb://host/test/original</parameter> <!--CHANGE-->
        <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
        <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>

        <target>
            <endpoint>
                <address format="soap12" uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <property name="transport.vfs.ReplyFileName"
                          expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')" scope="transport"/>
                <property action="set" name="OUT_ONLY" value="true"/>
                <send>
                    <endpoint>
						<address uri="vfs:smb://host/test/out"/> <!--CHANGE-->
                    </endpoint>
                </send>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
</definitions>

Objective: Using vfs transport to access a windows share

Prerequisites:
You will need access a windows shared folder. Just create a folder(called 'test') on a windows machine and create three sub folders in, out and original inside that folder.Then assign the permission to the network users to read and write into the root 'test' folder and the folders inside that directory.

Open ESB_HOME/repository/samples/synapse_sample_265.xml and edit the following values. Change transport.vfs.FileURI, transport.vfs.MoveAfterProcess, transport.vfs.MoveAfterFailure parameter values to the above in, original, original directories respectively. Change outSequence endpoint address uri to out directory with the prefix vfs:. Values you have to change are marked with <!--CHANGE-->.

Copy ESB_HOME/repository/samples/resources/vfs/test.xml to the directory given in transport.vfs.FileURI above.

Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

Enable vfs transport receiver and the vfs transport sender in the ESB axis2.xml. Just uncomment the VFSTransportListener and the VFSTransportSender in axis2.xml

Start the Synapse configuration numbered 265: i.e. wso2esb-samples -sn 265

VFS transport listener will pick the file from in directory and send it to the Axis2 service. The request XML file will be moved to original directory. The response from the Axis2 server will be saved to out directory.

Sample 266: Switching from TCP to HTTP/S

<definitions xmlns="http://ws.apache.org/ns/synapse"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd">

    <proxy name="StockQuoteProxy" transports="tcp">
        <target>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <inSequence>
                <log level="full"/>
                <property name="OUT_ONLY" value="true"/>
            </inSequence>
        </target>
    </proxy>

</definitions>

Objective: Demonstrate receiving SOAP messages over TCP and forwarding them over HTTP

Prerequisites:
You need to configure Synpase to use the TCP transport.The sample Axis2 client should also be setup to send TCP requests. Refer Setting Up the TCP Transport section in the sample setup guide for more details. Start Synpase using sample 266: ie synapse -sample 266
Start Axis2 server with SimpleStockService deployed

This sample is similar to Sample 250 . Only difference is instead of the JMS transport we will be using the TCP transport to receive messages. TCP is not an application layer protocol. Hence there are no application level headers available in the requests. Synapse has to simply read the XML content coming through the socket and dispatch it to the right proxy service based on the information available in the message payload itself. The TCP transport is capable of dispatching requests based on addressing headers or the first element in the SOAP body. In this sample, we will get the sample client to send WS-Addressing headers in the request. Therefore the dispatching will take place based on the addressing header values. Invoke the stockquote client using the following command. Note the TCP URL in the command.

ant stockquote -Daddurl=tcp://localhost:6060/services/StockQuoteProxy -Dmode=placeorder

The TCP transport will receive the message and hand it over to the mediation engine. Synapse will dispatch the request to the StockQuoteProxy service based on the addressing header values.
The sample Axis2 server console will print a message indicating that it has received the request:

Thu May 20 12:25:01 IST 2010 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 17621 stocks of IBM at $ 73.48068475255796

Sample 267: Switching from UDP to HTTP/S

<definitions xmlns="http://ws.apache.org/ns/synapse"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd">

    <proxy name="StockQuoteProxy" transports="udp">
        <target>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <inSequence>
                <log level="full"/>
                <property name="OUT_ONLY" value="true"/>
            </inSequence>
        </target>
        <parameter name="transport.udp.port">9999</parameter>
        <parameter name="transport.udp.contentType">text/xml</parameter>
        <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
</definitions>

Objective: Demonstrate receiving SOAP messages over UDP and forwarding them over HTTP

Prerequisites:
You need to configure Synpase to use the TCP transport.The sample Axis2 client should also be setup to send TCP requests. Refer Setting Up the TCP Transport section in the sample setup guide for more details. Start Synpase using sample 267: ie synapse -sample 267
Start Axis2 server with SimpleStockService deployed

This sample is similar to Sample 266. Only difference is instead of the TCP transport we will be using the UDP transport to receive messages. Invoke the stockquote client using the following command. Note the TCP URL in the command.

ant stockquote -Daddurl=udp://localhost:9999?contentType=text/xml -Dmode=placeorder

Since we have configured the content type as text/xml for the proxy service, incoming messages will be processed as SOAP 1.1 messages.
The sample Axis2 server console will print a message indicating that it has received the request:

Thu May 20 12:25:01 IST 2010 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 17621 stocks of IBM at $ 73.48068475255796

Sample 268: Proxy services with the Local transport

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy xmlns="http://ws.apache.org/ns/synapse" name="LocalTransportProxy"
           transports="https http" startOnLoad="true" trace="disable">
        <target>
            <endpoint name="ep1">
                <address uri="local://localhost/services/SecondProxy"/>
            </endpoint>
            <inSequence>
                <log level="full"/>
                <log level="custom">
                    <property name="LocalTransportProxy" value="In sequence of LocalTransportProxy invoked!"/>
                </log>
            </inSequence>
            <outSequence>
                <log level="custom">
                    <property name="LocalTransportProxy" value="Out sequence of LocalTransportProxy invoked!"/>
                </log>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
    <proxy xmlns="http://ws.apache.org/ns/synapse" name="SecondProxy"
           transports="https http" startOnLoad="true" trace="disable">
        <target>
            <endpoint name="ep2">
                <address uri="local://localhost/services/StockQuoteProxy"/>
            </endpoint>
            <inSequence>
                <log level="full"/>
                <log level="custom">
                    <property name="SecondProxy" value="In sequence of Second proxy invoked!"/>
                </log>
            </inSequence>
            <outSequence>
                <log level="custom">
                    <property name="SecondProxy" value="Out sequence of Second proxy invoked!"/>
                </log>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
    <proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy"
           startOnLoad="true">
        <target>
            <endpoint name="ep3">
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <log level="custom">
                    <property name="StockQuoteProxy"
                              value="Out sequence of StockQuote proxy invoked!"/>
                </log>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
</definitions>

Objective: Proxy services with the Local transport

This sample contains three proxy services. The stockquote client invokes the LocalTransportProxy. Then the message will be sent to the SecondProxy and then it will be sent to the StockQuoteProxy. The StockQuoteProxy will invoke the backend service and return the response to the client. In this sample, the communication between proxy services are done through the Local transport. Since Local transport calls are in-JVM calls, it will reduce the time taken for the communication between proxy services.

Prerequisites:
Start the Synapse configuration numbered 268: i.e. wso2esb-samples -sn 268
Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

Execute the stock quote client by requesting for a stock quote on the proxy service as follows:

ant stockquote -Daddurl=http://localhost:8280/services/LocalTransportProxy