Remove unintended dependency on Servlet API in SockJS
Add a factory method in ServerHttpRequest for creating a ServerHttpAsyncRequestControl.
This commit is contained in:
@@ -20,10 +20,9 @@ import java.io.IOException;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
import org.springframework.http.server.ServerHttpAsyncResponseControl;
|
||||
import org.springframework.http.server.ServerHttpAsyncRequestControl;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.http.server.ServletServerHttpAsyncRequestControl;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
@@ -48,7 +47,7 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
||||
|
||||
private ServerHttpResponse response;
|
||||
|
||||
private ServerHttpAsyncResponseControl asyncControl;
|
||||
private ServerHttpAsyncRequestControl asyncRequestControl;
|
||||
|
||||
private String protocol;
|
||||
|
||||
@@ -109,7 +108,7 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.asyncControl.start(-1);
|
||||
this.asyncRequestControl.start(-1);
|
||||
scheduleHeartbeat();
|
||||
tryFlushCache();
|
||||
}
|
||||
@@ -125,14 +124,14 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
||||
Assert.notNull(frameFormat, "expected frameFormat");
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.asyncControl = new ServletServerHttpAsyncRequestControl(this.request, this.response);
|
||||
this.asyncRequestControl = request.getAsyncRequestControl(response);
|
||||
this.frameFormat = frameFormat;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean isActive() {
|
||||
return ((this.asyncControl != null) && (!this.asyncControl.isCompleted()));
|
||||
return ((this.asyncRequestControl != null) && (!this.asyncRequestControl.isCompleted()));
|
||||
}
|
||||
|
||||
protected BlockingQueue<String> getMessageCache() {
|
||||
@@ -172,10 +171,10 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
||||
|
||||
protected synchronized void resetRequest() {
|
||||
updateLastActiveTime();
|
||||
if (isActive() && this.asyncControl.hasStarted()) {
|
||||
if (isActive() && this.asyncRequestControl.isStarted()) {
|
||||
try {
|
||||
logger.debug("Completing asynchronous request");
|
||||
this.asyncControl.complete();
|
||||
this.asyncRequestControl.complete();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.error("Failed to complete request: " + ex.getMessage());
|
||||
@@ -183,7 +182,7 @@ public abstract class AbstractHttpSockJsSession extends AbstractSockJsSession {
|
||||
}
|
||||
this.request = null;
|
||||
this.response = null;
|
||||
this.asyncControl = null;
|
||||
this.asyncRequestControl = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
package org.springframework.web.socket;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.springframework.http.server.ServerHttpAsyncResponseControl;
|
||||
import org.springframework.http.server.ServerHttpAsyncRequestControl;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.http.server.ServletServerHttpAsyncRequestControl;
|
||||
import org.springframework.http.server.ServletServerHttpRequest;
|
||||
import org.springframework.http.server.ServletServerHttpResponse;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
@@ -41,7 +40,7 @@ public class AbstractHttpRequestTests {
|
||||
|
||||
protected MockHttpServletResponse servletResponse;
|
||||
|
||||
protected ServerHttpAsyncResponseControl asyncControl;
|
||||
protected ServerHttpAsyncRequestControl asyncControl;
|
||||
|
||||
|
||||
@Before
|
||||
@@ -57,7 +56,7 @@ public class AbstractHttpRequestTests {
|
||||
protected void resetRequestAndResponse() {
|
||||
resetRequest();
|
||||
resetResponse();
|
||||
this.asyncControl = new ServletServerHttpAsyncRequestControl(this.request, this.response);
|
||||
this.asyncControl = this.request.getAsyncRequestControl(this.response);
|
||||
}
|
||||
|
||||
protected void resetRequest() {
|
||||
|
||||
@@ -246,7 +246,7 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
@Override
|
||||
protected void handleTransportRequest(ServerHttpRequest req, ServerHttpResponse res, WebSocketHandler handler,
|
||||
String sessionId, String transport) throws IOException, SockJsException {
|
||||
String sessionId, String transport) throws SockJsException {
|
||||
|
||||
this.sessionId = sessionId;
|
||||
this.transport = transport;
|
||||
|
||||
Reference in New Issue
Block a user