Search in sources :

Example 1 with SockJsMessageCodec

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());
    }
}
Also used : MediaType(org.springframework.http.MediaType) SockJsMessageCodec(org.springframework.web.socket.sockjs.frame.SockJsMessageCodec)

Example 2 with SockJsMessageCodec

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);
}
Also used : SockJsMessageCodec(org.springframework.web.socket.sockjs.frame.SockJsMessageCodec) SockJsFrame(org.springframework.web.socket.sockjs.frame.SockJsFrame)

Example 3 with SockJsMessageCodec

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();
}
Also used : SockJsMessageCodec(org.springframework.web.socket.sockjs.frame.SockJsMessageCodec) SockJsFrame(org.springframework.web.socket.sockjs.frame.SockJsFrame)

Aggregations

SockJsMessageCodec (org.springframework.web.socket.sockjs.frame.SockJsMessageCodec)3 SockJsFrame (org.springframework.web.socket.sockjs.frame.SockJsFrame)2 MediaType (org.springframework.http.MediaType)1