Integrating WebSocket with other Transports

Sample Number

451

Level

Introductory

Description

This sample demonstrates how to integrate WebSocket with HTTP transport.

Use Case

I have a HTTP client sending HTTP requests to UltraESB and I want to send the content of this HTTP request to WebSocket clients connected to a particular subscriber path and a HTTP 200 response back to the HTTP client

451

As shown in the above diagram, HTTP client send HTTP requests to the UltraESB. Then the UltraESB will obtain the content of this request and transmit it to the WebSocket clients connected to a particular subscriber path and send a HTTP 200 response to the HTTP client.

What is a Subscriber path of a WebSocket Client?

Subscriber path of a WebSocket can be described as the resource path of the URL a particular WebSocket client has connected to. As an example, assume a particular WebSocket client has connected to 'ws://localhost:8887/helloworld' URL. Then the subscriber path of that WebSocket client would be 'helloworld'.

Sample Configuration

The configuration for this use case consists of a proxy service, exposed on the WebSocket transport and HTTP transport. The proxy service clone the message, set its current payload and submit it to the 'ws-endpoint' and the original message is sent back to the HTTP client with 200 response code.

The 'ws-endpoint' has the address ’ws://broadcast/subscribers?subscribe_path=subscriber' which means that any message passed to this endpoint will be broadcasted to all the WebSocket clients connected to the 'subscriber' subscribed path. i.e. all the WebSocket clients connected to 'ws://localhost:8887/subscriber' will receive this message. For more information on WebSocket addresses please refer WebSocket Transport Guide

Proxy service configuration

 1    <u:proxy id="http-proxy">
 2    <u:transport id="http-8280">
 3    </u:transport>
 4    <u:transport id="ws-listener">
 5        <u:property name="ultra.transport.ws.subscribedPath" value="subscriber"/>
 6    </u:transport>
 7    <u:target>
 8        <u:inSequence>
 9            <u:java><![CDATA[
10                    final Message clonedMsg = msg.cloneMessage();
11                    clonedMsg.setCurrentPayload(msg.getCurrentPayload());
12                    mediation.sendResponse(msg, 200);
13                    mediation.sendToEndpoint(clonedMsg, "ws-endpoint");
14                ]]></u:java>
15        </u:inSequence>
16    </u:target>
17</u:proxy>
18
19
20<u:endpoint id="ws-endpoint">
21    <u:address>ws://broadcast/subscribers?subscribe_path=subscriber</u:address>
22</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-451.xml, or from the sample 451 configuration of the source tag.

In Action

To run the example, start the UltraESB sample configuration 451 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 451

Now start the SOA Toolbox, and open a new HTTP/s client and connect to http://localhost:8280/service/http-proxy. Next open the websocket-client.html client at samples/resources/websocket/ and connect to ws://localhost:8887/subscriber URL.

Browser Support
browser
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 send any message via HTTP client and the content of that message will be available in WebSocketClient.

In this topic
In this topic
Contact Us