org.springframework.web.socket.sockjs.SockJsService Java Examples

The following examples show how to use org.springframework.web.socket.sockjs.SockJsService. 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: WebSocketConfigurer.java    From computoser with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
public SimpleUrlHandlerMapping handlerMapping() {

    SockJsService sockJsService = new DefaultSockJsService(taskScheduler());

    Map<String, Object> urlMap = new HashMap<String, Object>();
    urlMap.put("/game/websocket/**", new SockJsHttpRequestHandler(sockJsService, gameHandler));

    SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
    hm.setUrlMap(urlMap);
    return hm;
}
 
Example #2
Source File: ServletWebSocketHandlerRegistration.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected void addSockJsServiceMapping(MultiValueMap<HttpRequestHandler, String> mappings,
		SockJsService sockJsService, WebSocketHandler handler, String pathPattern) {

	SockJsHttpRequestHandler httpHandler = new SockJsHttpRequestHandler(sockJsService, handler);
	mappings.add(httpHandler, pathPattern);
}
 
Example #3
Source File: SockJsHttpRequestHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new SockJsHttpRequestHandler.
 * @param sockJsService the SockJS service
 * @param webSocketHandler the websocket handler
 */
public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler) {
	Assert.notNull(sockJsService, "SockJsService must not be null");
	Assert.notNull(webSocketHandler, "WebSocketHandler must not be null");
	this.sockJsService = sockJsService;
	this.webSocketHandler =
			new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(webSocketHandler));
}
 
Example #4
Source File: HandlersBeanDefinitionParserTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void sockJsAttributes() {
	loadBeanDefinitions("websocket-config-handlers-sockjs-attributes.xml");

	SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(handlerMapping);

	SockJsHttpRequestHandler handler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
	assertNotNull(handler);
	unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);

	SockJsService sockJsService = handler.getSockJsService();
	assertNotNull(sockJsService);
	assertThat(sockJsService, instanceOf(TransportHandlingSockJsService.class));
	TransportHandlingSockJsService transportService = (TransportHandlingSockJsService) sockJsService;
	assertThat(transportService.getTaskScheduler(), instanceOf(TestTaskScheduler.class));
	assertThat(transportService.getTransportHandlers().values(),
			containsInAnyOrder(
					instanceOf(XhrPollingTransportHandler.class),
					instanceOf(XhrStreamingTransportHandler.class)));

	assertEquals("testSockJsService", transportService.getName());
	assertFalse(transportService.isWebSocketEnabled());
	assertFalse(transportService.isSessionCookieNeeded());
	assertEquals(2048, transportService.getStreamBytesLimit());
	assertEquals(256, transportService.getDisconnectDelay());
	assertEquals(1024, transportService.getHttpMessageCacheSize());
	assertEquals(20, transportService.getHeartbeatTime());
	assertEquals("/js/sockjs.min.js", transportService.getSockJsClientLibraryUrl());
	assertEquals(TestMessageCodec.class, transportService.getMessageCodec().getClass());

	List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors();
	assertThat(interceptors, contains(instanceOf(OriginHandshakeInterceptor.class)));
	assertTrue(transportService.shouldSuppressCors());
	assertTrue(transportService.getAllowedOrigins().contains("http://mydomain1.com"));
	assertTrue(transportService.getAllowedOrigins().contains("http://mydomain2.com"));
}
 
Example #5
Source File: SockJsServiceRegistration.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected SockJsService getSockJsService() {
	TransportHandlingSockJsService service = createSockJsService();
	service.setHandshakeInterceptors(this.interceptors);
	if (this.clientLibraryUrl != null) {
		service.setSockJsClientLibraryUrl(this.clientLibraryUrl);
	}
	if (this.streamBytesLimit != null) {
		service.setStreamBytesLimit(this.streamBytesLimit);
	}
	if (this.sessionCookieNeeded != null) {
		service.setSessionCookieNeeded(this.sessionCookieNeeded);
	}
	if (this.heartbeatTime != null) {
		service.setHeartbeatTime(this.heartbeatTime);
	}
	if (this.disconnectDelay != null) {
		service.setDisconnectDelay(this.disconnectDelay);
	}
	if (this.httpMessageCacheSize != null) {
		service.setHttpMessageCacheSize(this.httpMessageCacheSize);
	}
	if (this.webSocketEnabled != null) {
		service.setWebSocketEnabled(this.webSocketEnabled);
	}
	if (this.allowedOrigins != null) {
		service.setAllowedOrigins(this.allowedOrigins);
	}
	if (this.suppressCors != null) {
		service.setSuppressCors(this.suppressCors);
	}
	if (this.messageCodec != null) {
		service.setMessageCodec(this.messageCodec);
	}
	return service;
}
 
