WSO2 ESB - Transport Switching Samples

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 activeio-core-3.1.0.jar, activemq-core-5.2.0.jar, geronimo-jms_1.1_spec-1.1.1.jar and geronimo-j2ee-management_1.0_spec-1.0.jar into the lib/extensions 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 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 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 stock quote 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 in JMS in Synsape. ESB forwards this message to the HTTP EPR of the simple stock quote service hosted on the sample Axis2 server, and returns the reply back to the client through a JMS temporary queue.

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 property elements on the proxy service definition to specify the destination and connection factory etc.

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&
                    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="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 Synase 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, and sends back the response to the client over HTTP once the simple stock quote service responds with the stock quote reply over JMS to the ESB server. 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"/>
                                <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-->.

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/xsd">
                        <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.

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 sender in the Synapse axis2.xml. See Setting up mail transport sender

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/xsd"><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.