use of org.springframework.web.socket.sockjs.frame.SockJsFrame in project spring-framework by spring-projects.
the class PollingSockJsSession method flushCache.
@Override
protected void flushCache() throws SockJsTransportFailureException {
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);
}
use of org.springframework.web.socket.sockjs.frame.SockJsFrame in project spring-framework by spring-projects.
the class HttpSendingTransportHandlerTests method frameFormats.
@Test
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);
}
use of org.springframework.web.socket.sockjs.frame.SockJsFrame in project spring-framework by spring-projects.
the class StreamingSockJsSession method flushCache.
@Override
protected void flushCache() throws SockJsTransportFailureException {
while (!getMessageCache().isEmpty()) {
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()) {
logger.trace("Streamed bytes limit reached, recycling current request");
resetRequest();
this.byteCount = 0;
break;
}
}
scheduleHeartbeat();
}
use of org.springframework.web.socket.sockjs.frame.SockJsFrame in project spring-framework by spring-projects.
the class RestTemplateXhrTransportTests method connectReceiveAndCloseWithStompFrame.
@Test
public void connectReceiveAndCloseWithStompFrame() throws Exception {
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND);
accessor.setDestination("/destination");
MessageHeaders headers = accessor.getMessageHeaders();
Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.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));
verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
verifyNoMoreInteractions(this.webSocketHandler);
}
Aggregations