Search in sources :

Example 1 with TextWebSocketHandler

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

the class WebSocketHandlerRegistrationTests method interceptors.

@Test
public void interceptors() {
    WebSocketHandler handler = new TextWebSocketHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    this.registration.addHandler(handler, "/foo").addInterceptors(interceptor);
    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(1, mappings.size());
    Mapping mapping = mappings.get(0);
    assertEquals(handler, mapping.webSocketHandler);
    assertEquals("/foo", mapping.path);
    assertEquals(2, mapping.interceptors.length);
    assertEquals(interceptor, mapping.interceptors[0]);
    assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) 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 2 with TextWebSocketHandler

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

the class WebSocketHandlerRegistrationTests method minimal.

@Test
public void minimal() {
    WebSocketHandler handler = new TextWebSocketHandler();
    this.registration.addHandler(handler, "/foo", "/bar");
    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(2, mappings.size());
    Mapping m1 = mappings.get(0);
    assertEquals(handler, m1.webSocketHandler);
    assertEquals("/foo", m1.path);
    assertEquals(1, m1.interceptors.length);
    assertEquals(OriginHandshakeInterceptor.class, m1.interceptors[0].getClass());
    Mapping m2 = mappings.get(1);
    assertEquals(handler, m2.webSocketHandler);
    assertEquals("/bar", m2.path);
    assertEquals(1, m2.interceptors.length);
    assertEquals(OriginHandshakeInterceptor.class, m2.interceptors[0].getClass());
}
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 3 with TextWebSocketHandler

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

the class WebSocketHandlerRegistrationTests method handshakeHandler.

@Test
public void handshakeHandler() {
    WebSocketHandler handler = new TextWebSocketHandler();
    HandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
    this.registration.addHandler(handler, "/foo").setHandshakeHandler(handshakeHandler);
    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(1, mappings.size());
    Mapping mapping = mappings.get(0);
    assertEquals(handler, mapping.webSocketHandler);
    assertEquals("/foo", mapping.path);
    assertSame(handshakeHandler, mapping.handshakeHandler);
}
Also used : HandshakeHandler(org.springframework.web.socket.server.HandshakeHandler) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) Test(org.junit.Test)

Example 4 with TextWebSocketHandler

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

the class WebSocketHandlerRegistrationTests method emptyAllowedOrigin.

@Test
public void emptyAllowedOrigin() {
    WebSocketHandler handler = new TextWebSocketHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    this.registration.addHandler(handler, "/foo").addInterceptors(interceptor).setAllowedOrigins();
    List<Mapping> mappings = this.registration.getMappings();
    assertEquals(1, mappings.size());
    Mapping mapping = mappings.get(0);
    assertEquals(handler, mapping.webSocketHandler);
    assertEquals("/foo", mapping.path);
    assertEquals(2, mapping.interceptors.length);
    assertEquals(interceptor, mapping.interceptors[0]);
    assertEquals(OriginHandshakeInterceptor.class, mapping.interceptors[1].getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) 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 5 with TextWebSocketHandler

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

the class WebSocketHandlerRegistrationTests method handshakeHandlerPassedToSockJsRegistration.

@Test
public void handshakeHandlerPassedToSockJsRegistration() {
    WebSocketHandler handler = new TextWebSocketHandler();
    HandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
    this.registration.addHandler(handler, "/foo").setHandshakeHandler(handshakeHandler).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);
    WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) mapping.sockJsService.getTransportHandlers().get(TransportType.WEBSOCKET);
    assertSame(handshakeHandler, transportHandler.getHandshakeHandler());
}
Also used : HandshakeHandler(org.springframework.web.socket.server.HandshakeHandler) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) WebSocketHandler(org.springframework.web.socket.WebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) WebSocketTransportHandler(org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)16 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)12 WebSocketHttpHeaders (org.springframework.web.socket.WebSocketHttpHeaders)5 URI (java.net.URI)4 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)4 HandshakeHandler (org.springframework.web.socket.server.HandshakeHandler)2 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)2 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)1 TaskScheduler (org.springframework.scheduling.TaskScheduler)1 TextMessage (org.springframework.web.socket.TextMessage)1 WebSocketExtension (org.springframework.web.socket.WebSocketExtension)1 WebSocketSession (org.springframework.web.socket.WebSocketSession)1 LoggingWebSocketHandlerDecorator (org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator)1 TestWebSocketSession (org.springframework.web.socket.handler.TestWebSocketSession)1 WebSocketHandlerDecorator (org.springframework.web.socket.handler.WebSocketHandlerDecorator)1 SubProtocolWebSocketHandler (org.springframework.web.socket.messaging.SubProtocolWebSocketHandler)1 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)1 OriginHandshakeInterceptor (org.springframework.web.socket.server.support.OriginHandshakeInterceptor)1 WebSocketTransportHandler (org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler)1