use of org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService in project spring-framework by spring-projects.
the class TestMessageCodec method sockJsAttributes.
@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"));
}
use of org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService in project spring-security by spring-projects.
the class AbstractSecurityWebSocketMessageBrokerConfigurer method afterSingletonsInstantiated.
public void afterSingletonsInstantiated() {
if (sameOriginDisabled()) {
return;
}
String beanName = "stompWebSocketHandlerMapping";
SimpleUrlHandlerMapping mapping = context.getBean(beanName, SimpleUrlHandlerMapping.class);
Map<String, Object> mappings = mapping.getHandlerMap();
for (Object object : mappings.values()) {
if (object instanceof SockJsHttpRequestHandler) {
SockJsHttpRequestHandler sockjsHandler = (SockJsHttpRequestHandler) object;
SockJsService sockJsService = sockjsHandler.getSockJsService();
if (!(sockJsService instanceof TransportHandlingSockJsService)) {
throw new IllegalStateException("sockJsService must be instance of TransportHandlingSockJsService got " + sockJsService);
}
TransportHandlingSockJsService transportHandlingSockJsService = (TransportHandlingSockJsService) sockJsService;
List<HandshakeInterceptor> handshakeInterceptors = transportHandlingSockJsService.getHandshakeInterceptors();
List<HandshakeInterceptor> interceptorsToSet = new ArrayList<HandshakeInterceptor>(handshakeInterceptors.size() + 1);
interceptorsToSet.add(new CsrfTokenHandshakeInterceptor());
interceptorsToSet.addAll(handshakeInterceptors);
transportHandlingSockJsService.setHandshakeInterceptors(interceptorsToSet);
} else if (object instanceof WebSocketHttpRequestHandler) {
WebSocketHttpRequestHandler handler = (WebSocketHttpRequestHandler) object;
List<HandshakeInterceptor> handshakeInterceptors = handler.getHandshakeInterceptors();
List<HandshakeInterceptor> interceptorsToSet = new ArrayList<HandshakeInterceptor>(handshakeInterceptors.size() + 1);
interceptorsToSet.add(new CsrfTokenHandshakeInterceptor());
interceptorsToSet.addAll(handshakeInterceptors);
handler.setHandshakeInterceptors(interceptorsToSet);
} else {
throw new IllegalStateException("Bean " + beanName + " is expected to contain mappings to either a SockJsHttpRequestHandler or a WebSocketHttpRequestHandler but got " + object);
}
}
if (inboundRegistry.containsMapping() && !inboundRegistry.isSimpDestPathMatcherConfigured()) {
PathMatcher pathMatcher = getDefaultPathMatcher();
inboundRegistry.simpDestPathMatcher(pathMatcher);
}
}
Aggregations