use of org.springframework.web.socket.handler.TextWebSocketHandler in project spring-framework by spring-projects.
the class WebSocketHandlerRegistrationTests method interceptorsPassedToSockJsRegistration.
@Test
public void interceptorsPassedToSockJsRegistration() {
WebSocketHandler handler = new TextWebSocketHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins("http://mydomain1.com").withSockJS();
List<Mapping> mappings = this.registration.getMappings();
assertEquals(1, mappings.size());
Mapping mapping = mappings.get(0);
assertEquals(handler, mapping.webSocketHandler);
assertEquals("/foo/**", mapping.path);
assertNotNull(mapping.sockJsService);
assertTrue(mapping.sockJsService.getAllowedOrigins().contains("http://mydomain1.com"));
List<HandshakeInterceptor> interceptors = mapping.sockJsService.getHandshakeInterceptors();
assertEquals(interceptor, interceptors.get(0));
assertEquals(OriginHandshakeInterceptor.class, interceptors.get(1).getClass());
}
use of org.springframework.web.socket.handler.TextWebSocketHandler in project spring-framework by spring-projects.
the class WebSocketHandshakeTests method subProtocolNegotiation.
@Test
public void subProtocolNegotiation() throws Exception {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
headers.setSecWebSocketProtocol("foo");
URI url = new URI(getWsBaseUrl() + "/ws");
WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get();
assertEquals("foo", session.getAcceptedProtocol());
session.close();
}
use of org.springframework.web.socket.handler.TextWebSocketHandler in project spring-framework by spring-projects.
the class WebSocketConnectionManagerTests method clientLifecycle.
@Test
public void clientLifecycle() throws Exception {
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
WebSocketHandler handler = new TextWebSocketHandler();
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler, "/a");
manager.startInternal();
assertTrue(client.isRunning());
manager.stopInternal();
assertFalse(client.isRunning());
}
use of org.springframework.web.socket.handler.TextWebSocketHandler in project spring-framework by spring-projects.
the class WebSocketConnectionManagerTests method openConnection.
@Test
public void openConnection() throws Exception {
List<String> subprotocols = Arrays.asList("abc");
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
WebSocketHandler handler = new TextWebSocketHandler();
WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler, "/path/{id}", "123");
manager.setSubProtocols(subprotocols);
manager.openConnection();
WebSocketHttpHeaders expectedHeaders = new WebSocketHttpHeaders();
expectedHeaders.setSecWebSocketProtocol(subprotocols);
assertEquals(expectedHeaders, client.headers);
assertEquals(new URI("/path/123"), client.uri);
WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler;
assertEquals(LoggingWebSocketHandlerDecorator.class, loggingHandler.getClass());
assertSame(handler, loggingHandler.getDelegate());
}
use of org.springframework.web.socket.handler.TextWebSocketHandler in project spring-framework by spring-projects.
the class SockJsWebSocketHandlerTests method getSubProtocolsNone.
@Test
public void getSubProtocolsNone() throws Exception {
WebSocketHandler handler = new TextWebSocketHandler();
TaskScheduler scheduler = mock(TaskScheduler.class);
DefaultSockJsService service = new DefaultSockJsService(scheduler);
WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
assertNull(sockJsHandler.getSubProtocols());
}
Aggregations