Deprecate writePrelude in AbstractHttpSockJsSession
A logical follow-up on commit 43d937, this change also removes (or rather deprecates for now) writePrelude that is only of concern to streaming SockJS session implementations. Issue: SPR-12427
This commit is contained in:
parent
43d93712f1
commit
ab629a0e26
|
|
@ -16,12 +16,10 @@
|
|||
|
||||
package org.springframework.web.socket.sockjs.transport.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.frame.DefaultSockJsFrameFormat;
|
||||
import org.springframework.web.socket.sockjs.frame.SockJsFrameFormat;
|
||||
|
|
@ -70,10 +68,8 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
response.getBody().write('\r');
|
||||
response.getBody().write('\n');
|
||||
response.flush();
|
||||
protected byte[] getPrelude(ServerHttpRequest request) {
|
||||
return new byte[] { '\r', '\n' };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,18 +134,11 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) {
|
||||
protected byte[] getPrelude(ServerHttpRequest request) {
|
||||
// We already validated the parameter above...
|
||||
String callback = getCallbackParam(request);
|
||||
String html = String.format(PARTIAL_HTML_CONTENT, callback);
|
||||
try {
|
||||
response.getBody().write(html.getBytes(UTF8_CHARSET));
|
||||
response.flush();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
tryCloseWithSockJsTransportError(ex, CloseStatus.SERVER_ERROR);
|
||||
throw new SockJsTransportFailureException("Failed to write HTML content", getId(), ex);
|
||||
}
|
||||
return html.getBytes(UTF8_CHARSET);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,10 @@
|
|||
|
||||
package org.springframework.web.socket.sockjs.transport.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.frame.DefaultSockJsFrameFormat;
|
||||
import org.springframework.web.socket.sockjs.frame.SockJsFrameFormat;
|
||||
|
|
@ -38,6 +36,16 @@ import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSe
|
|||
*/
|
||||
public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHandler {
|
||||
|
||||
private static final byte[] PRELUDE = new byte[2049];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 2048; i++) {
|
||||
PRELUDE[i] = 'h';
|
||||
}
|
||||
PRELUDE[2048] = '\n';
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TransportType getTransportType() {
|
||||
return TransportType.XHR_STREAMING;
|
||||
|
|
@ -70,12 +78,8 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
for (int i = 0; i < 2048; i++) {
|
||||
response.getBody().write('h');
|
||||
}
|
||||
response.getBody().write('\n');
|
||||
response.flush();
|
||||
protected byte[] getPrelude(ServerHttpRequest request) {
|
||||
return PRELUDE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated as of 4.2 this method is no longer used for anything
|
||||
* @deprecated as of 4.2 this method is no longer used.
|
||||
*/
|
||||
@Deprecated
|
||||
protected abstract boolean isStreaming();
|
||||
|
|
@ -292,6 +292,11 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
|||
protected abstract void flushCache() throws SockJsTransportFailureException;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 4.2 this method is deprecated since the prelude is written
|
||||
* in {@link #handleRequestInternal} of the StreamingSockJsSession subclass.
|
||||
*/
|
||||
@Deprecated
|
||||
protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class PollingSockJsSession extends AbstractHttpSockJsSession {
|
|||
|
||||
|
||||
/**
|
||||
* @deprecated as of 4.2 this method is no longer used for anything
|
||||
* @deprecated as of 4.2 this method is no longer used.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import java.util.Map;
|
|||
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.SockJsTransportFailureException;
|
||||
import org.springframework.web.socket.sockjs.frame.SockJsFrame;
|
||||
|
|
@ -33,7 +35,7 @@ import org.springframework.web.socket.sockjs.transport.SockJsServiceConfig;
|
|||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class StreamingSockJsSession extends AbstractHttpSockJsSession {
|
||||
public abstract class StreamingSockJsSession extends AbstractHttpSockJsSession {
|
||||
|
||||
private int byteCount;
|
||||
|
||||
|
|
@ -46,7 +48,7 @@ public class StreamingSockJsSession extends AbstractHttpSockJsSession {
|
|||
|
||||
|
||||
/**
|
||||
* @deprecated as of 4.2 this method is no longer used for anything
|
||||
* @deprecated as of 4.2 this method is no longer used.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
|
|
@ -54,11 +56,21 @@ public class StreamingSockJsSession extends AbstractHttpSockJsSession {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the prelude to write to the response before any other data.
|
||||
* @since 4.2
|
||||
*/
|
||||
protected abstract byte[] getPrelude(ServerHttpRequest request);
|
||||
|
||||
@Override
|
||||
protected void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response,
|
||||
boolean initialRequest) throws IOException {
|
||||
|
||||
writePrelude(request, response);
|
||||
byte[] prelude = getPrelude(request);
|
||||
Assert.notNull(prelude);
|
||||
response.getBody().write(prelude);
|
||||
response.flush();
|
||||
|
||||
if (initialRequest) {
|
||||
writeFrame(SockJsFrame.openFrame());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,13 +118,8 @@ public class HttpSockJsSessionTests extends AbstractSockJsSessionTests<TestAbstr
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isStreaming() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writePrelude(ServerHttpRequest request, ServerHttpResponse response) throws IOException {
|
||||
response.getBody().write("hhh\n".getBytes());
|
||||
protected byte[] getPrelude(ServerHttpRequest request) {
|
||||
return "hhh\n".getBytes();
|
||||
}
|
||||
|
||||
public boolean wasCacheFlushed() {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.SockJsTransportFailureException;
|
||||
|
|
@ -56,8 +55,8 @@ public class TestHttpSockJsSession extends StreamingSockJsSession {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isStreaming() {
|
||||
return true;
|
||||
protected byte[] getPrelude(ServerHttpRequest request) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue