org.springframework.web.socket.sockjs.transport.TransportHandler Java Examples
The following examples show how to use
org.springframework.web.socket.sockjs.transport.TransportHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultSockJsService.java From spring4-understanding with Apache License 2.0 | 6 votes |
private static Set<TransportHandler> getDefaultTransportHandlers(Collection<TransportHandler> overrides) { Set<TransportHandler> result = new LinkedHashSet<TransportHandler>(8); result.add(new XhrPollingTransportHandler()); result.add(new XhrReceivingTransportHandler()); result.add(new XhrStreamingTransportHandler()); result.add(new JsonpPollingTransportHandler()); result.add(new JsonpReceivingTransportHandler()); result.add(new EventSourceTransportHandler()); result.add(new HtmlFileTransportHandler()); try { result.add(new WebSocketTransportHandler(new DefaultHandshakeHandler())); } catch (Exception ex) { Log logger = LogFactory.getLog(DefaultSockJsService.class); if (logger.isWarnEnabled()) { logger.warn("Failed to create a default WebSocketTransportHandler", ex); } } if (overrides != null) { result.addAll(overrides); } return result; }
Example #2
Source File: DefaultSockJsService.java From spring-analysis-note with MIT License | 6 votes |
private static Set<TransportHandler> getDefaultTransportHandlers(@Nullable Collection<TransportHandler> overrides) { Set<TransportHandler> result = new LinkedHashSet<>(8); result.add(new XhrPollingTransportHandler()); result.add(new XhrReceivingTransportHandler()); result.add(new XhrStreamingTransportHandler()); result.add(new EventSourceTransportHandler()); result.add(new HtmlFileTransportHandler()); try { result.add(new WebSocketTransportHandler(new DefaultHandshakeHandler())); } catch (Exception ex) { Log logger = LogFactory.getLog(DefaultSockJsService.class); if (logger.isWarnEnabled()) { logger.warn("Failed to create a default WebSocketTransportHandler", ex); } } if (overrides != null) { result.addAll(overrides); } return result; }
Example #3
Source File: DefaultSockJsService.java From java-technology-stack with MIT License | 6 votes |
private static Set<TransportHandler> getDefaultTransportHandlers(@Nullable Collection<TransportHandler> overrides) { Set<TransportHandler> result = new LinkedHashSet<>(8); result.add(new XhrPollingTransportHandler()); result.add(new XhrReceivingTransportHandler()); result.add(new XhrStreamingTransportHandler()); result.add(new EventSourceTransportHandler()); result.add(new HtmlFileTransportHandler()); try { result.add(new WebSocketTransportHandler(new DefaultHandshakeHandler())); } catch (Exception ex) { Log logger = LogFactory.getLog(DefaultSockJsService.class); if (logger.isWarnEnabled()) { logger.warn("Failed to create a default WebSocketTransportHandler", ex); } } if (overrides != null) { result.addAll(overrides); } return result; }
Example #4
Source File: DefaultSockJsService.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void setServletContext(ServletContext servletContext) { for (TransportHandler handler : getTransportHandlers().values()) { if (handler instanceof ServletContextAware) { ((ServletContextAware) handler).setServletContext(servletContext); } } }
Example #5
Source File: SockJsServiceRegistration.java From spring4-understanding with Apache License 2.0 | 5 votes |
public SockJsServiceRegistration setTransportHandlers(TransportHandler... handlers) { this.transportHandlers.clear(); if (!ObjectUtils.isEmpty(handlers)) { this.transportHandlers.addAll(Arrays.asList(handlers)); } return this; }
Example #6
Source File: SockJsServiceRegistration.java From spring4-understanding with Apache License 2.0 | 5 votes |
public SockJsServiceRegistration setTransportHandlerOverrides(TransportHandler... handlers) { this.transportHandlerOverrides.clear(); if (!ObjectUtils.isEmpty(handlers)) { this.transportHandlerOverrides.addAll(Arrays.asList(handlers)); } return this; }
Example #7
Source File: DefaultSockJsServiceTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void defaultTransportHandlers() { DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class)); Map<TransportType, TransportHandler> handlers = service.getTransportHandlers(); assertEquals(8, handlers.size()); assertNotNull(handlers.get(TransportType.WEBSOCKET)); assertNotNull(handlers.get(TransportType.XHR)); assertNotNull(handlers.get(TransportType.XHR_SEND)); assertNotNull(handlers.get(TransportType.XHR_STREAMING)); assertNotNull(handlers.get(TransportType.JSONP)); assertNotNull(handlers.get(TransportType.JSONP_SEND)); assertNotNull(handlers.get(TransportType.HTML_FILE)); assertNotNull(handlers.get(TransportType.EVENT_SOURCE)); }
Example #8
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From java-technology-stack with MIT License | 5 votes |
@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 = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler) .addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); }
Example #9
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From java-technology-stack with MIT License | 5 votes |
@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(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); }
Example #10
Source File: DefaultSockJsServiceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void customizedTransportHandlerList() { TransportHandlingSockJsService service = new TransportHandlingSockJsService( mock(TaskScheduler.class), new XhrPollingTransportHandler(), new XhrReceivingTransportHandler()); Map<TransportType, TransportHandler> actualHandlers = service.getTransportHandlers(); assertEquals(2, actualHandlers.size()); }
Example #11
Source File: DefaultSockJsServiceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void defaultTransportHandlersWithOverride() { XhrReceivingTransportHandler xhrHandler = new XhrReceivingTransportHandler(); DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class), xhrHandler); Map<TransportType, TransportHandler> handlers = service.getTransportHandlers(); assertEquals(6, handlers.size()); assertSame(xhrHandler, handlers.get(xhrHandler.getTransportType())); }
Example #12
Source File: DefaultSockJsServiceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void defaultTransportHandlers() { DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class)); Map<TransportType, TransportHandler> handlers = service.getTransportHandlers(); assertEquals(6, handlers.size()); assertNotNull(handlers.get(TransportType.WEBSOCKET)); assertNotNull(handlers.get(TransportType.XHR)); assertNotNull(handlers.get(TransportType.XHR_SEND)); assertNotNull(handlers.get(TransportType.XHR_STREAMING)); assertNotNull(handlers.get(TransportType.HTML_FILE)); assertNotNull(handlers.get(TransportType.EVENT_SOURCE)); }
Example #13
Source File: SockJsServiceRegistration.java From java-technology-stack with MIT License | 5 votes |
public SockJsServiceRegistration setTransportHandlerOverrides(TransportHandler... handlers) { this.transportHandlerOverrides.clear(); if (!ObjectUtils.isEmpty(handlers)) { this.transportHandlerOverrides.addAll(Arrays.asList(handlers)); } return this; }
Example #14
Source File: SockJsServiceRegistration.java From java-technology-stack with MIT License | 5 votes |
public SockJsServiceRegistration setTransportHandlers(TransportHandler... handlers) { this.transportHandlers.clear(); if (!ObjectUtils.isEmpty(handlers)) { this.transportHandlers.addAll(Arrays.asList(handlers)); } return this; }
Example #15
Source File: DefaultSockJsService.java From java-technology-stack with MIT License | 5 votes |
@Override public void setServletContext(ServletContext servletContext) { for (TransportHandler handler : getTransportHandlers().values()) { if (handler instanceof ServletContextAware) { ((ServletContextAware) handler).setServletContext(servletContext); } } }
Example #16
Source File: DefaultSockJsServiceTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void defaultTransportHandlersWithOverride() { XhrReceivingTransportHandler xhrHandler = new XhrReceivingTransportHandler(); DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class), xhrHandler); Map<TransportType, TransportHandler> handlers = service.getTransportHandlers(); assertEquals(8, handlers.size()); assertSame(xhrHandler, handlers.get(xhrHandler.getTransportType())); }
Example #17
Source File: DefaultSockJsServiceTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void customizedTransportHandlerList() { TransportHandlingSockJsService service = new TransportHandlingSockJsService( mock(TaskScheduler.class), new XhrPollingTransportHandler(), new XhrReceivingTransportHandler()); Map<TransportType, TransportHandler> actualHandlers = service.getTransportHandlers(); assertEquals(2, actualHandlers.size()); }
Example #18
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); }
Example #19
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring-analysis-note with MIT License | 5 votes |
@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(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); }
Example #20
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring-analysis-note with MIT License | 5 votes |
@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(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); }
Example #21
Source File: DefaultSockJsServiceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void customizedTransportHandlerList() { TransportHandlingSockJsService service = new TransportHandlingSockJsService( mock(TaskScheduler.class), new XhrPollingTransportHandler(), new XhrReceivingTransportHandler()); Map<TransportType, TransportHandler> actualHandlers = service.getTransportHandlers(); assertEquals(2, actualHandlers.size()); }
Example #22
Source File: DefaultSockJsServiceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void defaultTransportHandlersWithOverride() { XhrReceivingTransportHandler xhrHandler = new XhrReceivingTransportHandler(); DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class), xhrHandler); Map<TransportType, TransportHandler> handlers = service.getTransportHandlers(); assertEquals(6, handlers.size()); assertSame(xhrHandler, handlers.get(xhrHandler.getTransportType())); }
Example #23
Source File: DefaultSockJsServiceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void defaultTransportHandlers() { DefaultSockJsService service = new DefaultSockJsService(mock(TaskScheduler.class)); Map<TransportType, TransportHandler> handlers = service.getTransportHandlers(); assertEquals(6, handlers.size()); assertNotNull(handlers.get(TransportType.WEBSOCKET)); assertNotNull(handlers.get(TransportType.XHR)); assertNotNull(handlers.get(TransportType.XHR_SEND)); assertNotNull(handlers.get(TransportType.XHR_STREAMING)); assertNotNull(handlers.get(TransportType.HTML_FILE)); assertNotNull(handlers.get(TransportType.EVENT_SOURCE)); }
Example #24
Source File: SockJsServiceRegistration.java From spring-analysis-note with MIT License | 5 votes |
public SockJsServiceRegistration setTransportHandlerOverrides(TransportHandler... handlers) { this.transportHandlerOverrides.clear(); if (!ObjectUtils.isEmpty(handlers)) { this.transportHandlerOverrides.addAll(Arrays.asList(handlers)); } return this; }
Example #25
Source File: SockJsServiceRegistration.java From spring-analysis-note with MIT License | 5 votes |
public SockJsServiceRegistration setTransportHandlers(TransportHandler... handlers) { this.transportHandlers.clear(); if (!ObjectUtils.isEmpty(handlers)) { this.transportHandlers.addAll(Arrays.asList(handlers)); } return this; }
Example #26
Source File: DefaultSockJsService.java From spring-analysis-note with MIT License | 5 votes |
@Override public void setServletContext(ServletContext servletContext) { for (TransportHandler handler : getTransportHandlers().values()) { if (handler instanceof ServletContextAware) { ((ServletContextAware) handler).setServletContext(servletContext); } } }
Example #27
Source File: WebMvcStompWebSocketEndpointRegistrationTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 = "http://mydomain.com"; registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next(); assertEquals(Arrays.asList("/foo/**"), entry.getValue()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey(); assertNotNull(requestHandler.getWebSocketHandler()); DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService(); assertNotNull(sockJsService); Map<TransportType, TransportHandler> handlers = sockJsService.getTransportHandlers(); WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET); assertSame(handshakeHandler, transportHandler.getHandshakeHandler()); assertEquals(2, sockJsService.getHandshakeInterceptors().size()); assertEquals(interceptor, sockJsService.getHandshakeInterceptors().get(0)); assertEquals(OriginHandshakeInterceptor.class, sockJsService.getHandshakeInterceptors().get(1).getClass()); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); }
Example #28
Source File: HandlersBeanDefinitionParserTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings("unchecked") public void sockJs() { loadBeanDefinitions("websocket-config-handlers-sockjs.xml"); SimpleUrlHandlerMapping handlerMapping = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(handlerMapping); SockJsHttpRequestHandler testHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**"); assertNotNull(testHandler); unwrapAndCheckDecoratedHandlerType(testHandler.getWebSocketHandler(), TestWebSocketHandler.class); SockJsService testSockJsService = testHandler.getSockJsService(); SockJsHttpRequestHandler fooHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/foo/**"); assertNotNull(fooHandler); unwrapAndCheckDecoratedHandlerType(fooHandler.getWebSocketHandler(), FooWebSocketHandler.class); SockJsService sockJsService = fooHandler.getSockJsService(); assertNotNull(sockJsService); assertSame(testSockJsService, sockJsService); assertThat(sockJsService, instanceOf(DefaultSockJsService.class)); DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService; assertThat(defaultSockJsService.getTaskScheduler(), instanceOf(ThreadPoolTaskScheduler.class)); assertFalse(defaultSockJsService.shouldSuppressCors()); Map<TransportType, TransportHandler> transportHandlers = defaultSockJsService.getTransportHandlers(); assertThat(transportHandlers.values(), containsInAnyOrder( instanceOf(XhrPollingTransportHandler.class), instanceOf(XhrReceivingTransportHandler.class), instanceOf(JsonpPollingTransportHandler.class), instanceOf(JsonpReceivingTransportHandler.class), instanceOf(XhrStreamingTransportHandler.class), instanceOf(EventSourceTransportHandler.class), instanceOf(HtmlFileTransportHandler.class), instanceOf(WebSocketTransportHandler.class))); WebSocketTransportHandler handler = (WebSocketTransportHandler) transportHandlers.get(TransportType.WEBSOCKET); assertEquals(TestHandshakeHandler.class, handler.getHandshakeHandler().getClass()); List<HandshakeInterceptor> interceptors = defaultSockJsService.getHandshakeInterceptors(); assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class), instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class))); }
Example #29
Source File: HandlersBeanDefinitionParserTests.java From java-technology-stack with MIT License | 4 votes |
@Test @SuppressWarnings("unchecked") public void sockJs() { loadBeanDefinitions("websocket-config-handlers-sockjs.xml"); SimpleUrlHandlerMapping handlerMapping = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(handlerMapping); SockJsHttpRequestHandler testHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**"); assertNotNull(testHandler); unwrapAndCheckDecoratedHandlerType(testHandler.getWebSocketHandler(), TestWebSocketHandler.class); SockJsService testSockJsService = testHandler.getSockJsService(); SockJsHttpRequestHandler fooHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/foo/**"); assertNotNull(fooHandler); unwrapAndCheckDecoratedHandlerType(fooHandler.getWebSocketHandler(), FooWebSocketHandler.class); SockJsService sockJsService = fooHandler.getSockJsService(); assertNotNull(sockJsService); assertSame(testSockJsService, sockJsService); assertThat(sockJsService, instanceOf(DefaultSockJsService.class)); DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService; assertThat(defaultSockJsService.getTaskScheduler(), instanceOf(ThreadPoolTaskScheduler.class)); assertFalse(defaultSockJsService.shouldSuppressCors()); Map<TransportType, TransportHandler> handlerMap = defaultSockJsService.getTransportHandlers(); assertThat(handlerMap.values(), containsInAnyOrder( instanceOf(XhrPollingTransportHandler.class), instanceOf(XhrReceivingTransportHandler.class), instanceOf(XhrStreamingTransportHandler.class), instanceOf(EventSourceTransportHandler.class), instanceOf(HtmlFileTransportHandler.class), instanceOf(WebSocketTransportHandler.class))); WebSocketTransportHandler handler = (WebSocketTransportHandler) handlerMap.get(TransportType.WEBSOCKET); assertEquals(TestHandshakeHandler.class, handler.getHandshakeHandler().getClass()); List<HandshakeInterceptor> interceptors = defaultSockJsService.getHandshakeInterceptors(); assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class), instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class))); }
Example #30
Source File: HandlersBeanDefinitionParserTests.java From spring-analysis-note with MIT License | 4 votes |
@Test @SuppressWarnings("unchecked") public void sockJs() { loadBeanDefinitions("websocket-config-handlers-sockjs.xml"); SimpleUrlHandlerMapping handlerMapping = this.appContext.getBean(SimpleUrlHandlerMapping.class); assertNotNull(handlerMapping); SockJsHttpRequestHandler testHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**"); assertNotNull(testHandler); unwrapAndCheckDecoratedHandlerType(testHandler.getWebSocketHandler(), TestWebSocketHandler.class); SockJsService testSockJsService = testHandler.getSockJsService(); SockJsHttpRequestHandler fooHandler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/foo/**"); assertNotNull(fooHandler); unwrapAndCheckDecoratedHandlerType(fooHandler.getWebSocketHandler(), FooWebSocketHandler.class); SockJsService sockJsService = fooHandler.getSockJsService(); assertNotNull(sockJsService); assertSame(testSockJsService, sockJsService); assertThat(sockJsService, instanceOf(DefaultSockJsService.class)); DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsService; assertThat(defaultSockJsService.getTaskScheduler(), instanceOf(ThreadPoolTaskScheduler.class)); assertFalse(defaultSockJsService.shouldSuppressCors()); Map<TransportType, TransportHandler> handlerMap = defaultSockJsService.getTransportHandlers(); assertThat(handlerMap.values(), containsInAnyOrder( instanceOf(XhrPollingTransportHandler.class), instanceOf(XhrReceivingTransportHandler.class), instanceOf(XhrStreamingTransportHandler.class), instanceOf(EventSourceTransportHandler.class), instanceOf(HtmlFileTransportHandler.class), instanceOf(WebSocketTransportHandler.class))); WebSocketTransportHandler handler = (WebSocketTransportHandler) handlerMap.get(TransportType.WEBSOCKET); assertEquals(TestHandshakeHandler.class, handler.getHandshakeHandler().getClass()); List<HandshakeInterceptor> interceptors = defaultSockJsService.getHandshakeInterceptors(); assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class), instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class))); }