Top Description Fields Constructors Methods
org.springframework.web.socket.sockjs.transport.session

public abstract Class AbstractHttpSockJsSession

extends AbstractSockJsSession
Class Inheritance
Known Direct Subclasses
org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession, org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession
Imports
java.io.IOException, java.net.InetSocketAddress, .URI, java.security.Principal, java.util.Collections, .List, .Map, .Queue, java.util.concurrent.LinkedBlockingQueue, jakarta.servlet.ServletRequest, org.springframework.http.HttpHeaders, org.springframework.http.server.ServerHttpAsyncRequestControl, .ServerHttpRequest, .ServerHttpResponse, .ServletServerHttpRequest, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.filter.ShallowEtagHeaderFilter, org.springframework.web.socket.CloseStatus, .WebSocketExtension, .WebSocketHandler, org.springframework.web.socket.sockjs.SockJsException, .SockJsTransportFailureException, org.springframework.web.socket.sockjs.frame.SockJsFrame, .SockJsFrameFormat, org.springframework.web.socket.sockjs.transport.SockJsServiceConfig

An abstract base class for use with HTTP transport SockJS sessions.
Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
private volatile String
private volatile ServerHttpAsyncRequestControl
private volatile SockJsFrameFormat
private volatile HttpHeaders
private volatile InetSocketAddress
private final Queue<String>
private volatile Principal
private boolean
private volatile InetSocketAddress
private volatile ServerHttpResponse
private volatile URI
Inherited from org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession:
DISCONNECTED_CLIENT_LOG_CATEGORYloggerresponseLock

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
protected void
disconnect(CloseStatus status)

Implements abstract org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.disconnect.

Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.

protected abstract void
flushCache()

Called when the connection is active and ready to write to the response.

public String
public int
getBinaryMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getBinaryMessageSizeLimit.

Get the configured maximum size for an incoming binary message.

public List<WebSocketExtension>
getExtensions()

Implements org.springframework.web.socket.WebSocketSession.getExtensions.

Determine the negotiated extensions.

public HttpHeaders
getHandshakeHeaders()

Implements org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Return the headers used in the handshake request (never null).

public InetSocketAddress
getLocalAddress()

Implements org.springframework.web.socket.WebSocketSession.getLocalAddress.

Return the address on which the request was received.

protected Queue<String>
getMessageCache()

Return the SockJS buffer for messages stored transparently between polling requests.

public Principal
getPrincipal()

Implements org.springframework.web.socket.WebSocketSession.getPrincipal.

Return a java.security.Principal instance containing the name of the authenticated user.

public InetSocketAddress
getRemoteAddress()

Implements org.springframework.web.socket.WebSocketSession.getRemoteAddress.

Return the address of the remote client.

public int
getTextMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getTextMessageSizeLimit.

Get the configured maximum size for an incoming text message.

public URI
getUri()

Implements org.springframework.web.socket.WebSocketSession.getUri.

Return the URI used to open the WebSocket connection.

public void
handleInitialRequest(ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
,
SockJsFrameFormat
the transport-specific SocksJS frame format to use
frameFormat
)

Handle the first request for receiving messages on a SockJS HTTP transport based session.

protected abstract void
handleRequestInternal(ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
,
boolean
whether it is the first request for the session
initialRequest
)

Invoked when a SockJS transport request is received.

public void
handleSuccessiveRequest(ServerHttpRequest
the current request
request
,
ServerHttpResponse
the current response
response
,
SockJsFrameFormat
the transport-specific SocksJS frame format to use
frameFormat
)

Handle all requests, except the first one, to receive messages on a SockJS HTTP transport based session.

public boolean
isActive()

Implements abstract org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.isActive.

Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through.

protected void
protected final void
public void
setAcceptedProtocol(String
the sub-protocol to set
protocol
)

Unlike WebSocket where sub-protocol negotiation is part of the initial handshake, in HTTP transports the same negotiation must be emulated and the selected protocol set through this setter.

public void
setBinaryMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setBinaryMessageSizeLimit.

