Top Description Fields Constructors Methods
org.springframework.web.socket.config.annotation

public Class WebSocketTransportRegistration

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .List, org.springframework.lang.Nullable, org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory

Configure the processing of messages received from and sent to WebSocket clients.
Author
Rossen Stoyanchev
Since
4.0.3

Field Summary

Modifier and TypeField and Description
private final List<WebSocketHandlerDecoratorFactory>
private Integer
private Integer
private Integer
private Integer

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public WebSocketTransportRegistration
addDecoratorFactory(WebSocketHandlerDecoratorFactory factory)

Add a factory that to decorate the handler used to process WebSocket messages.

protected List<WebSocketHandlerDecoratorFactory>
protected Integer
getMessageSizeLimit()

Protected accessor for internal use.

protected Integer
getSendBufferSizeLimit()

Protected accessor for internal use.

protected Integer
getSendTimeLimit()

Protected accessor for internal use.

protected Integer
getTimeToFirstMessage()

Protected accessor for internal use.

public WebSocketTransportRegistration
setDecoratorFactories(WebSocketHandlerDecoratorFactory... factories)

Configure one or more factories to decorate the handler used to process WebSocket messages.

public WebSocketTransportRegistration
setMessageSizeLimit(int messageSizeLimit)

Configure the maximum size of an inbound sub-protocol message, such as a STOMP frame which may be aggregated from multiple WebSocket messages.

public WebSocketTransportRegistration
setSendBufferSizeLimit(int
the maximum number of bytes to buffer when sending messages; if the value is less than or equal to 0 then buffering is effectively disabled.
sendBufferSizeLimit
)

Configure the maximum amount of data to buffer when sending messages to a WebSocket session, or an HTTP response when SockJS fallback option are in use.

public WebSocketTransportRegistration
setSendTimeLimit(int
the timeout value in milliseconds; the value must be greater than 0, otherwise it is ignored.
timeLimit
)

Configure a time limit (in milliseconds) for the maximum amount of a time allowed when sending messages to a WebSocket session or writing to an HTTP response when SockJS fallback option are in use.

public WebSocketTransportRegistration
setTimeToFirstMessage(int
the maximum time allowed in milliseconds
timeToFirstMessage
)

Set the maximum time allowed in milliseconds after the WebSocket connection is established and before the first sub-protocol message is received.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decoratorFactoriesback to summary
private final List<WebSocketHandlerDecoratorFactory> decoratorFactories
messageSizeLimitback to summary
private Integer messageSizeLimit
Annotations
@Nullable
sendBufferSizeLimitback to summary
private Integer sendBufferSizeLimit
Annotations
@Nullable
sendTimeLimitback to summary
private Integer sendTimeLimit
Annotations
@Nullable
timeToFirstMessageback to summary
private Integer timeToFirstMessage
Annotations
@Nullable

Constructor Detail

WebSocketTransportRegistrationback to summary
public WebSocketTransportRegistration()

Method Detail

addDecoratorFactoryback to summary
public WebSocketTransportRegistration addDecoratorFactory(WebSocketHandlerDecoratorFactory factory)

Add a factory that to decorate the handler used to process WebSocket messages. This may be useful for some advanced use cases, for example to allow Spring Security to forcibly close the WebSocket session when the corresponding HTTP session expires.

Since
4.1.2
getDecoratorFactoriesback to summary
protected List<WebSocketHandlerDecoratorFactory> getDecoratorFactories()
getMessageSizeLimitback to summary
protected Integer getMessageSizeLimit()

Protected accessor for internal use.

Annotations
@Nullable
getSendBufferSizeLimitback to summary
protected Integer getSendBufferSizeLimit()

Protected accessor for internal use.

Annotations
@Nullable
getSendTimeLimitback to summary
protected Integer getSendTimeLimit()

Protected accessor for internal use.

Annotations
@Nullable
getTimeToFirstMessageback to summary
protected Integer getTimeToFirstMessage()

Protected accessor for internal use.

Annotations
@Nullable
setDecoratorFactoriesback to summary
public WebSocketTransportRegistration setDecoratorFactories(WebSocketHandlerDecoratorFactory... factories)

