Package org.springframework.web.socket

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


    String destHeader = "destination:/app/number";
    TextMessage message = create(StompCommand.SUBSCRIBE).headers("id:subs1", destHeader).build();

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

    try {
      assertTrue(clientHandler.latch.await(2, TimeUnit.SECONDS));
      String payload = clientHandler.actual.get(0).getPayload();
      assertTrue("Expected STOMP destination=/app/number, got " + payload, payload.contains(destHeader));
      assertTrue("Expected STOMP Payload=42, got " + payload, payload.contains("42"));
    }
    finally {
      session.close();
    }
  }
View Full Code Here

    String destHeader = "destination:/user/queue/error";
    TextMessage m1 = create(StompCommand.SUBSCRIBE).headers("id:subs1", destHeader).build();
    TextMessage m2 = create(StompCommand.SEND).headers("destination:/app/exception").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(payload.startsWith("MESSAGE\n"));
      assertTrue(payload.contains("destination:/user/queue/error\n"));
      assertTrue(payload.endsWith("Got error: Bad input\0"));
    }
    finally {
      session.close();
    }
  }
View Full Code Here

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

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

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

      String payload = clientHandler.actual.get(0).getPayload();
      assertTrue(payload.startsWith("MESSAGE\n"));
      assertTrue(payload.contains("destination:/topic/scopedBeanValue\n"));
      assertTrue(payload.endsWith("55\0"));
    }
    finally {
      session.close();
    }
  }
View Full Code Here

    EchoHandler.reset();
    PerConnectionWebSocketHandler handler = new PerConnectionWebSocketHandler(EchoHandler.class);
    handler.setBeanFactory(context.getBeanFactory());

    WebSocketSession session = new TestWebSocketSession();
    handler.afterConnectionEstablished(session);

    assertEquals(1, EchoHandler.initCount);
    assertEquals(0, EchoHandler.destroyCount);
View Full Code Here

  @Test
  public void connect() throws Exception {
    DefaultTransportRequest request = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET);
    request.connect(null, this.connectFuture);
    WebSocketSession session = mock(WebSocketSession.class);
    this.webSocketTransport.getConnectCallback().onSuccess(session);
    assertSame(session, this.connectFuture.get());
  }
View Full Code Here

  @Test
  public void connectWebSocket() throws Exception {
    setupInfoRequest(true);
    this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);
    assertTrue(this.webSocketTransport.invoked());
    WebSocketSession session = mock(WebSocketSession.class);
    this.webSocketTransport.getConnectCallback().onSuccess(session);
    verify(this.connectCallback).onSuccess(session);
    verifyNoMoreInteractions(this.connectCallback);
  }
View Full Code Here

    assertTrue(handshakeHandler instanceof TestHandshakeHandler);
    List<HandshakeInterceptor> interceptors = wsHttpRequestHandler.getHandshakeInterceptors();
    assertThat(interceptors, contains(instanceOf(FooTestInterceptor.class),
        instanceOf(BarTestInterceptor.class), instanceOf(OriginHandshakeInterceptor.class)));

    WebSocketSession session = new TestWebSocketSession("id");
    wsHttpRequestHandler.getWebSocketHandler().afterConnectionEstablished(session);
    assertEquals(true, session.getAttributes().get("decorated"));

    WebSocketHandler wsHandler = unwrapWebSocketHandler(wsHttpRequestHandler.getWebSocketHandler());
    assertNotNull(wsHandler);
    assertThat(wsHandler, Matchers.instanceOf(SubProtocolWebSocketHandler.class));
View Full Code Here

  public void fallbackAfterTransportFailure() throws Exception {
    this.errorFilter.responseStatusMap.put("/websocket", 200);
    this.errorFilter.responseStatusMap.put("/xhr_streaming", 500);
    TestClientHandler handler = new TestClientHandler();
    initSockJsClient(createWebSocketTransport(), createXhrTransport());
    WebSocketSession session = this.sockJsClient.doHandshake(handler, this.baseUrl + "/echo").get();
    assertEquals("Fallback didn't occur", XhrClientSockJsSession.class, session.getClass());
    TextMessage message = new TextMessage("message1");
    session.sendMessage(message);
    handler.awaitMessage(message, 5000);
  }
View Full Code Here

    TestClientHandler clientHandler = new TestClientHandler();
    this.errorFilter.sleepDelayMap.put("/xhr_streaming", 10000L);
    this.errorFilter.responseStatusMap.put("/xhr_streaming", 503);
    initSockJsClient(createXhrTransport());
    this.sockJsClient.setConnectTimeoutScheduler(this.wac.getBean(ThreadPoolTaskScheduler.class));
    WebSocketSession clientSession = sockJsClient.doHandshake(clientHandler, this.baseUrl + "/echo").get();
    assertEquals("Fallback didn't occur", XhrClientSockJsSession.class, clientSession.getClass());
    TextMessage message = new TextMessage("message1");
    clientSession.sendMessage(message);
    clientHandler.awaitMessage(message, 5000);
    clientSession.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.