Example #6
Source File: WebSocketHandlerRegistrationTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
public Mapping(WebSocketHandler handler, String path, SockJsService sockJsService) {
	this.webSocketHandler = handler;
	this.path = path;
	this.handshakeHandler = null;
	this.interceptors = null;
	this.sockJsService = (DefaultSockJsService) sockJsService;
}
 
Example #7
Source File: SockJsHttpRequestHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new SockJsHttpRequestHandler.
 * @param sockJsService the SockJS service
 * @param webSocketHandler the websocket handler
 */
public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler) {
	Assert.notNull(sockJsService, "SockJsService must not be null");
	Assert.notNull(webSocketHandler, "WebSocketHandler must not be null");
	this.sockJsService = sockJsService;
	this.webSocketHandler =
			new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(webSocketHandler));
}
 
Example #8
Source File: SockJsServiceRegistration.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected SockJsService getSockJsService() {
	TransportHandlingSockJsService service = createSockJsService();
	service.setHandshakeInterceptors(this.interceptors);

	if (this.clientLibraryUrl != null) {
		service.setSockJsClientLibraryUrl(this.clientLibraryUrl);
	}
	if (this.streamBytesLimit != null) {
		service.setStreamBytesLimit(this.streamBytesLimit);
	}
	if (this.sessionCookieNeeded != null) {
		service.setSessionCookieNeeded(this.sessionCookieNeeded);
	}
	if (this.heartbeatTime != null) {
		service.setHeartbeatTime(this.heartbeatTime);
	}
	if (this.disconnectDelay != null) {
		service.setDisconnectDelay(this.disconnectDelay);
	}
	if (this.httpMessageCacheSize != null) {
		service.setHttpMessageCacheSize(this.httpMessageCacheSize);
	}
	if (this.webSocketEnabled != null) {
		service.setWebSocketEnabled(this.webSocketEnabled);
	}
	if (this.suppressCors != null) {
		service.setSuppressCors(this.suppressCors);
	}
	service.setAllowedOrigins(this.allowedOrigins);

	if (this.messageCodec != null) {
		service.setMessageCodec(this.messageCodec);
	}
	return service;
}
 
Example #9
Source File: ServletWebSocketHandlerRegistration.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void addSockJsServiceMapping(MultiValueMap<HttpRequestHandler, String> mappings,
		SockJsService sockJsService, WebSocketHandler handler, String pathPattern) {

	SockJsHttpRequestHandler httpHandler = new SockJsHttpRequestHandler(sockJsService, handler);
	mappings.add(httpHandler, pathPattern);
}
 
Example #10
Source File: SockJsHttpRequestHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new SockJsHttpRequestHandler.
 * @param sockJsService the SockJS service
 * @param webSocketHandler the websocket handler
 */
public SockJsHttpRequestHandler(SockJsService sockJsService, WebSocketHandler webSocketHandler) {
	Assert.notNull(sockJsService, "SockJsService must not be null");
	Assert.notNull(webSocketHandler, "WebSocketHandler must not be null");
	this.sockJsService = sockJsService;
	this.webSocketHandler =
			new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(webSocketHandler));
}
 
