Top Description Inners Fields Constructors Methods
org.springframework.web.socket.messaging

public Class WebSocketStompClient

extends StompClientSupport
implements SmartLifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.SmartLifecycle, org.springframework.context.Phased, org.springframework.context.Lifecycle
Imports
java.io.IOException, java.net.URI, java.nio.ByteBuffer, java.time.Duration, java.util.Collections, .List, java.util.concurrent.CompletableFuture, .ScheduledFuture, java.util.function.BiConsumer, org.apache.commons.logging.Log, .LogFactory, org.springframework.context.Lifecycle, .SmartLifecycle, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.messaging.simp.stomp.BufferingStompDecoder, .ConnectionHandlingStompSession, .StompClientSupport, .StompDecoder, .StompEncoder, .StompHeaderAccessor, .StompHeaders, .StompSession, .StompSessionHandler, org.springframework.messaging.support.MessageHeaderAccessor, org.springframework.messaging.tcp.TcpConnection, .TcpConnectionHandler, org.springframework.scheduling.TaskScheduler, org.springframework.util.Assert, .MimeTypeUtils, org.springframework.web.socket.BinaryMessage, .CloseStatus, .TextMessage, .WebSocketHandler, .WebSocketHttpHeaders, .WebSocketMessage, .WebSocketSession, org.springframework.web.socket.client.WebSocketClient, org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator, org.springframework.web.socket.sockjs.transport.SockJsSession, org.springframework.web.util.UriComponentsBuilder

A STOMP over WebSocket client that connects using an implementation of WebSocketClient including SockJsClient.
Author
Rossen Stoyanchev
Since
4.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
WebSocketStompClient.StompWebSocketMessageCodec

Encode and decode STOMP WebSocket messages.

private class
WebSocketStompClient.WebSocketTcpConnectionHandlerAdapter

Adapt WebSocket to the TcpConnectionHandler and TcpConnection contracts.

Field Summary

Modifier and TypeField and Description
private boolean
private int
private static final Log
private int
private volatile boolean
private final WebSocketClient

Constructor Summary

AccessConstructor and Description
public
WebSocketStompClient(WebSocketClient
the WebSocket client to connect with
webSocketClient
)

Class constructor.

Method Summary

Modifier and TypeMethod and Description
public ListenableFuture<StompSession>

Returns:

a ListenableFuture for access to the session when ready for use
connect
(String
the url to connect to
url
,
StompSessionHandler
the session handler
handler
,
Object...
the URI variables to expand into the URL
uriVars
)
Deprecated since 6.0. as of 6.0, in favor of connectAsync(String, StompSessionHandler, Object...)

Connect to the given WebSocket URL and notify the given org.springframework.messaging.simp.stomp.StompSessionHandler when connected on the STOMP level after the CONNECTED frame is received.

public ListenableFuture<StompSession>

Returns:

a ListenableFuture for access to the session when ready for use
connect
(String
the url to connect to
url
,
WebSocketHttpHeaders
the headers for the WebSocket handshake
handshakeHeaders
,
StompSessionHandler
the session handler
handler
,
Object...
the URI variables to expand into the URL
uriVariables
)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake.

public ListenableFuture<StompSession>

Returns:

a ListenableFuture for access to the session when ready for use
connect
(String
the url to connect to
url
,
WebSocketHttpHeaders
headers for the WebSocket handshake
handshakeHeaders
,
StompHeaders
headers for the STOMP CONNECT frame
connectHeaders
,
StompSessionHandler
the session handler
handler
,
Object...
the URI variables to expand into the URL
uriVariables
)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake and StompHeaders for the STOMP CONNECT frame.

public ListenableFuture<StompSession>

Returns:

a ListenableFuture for access to the session when ready for use
connect
(URI
the url to connect to
url
,
WebSocketHttpHeaders
the headers for the WebSocket handshake
handshakeHeaders
,
StompHeaders
headers for the STOMP CONNECT frame
connectHeaders
,
StompSessionHandler
the STOMP session handler
sessionHandler
)

An overloaded version of connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...) that accepts a fully prepared java.net.URI.

public CompletableFuture<StompSession>

Returns:

a CompletableFuture for access to the session when ready for use
connectAsync
(String
the url to connect to
url
,
StompSessionHandler
the session handler
handler
,
Object...
the URI variables to expand into the URL
uriVars
)

Connect to the given WebSocket URL and notify the given org.springframework.messaging.simp.stomp.StompSessionHandler when connected on the STOMP level after the CONNECTED frame is received.

public CompletableFuture<StompSession>

Returns:

a ListenableFuture for access to the session when ready for use
connectAsync
(String
the url to connect to
url
,
WebSocketHttpHeaders
the headers for the WebSocket handshake
handshakeHeaders
,
StompSessionHandler
the session handler
handler
,
Object...
the URI variables to expand into the URL
uriVariables
)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake.

public CompletableFuture<StompSession>

Returns:

a CompletableFuture for access to the session when ready for use
connectAsync
(String
the url to connect to
url
,
WebSocketHttpHeaders
headers for the WebSocket handshake
handshakeHeaders
,
StompHeaders
headers for the STOMP CONNECT frame
connectHeaders
,
StompSessionHandler
the session handler
handler
,
Object...
the URI variables to expand into the URL
uriVariables
)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake and StompHeaders for the STOMP CONNECT frame.

public CompletableFuture<StompSession>

Returns:

a CompletableFuture for access to the session when ready for use
connectAsync
(URI
the url to connect to
url
,
WebSocketHttpHeaders
the headers for the WebSocket handshake
handshakeHeaders
,
StompHeaders
headers for the STOMP CONNECT frame
connectHeaders
,
StompSessionHandler
the STOMP session handler
sessionHandler
)

An overloaded version of connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...) that accepts a fully prepared java.net.URI.

public int
getInboundMessageSizeLimit()

Get the configured inbound message buffer size in bytes.

public int
getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the configured phase.

public WebSocketClient
getWebSocketClient()

Return the configured WebSocketClient.

public boolean
isAutoStartup()

Overrides default org.springframework.context.SmartLifecycle.isAutoStartup.

Return the value for the 'autoStartup' property.

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

protected StompHeaders
processConnectHeaders(StompHeaders
the headers to modify
connectHeaders
)

Overrides org.springframework.messaging.simp.stomp.StompClientSupport.processConnectHeaders.

Further initialize the StompHeaders, for example setting the heart-beat header if necessary.

public void
setAutoStartup(boolean autoStartup)

Set whether to auto-start the contained WebSocketClient when the Spring context has been refreshed.

public void
setInboundMessageSizeLimit(int inboundMessageSizeLimit)

Configure the maximum size allowed for inbound STOMP message.

public void
setPhase(int phase)

Specify the phase in which the WebSocket client should be started and subsequently closed.

public void
setTaskScheduler(TaskScheduler taskScheduler)

Overrides org.springframework.messaging.simp.stomp.StompClientSupport.setTaskScheduler.

Configure a scheduler to use for heartbeats and for receipt tracking.

public void
start()

Implements org.springframework.context.Lifecycle.start.

Start this component.

public void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

Inherited from org.springframework.messaging.simp.stomp.StompClientSupport:
createSessiongetDefaultHeartbeatgetMessageConvertergetReceiptTimeLimitgetTaskSchedulerisDefaultHeartbeatEnabledsetDefaultHeartbeatsetMessageConvertersetReceiptTimeLimit

Field Detail

autoStartupback to summary
private boolean autoStartup
inboundMessageSizeLimitback to summary
private int inboundMessageSizeLimit
loggerback to summary
private static final Log logger
phaseback to summary
private int phase
runningback to summary
private volatile boolean running
webSocketClientback to summary
private final WebSocketClient webSocketClient

Constructor Detail

WebSocketStompClientback to summary
public WebSocketStompClient(WebSocketClient webSocketClient)

Class constructor. Sets setDefaultHeartbeat to "0,0" but will reset it back to the preferred "10000,10000" when a setTaskScheduler is configured.

Parameters
webSocketClient:WebSocketClient

the WebSocket client to connect with

Method Detail

connectback to summary
public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars)

Deprecated

since 6.0.

as of 6.0, in favor of connectAsync(String, StompSessionHandler, Object...)

