public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
acceptedProtocol |
private ServerHttpAsyncRequestControl |
asyncRequestControl |
private SockJsFrameFormat |
frameFormat |
private HttpHeaders |
handshakeHeaders |
private java.net.InetSocketAddress |
localAddress |
private java.util.Queue<java.lang.String> |
messageCache |
private java.security.Principal |
principal |
private java.net.InetSocketAddress |
remoteAddress |
private boolean |
requestInitialized |
private ServerHttpResponse |
response |
private java.net.URI |
uri |
DISCONNECTED_CLIENT_LOG_CATEGORY, disconnectedClientLogger, logger
Constructor and Description |
---|
AbstractHttpSockJsSession(java.lang.String id,
SockJsServiceConfig config,
WebSocketHandler wsHandler,
java.util.Map<java.lang.String,java.lang.Object> attributes) |
Modifier and Type | Method and Description |
---|---|
protected void |
disconnect(CloseStatus status)
Actually close the underlying WebSocket session or in the case of HTTP
transports complete the underlying request.
|
protected abstract void |
flushCache()
Only called if the connection is currently active
|
java.lang.String |
getAcceptedProtocol()
Return the selected sub-protocol to use.
|
int |
getBinaryMessageSizeLimit()
Get the configured maximum size for an incoming binary message.
|
java.util.List<WebSocketExtension> |
getExtensions()
Return the negotiated extensions or
null if none was specified or
negotiated successfully. |
HttpHeaders |
getHandshakeHeaders()
Return the headers used in the handshake request.
|
java.net.InetSocketAddress |
getLocalAddress()
Return the address on which the request was received.
|
protected java.util.Queue<java.lang.String> |
getMessageCache()
Return the SockJS buffer for messages stored transparently between polling
requests.
|
java.security.Principal |
getPrincipal()
Return a
Principal instance containing the name of the
authenticated user. |
java.net.InetSocketAddress |
getRemoteAddress()
Return the address of the remote client.
|
protected ServerHttpResponse |
getResponse()
Return response for the current request, or
null if between requests. |
int |
getTextMessageSizeLimit()
Get the configured maximum size for an incoming text message.
|
java.net.URI |
getUri()
Return the URI used to open the WebSocket connection.
|
void |
handleInitialRequest(ServerHttpRequest request,
ServerHttpResponse response,
SockJsFrameFormat frameFormat)
Handle the first HTTP request, i.e.
|
void |
handleSuccessiveRequest(ServerHttpRequest request,
ServerHttpResponse response,
SockJsFrameFormat frameFormat)
Handle all HTTP requests part of the same SockJS session except for the very
first, initial request.
|
private void |
initRequest(ServerHttpRequest request,
ServerHttpResponse response,
SockJsFrameFormat frameFormat) |
boolean |
isActive()
Polling and Streaming sessions periodically close the current HTTP request and
wait for the next request to come through.
|
protected void |
resetRequest() |
protected void |
sendMessageInternal(java.lang.String message) |
void |
setAcceptedProtocol(java.lang.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.
|
void |
setBinaryMessageSizeLimit(int messageSizeLimit)
Configure the maximum size for an incoming binary message.
|
void |
setTextMessageSizeLimit(int messageSizeLimit)
Configure the maximum size for an incoming text message.
|
protected void |
startAsyncRequest() |
private void |
tryFlushCache() |
protected void |
writeFrameInternal(SockJsFrame frame) |
protected void |
writePrelude(ServerHttpRequest request,
ServerHttpResponse response) |
cancelHeartbeat, close, close, delegateConnectionClosed, delegateConnectionEstablished, delegateError, delegateMessages, disableHeartbeat, getAttributes, getId, getSockJsServiceConfig, getTimeSinceLastActive, isClosed, isNew, isOpen, scheduleHeartbeat, sendHeartbeat, sendMessage, toString, tryCloseWithSockJsTransportError, updateLastActiveTime, writeFrame
private volatile java.net.URI uri
private volatile HttpHeaders handshakeHeaders
private volatile java.security.Principal principal
private volatile java.net.InetSocketAddress localAddress
private volatile java.net.InetSocketAddress remoteAddress
private volatile java.lang.String acceptedProtocol
private volatile ServerHttpResponse response
private volatile ServerHttpAsyncRequestControl asyncRequestControl
private volatile SockJsFrameFormat frameFormat
private volatile boolean requestInitialized
private final java.util.Queue<java.lang.String> messageCache
public AbstractHttpSockJsSession(java.lang.String id, SockJsServiceConfig config, WebSocketHandler wsHandler, java.util.Map<java.lang.String,java.lang.Object> attributes)
public java.net.URI getUri()
WebSocketSession
public HttpHeaders getHandshakeHeaders()
WebSocketSession
public java.security.Principal getPrincipal()
WebSocketSession
Principal
instance containing the name of the
authenticated user. If the user has not been authenticated, the method returns
null
.public java.net.InetSocketAddress getLocalAddress()
WebSocketSession
public java.net.InetSocketAddress getRemoteAddress()
WebSocketSession
public void setAcceptedProtocol(java.lang.String protocol)
protocol
- the sub-protocol to setpublic java.lang.String getAcceptedProtocol()
protected ServerHttpResponse getResponse()
null
if between requests.protected java.util.Queue<java.lang.String> getMessageCache()
TransportHandlingSockJsService
public boolean isActive()
AbstractSockJsSession
isActive
in class AbstractSockJsSession
public void setTextMessageSizeLimit(int messageSizeLimit)
WebSocketSession
public int getTextMessageSizeLimit()
WebSocketSession
public void setBinaryMessageSizeLimit(int messageSizeLimit)
WebSocketSession
public int getBinaryMessageSizeLimit()
WebSocketSession
public java.util.List<WebSocketExtension> getExtensions()
WebSocketSession
null
if none was specified or
negotiated successfully.public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException
The "xhr" and "jsonp" (polling-based) transports completes the initial request as soon as the open frame is sent. Following that the client should start a successive polling request within the same SockJS session.
The "xhr_streaming", "eventsource", and "htmlfile" transports are streaming based and will leave the initial request open in order to stream one or more messages. However, even streaming based transports eventually recycle the long running request, after a certain number of bytes have been streamed (128K by default), and allow the client to start a successive request within the same SockJS session.
request
- the current requestresponse
- the current responseframeFormat
- the transport-specific SocksJS frame format to useSockJsException
handleSuccessiveRequest(org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse, org.springframework.web.socket.sockjs.frame.SockJsFrameFormat)
private void initRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat)
protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) throws java.io.IOException
java.io.IOException
public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException
The "xhr" and "jsonp" (polling-based) transports completes the request when the next message is sent, which could be an array of messages cached during the time between successive requests, or it could be a heartbeat message sent if no other messages were sent (by default within 25 seconds).
The "xhr_streaming", "eventsource", and "htmlfile" transports are streaming based and will leave the request open longer in order to stream messages over a period of time. However, even streaming based transports eventually recycle the long running request, after a certain number of bytes have been streamed (128K by default), and allow the client to start a successive request within the same SockJS session.
request
- the current requestresponse
- the current responseframeFormat
- the transport-specific SocksJS frame format to useSockJsException
handleInitialRequest(org.springframework.http.server.ServerHttpRequest, org.springframework.http.server.ServerHttpResponse, org.springframework.web.socket.sockjs.frame.SockJsFrameFormat)
protected void startAsyncRequest() throws SockJsException
SockJsException
protected final void sendMessageInternal(java.lang.String message) throws SockJsTransportFailureException
sendMessageInternal
in class AbstractSockJsSession
SockJsTransportFailureException
private void tryFlushCache() throws SockJsTransportFailureException
SockJsTransportFailureException
protected abstract void flushCache() throws SockJsTransportFailureException
SockJsTransportFailureException
protected void disconnect(CloseStatus status)
AbstractSockJsSession
disconnect
in class AbstractSockJsSession
protected void resetRequest()
protected void writeFrameInternal(SockJsFrame frame) throws java.io.IOException
writeFrameInternal
in class AbstractSockJsSession
java.io.IOException