use of org.springframework.web.socket.sockjs.frame.SockJsMessageCodec in project spring-framework by spring-projects.
the class JsonpReceivingTransportHandler method readMessages.
@Override
protected String[] readMessages(ServerHttpRequest request) throws IOException {
SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec();
MediaType contentType = request.getHeaders().getContentType();
if (contentType != null && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
MultiValueMap<String, String> map = this.formConverter.read(null, request);
String d = map.getFirst("d");
return (StringUtils.hasText(d) ? messageCodec.decode(d) : null);
} else {
return messageCodec.decodeInputStream(request.getBody());
}
}
use of org.springframework.web.socket.sockjs.frame.SockJsMessageCodec 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.SockJsMessageCodec 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();
}
Aggregations