use of org.springframework.web.socket.sockjs.transport.TransportHandler in project spring-integration by spring-projects.
the class WebSocketParserTests method testDefaultInboundChannelAdapterAndServerContainer.
@Test
@SuppressWarnings("unckecked")
public void testDefaultInboundChannelAdapterAndServerContainer() {
Map<?, ?> urlMap = TestUtils.getPropertyValue(this.handlerMapping, "urlMap", Map.class);
assertEquals(1, urlMap.size());
assertTrue(urlMap.containsKey("/ws/**"));
Object mappedHandler = urlMap.get("/ws/**");
// WebSocketHttpRequestHandler -> ExceptionWebSocketHandlerDecorator - > LoggingWebSocketHandlerDecorator
// -> IntegrationWebSocketContainer$IntegrationWebSocketHandler
assertSame(TestUtils.getPropertyValue(this.serverWebSocketContainer, "webSocketHandler"), TestUtils.getPropertyValue(mappedHandler, "webSocketHandler.delegate.delegate"));
assertSame(this.handshakeHandler, TestUtils.getPropertyValue(this.serverWebSocketContainer, "handshakeHandler"));
HandshakeInterceptor[] interceptors = TestUtils.getPropertyValue(this.serverWebSocketContainer, "interceptors", HandshakeInterceptor[].class);
assertNotNull(interceptors);
assertEquals(1, interceptors.length);
assertSame(this.handshakeInterceptor, interceptors[0]);
assertEquals(100, TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendTimeLimit"));
assertEquals(100000, TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferSizeLimit"));
assertArrayEquals(new String[] { "http://foo.com" }, TestUtils.getPropertyValue(this.serverWebSocketContainer, "origins", String[].class));
WebSocketHandlerDecoratorFactory[] decoratorFactories = TestUtils.getPropertyValue(this.serverWebSocketContainer, "decoratorFactories", WebSocketHandlerDecoratorFactory[].class);
assertNotNull(decoratorFactories);
assertEquals(1, decoratorFactories.length);
assertSame(this.decoratorFactory, decoratorFactories[0]);
TransportHandlingSockJsService sockJsService = TestUtils.getPropertyValue(mappedHandler, "sockJsService", TransportHandlingSockJsService.class);
assertSame(this.taskScheduler, sockJsService.getTaskScheduler());
assertSame(this.sockJsMessageCodec, sockJsService.getMessageCodec());
Map<TransportType, TransportHandler> transportHandlers = sockJsService.getTransportHandlers();
// If "handshake-handler" is provided, "transport-handlers" isn't allowed
assertEquals(8, transportHandlers.size());
assertSame(this.handshakeHandler, TestUtils.getPropertyValue(transportHandlers.get(TransportType.WEBSOCKET), "handshakeHandler"));
assertEquals(4000L, sockJsService.getDisconnectDelay());
assertEquals(30000L, sockJsService.getHeartbeatTime());
assertEquals(10000, sockJsService.getHttpMessageCacheSize());
assertEquals(2000, sockJsService.getStreamBytesLimit());
assertEquals("https://foo.sock.js", sockJsService.getSockJsClientLibraryUrl());
assertFalse(sockJsService.isSessionCookieNeeded());
assertFalse(sockJsService.isWebSocketEnabled());
assertTrue(sockJsService.shouldSuppressCors());
assertSame(this.serverWebSocketContainer, TestUtils.getPropertyValue(this.defaultInboundAdapter, "webSocketContainer"));
assertNull(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverters"));
assertEquals(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverter.converters"), TestUtils.getPropertyValue(this.defaultInboundAdapter, "defaultConverters"));
assertEquals(String.class, TestUtils.getPropertyValue(this.defaultInboundAdapter, "payloadType", AtomicReference.class).get());
assertTrue(TestUtils.getPropertyValue(this.defaultInboundAdapter, "useBroker", Boolean.class));
assertSame(this.brokerHandler, TestUtils.getPropertyValue(this.defaultInboundAdapter, "brokerHandler"));
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.defaultInboundAdapter, "subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"), instanceOf(PassThruSubProtocolHandler.class));
assertTrue(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class).isEmpty());
}
use of org.springframework.web.socket.sockjs.transport.TransportHandler in project spring-framework by spring-projects.
the class TestMessageCodec method sockJs.
@Test
public void sockJs() {
loadBeanDefinitions("websocket-config-handlers-sockjs.xml");
SimpleUrlHandlerMapping handlerMapping = this.appContext.getBean(SimpleUrlHandlerMapping.class);
assertThat(handlerMapping).isNotNull();
SockJsHttpRequestHandler testHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
assertThat(testHandler).isNotNull();
unwrapAndCheckDecoratedHandlerType(testHandler.getWebSocketHandler(), TestWebSocketHandler.class);
SockJsService testSockJsService = testHandler.getSockJsService();
SockJsHttpRequestHandler fooHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/foo/**");
assertThat(fooHandler).isNotNull();
unwrapAndCheckDecoratedHandlerType(fooHandler.getWebSocketHandler(), FooWebSocketHandler.class);
SockJsService sockJsService = fooHandler.getSockJsService();
assertThat(sockJsService).isNotNull();
assertThat(sockJsService).isSameAs(testSockJsService);
assertThat(sockJsService).isInstanceOf(DefaultSockJsService.class);
DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService;
assertThat(defaultSockJsService.getTaskScheduler()).isInstanceOf(ThreadPoolTaskScheduler.class);
assertThat(defaultSockJsService.shouldSuppressCors()).isFalse();
Map<TransportType, TransportHandler> handlerMap = defaultSockJsService.getTransportHandlers();
assertThat(handlerMap.values()).extracting("class").containsExactlyInAnyOrder(XhrPollingTransportHandler.class, XhrReceivingTransportHandler.class, XhrStreamingTransportHandler.class, EventSourceTransportHandler.class, HtmlFileTransportHandler.class, WebSocketTransportHandler.class);
WebSocketTransportHandler handler = (WebSocketTransportHandler) handlerMap.get(TransportType.WEBSOCKET);
assertThat(handler.getHandshakeHandler().getClass()).isEqualTo(TestHandshakeHandler.class);
List<HandshakeInterceptor> interceptors = defaultSockJsService.getHandshakeInterceptors();
assertThat(interceptors).extracting("class").containsExactlyInAnyOrder(FooTestInterceptor.class, BarTestInterceptor.class, OriginHandshakeInterceptor.class);
}
use of org.springframework.web.socket.sockjs.transport.TransportHandler in project spring-framework by spring-projects.
the class DefaultSockJsServiceTests method customizedTransportHandlerList.
@Test
public void customizedTransportHandlerList() {
TransportHandlingSockJsService service = new TransportHandlingSockJsService(mock(TaskScheduler.class), new XhrPollingTransportHandler(), new XhrReceivingTransportHandler());
Map<TransportType, TransportHandler> actualHandlers = service.getTransportHandlers();
assertThat(actualHandlers.size()).isEqualTo(2);
}
use of org.springframework.web.socket.sockjs.transport.TransportHandler 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.TransportHandler 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