<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
  ~  Licensed to the Apache Software Foundation (ASF) under one
  ~  or more contributor license agreements.  See the NOTICE file
  ~  distributed with this work for additional information
  ~  regarding copyright ownership.  The ASF licenses this file
  ~  to you under the Apache License, Version 2.0 (the
  ~  "License"); you may not use this file except in compliance
  ~  with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<document>
    <properties>
        <title>Apache Synapse - Sample 265</title>
    </properties>
    <body>
        <section name="Sample 265: Switching from TCP to HTTP/S">
            <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

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

&lt;/definitions&gt;</div>
            <subsection name="Objective">
                <p>
                    Demonstrate the ability of Synapse to receive raw TCP messages and send them to
                    HTTP endpoints
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
                        </li>
                        <li>
                            Enable the TCP transport receiver for Synapse (refer
                            <a href="setup/tcp_udp.html#tcp">TCP transport setup guide</a>).
                        </li>
                        <li>
                            Start Synapse using the configuration numbered 265 (repository/conf/sample/synapse_sample_265.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 265<br/>
                                Windows: synapse.bat -sample 265
                            </div>
                        </li>
                        <li>
                            Enable the TCP transport sender for the sample Axis2 client (refer
                            <a href="setup/tcp_udp.html#tcp">TCP transport setup guide</a> for
                            details).
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    This sample is similar to <a href="sample250.html">Sample 250</a>. 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.
                </p>
                <p>
                    Invoke the stockquote client using the following command. Note the TCP URL in the
                    command.
                </p>
                <div class="command">ant stockquote -Daddurl=tcp://localhost:6060/services/StockQuoteProxy -Dmode=placeorder</div>
                <p>
                    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.
                </p>
                <p>
                    When the proxy service forwards the message to the sample Axis2 server over HTTP,
                    sample server will print the following entry to confirm that the request has
                    been received.
                </p>
                <div class="consoleOutput">Thu May 20 12:25:01 IST 2010 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 17621 stocks of IBM at $ 73.48068475255796</div>
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>