This commit is contained in:
Rossen Stoyanchev 2014-03-23 01:01:39 -04:00
parent cbd5af3a03
commit 7651f83b4c
1 changed files with 39 additions and 28 deletions

View File

@ -48,17 +48,6 @@ import org.springframework.web.socket.sockjs.transport.SockJsServiceConfig;
*/
public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
private final Queue<String> messageCache;
private volatile ServerHttpResponse response;
private volatile ServerHttpAsyncRequestControl asyncRequestControl;
private volatile SockJsFrameFormat frameFormat;
private volatile boolean requestInitialized;
private volatile URI uri;
@ -73,6 +62,18 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
private volatile String acceptedProtocol;
private volatile ServerHttpResponse response;
private volatile ServerHttpAsyncRequestControl asyncRequestControl;
private volatile SockJsFrameFormat frameFormat;
private volatile boolean requestInitialized;
private final Queue<String> messageCache;
public AbstractHttpSockJsSession(String id, SockJsServiceConfig config,
WebSocketHandler wsHandler, Map<String, Object> attributes) {
@ -107,9 +108,9 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
}
/**
* 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.
* 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.
* @param protocol the sub-protocol to set
*/
public void setAcceptedProtocol(String protocol) {
@ -123,6 +124,30 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
return this.acceptedProtocol;
}
/**
* Return response for the current request, or {@code null} if between requests.
*/
protected ServerHttpResponse getResponse() {
return this.response;
}
/**
* Return the SockJS buffer for messages stored transparently between polling
* requests. If the polling request takes longer than 5 seconds, the session
* will be closed.
*
* @see org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService
*/
protected Queue<String> getMessageCache() {
return this.messageCache;
}
@Override
public boolean isActive() {
ServerHttpAsyncRequestControl control = this.asyncRequestControl;
return (control != null && !control.isCompleted());
}
@Override
public List<WebSocketExtension> getExtensions() {
return Collections.emptyList();
@ -246,20 +271,6 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
}
}
@Override
public boolean isActive() {
ServerHttpAsyncRequestControl control = this.asyncRequestControl;
return (control != null && !control.isCompleted());
}
protected Queue<String> getMessageCache() {
return this.messageCache;
}
protected ServerHttpResponse getResponse() {
return this.response;
}
@Override
protected final void sendMessageInternal(String message) throws SockJsTransportFailureException {
this.messageCache.add(message);