Invoking a back-end service via WebSocket

Sample Number





This sample demonstrates how a WebSocket client could make a back-end service call via UltraESB.

Use Case

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.

Sample Configuration

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>
19<u:endpoint id="stockquoteservice">
20    <u:address>http://localhost:9000/service/SimpleStockQuoteService</u:address>
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.

In Action

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
$ ./ -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="" xmlns:soap="">

Then you would receive the below response for the message

SOAP response message

<?xml version="1.0" ?>
<S:Envelope xmlns:S="">
        <ns2:getQuoteResponse xmlns:ns2="">
                <lastTradeTimestamp>Thu May 08 15:12:32 IST 2014
                <name>ADRT Company</name>

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.

In this topic
In this topic
Contact Us