Package org.springframework.web.socket.sockjs.transport.handler

Examples of org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService


  }

  @Bean
  public SimpleUrlHandlerMapping handlerMapping() {

    DefaultSockJsService sockJsService = new DefaultSockJsService(sockJsTaskScheduler());
    sockJsService.setSockJsClientLibraryUrl("https://cdn.sockjs.org/sockjs-0.3.4.min.js");

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

    SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
View Full Code Here


    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)));
  }
View Full Code Here

    assertNotNull(wsHandler);
    assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
    assertNotNull(sockJsHttpRequestHandler.getSockJsService());
    assertThat(sockJsHttpRequestHandler.getSockJsService(), Matchers.instanceOf(DefaultSockJsService.class));

    DefaultSockJsService defaultSockJsService = (DefaultSockJsService) sockJsHttpRequestHandler.getSockJsService();
    WebSocketTransportHandler wsTransportHandler = (WebSocketTransportHandler) defaultSockJsService
        .getTransportHandlers().get(TransportType.WEBSOCKET);
    assertNotNull(wsTransportHandler.getHandshakeHandler());
    assertThat(wsTransportHandler.getHandshakeHandler(), Matchers.instanceOf(TestHandshakeHandler.class));
    assertFalse(defaultSockJsService.shouldSuppressCors());

    ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) defaultSockJsService.getTaskScheduler();
    assertEquals(Runtime.getRuntime().availableProcessors(), scheduler.getScheduledThreadPoolExecutor().getCorePoolSize());
    assertTrue(scheduler.getScheduledThreadPoolExecutor().getRemoveOnCancelPolicy());

    interceptors = defaultSockJsService.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
        instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));
    assertEquals(Arrays.asList("http://mydomain3.com", "http://mydomain4.com"), defaultSockJsService.getAllowedOrigins());

    UserSessionRegistry userSessionRegistry = this.appContext.getBean(UserSessionRegistry.class);
    assertNotNull(userSessionRegistry);

    UserDestinationResolver userDestResolver = this.appContext.getBean(UserDestinationResolver.class);
View Full Code Here

      Assert.state(this.transportHandlerOverrides.isEmpty(),
          "Specify either TransportHandlers or TransportHandler overrides, not both");
      return new TransportHandlingSockJsService(this.taskScheduler, this.transportHandlers);
    }
    else {
      return new DefaultSockJsService(this.taskScheduler, this.transportHandlerOverrides);
    }
  }
View Full Code Here

    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();
    assertEquals(Arrays.asList(origin), sockJsService.getAllowedOrigins());
    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();
    assertEquals(Arrays.asList(origin), sockJsService.getAllowedOrigins());
    assertFalse(sockJsService.shouldSuppressCors());
  }
View Full Code Here

    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.shouldSuppressCors());
  }
View Full Code Here

    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(Arrays.asList(interceptor), sockJsService.getHandshakeInterceptors());
  }
View Full Code Here

    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());
    assertEquals(Arrays.asList(origin), sockJsService.getAllowedOrigins());
  }
View Full Code Here

    private GameHandler gameHandler;

    @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();
View Full Code Here

TOP

Related Classes of org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.