Configure the maximum size for an incoming binary message.

public void
setTextMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setTextMessageSizeLimit.

Configure the maximum size for an incoming text message.

protected void
Inherited from org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession:
cancelHeartbeatcloseclosedelegateConnectionCloseddelegateConnectionEstablisheddelegateErrordelegateMessagesdisableHeartbeatgetAttributesgetIdgetMessageCodecgetSockJsServiceConfiggetTimeSinceLastActiveisClosedisNewisOpenscheduleHeartbeatsendHeartbeatsendMessagetoStringtryCloseWithSockJsTransportErrorupdateLastActiveTimewriteFrame

Field Detail

acceptedProtocolback to summary
private volatile String acceptedProtocol
Annotations
@Nullable
asyncRequestControlback to summary
private volatile ServerHttpAsyncRequestControl asyncRequestControl
Annotations
@Nullable
frameFormatback to summary
private volatile SockJsFrameFormat frameFormat
Annotations
@Nullable
handshakeHeadersback to summary
private volatile HttpHeaders handshakeHeaders
Annotations
@Nullable
localAddressback to summary
private volatile InetSocketAddress localAddress
Annotations
@Nullable
messageCacheback to summary
private final Queue<String> messageCache
principalback to summary
private volatile Principal principal
Annotations
@Nullable
readyToSendback to summary
private boolean readyToSend
remoteAddressback to summary
private volatile InetSocketAddress remoteAddress
Annotations
@Nullable
responseback to summary
private volatile ServerHttpResponse response
Annotations
@Nullable
uriback to summary
private volatile URI uri
Annotations
@Nullable

Constructor Detail

AbstractHttpSockJsSessionback to summary
public AbstractHttpSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler wsHandler, Map<String, Object> attributes)

Method Detail

disableShallowEtagHeaderFilterback to summary
private void disableShallowEtagHeaderFilter(ServerHttpRequest request)
disconnectback to summary
protected void disconnect(CloseStatus status)

Implements abstract org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.disconnect.

Doc from org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.disconnect.

Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.

Annotations
@Override
flushCacheback to summary
protected abstract void flushCache() throws SockJsTransportFailureException

Called when the connection is active and ready to write to the response. Subclasses should only call this method from a method where the "responseLock" is acquired.

getAcceptedProtocolback to summary
public String getAcceptedProtocol()

Implements org.springframework.web.socket.WebSocketSession.getAcceptedProtocol.

Return the selected sub-protocol to use.

Returns:String

Doc from org.springframework.web.socket.WebSocketSession.getAcceptedProtocol.

the protocol identifier, or null if no protocol was specified or negotiated successfully

Annotations
@Override
@Nullable
getBinaryMessageSizeLimitback to summary
public int getBinaryMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getBinaryMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.getBinaryMessageSizeLimit.

Get the configured maximum size for an incoming binary message.

Annotations
@Override
getExtensionsback to summary
public List<WebSocketExtension> getExtensions()

Implements org.springframework.web.socket.WebSocketSession.getExtensions.

Doc from org.springframework.web.socket.WebSocketSession.getExtensions.

Determine the negotiated extensions.

Returns:List<WebSocketExtension>

the list of extensions, or an empty list if no extension was specified or negotiated successfully

Annotations
@Override
getHandshakeHeadersback to summary
public HttpHeaders getHandshakeHeaders()

Implements org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Doc from org.springframework.web.socket.WebSocketSession.getHandshakeHeaders.

Return the headers used in the handshake request (never null).

Annotations
@Override
getLocalAddressback to summary
public InetSocketAddress getLocalAddress()

Implements org.springframework.web.socket.WebSocketSession.getLocalAddress.

Doc from org.springframework.web.socket.WebSocketSession.getLocalAddress.

Return the address on which the request was received.

Annotations
@Override
@Nullable
getMessageCacheback to summary
protected Queue<String> getMessageCache()

Return the SockJS buffer for messages stored transparently between polling requests. If the polling request takes longer than 5 seconds, the session is closed.