Configure one or more factories to decorate the handler used to process WebSocket messages. This may be useful in some advanced use cases, for example to allow Spring Security to forcibly close the WebSocket session when the corresponding HTTP session expires.

Since
4.1.2
setMessageSizeLimitback to summary
public WebSocketTransportRegistration setMessageSizeLimit(int messageSizeLimit)

Configure the maximum size of an inbound sub-protocol message, such as a STOMP frame which may be aggregated from multiple WebSocket messages.

The default value is 64K (i.e. 64 * 1024).

Note

This is not the same as the size of an individual WebSocket message which needs to be configured at the WebSocket server level instead. See the reference documentation for details.

setSendBufferSizeLimitback to summary
public WebSocketTransportRegistration setSendBufferSizeLimit(int sendBufferSizeLimit)

Configure the maximum amount of data to buffer when sending messages to a WebSocket session, or an HTTP response when SockJS fallback option are in use.

In general WebSocket servers expect that messages to a single WebSocket session are sent from a single thread at a time. This is automatically guaranteed when using @EnableWebSocketMessageBroker configuration. If message sending is slow, or at least slower than rate of messages sending, subsequent messages are buffered until either the sendTimeLimit or the sendBufferSizeLimit are reached at which point the session state is cleared and an attempt is made to close the session.

Note

that closing the session may not succeed in actually closing the physical socket and may also hang. This is true especially when using blocking IO such as the BIO connector in Tomcat configured by default on Tomcat 7. Therefore, it is recommended to ensure the server is using non-blocking IO such as Tomcat's NIO connector used by default on Tomcat 8. If you must use blocking IO consider customizing OS-level TCP settings, for example /proc/sys/net/ipv4/tcp_retries2 on Linux.

The default value is 512K (i.e. 512 * 1024).

Parameters
sendBufferSizeLimit:int

the maximum number of bytes to buffer when sending messages; if the value is less than or equal to 0 then buffering is effectively disabled.

setSendTimeLimitback to summary
public WebSocketTransportRegistration setSendTimeLimit(int timeLimit)

Configure a time limit (in milliseconds) for the maximum amount of a time allowed when sending messages to a WebSocket session or writing to an HTTP response when SockJS fallback option are in use.

In general WebSocket servers expect that messages to a single WebSocket session are sent from a single thread at a time. This is automatically guaranteed when using @EnableWebSocketMessageBroker configuration. If message sending is slow, or at least slower than rate of messages sending, subsequent messages are buffered until either the sendTimeLimit or the sendBufferSizeLimit are reached at which point the session state is cleared and an attempt is made to close the session.

Note

that the session time limit is checked only on attempts to send additional messages. So if only a single message is sent and it hangs, the session will not time out until another message is sent or the underlying physical socket times out. So this is not a replacement for WebSocket server or HTTP connection timeout but is rather intended to control the extent of buffering of unsent messages.

Note

that closing the session may not succeed in actually closing the physical socket and may also hang. This is true especially when using blocking IO such as the BIO connector in Tomcat that is used by default on Tomcat 7. Therefore, it is recommended to ensure the server is using non-blocking IO such as Tomcat's NIO connector that is used by default on Tomcat 8. If you must use blocking IO consider customizing OS-level TCP settings, for example /proc/sys/net/ipv4/tcp_retries2 on Linux.

The default value is 10 seconds (i.e. 10 * 1000).

Parameters
timeLimit:int

the timeout value in milliseconds; the value must be greater than 0, otherwise it is ignored.

setTimeToFirstMessageback to summary
public WebSocketTransportRegistration setTimeToFirstMessage(int timeToFirstMessage)

Set the maximum time allowed in milliseconds after the WebSocket connection is established and before the first sub-protocol message is received.

This handler is for WebSocket connections that use a sub-protocol. Therefore, we expect the client to send at least one sub-protocol message in the beginning, or else we assume the connection isn't doing well, e.g. proxy issue, slow network, and can be closed.

By default this is set to 60,000 (1 minute).

Parameters
timeToFirstMessage:int

the maximum time allowed in milliseconds

Since
5.1