Refactor and polish SockJS package structure
After this change the top-level sockjs package contains the main types for use in applications.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs;
|
||||
package org.springframework.web.socket.sockjs.support;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.SockJsProcessingException;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -77,7 +79,7 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
handleRequest("GET", "/a/server/session/xhr", HttpStatus.OK);
|
||||
|
||||
assertEquals("session", this.service.sessionId);
|
||||
assertEquals(TransportType.XHR, this.service.transportType);
|
||||
assertEquals(TransportType.XHR.value(), this.service.transport);
|
||||
assertSame(this.handler, this.service.handler);
|
||||
|
||||
this.service.setValidSockJsPrefixes("/b");
|
||||
@@ -96,7 +98,7 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
handleRequest("GET", "/a/server/session/xhr", HttpStatus.OK);
|
||||
|
||||
assertEquals("session", this.service.sessionId);
|
||||
assertEquals(TransportType.XHR, this.service.transportType);
|
||||
assertEquals(TransportType.XHR.value(), this.service.transport);
|
||||
assertSame(this.handler, this.service.handler);
|
||||
}
|
||||
|
||||
@@ -107,7 +109,7 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
handleRequest("GET", "/a/server/session/xhr", HttpStatus.OK);
|
||||
|
||||
assertEquals("session", this.service.sessionId);
|
||||
assertEquals(TransportType.XHR, this.service.transportType);
|
||||
assertEquals(TransportType.XHR.value(), this.service.transport);
|
||||
assertSame(this.handler, this.service.handler);
|
||||
}
|
||||
|
||||
@@ -216,7 +218,7 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
private String sessionId;
|
||||
|
||||
private TransportType transportType;
|
||||
private String transport;
|
||||
|
||||
private WebSocketHandler handler;
|
||||
|
||||
@@ -224,11 +226,6 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
super(scheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SockJsMessageCodec getMessageCodecRequired() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleRawWebSocketRequest(ServerHttpRequest request,
|
||||
ServerHttpResponse response, WebSocketHandler handler) throws IOException {
|
||||
@@ -237,15 +234,19 @@ public class AbstractSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTransportRequest(ServerHttpRequest request,
|
||||
ServerHttpResponse response, String sessionId,
|
||||
TransportType transportType, WebSocketHandler handler)
|
||||
throws IOException, TransportErrorException {
|
||||
protected void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response,
|
||||
WebSocketHandler handler, String sessionId, String transport)
|
||||
throws IOException, SockJsProcessingException {
|
||||
|
||||
this.sessionId = sessionId;
|
||||
this.transportType = transportType;
|
||||
this.transport = transport;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidTransportType(String transportType) {
|
||||
return TransportType.fromValue(transportType) != null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs;
|
||||
package org.springframework.web.socket.sockjs.transport;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs.transport;
|
||||
package org.springframework.web.socket.sockjs.transport.handler;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -29,14 +29,15 @@ import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.AbstractSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.SockJsConfiguration;
|
||||
import org.springframework.web.socket.sockjs.SockJsSessionFactory;
|
||||
import org.springframework.web.socket.sockjs.StubSockJsConfig;
|
||||
import org.springframework.web.socket.sockjs.TestSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.TransportErrorException;
|
||||
import org.springframework.web.socket.sockjs.TransportHandler;
|
||||
import org.springframework.web.socket.sockjs.TransportType;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.sockjs.SockJsProcessingException;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.TransportType;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.SockJsSessionFactory;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig;
|
||||
import org.springframework.web.socket.sockjs.transport.session.TestSockJsSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
@@ -83,7 +84,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
WebSocketHandler webSocketHandler = mock(WebSocketHandler.class);
|
||||
|
||||
DefaultSockJsService service = new DefaultSockJsService(taskScheduler, transportHandlers);
|
||||
service.handleTransportRequest(this.request, this.response, "123", TransportType.XHR, webSocketHandler);
|
||||
service.handleTransportRequest(this.request, this.response, webSocketHandler, "123", TransportType.XHR.value());
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus());
|
||||
assertNotNull(xhrHandler.session);
|
||||
@@ -107,7 +108,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
Set<TransportHandler> transportHandlers = Collections.<TransportHandler>singleton(xhrHandler);
|
||||
|
||||
DefaultSockJsService service = new DefaultSockJsService(taskScheduler, transportHandlers);
|
||||
service.handleTransportRequest(this.request, this.response, "123", TransportType.XHR, null);
|
||||
service.handleTransportRequest(this.request, this.response, null, "123", TransportType.XHR.value());
|
||||
|
||||
assertEquals(204, this.servletResponse.getStatus());
|
||||
assertEquals("*", this.response.getHeaders().getFirst("Access-Control-Allow-Origin"));
|
||||
@@ -122,7 +123,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
Set<TransportHandler> transportHandlers = new HashSet<>();
|
||||
DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class), transportHandlers);
|
||||
service.handleTransportRequest(this.request, this.response, "123", TransportType.XHR, null);
|
||||
service.handleTransportRequest(this.request, this.response, null, "123", TransportType.XHR.value());
|
||||
|
||||
assertEquals(404, this.servletResponse.getStatus());
|
||||
}
|
||||
@@ -135,20 +136,20 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
Set<TransportHandler> transportHandlers = new HashSet<>();
|
||||
transportHandlers.add(new StubXhrTransportHandler());
|
||||
transportHandlers.add(new StubXhrSendTransportHandler());
|
||||
WebSocketHandler webSocketHandler = mock(WebSocketHandler.class);
|
||||
WebSocketHandler wsHandler = mock(WebSocketHandler.class);
|
||||
DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class), transportHandlers);
|
||||
|
||||
service.handleTransportRequest(this.request, this.response, "123", TransportType.XHR_SEND, webSocketHandler);
|
||||
service.handleTransportRequest(this.request, this.response, wsHandler, "123", TransportType.XHR_SEND.value());
|
||||
|
||||
assertEquals(404, this.servletResponse.getStatus()); // dropped (no session)
|
||||
|
||||
resetResponse();
|
||||
service.handleTransportRequest(this.request, this.response, "123", TransportType.XHR, webSocketHandler);
|
||||
service.handleTransportRequest(this.request, this.response, wsHandler, "123", TransportType.XHR.value());
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus());
|
||||
|
||||
resetResponse();
|
||||
service.handleTransportRequest(this.request, this.response, "123", TransportType.XHR_SEND, webSocketHandler);
|
||||
service.handleTransportRequest(this.request, this.response, wsHandler, "123", TransportType.XHR_SEND.value());
|
||||
|
||||
assertEquals(200, this.servletResponse.getStatus());
|
||||
}
|
||||
@@ -158,20 +159,16 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
WebSocketHandler webSocketHandler;
|
||||
|
||||
AbstractSockJsSession session;
|
||||
WebSocketSession session;
|
||||
|
||||
@Override
|
||||
public TransportType getTransportType() {
|
||||
return TransportType.XHR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSockJsConfiguration(SockJsConfiguration sockJsConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
|
||||
WebSocketHandler handler, AbstractSockJsSession session) throws TransportErrorException {
|
||||
WebSocketHandler handler, WebSocketSession session) throws SockJsProcessingException {
|
||||
|
||||
this.webSocketHandler = handler;
|
||||
this.session = session;
|
||||
@@ -179,7 +176,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
|
||||
@Override
|
||||
public AbstractSockJsSession createSession(String sessionId, WebSocketHandler webSocketHandler) {
|
||||
return new TestSockJsSession(sessionId, new StubSockJsConfig(), webSocketHandler);
|
||||
return new TestSockJsSession(sessionId, new StubSockJsServiceConfig(), webSocketHandler);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -191,13 +188,9 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
|
||||
return TransportType.XHR_SEND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSockJsConfiguration(SockJsConfiguration sockJsConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
|
||||
WebSocketHandler handler, AbstractSockJsSession session) throws TransportErrorException {
|
||||
WebSocketHandler handler, WebSocketSession session) throws SockJsProcessingException {
|
||||
|
||||
if (session == null) {
|
||||
response.setStatusCode(HttpStatus.NOT_FOUND);
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs.transport;
|
||||
package org.springframework.web.socket.sockjs.transport.handler;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -23,10 +23,13 @@ import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.AbstractSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.StubSockJsConfig;
|
||||
import org.springframework.web.socket.sockjs.TestSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.TransportErrorException;
|
||||
import org.springframework.web.socket.sockjs.SockJsProcessingException;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.AbstractHttpReceivingTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.JsonpTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.XhrTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig;
|
||||
import org.springframework.web.socket.sockjs.transport.session.TestSockJsSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -105,7 +108,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTest
|
||||
@Test
|
||||
public void delegateMessageException() throws Exception {
|
||||
|
||||
StubSockJsConfig sockJsConfig = new StubSockJsConfig();
|
||||
StubSockJsServiceConfig sockJsConfig = new StubSockJsServiceConfig();
|
||||
|
||||
this.servletRequest.setContent("[\"x\"]".getBytes("UTF-8"));
|
||||
|
||||
@@ -117,11 +120,11 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTest
|
||||
|
||||
try {
|
||||
XhrTransportHandler transportHandler = new XhrTransportHandler();
|
||||
transportHandler.setSockJsConfiguration(sockJsConfig);
|
||||
transportHandler.setSockJsServiceConfiguration(sockJsConfig);
|
||||
transportHandler.handleRequest(this.request, this.response, webSocketHandler, session);
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (TransportErrorException ex) {
|
||||
catch (SockJsProcessingException ex) {
|
||||
assertEquals(CloseStatus.SERVER_ERROR, session.getStatus());
|
||||
}
|
||||
}
|
||||
@@ -131,9 +134,9 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTest
|
||||
throws Exception {
|
||||
|
||||
WebSocketHandler webSocketHandler = mock(WebSocketHandler.class);
|
||||
AbstractSockJsSession session = new TestSockJsSession("1", new StubSockJsConfig(), webSocketHandler);
|
||||
AbstractSockJsSession session = new TestSockJsSession("1", new StubSockJsServiceConfig(), webSocketHandler);
|
||||
|
||||
transportHandler.setSockJsConfiguration(new StubSockJsConfig());
|
||||
transportHandler.setSockJsServiceConfiguration(new StubSockJsServiceConfig());
|
||||
transportHandler.handleRequest(this.request, this.response, webSocketHandler, session);
|
||||
|
||||
assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString());
|
||||
@@ -145,7 +148,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTest
|
||||
resetResponse();
|
||||
|
||||
WebSocketHandler webSocketHandler = mock(WebSocketHandler.class);
|
||||
AbstractSockJsSession session = new TestSockJsSession("1", new StubSockJsConfig(), webSocketHandler);
|
||||
AbstractSockJsSession session = new TestSockJsSession("1", new StubSockJsServiceConfig(), webSocketHandler);
|
||||
|
||||
new XhrTransportHandler().handleRequest(this.request, this.response, webSocketHandler, session);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs.transport;
|
||||
package org.springframework.web.socket.sockjs.transport.handler;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
@@ -23,10 +23,18 @@ import org.junit.Test;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.web.socket.AbstractHttpRequestTests;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.AbstractSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.SockJsFrame;
|
||||
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
|
||||
import org.springframework.web.socket.sockjs.StubSockJsConfig;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame.FrameFormat;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.AbstractHttpSendingTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.EventSourceTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.HtmlFileTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.JsonpPollingTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.XhrPollingTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.handler.XhrStreamingTransportHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
@@ -41,7 +49,7 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
|
||||
private WebSocketHandler webSocketHandler;
|
||||
|
||||
private StubSockJsConfig sockJsConfig;
|
||||
private StubSockJsServiceConfig sockJsConfig;
|
||||
|
||||
private TaskScheduler taskScheduler;
|
||||
|
||||
@@ -54,7 +62,7 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
this.webSocketHandler = mock(WebSocketHandler.class);
|
||||
this.taskScheduler = mock(TaskScheduler.class);
|
||||
|
||||
this.sockJsConfig = new StubSockJsConfig();
|
||||
this.sockJsConfig = new StubSockJsServiceConfig();
|
||||
this.sockJsConfig.setTaskScheduler(this.taskScheduler);
|
||||
}
|
||||
|
||||
@@ -62,7 +70,7 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
public void handleRequestXhr() throws Exception {
|
||||
|
||||
XhrPollingTransportHandler transportHandler = new XhrPollingTransportHandler();
|
||||
transportHandler.setSockJsConfiguration(this.sockJsConfig);
|
||||
transportHandler.setSockJsServiceConfiguration(this.sockJsConfig);
|
||||
|
||||
AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
@@ -89,7 +97,7 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
public void jsonpTransport() throws Exception {
|
||||
|
||||
JsonpPollingTransportHandler transportHandler = new JsonpPollingTransportHandler();
|
||||
transportHandler.setSockJsConfiguration(this.sockJsConfig);
|
||||
transportHandler.setSockJsServiceConfiguration(this.sockJsConfig);
|
||||
PollingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
|
||||
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
@@ -110,7 +118,7 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
public void handleRequestXhrStreaming() throws Exception {
|
||||
|
||||
XhrStreamingTransportHandler transportHandler = new XhrStreamingTransportHandler();
|
||||
transportHandler.setSockJsConfiguration(this.sockJsConfig);
|
||||
transportHandler.setSockJsServiceConfiguration(this.sockJsConfig);
|
||||
AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
|
||||
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
@@ -124,7 +132,7 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
public void htmlFileTransport() throws Exception {
|
||||
|
||||
HtmlFileTransportHandler transportHandler = new HtmlFileTransportHandler();
|
||||
transportHandler.setSockJsConfiguration(this.sockJsConfig);
|
||||
transportHandler.setSockJsServiceConfiguration(this.sockJsConfig);
|
||||
StreamingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
|
||||
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
@@ -145,7 +153,7 @@ public class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests
|
||||
public void eventSourceTransport() throws Exception {
|
||||
|
||||
EventSourceTransportHandler transportHandler = new EventSourceTransportHandler();
|
||||
transportHandler.setSockJsConfiguration(this.sockJsConfig);
|
||||
transportHandler.setSockJsServiceConfiguration(this.sockJsConfig);
|
||||
StreamingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler);
|
||||
|
||||
transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs.transport;
|
||||
package org.springframework.web.socket.sockjs.transport.session;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -28,12 +28,11 @@ import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.BaseAbstractSockJsSessionTests;
|
||||
import org.springframework.web.socket.sockjs.SockJsConfiguration;
|
||||
import org.springframework.web.socket.sockjs.SockJsFrame;
|
||||
import org.springframework.web.socket.sockjs.SockJsFrame.DefaultFrameFormat;
|
||||
import org.springframework.web.socket.sockjs.SockJsFrame.FrameFormat;
|
||||
import org.springframework.web.socket.sockjs.transport.AbstractHttpSockJsSessionTests.TestAbstractHttpSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame.DefaultFrameFormat;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame.FrameFormat;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSessionTests.TestAbstractHttpSockJsSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -128,7 +127,7 @@ public class AbstractHttpSockJsSessionTests extends BaseAbstractSockJsSessionTes
|
||||
private boolean heartbeatScheduled;
|
||||
|
||||
|
||||
public TestAbstractHttpSockJsSession(SockJsConfiguration config, WebSocketHandler handler) {
|
||||
public TestAbstractHttpSockJsSession(SockJsServiceConfig config, WebSocketHandler handler) {
|
||||
super("1", config, handler);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs;
|
||||
package org.springframework.web.socket.sockjs.transport.session;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Date;
|
||||
@@ -24,6 +24,9 @@ import java.util.concurrent.ScheduledFuture;
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.sockjs.SockJsProcessingException;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
@@ -210,7 +213,7 @@ public class AbstractSockJsSessionTests extends BaseAbstractSockJsSessionTests<T
|
||||
this.session.writeFrame(SockJsFrame.openFrame());
|
||||
fail("expected exception");
|
||||
}
|
||||
catch (TransportErrorException ex) {
|
||||
catch (SockJsProcessingException ex) {
|
||||
assertEquals(CloseStatus.SERVER_ERROR, this.session.getStatus());
|
||||
verify(this.webSocketHandler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR);
|
||||
}
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs;
|
||||
package org.springframework.web.socket.sockjs.transport.session;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -32,7 +33,7 @@ public abstract class BaseAbstractSockJsSessionTests<S extends AbstractSockJsSes
|
||||
|
||||
protected WebSocketHandler webSocketHandler;
|
||||
|
||||
protected StubSockJsConfig sockJsConfig;
|
||||
protected StubSockJsServiceConfig sockJsConfig;
|
||||
|
||||
protected TaskScheduler taskScheduler;
|
||||
|
||||
@@ -44,7 +45,7 @@ public abstract class BaseAbstractSockJsSessionTests<S extends AbstractSockJsSes
|
||||
this.webSocketHandler = mock(WebSocketHandler.class);
|
||||
this.taskScheduler = mock(TaskScheduler.class);
|
||||
|
||||
this.sockJsConfig = new StubSockJsConfig();
|
||||
this.sockJsConfig = new StubSockJsServiceConfig();
|
||||
this.sockJsConfig.setTaskScheduler(this.taskScheduler);
|
||||
|
||||
this.session = initSockJsSession();
|
||||
@@ -14,16 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs;
|
||||
package org.springframework.web.socket.sockjs.transport.session;
|
||||
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.web.socket.sockjs.support.Jackson2SockJsMessageCodec;
|
||||
import org.springframework.web.socket.sockjs.support.frame.Jackson2SockJsMessageCodec;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsMessageCodec;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class StubSockJsConfig implements SockJsConfiguration {
|
||||
public class StubSockJsServiceConfig implements SockJsServiceConfig {
|
||||
|
||||
private int streamBytesLimit = 128 * 1024;
|
||||
|
||||
@@ -62,12 +63,8 @@ public class StubSockJsConfig implements SockJsConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SockJsMessageCodec getMessageCodecRequired() {
|
||||
return this.messageCodec;
|
||||
}
|
||||
|
||||
public SockJsMessageCodec getMessageCodec() {
|
||||
return messageCodec;
|
||||
return this.messageCodec;
|
||||
}
|
||||
|
||||
public void setMessageCodec(SockJsMessageCodec messageCodec) {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs;
|
||||
package org.springframework.web.socket.sockjs.transport.session;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -22,6 +22,8 @@ import java.util.List;
|
||||
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.support.frame.SockJsFrame;
|
||||
import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
@@ -43,7 +45,7 @@ public class TestSockJsSession extends AbstractSockJsSession {
|
||||
private String subProtocol;
|
||||
|
||||
|
||||
public TestSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) {
|
||||
public TestSockJsSession(String sessionId, SockJsServiceConfig config, WebSocketHandler handler) {
|
||||
super(sessionId, config, handler);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.sockjs.transport;
|
||||
package org.springframework.web.socket.sockjs.transport.session;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,9 +27,8 @@ import org.junit.Test;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketHandler;
|
||||
import org.springframework.web.socket.sockjs.BaseAbstractSockJsSessionTests;
|
||||
import org.springframework.web.socket.sockjs.SockJsConfiguration;
|
||||
import org.springframework.web.socket.sockjs.transport.WebSocketServerSockJsSessionTests.TestWebSocketServerSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession;
|
||||
import org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSessionTests.TestWebSocketServerSockJsSession;
|
||||
import org.springframework.web.socket.support.TestWebSocketSession;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -134,7 +133,7 @@ public class WebSocketServerSockJsSessionTests extends BaseAbstractSockJsSession
|
||||
|
||||
private final List<String> heartbeatSchedulingEvents = new ArrayList<>();
|
||||
|
||||
public TestWebSocketServerSockJsSession(SockJsConfiguration config, WebSocketHandler handler) {
|
||||
public TestWebSocketServerSockJsSession(SockJsServiceConfig config, WebSocketHandler handler) {
|
||||
super("1", config, handler);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user