Connect to the given WebSocket URL and notify the given org.springframework.messaging.simp.stomp.StompSessionHandler when connected on the STOMP level after the CONNECTED frame is received.

Parameters
url:String

the url to connect to

handler:StompSessionHandler

the session handler

uriVars:Object[]

the URI variables to expand into the URL

Returns:ListenableFuture<StompSession>

a ListenableFuture for access to the session when ready for use

Annotations
@Deprecated
since:6.0
connectback to summary
public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake.

Parameters
url:String

the url to connect to

handshakeHeaders:WebSocketHttpHeaders

the headers for the WebSocket handshake

handler:StompSessionHandler

the session handler

uriVariables:Object[]

the URI variables to expand into the URL

Returns:ListenableFuture<StompSession>

a ListenableFuture for access to the session when ready for use

Annotations
@Deprecated
since:6.0
connectback to summary
public ListenableFuture<StompSession> connect(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake and StompHeaders for the STOMP CONNECT frame.

Parameters
url:String

the url to connect to

handshakeHeaders:WebSocketHttpHeaders

headers for the WebSocket handshake

connectHeaders:StompHeaders

headers for the STOMP CONNECT frame

handler:StompSessionHandler

the session handler

uriVariables:Object[]

the URI variables to expand into the URL

Returns:ListenableFuture<StompSession>

a ListenableFuture for access to the session when ready for use

Annotations
@Deprecated
since:6.0
connectback to summary
public ListenableFuture<StompSession> connect(URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler)

An overloaded version of connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...) that accepts a fully prepared java.net.URI.

Parameters
url:URI

the url to connect to

handshakeHeaders:WebSocketHttpHeaders

the headers for the WebSocket handshake

connectHeaders:StompHeaders

headers for the STOMP CONNECT frame

sessionHandler:StompSessionHandler

the STOMP session handler

Returns:ListenableFuture<StompSession>

a ListenableFuture for access to the session when ready for use

Annotations
@Deprecated
since:6.0
connectAsyncback to summary
public CompletableFuture<StompSession> connectAsync(String url, StompSessionHandler handler, Object... uriVars)

Connect to the given WebSocket URL and notify the given org.springframework.messaging.simp.stomp.StompSessionHandler when connected on the STOMP level after the CONNECTED frame is received.

Parameters
url:String

the url to connect to

handler:StompSessionHandler

the session handler

uriVars:Object[]

the URI variables to expand into the URL

Returns:CompletableFuture<StompSession>

a CompletableFuture for access to the session when ready for use

Since
6.0
connectAsyncback to summary
public CompletableFuture<StompSession> connectAsync(String url, WebSocketHttpHeaders handshakeHeaders, StompSessionHandler handler, Object... uriVariables)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake.

Parameters
url:String

the url to connect to

handshakeHeaders:WebSocketHttpHeaders

the headers for the WebSocket handshake

handler:StompSessionHandler

the session handler

uriVariables:Object[]

the URI variables to expand into the URL

Returns:CompletableFuture<StompSession>

a ListenableFuture for access to the session when ready for use

Since
6.0
connectAsyncback to summary
public CompletableFuture<StompSession> connectAsync(String url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables)

An overloaded version of connect(String, StompSessionHandler, Object...) that also accepts WebSocketHttpHeaders to use for the WebSocket handshake and StompHeaders for the STOMP CONNECT frame.

Parameters
url:String

the url to connect to

handshakeHeaders:WebSocketHttpHeaders

headers for the WebSocket handshake

connectHeaders:StompHeaders

headers for the STOMP CONNECT frame

handler:StompSessionHandler

the session handler

uriVariables:Object[]

the URI variables to expand into the URL

Returns:CompletableFuture<StompSession>

a CompletableFuture for access to the session when ready for use

Since
6.0
connectAsyncback to summary
public CompletableFuture<StompSession> connectAsync(URI url, WebSocketHttpHeaders handshakeHeaders, StompHeaders connectHeaders, StompSessionHandler sessionHandler)

An overloaded version of connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...) that accepts a fully prepared java.net.URI.

Parameters
url:URI

the url to connect to

