WebsocketContext

WebsocketContext holds the connection and message state used by WebsocketAction. Unlike an HTTP request context, it is associated with a persistent WebSocket channel.

Overview

It exposes the WebSocket Session, handshake information, the incoming JSONMessage, and open parameters. PushActions can be transmitted through the connection.

This preview identifies the information typically available when a WebSocket connection is opened.

CODE
WebsocketContext context = ...;
Session session = context.getWebsocketSession();
HttpSession httpSession = context.getHttpSession();
RESULT
WebSocket session
HTTP session
Handshake parameters

Messages example

This preview illustrates the message-processing path from an incoming message to a PushAction sent to the connected browser.

CODE
JSONMessage message = context.getWebsocketMessage();
context.sendClientAction(
    new PushAction.UpdateElement("result",new Text("Received"))
);
RESULT
Incoming JSON message
WebsocketAction dispatch
PushAction response

How it works

CODE
WebsocketContext context = ...;
Session session = context.getWebsocketSession();
JSONMessage message = context.getWebsocketMessage();

Sending updates

PushAction can replace a component on the connected client without a new HTTP navigation.

CODE
context.sendClientAction(
    new PushAction.UpdateElement("result",new Text("Message received"))
);

Design guidance

WebSocket examples require a configured WebSocket endpoint and an actual live connection. These previews explain the roles of the objects; they do not pretend to open a connection.

Full API reference

These examples introduce the most important behavior without attempting to document every method. For the complete reference, see https://doc.jdance.org.