diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java index cdd15fa51d9..67725e2f7e8 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java @@ -48,17 +48,6 @@ import org.springframework.web.socket.sockjs.transport.SockJsServiceConfig; */ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession { - private final Queue 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 messageCache; + + public AbstractHttpSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler wsHandler, Map 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 getMessageCache() { + return this.messageCache; + } + + @Override + public boolean isActive() { + ServerHttpAsyncRequestControl control = this.asyncRequestControl; + return (control != null && !control.isCompleted()); + } + @Override public List 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 getMessageCache() { - return this.messageCache; - } - - protected ServerHttpResponse getResponse() { - return this.response; - } - @Override protected final void sendMessageInternal(String message) throws SockJsTransportFailureException { this.messageCache.add(message);