Package org.springframework.web.socket.sockjs.frame

Examples of org.springframework.web.socket.sockjs.frame.SockJsFrame


    }
    else if (sockJsSession.isClosed()) {
      if (logger.isDebugEnabled()) {
        logger.debug("Connection already closed (but not removed yet) for " + sockJsSession);
      }
      SockJsFrame frame = SockJsFrame.closeFrameGoAway();
      try {
        response.getBody().write(frame.getContentBytes());
      }
      catch (IOException ex) {
        throw new SockJsException("Failed to send " + frame, sockJsSession.getId(), ex);
      }
    }
View Full Code Here


  public void frameFormats() throws Exception {

    this.servletRequest.setQueryString("c=callback");
    this.servletRequest.addParameter("c", "callback");

    SockJsFrame frame = SockJsFrame.openFrame();

    SockJsFrameFormat format = new XhrPollingTransportHandler().getFrameFormat(this.request);
    String formatted = format.format(frame);
    assertEquals(frame.getContent() + "\n", formatted);

    format = new XhrStreamingTransportHandler().getFrameFormat(this.request);
    formatted = format.format(frame);
    assertEquals(frame.getContent() + "\n", formatted);

    format = new HtmlFileTransportHandler().getFrameFormat(this.request);
    formatted = format.format(frame);
    assertEquals("<script>\np(\"" + frame.getContent() + "\");\n</script>\r\n", formatted);

    format = new EventSourceTransportHandler().getFrameFormat(this.request);
    formatted = format.format(frame);
    assertEquals("data: " + frame.getContent() + "\r\n\r\n", formatted);

    format = new JsonpPollingTransportHandler().getFrameFormat(this.request);
    formatted = format.format(frame);
    assertEquals("callback(\"" + frame.getContent() + "\");\r\n", formatted);
  }
View Full Code Here

  }

  protected abstract void disconnect(CloseStatus status) throws IOException;

  public void handleFrame(String payload) {
    SockJsFrame frame = new SockJsFrame(payload);
    if (SockJsFrameType.OPEN.equals(frame.getType())) {
      handleOpenFrame();
    }
    else if (SockJsFrameType.MESSAGE.equals(frame.getType())) {
      handleMessageFrame(frame);
    }
    else if (SockJsFrameType.CLOSE.equals(frame.getType())) {
      handleCloseFrame(frame);
    }
    else if (SockJsFrameType.HEARTBEAT.equals(frame.getType())) {
      if (logger.isTraceEnabled()) {
        logger.trace("Received heartbeat in " + this);
      }
    }
    else {
View Full Code Here

    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);

    verify(this.webSocketHandler).afterConnectionEstablished(any());
    verify(this.webSocketHandler).handleMessage(any(), eq(textMessage));
View Full Code Here

  @Override
  protected void flushCache() throws SockJsTransportFailureException {
    do {
      String message = getMessageCache().poll();
      SockJsMessageCodec messageCodec = getSockJsServiceConfig().getMessageCodec();
      SockJsFrame frame = SockJsFrame.messageFrame(messageCodec, message);
      writeFrame(frame);

      this.byteCount += frame.getContentBytes().length + 1;
      if (logger.isTraceEnabled()) {
        logger.trace(this.byteCount + " bytes written so far, "
            + getMessageCache().size() + " more messages not flushed");
      }
      if (this.byteCount >= getSockJsServiceConfig().getStreamBytesLimit()) {
View Full Code Here

    String[] messages = new String[getMessageCache().size()];
    for (int i = 0; i < messages.length; i++) {
      messages[i] = getMessageCache().poll();
    }
    SockJsMessageCodec messageCodec = getSockJsServiceConfig().getMessageCodec();
    SockJsFrame frame = SockJsFrame.messageFrame(messageCodec, messages);
    writeFrame(frame);
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.socket.sockjs.frame.SockJsFrame

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.