Apache Synapse

##### Main Menu

- Home
- Download
- History
- License
- Thanks
- Sponsorship
- Security

##### Documentation

- Installation Guide
- Quick Start Guide
- Samples Setup Guide
- Samples Catalog
- Configuration Language
- Mediators Catalog
- Transports Catalog
- Extending Synapse
- Upgrading
- Deployment
- Javadocs
- FAQ

##### Developer Resources

- Developer Guide
- Development Best Practices
- Release Process

##### Project Details

- Overview
- Mailing Lists
- Source Repository
- Issue Tracking
- Dependencies
- Project Team
- Project Summary

##### Previous Releases

- Version 1.2
- Version 1.1.1
- Version 1.1
- Version 1.0

## Sample 152: Switching Transports and Message Format from SOAP to REST/POX

<definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="StockQuoteProxy" transports="https"> <target> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="pox"/> </endpoint> <outSequence> <send/> </outSequence> </target> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions>

### Objective

Demonstrate implementing simple transport switching and message format switching scenarios using proxy services

### Pre-requisites

- Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
- Start Synapse using the configuration numbered 152 (repository/conf/sample/synapse_sample_152.xml)
  Unix/Linux: sh synapse.sh -sample 152
  Windows: synapse.bat -sample 152

### Executing the Client

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.

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

Accessing this over HTTPS causes the proxy service to access the SimpleStockQuoteService on the sample Axis2 server using REST/POX.

ant stockquote -Dtrpurl=https://localhost:8243/services/StockQuoteProxy

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.

POST /services/SimpleStockQuoteService HTTP/1.1 Host: 127.0.0.1 SOAPAction: urn:getQuote Content-Type: application/xml; charset=UTF-8;action="urn:getQuote"; Transfer-Encoding: chunked Connection: Keep-Alive User-Agent: Synapse-HttpComponents-NIO 75 <m0:getQuote xmlns:m0="http://services.samples"> <m0:request> <m0:symbol>IBM</m0:symbol> </m0:request> </m0:getQuote>
HTTP/1.1 200 OK Content-Type: application/xml; charset=UTF-8;action="http://services.samples/SimpleStockQuoteServicePortType/getQuoteResponse"; Date: Tue, 24 Apr 2007 14:42:11 GMT Server: Synapse-HttpComponents-NIO Transfer-Encoding: chunked Connection: Keep-Alive 2b3 <ns:getQuoteResponse xmlns:ns="http://services.samples/xsd"> <ns:return> <ns:change>3.7730036841862384</ns:change> <ns:earnings>-9.950236235550818</ns:earnings> <ns:high>-80.23868444613285</ns:high> <ns:last>80.50750970812187</ns:last> <ns:lastTradeTimestamp>Tue Apr 24 20:42:11 LKT 2007</ns:lastTradeTimestamp> <ns:low>-79.67368355714606</ns:low> <ns:marketCap>4.502043663670823E7</ns:marketCap> <ns:name>IBM Company</ns:name> <ns:open>-80.02229531286982</ns:open> <ns:peRatio>25.089295161182022</ns:peRatio> <ns:percentageChange>4.28842665653824</ns:percentageChange> <ns:prevClose>87.98107059692451</ns:prevClose> <ns:symbol>IBM</ns:symbol> <ns:volume>19941</ns:volume> </ns:return> </ns:getQuoteResponse>

Back to Catalog