org.springframework.web.socket.sockjs.frame.SockJsMessageCodec Java Examples

The following examples show how to use org.springframework.web.socket.sockjs.frame.SockJsMessageCodec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StreamingSockJsSession.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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();
}
 
Example #2
Source File: StreamingSockJsSession.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example #3
Source File: StreamingSockJsSession.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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();
}
 
Example #4
Source File: PollingSockJsSession.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example #5
Source File: DefaultTransportRequest.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public DefaultTransportRequest(SockJsUrlInfo sockJsUrlInfo,
		@Nullable HttpHeaders handshakeHeaders, @Nullable HttpHeaders httpRequestHeaders,
		Transport transport, TransportType serverTransportType, SockJsMessageCodec codec) {

	Assert.notNull(sockJsUrlInfo, "SockJsUrlInfo is required");
	Assert.notNull(transport, "Transport is required");
	Assert.notNull(serverTransportType, "TransportType is required");
	Assert.notNull(codec, "SockJsMessageCodec is required");
	this.sockJsUrlInfo = sockJsUrlInfo;
	this.handshakeHeaders = (handshakeHeaders != null ? handshakeHeaders : new HttpHeaders());
	this.httpRequestHeaders = (httpRequestHeaders != null ? httpRequestHeaders : new HttpHeaders());
	this.transport = transport;
	this.serverTransportType = serverTransportType;
	this.codec = codec;
}
 
Example #6
Source File: DefaultTransportRequest.java    From java-technology-stack with MIT License 5 votes vote down vote up
public DefaultTransportRequest(SockJsUrlInfo sockJsUrlInfo,
		@Nullable HttpHeaders handshakeHeaders, @Nullable HttpHeaders httpRequestHeaders,
		Transport transport, TransportType serverTransportType, SockJsMessageCodec codec) {

	Assert.notNull(sockJsUrlInfo, "SockJsUrlInfo is required");
	Assert.notNull(transport, "Transport is required");
	Assert.notNull(serverTransportType, "TransportType is required");
	Assert.notNull(codec, "SockJsMessageCodec is required");
	this.sockJsUrlInfo = sockJsUrlInfo;
	this.handshakeHeaders = (handshakeHeaders != null ? handshakeHeaders : new HttpHeaders());
	this.httpRequestHeaders = (httpRequestHeaders != null ? httpRequestHeaders : new HttpHeaders());
	this.transport = transport;
	this.serverTransportType = serverTransportType;
	this.codec = codec;
}
 
Example #7
Source File: JsonpReceivingTransportHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
	}
}
 
Example #8
Source File: PollingSockJsSession.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
}
 
Example #9
Source File: PollingSockJsSession.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
	resetRequest();
}
 
Example #10
Source File: DefaultTransportRequest.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public DefaultTransportRequest(SockJsUrlInfo sockJsUrlInfo,
		HttpHeaders handshakeHeaders, HttpHeaders httpRequestHeaders,
		Transport transport, TransportType serverTransportType, SockJsMessageCodec codec) {

	Assert.notNull(sockJsUrlInfo, "SockJsUrlInfo is required");
	Assert.notNull(transport, "Transport is required");
	Assert.notNull(serverTransportType, "TransportType is required");
	Assert.notNull(codec, "SockJsMessageCodec is required");
	this.sockJsUrlInfo = sockJsUrlInfo;
	this.handshakeHeaders = (handshakeHeaders != null ? handshakeHeaders : new HttpHeaders());
	this.httpRequestHeaders = (httpRequestHeaders != null ? httpRequestHeaders : new HttpHeaders());
	this.transport = transport;
	this.serverTransportType = serverTransportType;
	this.codec = codec;
}
 
Example #11
Source File: AbstractSockJsSession.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected SockJsMessageCodec getMessageCodec() {
	return this.config.getMessageCodec();
}
 
Example #12
Source File: TransportHandlingSockJsService.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * The codec to use for encoding and decoding SockJS messages.
 */
public void setMessageCodec(SockJsMessageCodec messageCodec) {
	this.messageCodec = messageCodec;
}
 
Example #13
Source File: TransportHandlingSockJsService.java    From java-technology-stack with MIT License 4 votes vote down vote up
public SockJsMessageCodec getMessageCodec() {
	Assert.state(this.messageCodec != null, "A SockJsMessageCodec is required but not available: " +
			"Add Jackson to the classpath, or configure a custom SockJsMessageCodec.");
	return this.messageCodec;
}
 
Example #14
Source File: StubSockJsServiceConfig.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public SockJsMessageCodec getMessageCodec() {
	return this.messageCodec;
}
 
Example #15
Source File: StubSockJsServiceConfig.java    From java-technology-stack with MIT License 4 votes vote down vote up
public void setMessageCodec(SockJsMessageCodec messageCodec) {
	this.messageCodec = messageCodec;
}
 
Example #16
Source File: AbstractClientSockJsSession.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public SockJsMessageCodec getMessageCodec() {
	return this.request.getMessageCodec();
}
 
Example #17
Source File: SockJsClient.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return the SockJsMessageCodec to use.
 */
public SockJsMessageCodec getMessageCodec() {
	return this.messageCodec;
}
 
Example #18
Source File: DefaultTransportRequest.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public SockJsMessageCodec getMessageCodec() {
	return this.codec;
}
 
Example #19
Source File: StubSockJsServiceConfig.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public void setMessageCodec(SockJsMessageCodec messageCodec) {
	this.messageCodec = messageCodec;
}
 
Example #20
Source File: TransportHandlingSockJsService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * The codec to use for encoding and decoding SockJS messages.
 */
public void setMessageCodec(SockJsMessageCodec messageCodec) {
	this.messageCodec = messageCodec;
}
 
Example #21
Source File: TransportHandlingSockJsService.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public SockJsMessageCodec getMessageCodec() {
	Assert.state(this.messageCodec != null, "A SockJsMessageCodec is required but not available: " +
			"Add Jackson 2 to the classpath, or configure a custom SockJsMessageCodec.");
	return this.messageCodec;
}
 
Example #22
Source File: StubSockJsServiceConfig.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public SockJsMessageCodec getMessageCodec() {
	return this.messageCodec;
}
 
Example #23
Source File: AbstractClientSockJsSession.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public SockJsMessageCodec getMessageCodec() {
	return this.request.getMessageCodec();
}
 
Example #24
Source File: AbstractSockJsSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected SockJsMessageCodec getMessageCodec() {
	return this.config.getMessageCodec();
}
 
Example #25
Source File: DefaultTransportRequest.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public SockJsMessageCodec getMessageCodec() {
	return this.codec;
}
 
Example #26
Source File: SockJsClient.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the SockJsMessageCodec to use.
 */
public SockJsMessageCodec getMessageCodec() {
	Assert.state(this.messageCodec != null, "No SockJsMessageCodec set");
	return this.messageCodec;
}
 
Example #27
Source File: SockJsClient.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the SockJsMessageCodec to use.
 */
public SockJsMessageCodec getMessageCodec() {
	Assert.state(this.messageCodec != null, "No SockJsMessageCodec set");
	return this.messageCodec;
}
 
Example #28
Source File: AbstractClientSockJsSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
public SockJsMessageCodec getMessageCodec() {
	return this.request.getMessageCodec();
}
 
Example #29
Source File: DefaultTransportRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public SockJsMessageCodec getMessageCodec() {
	return this.codec;
}
 
Example #30
Source File: StubSockJsServiceConfig.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public void setMessageCodec(SockJsMessageCodec messageCodec) {
	this.messageCodec = messageCodec;
}