Example #11
Source File: HandlersBeanDefinitionParserTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void sockJsAttributes() {
	loadBeanDefinitions("websocket-config-handlers-sockjs-attributes.xml");

	SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(handlerMapping);

	SockJsHttpRequestHandler handler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
	assertNotNull(handler);
	unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);

	SockJsService sockJsService = handler.getSockJsService();
	assertNotNull(sockJsService);
	assertThat(sockJsService, instanceOf(TransportHandlingSockJsService.class));
	TransportHandlingSockJsService transportService = (TransportHandlingSockJsService) sockJsService;
	assertThat(transportService.getTaskScheduler(), instanceOf(TestTaskScheduler.class));
	assertThat(transportService.getTransportHandlers().values(),
			containsInAnyOrder(
					instanceOf(XhrPollingTransportHandler.class),
					instanceOf(XhrStreamingTransportHandler.class)));

	assertEquals("testSockJsService", transportService.getName());
	assertFalse(transportService.isWebSocketEnabled());
	assertFalse(transportService.isSessionCookieNeeded());
	assertEquals(2048, transportService.getStreamBytesLimit());
	assertEquals(256, transportService.getDisconnectDelay());
	assertEquals(1024, transportService.getHttpMessageCacheSize());
	assertEquals(20, transportService.getHeartbeatTime());
	assertEquals("/js/sockjs.min.js", transportService.getSockJsClientLibraryUrl());
	assertEquals(TestMessageCodec.class, transportService.getMessageCodec().getClass());

	List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors();
	assertThat(interceptors, contains(instanceOf(OriginHandshakeInterceptor.class)));
	assertTrue(transportService.shouldSuppressCors());
	assertTrue(transportService.getAllowedOrigins().contains("https://mydomain1.com"));
	assertTrue(transportService.getAllowedOrigins().contains("https://mydomain2.com"));
}
 
Example #12
Source File: WebSocketHandlerRegistrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public Mapping(WebSocketHandler handler, String path, SockJsService sockJsService) {
	this.webSocketHandler = handler;
	this.path = path;
	this.handshakeHandler = null;
	this.interceptors = null;
	this.sockJsService = (DefaultSockJsService) sockJsService;
}
 
Example #13
Source File: WebSocketHandlerRegistrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public Mapping(WebSocketHandler handler, String path, SockJsService sockJsService) {
	this.webSocketHandler = handler;
	this.path = path;
	this.handshakeHandler = null;
	this.interceptors = null;
	this.sockJsService = (DefaultSockJsService) sockJsService;
}
 
Example #14
Source File: HandlersBeanDefinitionParserTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void sockJsAttributes() {
	loadBeanDefinitions("websocket-config-handlers-sockjs-attributes.xml");

	SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(handlerMapping);

	SockJsHttpRequestHandler handler = (SockJsHttpRequestHandler) handlerMapping.getUrlMap().get("/test/**");
	assertNotNull(handler);
	unwrapAndCheckDecoratedHandlerType(handler.getWebSocketHandler(), TestWebSocketHandler.class);

	SockJsService sockJsService = handler.getSockJsService();
	assertNotNull(sockJsService);
	assertThat(sockJsService, instanceOf(TransportHandlingSockJsService.class));
	TransportHandlingSockJsService transportService = (TransportHandlingSockJsService) sockJsService;
	assertThat(transportService.getTaskScheduler(), instanceOf(TestTaskScheduler.class));
	assertThat(transportService.getTransportHandlers().values(),
			containsInAnyOrder(
					instanceOf(XhrPollingTransportHandler.class),
					instanceOf(XhrStreamingTransportHandler.class)));

	assertEquals("testSockJsService", transportService.getName());
	assertFalse(transportService.isWebSocketEnabled());
	assertFalse(transportService.isSessionCookieNeeded());
	assertEquals(2048, transportService.getStreamBytesLimit());
	assertEquals(256, transportService.getDisconnectDelay());
	assertEquals(1024, transportService.getHttpMessageCacheSize());
	assertEquals(20, transportService.getHeartbeatTime());
	assertEquals("/js/sockjs.min.js", transportService.getSockJsClientLibraryUrl());
	assertEquals(TestMessageCodec.class, transportService.getMessageCodec().getClass());

	List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors();
	assertThat(interceptors, contains(instanceOf(OriginHandshakeInterceptor.class)));
	assertTrue(transportService.shouldSuppressCors());
	assertTrue(transportService.getAllowedOrigins().contains("http://mydomain1.com"));
	assertTrue(transportService.getAllowedOrigins().contains("http://mydomain2.com"));
}
 
