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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations