Search in sources :

Example 6 with DefaultSockJsService

use of org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService in project spring-framework by spring-projects.

the class WebMvcStompWebSocketEndpointRegistrationTests method allowedOriginsWithSockJsService.

@Test
public void allowedOriginsWithSockJsService() {
    WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    String origin = "http://mydomain.com";
    registration.setAllowedOrigins(origin).withSockJS();
    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) mappings.entrySet().iterator().next().getKey();
    assertNotNull(requestHandler.getSockJsService());
    DefaultSockJsService sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
    assertTrue(sockJsService.getAllowedOrigins().contains(origin));
    assertFalse(sockJsService.shouldSuppressCors());
    registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    registration.withSockJS().setAllowedOrigins(origin);
    mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    requestHandler = (SockJsHttpRequestHandler) mappings.entrySet().iterator().next().getKey();
    assertNotNull(requestHandler.getSockJsService());
    sockJsService = (DefaultSockJsService) requestHandler.getSockJsService();
    assertTrue(sockJsService.getAllowedOrigins().contains(origin));
    assertFalse(sockJsService.shouldSuppressCors());
}
Also used : SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) DefaultSockJsService(org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 SockJsHttpRequestHandler (org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler)6 DefaultSockJsService (org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService)6 HttpRequestHandler (org.springframework.web.HttpRequestHandler)5 WebSocketHttpRequestHandler (org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)5 WebSocketTransportHandler (org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler)4 TransportHandler (org.springframework.web.socket.sockjs.transport.TransportHandler)3 TransportType (org.springframework.web.socket.sockjs.transport.TransportType)3 List (java.util.List)2 Map (java.util.Map)2 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)2 MultiValueMap (org.springframework.util.MultiValueMap)2 SimpleUrlHandlerMapping (org.springframework.web.servlet.handler.SimpleUrlHandlerMapping)2 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)2 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)2 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)2 OriginHandshakeInterceptor (org.springframework.web.socket.server.support.OriginHandshakeInterceptor)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 CustomScopeConfigurer (org.springframework.beans.factory.config.CustomScopeConfigurer)1