Example #15
Source File: SockJsServiceRegistration.java    From spring-analysis-note with MIT License 5 votes vote down vote up
protected SockJsService getSockJsService() {
	TransportHandlingSockJsService service = createSockJsService();
	service.setHandshakeInterceptors(this.interceptors);

	if (this.clientLibraryUrl != null) {
		service.setSockJsClientLibraryUrl(this.clientLibraryUrl);
	}
	if (this.streamBytesLimit != null) {
		service.setStreamBytesLimit(this.streamBytesLimit);
	}
	if (this.sessionCookieNeeded != null) {
		service.setSessionCookieNeeded(this.sessionCookieNeeded);
	}
	if (this.heartbeatTime != null) {
		service.setHeartbeatTime(this.heartbeatTime);
	}
	if (this.disconnectDelay != null) {
		service.setDisconnectDelay(this.disconnectDelay);
	}
	if (this.httpMessageCacheSize != null) {
		service.setHttpMessageCacheSize(this.httpMessageCacheSize);
	}
	if (this.webSocketEnabled != null) {
		service.setWebSocketEnabled(this.webSocketEnabled);
	}
	if (this.suppressCors != null) {
		service.setSuppressCors(this.suppressCors);
	}
	service.setAllowedOrigins(this.allowedOrigins);

	if (this.messageCodec != null) {
		service.setMessageCodec(this.messageCodec);
	}
	return service;
}
 
Example #16
Source File: ServletWebSocketHandlerRegistration.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void addSockJsServiceMapping(MultiValueMap<HttpRequestHandler, String> mappings,
		SockJsService sockJsService, WebSocketHandler handler, String pathPattern) {

	SockJsHttpRequestHandler httpHandler = new SockJsHttpRequestHandler(sockJsService, handler);
	mappings.add(httpHandler, pathPattern);
}
 
Example #17
Source File: WebSocketHandlerRegistrationTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void addSockJsServiceMapping(List<Mapping> mappings, SockJsService sockJsService,
		WebSocketHandler wsHandler, String pathPattern) {

	mappings.add(new Mapping(wsHandler, pathPattern, sockJsService));
}
 
Example #18
Source File: AbstractWebSocketHandlerRegistration.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected abstract void addSockJsServiceMapping(M mappings, SockJsService sockJsService,
WebSocketHandler handler, String pathPattern);
 
Example #19
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)));
}
 
Example #20
Source File: WebMvcStompWebSocketEndpointRegistration.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected SockJsService getSockJsService() {
	return super.getSockJsService();
}
 
Example #21
Source File: WebSocketHandlerRegistrationTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void addSockJsServiceMapping(List<Mapping> mappings, SockJsService sockJsService,
		WebSocketHandler wsHandler, String pathPattern) {

	mappings.add(new Mapping(wsHandler, pathPattern, sockJsService));
}
 
Example #22
Source File: SockJsHttpRequestHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return the {@link SockJsService}.
 */
public SockJsService getSockJsService() {
	return this.sockJsService;
}
 
Example #23
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 #24
Source File: AbstractWebSocketHandlerRegistration.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected abstract void addSockJsServiceMapping(M mappings, SockJsService sockJsService,
WebSocketHandler handler, String pathPattern);
 
Example #25
Source File: SockJsHttpRequestHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the {@link SockJsService}.
 */
public SockJsService getSockJsService() {
	return this.sockJsService;
}
 
Example #26
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 #27
Source File: WebSocketHandlerRegistrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void addSockJsServiceMapping(List<Mapping> mappings, SockJsService sockJsService,
		WebSocketHandler wsHandler, String pathPattern) {

	mappings.add(new Mapping(wsHandler, pathPattern, sockJsService));
}
 
Example #28
Source File: AbstractWebSocketHandlerRegistration.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected abstract void addSockJsServiceMapping(M mappings, SockJsService sockJsService,
WebSocketHandler handler, String pathPattern);
 
Example #29
Source File: SockJsHttpRequestHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the {@link SockJsService}.
 */
public SockJsService getSockJsService() {
	return this.sockJsService;
}