Examples of WebSocketSession


Examples of org.springframework.web.socket.WebSocketSession

          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

Examples of org.springframework.web.socket.WebSocketSession

    }
  }

  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

Examples of org.springframework.web.socket.WebSocketSession


  @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

Examples of org.springframework.web.socket.WebSocketSession

  }

  @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

Examples of org.springframework.web.socket.WebSocketSession

  }

  @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

Examples of org.springframework.web.socket.WebSocketSession

    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

Examples of org.springframework.web.socket.WebSocketSession

  @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

Examples of org.springframework.web.socket.WebSocketSession

  @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

Examples of org.springframework.web.socket.WebSocketSession

    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

Examples of org.springframework.web.socket.WebSocketSession

    TextMessage m1 = create(StompCommand.SUBSCRIBE).headers("id:subs1", "destination:/topic/foo").build();
    TextMessage m2 = create(StompCommand.SEND).headers("destination:/topic/foo").body("5").build();

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

    try {
      assertTrue(clientHandler.latch.await(2, TimeUnit.SECONDS));

      String payload = clientHandler.actual.get(0).getPayload();
      assertTrue("Expected STOMP MESSAGE, got " + payload, payload.startsWith("MESSAGE\n"));
    }
    finally {
      session.close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.