2 Transports
Ralph Schaer edited this page 2026-10-30 16:08:52 +01:00

Transports

The servlet and reactive modules provide WebSocket transport. The servlet module also includes a separate HTTP long-poll configuration. Both use the same core message model, broker, dealer, and authentication-provider API.

WebSocket

Enable @EnableServletWamp or @EnableReactiveWamp to expose /wamp. Complete the WebSocket handshake with a supported subprotocol, then send WAMP HELLO and receive WELCOME before application messages.

Subprotocol WebSocket frames Long-poll response content type
wamp.2.json Text application/json
wamp.2.msgpack Binary application/octet-stream
wamp.2.cbor Binary application/octet-stream
wamp.2.smile Binary application/octet-stream

The servlet default PreferBinaryHandshakeHandler prefers MessagePack, then Smile, then CBOR among the offered protocols, with normal negotiation as fallback. Reactive negotiation uses Spring's HandshakeWebSocketService. See Configuration for endpoint, origin, handshake, and buffer customization.

Enable servlet long polling

Use the wamp2spring-servlet dependency with a servlet web application:

import org.springframework.context.annotation.Configuration;
import ch.rasc.wamp2spring.servlet.longpoll.EnableServletWampLongpoll;

@Configuration
@EnableServletWampLongpoll
public class LongpollConfiguration {
}

This imports a complete long-poll/core configuration; it is a separate setup from @EnableServletWamp. See Configuration before composing multiple transport configurations.

All endpoints use POST:

Endpoint Request Response
/wamp/open JSON {"protocols":["wamp.2.json"]} HTTP 200 with {"transport":"...","protocol":"wamp.2.json"}
/wamp/{transport}/send One WAMP message encoded in the selected format HTTP 204 on acceptance
/wamp/{transport}/receive Empty body HTTP 200 with one encoded WAMP message, or HTTP 204 after the receive timeout
/wamp/{transport}/close Empty body HTTP 204 after releasing the transport and WAMP session

protocols must be a nonempty list of nonblank protocol names; the first supported entry wins. The original singular protocol field is also accepted when protocols is absent. Unsupported formats and malformed payloads return HTTP 400. Unknown/removed transport IDs return HTTP 404. Only one receive may be pending per transport; an overlapping receive returns HTTP 409.

The opening response creates a transport, not an established WAMP session. For a minimal JSON flow:

POST /wamp/open
Content-Type: application/json
{"protocols":["wamp.2.json"]}

POST /wamp/{transport}/send
Content-Type: application/json
[1,"default",{"roles":{"caller":{},"subscriber":{}}}]

POST /wamp/{transport}/receive

Replace {transport} with the opening response's transport ID. The receive returns WELCOME (message code 2), or a challenge/abort when authentication is requested. Complete any challenge, then use the same send/receive loop for application traffic. Each receive returns one message, not a batch. HTTP 204 from send only acknowledges transport acceptance; a WAMP error may arrive on receive.

The principal is captured on /open. Subsequent operations identify the transport by its ID; the controller does not compare a new request principal to the opening principal. Protect these URLs through your application's HTTP access rules and keep transport IDs private. Configure HTTP CORS/CSRF behavior in the servlet application; WebSocket registration options do not configure these endpoints.

Timeouts and cleanup

Implement WampServletLongpollConfigurer on a Spring bean:

import java.time.Duration;
import org.springframework.context.annotation.Configuration;
import ch.rasc.wamp2spring.servlet.longpoll.WampServletLongpollConfigurer;

@Configuration
public class LongpollOptions implements WampServletLongpollConfigurer {
  @Override
  public Duration getReceiveTimeout() {
    return Duration.ofSeconds(25);
  }

  @Override
  public Duration getTransportIdleTimeout() {
    return Duration.ofSeconds(90);
  }

  @Override
  public int getMaxQueueSize() {
    return 200;
  }
}
Setting Default
getReceiveTimeout() 30 seconds
getTransportIdleTimeout() 60 seconds
getMaxQueueSize() 100 queued messages per transport

Idle cleanup runs at the idle-timeout interval. A pending receive keeps its transport active; outbound traffic alone does not refresh an abandoned transport. Queue overflow closes the transport. Close, idle expiry, and overflow publish disconnect cleanup so registrations, subscriptions, and sessions are released. Queued terminal ABORT/GOODBYE messages can drain before removal. Application shutdown stops the cleanup scheduler and closes remaining transports.

There is no reactive long-poll transport, RawSocket adapter, or batched-protocol support in this repository.

Source: long-poll implementation, long-poll tests.