Using a Simple Proxy Service¶
This example demonstrates how to use a simple proxy service to expose a back-end service. In this example, a request received by the proxy service is forwarded to the sample service hosted in the backend.
Synapse configuration¶
Following is a sample proxy service configuration that we can used to implement this scenario. See the instructions on how to build and run this example.
An inSequence
or endpoint
or both of these would decide how the message would be handled after the proxy service receives the message. The
outSequence
defines how the response is handled before it is sent back to the client.
<proxy name="StockQuoteProxy" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
<outSequence>
<send/>
</outSequence>
</target>
<publishWSDL uri="file:/path/to/sample_proxy_1.wsdl"/>
</proxy>
Build and run¶
Create the artifacts:
- Set up WSO2 Integration Studio.
- Create an ESB Integration project.
-
Create the proxy service with the configurations given above.
Tip
Download the wsdl file (
sample_proxy_1.wsdl
) from sample_proxy_1.wsdl. The wsdl uri in the proxy service needs to be updated with the path to thissample_proxy_1.wsdl
file. -
Deploy the artifacts in your Micro Integrator.
When the Micro Integrator starts, you could go to the following URL and view the WSDL generated for the proxy service defined in the configuration.
http://localhost:8290/services/StockQuoteProxy?wsdl
This WSDL is based on the source WSDL supplied in the proxy service definition and is updated to reflect the proxy service EPR.
Set up the back-end service:
- Download the stockquote_service.jar.
-
Open a terminal, navigate to the location of the downloaded service, and run it using the following command:
java -jar stockquote_service.jar
Set up the SoapUI client.
- Download and Install SoapUI to run this SOAP service.
- Create a new SOAP project in the SoapUI using following wsdl file:
http://localhost:8290/services/StockQuoteProxy?wsdl
Send requests to the proxy service:
-
Send the following payload to receive a response containing the last sales price for the stock. You can use the
getQuote
operation.<ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <ser:request> <xsd:symbol>IBM</xsd:symbol> </ser:request> </ser:getQuote>
-
Send the following payload to get simple quote response containing the last sales price for stock. You can use the
getSimpleQuote
operation.<ser:getSimpleQuote xmlns:ser="http://services.samples"> <ser:symbol>IBM</ser:symbol> </ser:getSimpleQuote>
-
Send the following payload to get quote reports for the stock over a number of days (i.e. last 100 days of the year). You can use the
getFullQuote
operation.<ser:getFullQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <ser:request> <xsd:symbol>IBM</xsd:symbol> </ser:request> </ser:getFullQuote>
-
Send the following payload as an order for stocks using a one way request. For this you can use placeOrder operation.
<ser:placeOrder xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <ser:order> <xsd:price>3.141593E0</xsd:price> <xsd:quantity>4</xsd:quantity> <xsd:symbol>IBM</xsd:symbol> </ser:order> </ser:placeOrder>
-
Send the following paylaod to get a market activity report for the day (i.e. quotes for multiple symbols). You can use the
getMarketActivity
operation.<ser:getMarketActivity xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd"> <ser:request> <xsd:symbols>IBM</xsd:symbols> ... <xsd:symbols>MSFT</xsd:symbols> </ser:request> </ser:getMarketActivity>