Package org.springframework.web.socket

Examples of org.springframework.web.socket.TextMessage


  @Test
  public void sendSubscribeToControllerAndReceiveReply() throws Exception {

    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 {
View Full Code Here


  @Test
  public void handleExceptionAndSendToUser() throws Exception {

    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 {
View Full Code Here

  }

  @Test
  public void webSocketScope() throws Exception {

    TextMessage message1 = create(StompCommand.SUBSCRIBE)
        .headers("id:subs1", "destination:/topic/scopedBeanValue").build();

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

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

    Map<String, ?> sessions = (Map<String, ?>) new DirectFieldAccessor(this.webSocketHandler).getPropertyValue("sessions");
    new DirectFieldAccessor(sessions.get("id1")).setPropertyValue("createTime", sixtyOneSecondsAgo);
    new DirectFieldAccessor(sessions.get("id2")).setPropertyValue("createTime", sixtyOneSecondsAgo);

    this.webSocketHandler.start();
    this.webSocketHandler.handleMessage(session1, new TextMessage("foo"));

    assertTrue(session1.isOpen());
    assertFalse(session2.isOpen());
    assertNull(session1.getCloseStatus());
    assertEquals(CloseStatus.SESSION_NOT_RELIABLE, session2.getCloseStatus());
View Full Code Here

    sb.append("\n");
    if (this.body != null) {
      sb.append(this.body);
    }
    sb.append("\u0000");
    return new TextMessage(sb.toString());
  }
View Full Code Here

    WebSocketHandler wsHandler = mock(WebSocketHandler.class);
    TestHttpSockJsSession session = new TestHttpSockJsSession("1", sockJsConfig, wsHandler, null);
    session.delegateConnectionEstablished();

    willThrow(new Exception()).given(wsHandler).handleMessage(session, new TextMessage("x"));

    try {
      XhrReceivingTransportHandler transportHandler = new XhrReceivingTransportHandler();
      transportHandler.initialize(sockJsConfig);
      transportHandler.handleRequest(this.request, this.response, wsHandler, session);
View Full Code Here

    transportHandler.initialize(new StubSockJsServiceConfig());
    transportHandler.handleRequest(this.request, this.response, wsHandler, session);

    assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString());
    verify(wsHandler).handleMessage(session, new TextMessage("x"));
  }
View Full Code Here

    Assert.state(State.OPEN.equals(this.state), this + " is not open, current state=" + this.state);
    Assert.isInstanceOf(TextMessage.class, message, this + " supports text messages only.");
    String payload = ((TextMessage) message).getPayload();
    payload = getMessageCodec().encode(new String[] { payload });
    payload = payload.substring(1); // the client-side doesn't need message framing (letter "a")
    message = new TextMessage(payload);
    if (logger.isTraceEnabled()) {
      logger.trace("Sending message " + message + " in " + this);
    }
    sendInternal((TextMessage) message);
  }
View Full Code Here

      logger.trace("Processing SockJS message frame " + frame.getContent() + " in " + this);
    }
    for (String message : messages) {
      try {
        if (isOpen()) {
          this.webSocketHandler.handleMessage(this, new TextMessage(message));
        }
      }
      catch (Throwable ex) {
        Class<?> type = this.webSocketHandler.getClass();
        logger.error(type + ".handleMessage threw an exception on " + frame + " in " + this, ex);
View Full Code Here

  }

  @Test
  public void afterSessionInitialized() throws Exception {
    this.session.initializeDelegateSession(this.webSocketSession);
    assertEquals(Collections.singletonList(new TextMessage("o")), this.webSocketSession.getSentMessages());
    assertEquals(Arrays.asList("schedule"), this.session.heartbeatSchedulingEvents);
    verify(this.webSocketHandler).afterConnectionEstablished(this.session);
    verifyNoMoreInteractions(this.taskScheduler, this.webSocketHandler);
  }
View Full Code Here

TOP

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

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.