use of org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler in project spring-framework by spring-projects.
the class WebMvcStompWebSocketEndpointRegistrationTests method handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins.
@Test
public void handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins() {
WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
String origin = "https://mydomain.com";
registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin).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);
assertThat(sockJsService.getAllowedOrigins().contains(origin)).isTrue();
}
use of org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler 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);
}
Aggregations