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

Examples of org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService


    given(this.jsonpHandler.getTransportType()).willReturn(TransportType.JSONP);
    given(this.jsonpHandler.createSession(sessionId, this.wsHandler, attributes)).willReturn(this.session);
    given(this.jsonpSendHandler.getTransportType()).willReturn(TransportType.JSONP_SEND);
    given(this.wsTransportHandler.getTransportType()).willReturn(TransportType.WEBSOCKET);

    this.service = new TransportHandlingSockJsService(this.taskScheduler, this.xhrHandler, this.xhrSendHandler);
  }
View Full Code Here


    assertSame(xhrHandler, handlers.get(xhrHandler.getTransportType()));
  }

  @Test
  public void customizedTransportHandlerList() {
    TransportHandlingSockJsService service = new TransportHandlingSockJsService(
        mock(TaskScheduler.class), new XhrPollingTransportHandler(), new XhrReceivingTransportHandler());
    Map<TransportType, TransportHandler> actualHandlers = service.getTransportHandlers();

    assertEquals(2, actualHandlers.size());
  }
View Full Code Here

    verify(this.xhrSendHandler).handleRequest(this.request, this.response, this.wsHandler, this.session);
  }

  @Test
   public void handleTransportRequestJsonp() throws Exception {
    TransportHandlingSockJsService jsonpService = new TransportHandlingSockJsService(this.taskScheduler, this.jsonpHandler, this.jsonpSendHandler);
    String sockJsPath = sessionUrlPrefix+ "jsonp";
    setRequest("GET", sockJsPrefix + sockJsPath);
    jsonpService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    assertNotEquals(404, this.servletResponse.getStatus());

    resetRequestAndResponse();
    jsonpService.setAllowedOrigins(Arrays.asList("http://mydomain1.com"));
    setRequest("GET", sockJsPrefix + sockJsPath);
    jsonpService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    assertEquals(404, this.servletResponse.getStatus());

    resetRequestAndResponse();
    jsonpService.setAllowedOrigins(null);
    setRequest("GET", sockJsPrefix + sockJsPath);
    jsonpService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    assertEquals(404, this.servletResponse.getStatus());
  }
View Full Code Here

    assertEquals(404, this.servletResponse.getStatus());
  }

  @Test
  public void handleTransportRequestWebsocket() throws Exception {
    TransportHandlingSockJsService wsService = new TransportHandlingSockJsService(this.taskScheduler, this.wsTransportHandler);
    String sockJsPath = "/websocket";
    setRequest("GET", sockJsPrefix + sockJsPath);
    wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    assertNotEquals(403, this.servletResponse.getStatus());

    resetRequestAndResponse();
    OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
    interceptor.setAllowedOrigins(Arrays.asList("http://mydomain1.com"));
    wsService.setHandshakeInterceptors(Arrays.asList(interceptor));
    setRequest("GET", sockJsPrefix + sockJsPath);
    setOrigin("http://mydomain1.com");
    wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    assertNotEquals(403, this.servletResponse.getStatus());

    resetRequestAndResponse();
    setRequest("GET", sockJsPrefix + sockJsPath);
    setOrigin("http://mydomain2.com");
    wsService.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
    assertEquals(403, this.servletResponse.getStatus());
  }
View Full Code Here

    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(TestMessageCodec.class, transportService.getMessageCodec().getClass());

    List<HandshakeInterceptor> interceptors = transportService.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(OriginHandshakeInterceptor.class)));
    assertEquals(Arrays.asList("http://mydomain1.com", "http://mydomain2.com"), transportService.getAllowedOrigins());
    assertTrue(transportService.shouldSuppressCors());
  }
View Full Code Here

    }
    return this;
  }

  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);
    }
    if (!this.allowedOrigins.isEmpty()) {
      service.setAllowedOrigins(this.allowedOrigins);
    }
    if (this.messageCodec != null) {
      service.setMessageCodec(this.messageCodec);
    }
    return service;
  }
View Full Code Here

  private TransportHandlingSockJsService createSockJsService() {
    if (!this.transportHandlers.isEmpty()) {
      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

TOP

Related Classes of org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService

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.