Search in sources :

Example 11 with WebSocketHandler

use of org.springframework.web.socket.WebSocketHandler 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());
}
Also used : WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) Test(org.junit.Test)

Example 12 with WebSocketHandler

use of org.springframework.web.socket.WebSocketHandler 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());
}
Also used : WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) URI(java.net.URI) WebSocketHandlerDecorator(org.springframework.web.socket.handler.WebSocketHandlerDecorator) LoggingWebSocketHandlerDecorator(org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator) Test(org.junit.Test)

Example 13 with WebSocketHandler

use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.

the class HttpReceivingTransportHandlerTests method readMessagesNoSession.

@Test(expected = IllegalArgumentException.class)
public void readMessagesNoSession() throws Exception {
    WebSocketHandler webSocketHandler = mock(WebSocketHandler.class);
    new XhrReceivingTransportHandler().handleRequest(this.request, this.response, webSocketHandler, null);
}
Also used : WebSocketHandler(org.springframework.web.socket.WebSocketHandler) Test(org.junit.Test)

Example 14 with WebSocketHandler

use of org.springframework.web.socket.WebSocketHandler in project spring-framework by spring-projects.

the class HttpReceivingTransportHandlerTests method handleRequestAndExpectFailure.

private void handleRequestAndExpectFailure() throws Exception {
    resetResponse();
    WebSocketHandler wsHandler = mock(WebSocketHandler.class);
    AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);
    new XhrReceivingTransportHandler().handleRequest(this.request, this.response, wsHandler, session);
    assertEquals(500, this.servletResponse.getStatus());
    verifyNoMoreInteractions(wsHandler);
}
Also used : TestHttpSockJsSession(org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) AbstractSockJsSession(org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession) StubSockJsServiceConfig(org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig)

Example 15 with WebSocketHandler

use of org.springframework.web.socket.WebSocketHandler 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());
}
Also used : WebSocketServerSockJsSession(org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TaskScheduler(org.springframework.scheduling.TaskScheduler) Test(org.junit.Test)

Aggregations

WebSocketHandler (org.springframework.web.socket.WebSocketHandler)44 Test (org.junit.Test)36 HashMap (java.util.HashMap)14 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)14 WebSocketHttpHeaders (org.springframework.web.socket.WebSocketHttpHeaders)5 SubProtocolWebSocketHandler (org.springframework.web.socket.messaging.SubProtocolWebSocketHandler)5 MockHttpSession (org.springframework.mock.web.test.MockHttpSession)4 TextMessage (org.springframework.web.socket.TextMessage)4 HandshakeHandler (org.springframework.web.socket.server.HandshakeHandler)4 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)4 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)3 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)3 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)3 URI (java.net.URI)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 MessageHandler (org.springframework.messaging.MessageHandler)2 SimpAnnotationMethodMessageHandler (org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler)2 SimpleBrokerMessageHandler (org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler)2 StompBrokerRelayMessageHandler (org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler)2 DefaultUserDestinationResolver (org.springframework.messaging.simp.user.DefaultUserDestinationResolver)2