Package org.springframework.web.socket

Examples of org.springframework.web.socket.WebSocketSession


      log.info("SessionId: " + client.getSession().getSessionId());

      JsonRpcClientWebSocket webSocketClient = (JsonRpcClientWebSocket) client;

      WebSocketSession session = webSocketClient.getWebSocketSession();
      session.close();

      Assert.assertEquals("old",
          client.sendRequest("sessiontest", String.class));
      Assert.assertEquals("old",
          client.sendRequest("sessiontest", String.class));
View Full Code Here


          client.sendRequest("sessiontest", String.class));
      Assert.assertEquals("old",
          client.sendRequest("sessiontest", String.class));

      JsonRpcClientWebSocket webSocketClient = (JsonRpcClientWebSocket) client;
      WebSocketSession session = webSocketClient.getWebSocketSession();
      session.close();

      Thread.sleep(1000);

      try {
        client.sendRequest("sessiontest", String.class);
View Full Code Here

    }
  }

  private void sendMessage(String sessionId, String json) {

    final WebSocketSession session = sessions.get(sessionId);
    if (session == null) {
      logger.error("Session not found for sessionId " + sessionId);
      return;
    }

    try {
      if (session.isOpen()) {
        session.sendMessage(new TextMessage(json));
      } else {
        sessions.remove(session.getId());
      }
    } catch (IOException e) {
      logger.error("Sending of message '" + json + "' failed", e);
    }
  }
View Full Code Here


  @Test
  public void localAddress() throws Exception {
    URI uri = new URI("ws://example.com/abc");
    WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();

    assertNotNull(session.getLocalAddress());
    assertEquals(80, session.getLocalAddress().getPort());
  }
View Full Code Here

  }

  @Test
  public void localAddressWss() throws Exception {
    URI uri = new URI("wss://example.com/abc");
    WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();

    assertNotNull(session.getLocalAddress());
    assertEquals(443, session.getLocalAddress().getPort());
  }
View Full Code Here

  }

  @Test
  public void remoteAddress() throws Exception {
    URI uri = new URI("wss://example.com/abc");
    WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();

    assertNotNull(session.getRemoteAddress());
    assertEquals("example.com", session.getRemoteAddress().getHostName());
    assertEquals(443, session.getLocalAddress().getPort());
  }
View Full Code Here

    URI uri = new URI("ws://example.com/abc");
    List<String> protocols = Arrays.asList("abc");
    this.headers.setSecWebSocketProtocol(protocols);
    this.headers.add("foo", "bar");

    WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();

    assertEquals(Collections.singletonMap("foo", Arrays.asList("bar")), session.getHandshakeHeaders());
  }
View Full Code Here

  @Test
  public void taskExecutor() throws Exception {

    URI uri = new URI("ws://example.com/abc");
    this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor());
    WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();

    assertNotNull(session);
  }
View Full Code Here

  @Test
  public void sendMessageToController() throws Exception {

    TextMessage message = create(StompCommand.SEND).headers("destination:/app/simple").build();
    WebSocketSession session = doHandshake(new TestClientWebSocketHandler(0, message), "/ws").get();

    SimpleController controller = this.wac.getBean(SimpleController.class);
    try {
      assertTrue(controller.latch.await(10, TimeUnit.SECONDS));
    }
    finally {
      session.close();
    }
  }
View Full Code Here

    TextMessage message2 = create(StompCommand.SEND)
        .headers("destination:/app/increment").body("5").build();

    TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(1, message1, message2);
    WebSocketSession session = doHandshake(clientHandler, "/ws").get();

    try {
      assertTrue(clientHandler.latch.await(2, TimeUnit.SECONDS));
    }
    finally {
      session.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.socket.WebSocketSession

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.