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. * *

{@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 — and Tomcat's buffer defaults to 8 192 bytes. Cross that and * Tomcat closes the connection with WebSocket status 1009 before Spring ever * sees the frame, so raising Spring's limit alone changes nothing. * *

Active under the {@code bigframes} profile so the companion test can show both behaviours * from one build. * * @see docs/05-limits.md */ @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; } }