Package org.springframework.web.socket

Examples of org.springframework.web.socket.TextMessage


  @Test
  public void afterSessionInitializedOpenFrameFirst() throws Exception {
    TextWebSocketHandler handler = new TextWebSocketHandler() {
      @Override
      public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        session.sendMessage(new TextMessage("go go"));
      }
    };
    TestWebSocketServerSockJsSession session = new TestWebSocketServerSockJsSession(this.sockJsConfig, handler, null);
    session.initializeDelegateSession(this.webSocketSession);
    List<TextMessage> expected = Arrays.asList(new TextMessage("o"), new TextMessage("a[\"go go\"]"));
    assertEquals(expected, this.webSocketSession.getSentMessages());
  }
View Full Code Here


    assertEquals(expected, this.webSocketSession.getSentMessages());
  }

  @Test
  public void handleMessageEmptyPayload() throws Exception {
    this.session.handleMessage(new TextMessage(""), this.webSocketSession);
    verifyNoMoreInteractions(this.webSocketHandler);
  }
View Full Code Here

      return;
    }
  }

  private void handleTextMessage(javax.websocket.Session session, String payload, boolean isLast) {
    TextMessage textMessage = new TextMessage(payload, isLast);
    try {
      this.handler.handleMessage(this.wsSession, textMessage);
    }
    catch (Throwable t) {
      ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, t, logger);
View Full Code Here

  }

  @Test
  public void handleMessage() throws Exception {

    TextMessage message = new TextMessage("[\"x\"]");
    this.session.handleMessage(message, this.webSocketSession);

    verify(this.webSocketHandler).handleMessage(this.session, new TextMessage("x"));
    verifyNoMoreInteractions(this.webSocketHandler);
  }
View Full Code Here

    String body = "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);

    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
    verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
    verifyNoMoreInteractions(this.webSocketHandler);
  }
View Full Code Here

    String body = sb.toString() + "\n" + "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);

    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
    verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
    verifyNoMoreInteractions(this.webSocketHandler);
  }
View Full Code Here

    StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
    accessor.setDestination("/destination");
    MessageHeaders headers = accessor.getMessageHeaders();
    Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(Charset.forName("UTF-8")), headers);
    byte[] bytes = new StompEncoder().encode(message);
    TextMessage textMessage = new TextMessage(bytes);
    SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload());

    String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]";
    ClientHttpResponse response = response(HttpStatus.OK, body);
    connect(response);
View Full Code Here

  @Test
  public void handleFrameMessage() throws Exception {
    this.session.handleFrame(SockJsFrame.openFrame().getContent());
    this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
    verify(this.handler).afterConnectionEstablished(this.session);
    verify(this.handler).handleMessage(this.session, new TextMessage("foo"));
    verify(this.handler).handleMessage(this.session, new TextMessage("bar"));
    verifyNoMoreInteractions(this.handler);
  }
View Full Code Here

  }

  @Test
  public void handleFrameMessageWithWebSocketHandlerException() throws Exception {
    this.session.handleFrame(SockJsFrame.openFrame().getContent());
    willThrow(new IllegalStateException("Fake error")).given(this.handler).handleMessage(this.session, new TextMessage("foo"));
    willThrow(new IllegalStateException("Fake error")).given(this.handler).handleMessage(this.session, new TextMessage("bar"));
    this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
    assertThat(this.session.isOpen(), equalTo(true));
    verify(this.handler).afterConnectionEstablished(this.session);
    verify(this.handler).handleMessage(this.session, new TextMessage("foo"));
    verify(this.handler).handleMessage(this.session, new TextMessage("bar"));
    verifyNoMoreInteractions(this.handler);
  }
View Full Code Here

  }

  @Test
  public void send() throws Exception {
    this.session.handleFrame(SockJsFrame.openFrame().getContent());
    this.session.sendMessage(new TextMessage("foo"));
    assertThat(this.session.sentMessage, equalTo(new TextMessage("[\"foo\"]")));
  }
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.