Sample Number |
450 |
Level |
|
Description |
This sample demonstrates how a WebSocket client could make a back-end service call via UltraESB. |
I have clients sending SOAP messages through WebSocket connections established between UltraESB and clients and I want to send these SOAP messages to a Web Service via HTTP and send back the reply received from Web Service to WebSocket clients.
As shown in the above diagram, instead of directly talking to the back-end service, UltraESB acts as the proxy for all the requests going to the back-end server.
The configuration for this use case is straight forward which consists of a proxy service, exposed on the WebSocket transport and forwards the incoming message from WebSocket clients into the target back-end service configured using the 'stockquoteservice' endpoint. The reply from back-end service will be sent back to the original WebSocket client.
Proxy service configuration
1<u:proxy id="soap-proxy">
2 <u:transport id="ws-listener">
3 </u:transport>
4 <u:target>
5 <u:inSequence>
6 <u:java import="org.adroitlogic.ultraesb.api.format.WebSocketMessage.Opcode;"><![CDATA[
7 Opcode opcode = mediation.getWebSocketSupport().getOpcode(msg);
8 if (opcode == Opcode.TEXT) {
9 mediation.sendToEndpoint(msg, "stockquoteservice");
10 }
11 ]]></u:java>
12 </u:inSequence>
13 <u:outDestination>
14 <u:address type="response"/>
15 </u:outDestination>
16 </u:target>
17</u:proxy>
18
19<u:endpoint id="stockquoteservice">
20 <u:address>http://localhost:9000/service/SimpleStockQuoteService</u:address>
21</u:endpoint>
Note For the simplicity the complete configuration is not displayed here, you may look at the complete configuration either from the binary distribution under samples/conf/ultra-sample-450.xml, or from the sample 450 configuration of the source tag. |
To run the example, start the UltraESB sample configuration 450 via the ToolBox or on the command line as follows.
Running the sample from startup script
$ cd /opt/ultraesb-2.6.1/bin $ ./ultraesb.sh -sample 450
Now start the SOA Toolbox, and fire-up the sample Jetty server on port 9000 and open the websocket-client.html Client at samples/resources/websocket/ and connect to ws://localhost:8887/soap-proxy URL.
Browser Support You must open websocket-client.html file using a browser which has native WebSocket support such as Internet Explorer 10+, Mozilla Firefox 11+, Google Chrome 16+, Opera 12.10+ or Safari 6+ |
Now Copy below SOAP message and send it via WebSocket client.
Sample SOAP message
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.services.samples/">
<soapenv:Body>
<soap:getQuote>
<request>
<symbol>ADRT</symbol>
</request>
</soap:getQuote>
</soapenv:Body>
Then you would receive the below response for the message
SOAP response message
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getQuoteResponse xmlns:ns2="http://soap.services.samples/">
<return>
<change>3.8369417425193624</change>
<earnings>-8.659323165068999</earnings>
<high>-80.83100956269186</high>
<last>81.14311533055167</last>
<lastTradeTimestamp>Thu May 08 15:12:32 IST 2014
</lastTradeTimestamp>
<low>83.29617110533702</low>
<marketCap>9551865.34063657</marketCap>
<name>ADRT Company</name>
<open>-79.80245660536787</open>
<peRatio>25.04219585555329</peRatio>
<percentageChange>4.244522087850373</percentageChange>
<prevClose>90.39749736495239</prevClose>
<symbol>ADRT</symbol>
<volume>18206</volume>
</return>
</ns2:getQuoteResponse>
</S:Body>
</S:Envelope>
Basically what happens here is that the WebSocket message received from the client to the UltraESB is forwarded to the back-end service by the inSequence of the soap-proxy service. Then the response receive from the back-end service is transmitted back to the original web socket client through the outDestination of the soap-proxy service.