org.springframework.web.socket.sockjs.transport.handler.HtmlFileTransportHandler Java Examples

The following examples show how to use org.springframework.web.socket.sockjs.transport.handler.HtmlFileTransportHandler. 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: HandlersBeanDefinitionParserTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@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 #2
Source File: HandlersBeanDefinitionParserTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@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 #3
Source File: HandlersBeanDefinitionParserTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@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)));
}