handshakeHeaders:WebSocketHttpHeaders

the headers for the WebSocket handshake

connectHeaders:StompHeaders

headers for the STOMP CONNECT frame

sessionHandler:StompSessionHandler

the STOMP session handler

Returns:CompletableFuture<StompSession>

a CompletableFuture for access to the session when ready for use

Since
6.0
getInboundMessageSizeLimitback to summary
public int getInboundMessageSizeLimit()

Get the configured inbound message buffer size in bytes.

getPhaseback to summary
public int getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the configured phase.

Annotations
@Override
getWebSocketClientback to summary
public WebSocketClient getWebSocketClient()

Return the configured WebSocketClient.

isAutoStartupback to summary
public boolean isAutoStartup()

Overrides default org.springframework.context.SmartLifecycle.isAutoStartup.

Return the value for the 'autoStartup' property. If "true", this client will automatically start and stop the contained WebSocketClient.

Annotations
@Override
isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Doc from org.springframework.context.Lifecycle.isRunning.

Check whether this component is currently running.

In the case of a container, this will return true only if all components that apply are currently running.

Returns:boolean

whether the component is currently running

Annotations
@Override
processConnectHeadersback to summary
protected StompHeaders processConnectHeaders(StompHeaders connectHeaders)

Overrides org.springframework.messaging.simp.stomp.StompClientSupport.processConnectHeaders.

Doc from org.springframework.messaging.simp.stomp.StompClientSupport.processConnectHeaders.

Further initialize the StompHeaders, for example setting the heart-beat header if necessary.

Parameters
connectHeaders:StompHeaders

the headers to modify

Returns:StompHeaders

the modified headers

Annotations
@Override
setAutoStartupback to summary
public void setAutoStartup(boolean autoStartup)

Set whether to auto-start the contained WebSocketClient when the Spring context has been refreshed.

Default is "true".

setInboundMessageSizeLimitback to summary
public void setInboundMessageSizeLimit(int inboundMessageSizeLimit)

Configure the maximum size allowed for inbound STOMP message. Since a STOMP message can be received in multiple WebSocket messages, buffering may be required and this property determines the maximum buffer size per message.

By default this is set to 64 * 1024 (64K).

setPhaseback to summary
public void setPhase(int phase)

Specify the phase in which the WebSocket client should be started and subsequently closed. The startup order proceeds from lowest to highest, and the shutdown order is the reverse of that.

By default this is Integer.MAX_VALUE meaning that the WebSocket client is started as late as possible and stopped as soon as possible.

setTaskSchedulerback to summary
public void setTaskScheduler(TaskScheduler taskScheduler)

Overrides org.springframework.messaging.simp.stomp.StompClientSupport.setTaskScheduler.

Doc from org.springframework.messaging.simp.stomp.StompClientSupport.setTaskScheduler.

Configure a scheduler to use for heartbeats and for receipt tracking.

Note

Some transports have built-in support to work with heartbeats and therefore do not require a TaskScheduler. Receipts however, if needed, do require a TaskScheduler to be configured.

By default, this is not set.

Also automatically sets the defaultHeartbeat property to "10000,10000" if it is currently set to "0,0".

Annotations
@Override
startback to summary
public void start()

Implements org.springframework.context.Lifecycle.start.

Doc from org.springframework.context.Lifecycle.start.

Start this component.

Should not throw an exception if the component is already running.

In the case of a container, this will propagate the start signal to all components that apply.

Annotations
@Override
stopback to summary
public void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing SmartLifecycle and its stop(Runnable) variant when asynchronous stop behavior is necessary.

Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecycle beans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.

Should not throw an exception if the component is not running (not started yet).

In the case of a container, this will propagate the stop signal to all components that apply.

Annotations
@Override
org.springframework.web.socket.messaging back to summary

private Class WebSocketStompClient.StompWebSocketMessageCodec

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.messaging.WebSocketStompClient.StompWebSocketMessageCodec

Encode and decode STOMP WebSocket messages.

Field Summary

Modifier and TypeField and Description
private final BufferingStompDecoder
private static final StompDecoder
private static final StompEncoder

Constructor Summary