See Also
org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService
getPrincipalback to summary
public Principal getPrincipal()

Implements org.springframework.web.socket.WebSocketSession.getPrincipal.

Doc from org.springframework.web.socket.WebSocketSession.getPrincipal.

Return a java.security.Principal instance containing the name of the authenticated user.

If the user has not been authenticated, the method returns null.

Annotations
@Override
@Nullable
getRemoteAddressback to summary
public InetSocketAddress getRemoteAddress()

Implements org.springframework.web.socket.WebSocketSession.getRemoteAddress.

Doc from org.springframework.web.socket.WebSocketSession.getRemoteAddress.

Return the address of the remote client.

Annotations
@Override
@Nullable
getTextMessageSizeLimitback to summary
public int getTextMessageSizeLimit()

Implements org.springframework.web.socket.WebSocketSession.getTextMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.getTextMessageSizeLimit.

Get the configured maximum size for an incoming text message.

Annotations
@Override
getUriback to summary
public URI getUri()

Implements org.springframework.web.socket.WebSocketSession.getUri.

Doc from org.springframework.web.socket.WebSocketSession.getUri.

Return the URI used to open the WebSocket connection.

Annotations
@Override
handleInitialRequestback to summary
public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException

Handle the first request for receiving messages on a SockJS HTTP transport based session.

Long polling-based transports (e.g. "xhr", "jsonp") complete the request after writing the open frame. Streaming-based transports ("xhr_streaming", "eventsource", and "htmlfile") leave the response open longer for further streaming of message frames but will also close it eventually after some amount of data has been sent.

Parameters
request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

frameFormat:SockJsFrameFormat

the transport-specific SocksJS frame format to use

handleRequestInternalback to summary
protected abstract void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, boolean initialRequest) throws IOException

Invoked when a SockJS transport request is received.

Parameters
request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

initialRequest:boolean

whether it is the first request for the session

handleSuccessiveRequestback to summary
public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException

Handle all requests, except the first one, to receive messages on a SockJS HTTP transport based session.

Long polling-based transports (e.g. "xhr", "jsonp") complete the request after writing any buffered message frames (or the next one). Streaming-based transports ("xhr_streaming", "eventsource", and "htmlfile") leave the response open longer for further streaming of message frames but will also close it eventually after some amount of data has been sent.

Parameters
request:ServerHttpRequest

the current request

response:ServerHttpResponse

the current response

frameFormat:SockJsFrameFormat

the transport-specific SocksJS frame format to use

isActiveback to summary
public boolean isActive()

Implements abstract org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.isActive.

Doc from org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.isActive.

Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through. During this "downtime" the session is still open but inactive and unable to send messages and therefore has to buffer them temporarily. A WebSocket session by contrast is stateful and remain active until closed.

Annotations
@Override
resetRequestback to summary
protected void resetRequest()
sendMessageInternalback to summary
protected final void sendMessageInternal(String message) throws SockJsTransportFailureException

Implements abstract org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendMessageInternal.

Annotations
@Override
setAcceptedProtocolback to summary
public void setAcceptedProtocol(String protocol)

Unlike WebSocket where sub-protocol negotiation is part of the initial handshake, in HTTP transports the same negotiation must be emulated and the selected protocol set through this setter.

Parameters
protocol:String

the sub-protocol to set

setBinaryMessageSizeLimitback to summary
public void setBinaryMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setBinaryMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.setBinaryMessageSizeLimit.

Configure the maximum size for an incoming binary message.

Annotations
@Override
setTextMessageSizeLimitback to summary
public void setTextMessageSizeLimit(int messageSizeLimit)

Implements org.springframework.web.socket.WebSocketSession.setTextMessageSizeLimit.

Doc from org.springframework.web.socket.WebSocketSession.setTextMessageSizeLimit.

Configure the maximum size for an incoming text message.

Annotations
@Override
writeFrameInternalback to summary
protected void writeFrameInternal(SockJsFrame frame) throws IOException

Implements abstract org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.writeFrameInternal.

Annotations
@Override