<?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 152</title>
    </properties>
    <body>
        <section name="Sample 152: Switching Transports and Message Format from SOAP to REST/POX">
            <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;proxy name="StockQuoteProxy" transports="https"&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService" format="pox"/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/&gt;
    &lt;/proxy&gt;

&lt;/definitions&gt;</div>
            <subsection name="Objective">
                <p>
                    Demonstrate implementing simple transport switching and message format switching
                    scenarios using proxy services
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
                        </li>
                        <li>
                            Start Synapse using the configuration numbered 152 (repository/conf/sample/synapse_sample_152.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 152<br/>
                                Windows: synapse.bat -sample 152
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>
                    This configuration demonstrates how a proxy service can be exposed on a subset
                    of available transports, and how it could switch from one transport to another.
                    This example exposes the created proxy service only on HTTPS, and thus if the
                    user tries to access it over HTTP, it would result in a fault.
                </p>
                <div class="consoleOutput">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy
...
 [java] org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) /soap/StockQuoteProxy</div>

                <p>
                    Accessing this over HTTPS causes the proxy service to access the SimpleStockQuoteService
                    on the sample Axis2 server using REST/POX.
                </p>
                <div class="command">ant stockquote -Dtrpurl=https://localhost:8243/services/StockQuoteProxy</div>

                <p>
                    TCPMon can be used to trace the actual REST/POX messages exchanged between Synapse
                    and the sample Axis2 server. Synapse converts the POX response back to SOAP before
                    sending it back to the client.
                </p>
                <div class="consoleOutput">POST /services/SimpleStockQuoteService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:getQuote
Content-Type: application/xml; charset=UTF-8;action=&quot;urn:getQuote&quot;;
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO

75
&lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
   &lt;m0:request&gt;
      &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
   &lt;/m0:request&gt;
&lt;/m0:getQuote&gt;</div>
                
                <div class="consoleOutput">HTTP/1.1 200 OK
Content-Type: application/xml; charset=UTF-8;action=&quot;http://services.samples/SimpleStockQuoteServicePortType/getQuoteResponse&quot;;
Date: Tue, 24 Apr 2007 14:42:11 GMT
Server: Synapse-HttpComponents-NIO
Transfer-Encoding: chunked
Connection: Keep-Alive

2b3
&lt;ns:getQuoteResponse xmlns:ns=&quot;http://services.samples&quot;&gt;
   &lt;ns:return&gt;
      &lt;ns:change&gt;3.7730036841862384&lt;/ns:change&gt;
      &lt;ns:earnings&gt;-9.950236235550818&lt;/ns:earnings&gt;
      &lt;ns:high&gt;-80.23868444613285&lt;/ns:high&gt;
      &lt;ns:last&gt;80.50750970812187&lt;/ns:last&gt;
      &lt;ns:lastTradeTimestamp&gt;Tue Apr 24 20:42:11 LKT 2007&lt;/ns:lastTradeTimestamp&gt;
      &lt;ns:low&gt;-79.67368355714606&lt;/ns:low&gt;
      &lt;ns:marketCap&gt;4.502043663670823E7&lt;/ns:marketCap&gt;
      &lt;ns:name&gt;IBM Company&lt;/ns:name&gt;
      &lt;ns:open&gt;-80.02229531286982&lt;/ns:open&gt;
      &lt;ns:peRatio&gt;25.089295161182022&lt;/ns:peRatio&gt;
      &lt;ns:percentageChange&gt;4.28842665653824&lt;/ns:percentageChange&gt;
      &lt;ns:prevClose&gt;87.98107059692451&lt;/ns:prevClose&gt;
      &lt;ns:symbol&gt;IBM&lt;/ns:symbol&gt;
      &lt;ns:volume&gt;19941&lt;/ns:volume&gt;
   &lt;/ns:return&gt;
&lt;/ns:getQuoteResponse&gt;</div>

            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>