AccessConstructor and Description
public
StompWebSocketMessageCodec(int messageSizeLimit)

Method Summary

Modifier and TypeMethod and Description
public List<Message<byte[]>>
decode(WebSocketMessage<?> webSocketMessage)

public WebSocketMessage<?>
encode(Message<byte[]> message, Class<? extends WebSocketSession> sessionType)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferingDecoderback to summary
private final BufferingStompDecoder bufferingDecoder
DECODERback to summary
private static final StompDecoder DECODER
ENCODERback to summary
private static final StompEncoder ENCODER

Constructor Detail

StompWebSocketMessageCodecback to summary
public StompWebSocketMessageCodec(int messageSizeLimit)

Method Detail

decodeback to summary
public List<Message<byte[]>> decode(WebSocketMessage<?> webSocketMessage)
encodeback to summary
public WebSocketMessage<?> encode(Message<byte[]> message, Class<? extends WebSocketSession> sessionType)
org.springframework.web.socket.messaging back to summary

private Class WebSocketStompClient.WebSocketTcpConnectionHandlerAdapter

extends Object
implements BiConsumer<WebSocketSession, Throwable>, WebSocketHandler, TcpConnection<byte[]>
Class Inheritance
  • java.lang.Object
  • org.springframework.web.socket.messaging.WebSocketStompClient.WebSocketTcpConnectionHandlerAdapter
All Implemented Interfaces
org.springframework.messaging.tcp.TcpConnection, java.io.Closeable, java.lang.AutoCloseable, org.springframework.web.socket.WebSocketHandler, java.util.function.BiConsumer

Adapt WebSocket to the TcpConnectionHandler and TcpConnection contracts.

Field Summary

Modifier and TypeField and Description
private final WebSocketStompClient.StompWebSocketMessageCodec
private volatile long
private volatile long
private ScheduledFuture<?>
private volatile WebSocketSession
private final TcpConnectionHandler<byte[]>
private ScheduledFuture<?>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
accept(WebSocketSession
the first input argument
webSocketSession
,
Throwable
the second input argument
throwable
)

Implements java.util.function.BiConsumer.accept.

Performs this operation on the given arguments.

public void
afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred.

public void
afterConnectionEstablished(WebSocketSession session)

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.

private static void
private void
public void
public void
handleMessage(WebSocketSession session, WebSocketMessage<?> webSocketMessage)

Implements org.springframework.web.socket.WebSocketHandler.handleMessage.

Invoked when a new WebSocket message arrives.

public void
handleTransportError(WebSocketSession session, Throwable ex)

Implements org.springframework.web.socket.WebSocketHandler.handleTransportError.

Handle an error from the underlying WebSocket message transport.

public void
onReadInactivity(final Runnable
the task to invoke
runnable
,
final long
the amount of inactive time in milliseconds
duration
)

Implements org.springframework.messaging.tcp.TcpConnection.onReadInactivity.

Register a task to invoke after a period of read inactivity.

public void
onWriteInactivity(final Runnable
the task to invoke
runnable
,
final long
the amount of inactive time in milliseconds
duration
)

Implements org.springframework.messaging.tcp.TcpConnection.onWriteInactivity.

Register a task to invoke after a period of write inactivity.

public CompletableFuture<Void>
sendAsync(Message<byte[]>
the message
message
)

Implements org.springframework.messaging.tcp.TcpConnection.sendAsync.

Send the given message.

public boolean
supportsPartialMessages()

Implements org.springframework.web.socket.WebSocketHandler.supportsPartialMessages.

Whether the WebSocketHandler handles partial messages.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

codecback to summary
private final WebSocketStompClient.StompWebSocketMessageCodec codec
lastReadTimeback to summary
private volatile long lastReadTime
lastWriteTimeback to summary
private volatile long lastWriteTime
readInactivityFutureback to summary
private ScheduledFuture<?> readInactivityFuture
Annotations
@Nullable
sessionback to summary
private volatile WebSocketSession session
Annotations
@Nullable
stompSessionback to summary
private final TcpConnectionHandler<byte[]> stompSession
writeInactivityFutureback to summary
private ScheduledFuture<?> writeInactivityFuture
Annotations
@Nullable

