Search in sources :

Example 1 with WebSocketHandlerDecorator

use of org.springframework.web.socket.handler.WebSocketHandlerDecorator 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)

Aggregations

URI (java.net.URI)1 Test (org.junit.Test)1 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)1 WebSocketHttpHeaders (org.springframework.web.socket.WebSocketHttpHeaders)1 LoggingWebSocketHandlerDecorator (org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator)1 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)1 WebSocketHandlerDecorator (org.springframework.web.socket.handler.WebSocketHandlerDecorator)1