use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project spring-framework by spring-projects.
the class WebMvcStompWebSocketEndpointRegistrationTests method handshakeHandlerAndInterceptor.
@Test
public void handshakeHandlerAndInterceptor() {
WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor);
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
assertThat(mappings.size()).isEqualTo(1);
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
assertThat(requestHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
assertThat(requestHandler.getHandshakeInterceptors().size()).isEqualTo(2);
assertThat(requestHandler.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
assertThat(requestHandler.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
}
use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project spring-framework by spring-projects.
the class WebMvcStompWebSocketEndpointRegistrationTests method handshakeHandlerInterceptorWithSockJsService.
@Test
public void handshakeHandlerInterceptorWithSockJsService() {
WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).withSockJS();
MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
assertThat(mappings.size()).isEqualTo(1);
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo/**"));
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
assertThat(sockJsService).isNotNull();
Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers();
WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET);
assertThat(transportHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
assertThat(sockJsService.getHandshakeInterceptors().size()).isEqualTo(2);
assertThat(sockJsService.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
assertThat(sockJsService.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
}
use of org.springframework.web.socket.server.support.DefaultHandshakeHandler in project spring-framework by spring-projects.
the class TestMessageCodec method webSocketHandlers.
@Test
public void webSocketHandlers() {
loadBeanDefinitions("websocket-config-handlers.xml");
Map<String, HandlerMapping> handlersMap = this.appContext.getBeansOfType(HandlerMapping.class);
assertThat(handlersMap).isNotNull();
assertThat(handlersMap).hasSize(2);
for (HandlerMapping hm : handlersMap.values()) {
boolean condition2 = hm instanceof SimpleUrlHandlerMapping;
assertThat(condition2).isTrue();
SimpleUrlHandlerMapping shm = (SimpleUrlHandlerMapping) hm;
if (shm.getUrlMap().keySet().contains("/foo")) {
assertThat(shm.getUrlMap()).containsOnlyKeys("/foo", "/bar");
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/foo");
assertThat(handler).isNotNull();
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), FooWebSocketHandler.class);
HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
assertThat(handshakeHandler).isNotNull();
boolean condition1 = handshakeHandler instanceof DefaultHandshakeHandler;
assertThat(condition1).isTrue();
assertThat(handler.getHandshakeInterceptors().isEmpty()).isFalse();
boolean condition = handler.getHandshakeInterceptors().get(0) instanceof OriginHandshakeInterceptor;
assertThat(condition).isTrue();
} else {
assertThat(shm.getUrlMap()).containsOnlyKeys("/test");
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) shm.getUrlMap().get("/test");
assertThat(handler).isNotNull();
unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);
HandshakeHandler handshakeHandler = handler.getHandshakeHandler();
assertThat(handshakeHandler).isNotNull();
boolean condition1 = handshakeHandler instanceof DefaultHandshakeHandler;
assertThat(condition1).isTrue();
assertThat(handler.getHandshakeInterceptors().isEmpty()).isFalse();
boolean condition = handler.getHandshakeInterceptors().get(0) instanceof OriginHandshakeInterceptor;
assertThat(condition).isTrue();
}
}
}
Aggregations