From 14e87d27334f90141f10733b57de810f08c6a6ac Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 12 Dec 2018 11:57:51 -0500 Subject: [PATCH] Add reference to ConcurrentWebSocketSessionDecorator in the docs. Issue: SPR-12886 --- .../org/springframework/web/socket/WebSocketSession.java | 7 +++++++ src/docs/asciidoc/web/websocket.adoc | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java index 9016c3e830..19e6b01913 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketSession.java @@ -120,6 +120,13 @@ public interface WebSocketSession extends Closeable { /** * Send a WebSocket message: either {@link TextMessage} or {@link BinaryMessage}. + * + *

Note: The underlying standard WebSocket session (JSR-356) does + * not allow concurrent sending. Therefore sending must be synchronized. To ensure + * that, one option is to wrap the {@code WebSocketSession} with the + * {@link org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator + * ConcurrentWebSocketSessionDecorator}. + * @see org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator */ void sendMessage(WebSocketMessage message) throws IOException; diff --git a/src/docs/asciidoc/web/websocket.adoc b/src/docs/asciidoc/web/websocket.adoc index 25eb5b3589..fe117eb209 100644 --- a/src/docs/asciidoc/web/websocket.adoc +++ b/src/docs/asciidoc/web/websocket.adoc @@ -102,12 +102,18 @@ The following example shows the XML configuration equivalent of the preceding ex ---- ==== -The pereceding example is for use in Spring MVC applications and should be included in the +The preceding example is for use in Spring MVC applications and should be included in the configuration of a <>. However, Spring's WebSocket support does not depend on Spring MVC. It is relatively simple to integrate a `WebSocketHandler` into other HTTP-serving environments with the help of {api-spring-framework}/web/socket/server/support/WebSocketHttpRequestHandler.html[`WebSocketHttpRequestHandler`]. +When using the `WebSocketHandler` API directly vs indirectly, e.g. through the +<> messaging, the application must synchronize the sending of messages +since the underlying standard WebSocket session (JSR-356) does not allow concurrent +sending. One option is to wrap the `WebSocketSession` with +{api-spring-framework}/web/socket/handler/ConcurrentWebSocketSessionDecorator.html[`ConcurrentWebSocketSessionDecorator`]. + [[websocket-server-handshake]]