Files
spring-messaging-demo/sse-websocket/src/main/java/com/ankurm/ssews/WebSocketBufferConfig.java
T
2026-09-04 00:52:18 +05:30

36 lines
1.6 KiB
Java

package com.ankurm.ssews;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;
/**
* The other half of the message size limit — the half that is not in Spring.
*
* <p>{@code WebSocketTransportRegistration.setMessageSizeLimit(64 * 1024)} is not the limit that
* bites first. Spring's {@code SubProtocolWebSocketHandler} does not support partial messages,
* so the servlet container has to buffer each WebSocket text message whole before handing it
* over &mdash; and Tomcat's buffer defaults to <strong>8&nbsp;192 bytes</strong>. Cross that and
* Tomcat closes the connection with WebSocket status <strong>1009</strong> before Spring ever
* sees the frame, so raising Spring's limit alone changes nothing.
*
* <p>Active under the {@code bigframes} profile so the companion test can show both behaviours
* from one build.
*
* @see <a href="../../../../../docs/05-limits.md">docs/05-limits.md</a>
*/
@Configuration
@Profile("bigframes")
public class WebSocketBufferConfig {
@Bean
public ServletServerContainerFactoryBean createWebSocketContainer(
@org.springframework.beans.factory.annotation.Value("${ws.buffer-bytes:262144}") int bytes) {
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
container.setMaxTextMessageBufferSize(bytes);
container.setMaxBinaryMessageBufferSize(bytes);
return container;
}
}