public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession
DISCONNECTED_CLIENT_LOG_CATEGORY, disconnectedClientLogger, logger, responseLock
Constructor and Description |
---|
AbstractHttpSockJsSession(String id,
SockJsServiceConfig config,
WebSocketHandler wsHandler,
Map<String,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()
Called when the connection is active and ready to write to the response.
|
String |
getAcceptedProtocol()
Return the selected sub-protocol to use.
|
int |
getBinaryMessageSizeLimit()
Get the configured maximum size for an incoming binary message.
|
List<WebSocketExtension> |
getExtensions()
Determine the negotiated extensions.
|
HttpHeaders |
getHandshakeHeaders()
Return the headers used in the handshake request (never
null ). |
InetSocketAddress |
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.
|
Principal |
getPrincipal()
Return a
Principal instance containing the name
of the authenticated user. |
InetSocketAddress |
getRemoteAddress()
Return the address of the remote client.
|
int |
getTextMessageSizeLimit()
Get the configured maximum size for an incoming text message.
|
URI |
getUri()
Return the URI used to open the WebSocket connection.
|
void |
handleInitialRequest(ServerHttpRequest request,
ServerHttpResponse response,
SockJsFrameFormat frameFormat)
Handle the first request for receiving messages on a SockJS HTTP transport
based session.
|
protected abstract void |
handleRequestInternal(ServerHttpRequest request,
ServerHttpResponse response,
boolean initialRequest)
Invoked when a SockJS transport request is received.
|
void |
handleSuccessiveRequest(ServerHttpRequest request,
ServerHttpResponse response,
SockJsFrameFormat frameFormat)
Handle all requests, except the first one, to receive messages on a SockJS
HTTP transport based session.
|
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(String message) |
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.
|
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 |
writeFrameInternal(SockJsFrame frame) |
cancelHeartbeat, close, close, delegateConnectionClosed, delegateConnectionEstablished, delegateError, delegateMessages, disableHeartbeat, getAttributes, getId, getMessageCodec, getSockJsServiceConfig, getTimeSinceLastActive, isClosed, isNew, isOpen, scheduleHeartbeat, sendHeartbeat, sendMessage, toString, tryCloseWithSockJsTransportError, updateLastActiveTime, writeFrame
public AbstractHttpSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler wsHandler, Map<String,Object> attributes)
public URI getUri()
WebSocketSession
public HttpHeaders getHandshakeHeaders()
WebSocketSession
null
).@Nullable public Principal getPrincipal()
WebSocketSession
Principal
instance containing the name
of the authenticated user.
If the user has not been authenticated, the method returns null
.
@Nullable public InetSocketAddress getLocalAddress()
WebSocketSession
@Nullable public InetSocketAddress getRemoteAddress()
WebSocketSession
public void setAcceptedProtocol(@Nullable String protocol)
protocol
- the sub-protocol to set@Nullable public String getAcceptedProtocol()
null
if no protocol
was specified or negotiated successfullyprotected Queue<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 List<WebSocketExtension> getExtensions()
WebSocketSession
public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException
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.
request
- the current requestresponse
- the current responseframeFormat
- the transport-specific SocksJS frame format to useSockJsException
public void handleSuccessiveRequest(ServerHttpRequest request, ServerHttpResponse response, SockJsFrameFormat frameFormat) throws SockJsException
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.
request
- the current requestresponse
- the current responseframeFormat
- the transport-specific SocksJS frame format to useSockJsException
protected abstract void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, boolean initialRequest) throws IOException
request
- the current requestresponse
- the current responseinitialRequest
- whether it is the first request for the sessionIOException
protected final void sendMessageInternal(String message) throws SockJsTransportFailureException
sendMessageInternal
in class AbstractSockJsSession
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 IOException
writeFrameInternal
in class AbstractSockJsSession
IOException