Constructor Detail

WebSocketTcpConnectionHandlerAdapterback to summary
public WebSocketTcpConnectionHandlerAdapter(TcpConnectionHandler<byte[]> stompSession)

Method Detail

acceptback to summary
public void accept(WebSocketSession webSocketSession, Throwable throwable)

Implements java.util.function.BiConsumer.accept.

Doc from java.util.function.BiConsumer.accept.

Performs this operation on the given arguments.

Parameters
webSocketSession:WebSocketSession

the first input argument

throwable:Throwable

the second input argument

Annotations
@Override
afterConnectionClosedback to summary
public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Doc from org.springframework.web.socket.WebSocketHandler.afterConnectionClosed.

Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred. Although the session may technically still be open, depending on the underlying implementation, sending messages at this point is discouraged and most likely will not succeed.

Annotations
@Override
afterConnectionEstablishedback to summary
public void afterConnectionEstablished(WebSocketSession session)

Implements org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Doc from org.springframework.web.socket.WebSocketHandler.afterConnectionEstablished.

Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.

Annotations
@Override
cancelFutureback to summary
private static void cancelFuture(ScheduledFuture<?> future)
cancelInactivityTasksback to summary
private void cancelInactivityTasks()
closeback to summary
public void close()

Implements org.springframework.messaging.tcp.TcpConnection.close.

Doc from org.springframework.messaging.tcp.TcpConnection.close.

Close the connection.

Annotations
@Override
handleMessageback to summary
public void handleMessage(WebSocketSession session, WebSocketMessage<?> webSocketMessage)

Implements org.springframework.web.socket.WebSocketHandler.handleMessage.

Doc from org.springframework.web.socket.WebSocketHandler.handleMessage.

Invoked when a new WebSocket message arrives.

Annotations
@Override
handleTransportErrorback to summary
public void handleTransportError(WebSocketSession session, Throwable ex)

Implements org.springframework.web.socket.WebSocketHandler.handleTransportError.

Doc from org.springframework.web.socket.WebSocketHandler.handleTransportError.

Handle an error from the underlying WebSocket message transport.

Annotations
@Override
onReadInactivityback to summary
public void onReadInactivity(final Runnable runnable, final long duration)

Implements org.springframework.messaging.tcp.TcpConnection.onReadInactivity.

Doc from org.springframework.messaging.tcp.TcpConnection.onReadInactivity.

Register a task to invoke after a period of read inactivity.

Parameters
runnable:Runnable

the task to invoke

duration:long

the amount of inactive time in milliseconds

Annotations
@Override
onWriteInactivityback to summary
public void onWriteInactivity(final Runnable runnable, final long duration)

Implements org.springframework.messaging.tcp.TcpConnection.onWriteInactivity.

Doc from org.springframework.messaging.tcp.TcpConnection.onWriteInactivity.

Register a task to invoke after a period of write inactivity.

Parameters
runnable:Runnable

the task to invoke

duration:long

the amount of inactive time in milliseconds

Annotations
@Override
sendAsyncback to summary
public CompletableFuture<Void> sendAsync(Message<byte[]> message)

Implements org.springframework.messaging.tcp.TcpConnection.sendAsync.

Doc from org.springframework.messaging.tcp.TcpConnection.sendAsync.

Send the given message.

Parameters
message:Message<byte[]>

the message

Returns:CompletableFuture<Void>

a CompletableFuture that can be used to determine when and if the message was successfully sent

Annotations
@Override
supportsPartialMessagesback to summary
public boolean supportsPartialMessages()

Implements org.springframework.web.socket.WebSocketHandler.supportsPartialMessages.

Doc from org.springframework.web.socket.WebSocketHandler.supportsPartialMessages.

Whether the WebSocketHandler handles partial messages. If this flag is set to true and the underlying WebSocket server supports partial messages, then a large WebSocket message, or one of an unknown size may be split and maybe received over multiple calls to handleMessage(WebSocketSession, WebSocketMessage). The flag org.springframework.web.socket.WebSocketMessage#isLast() indicates if the message is partial and whether it is the last part.

Annotations
@Override
updateLastWriteTimeback to summary
private void updateLastWriteTime()