diff --git a/src/asciidoc/index.adoc b/src/asciidoc/index.adoc index b23d6689bf..7841c8d385 100644 --- a/src/asciidoc/index.adoc +++ b/src/asciidoc/index.adoc @@ -36969,6 +36969,126 @@ Java initialization API, if required: ---- +[[websocket-server-runtime-configuration]] +==== Configuring the WebSocket Engine + +Each underlying WebSocket engine exposes configuration properties that control +runtime characteristics such as the size of message buffer sizes, idle timeout, +and others. + +For Tomcat, WildFly, and Glassfish add a `WebSocketContainerFactoryBean` to your +WebSocket Java config: + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @Configuration + @EnableWebSocket + public class WebSocketConfig implements WebSocketConfigurer { + + @Bean + public WebSocketContainerFactoryBean createWebSocketContainer() { + WebSocketContainerFactoryBean container = new WebSocketContainerFactoryBean(); + container.setMaxTextMessageBufferSize(8192); + container.setMaxBinaryMessageBufferSize(8192); + return container; + } + + } +---- + +or WebSocket XML namespace: + +[source,xml,indent=0] +[subs="verbatim,quotes,attributes"] +---- + + + + + + + + +---- + +For Jetty, you'll need to supply a pre-configured Jetty `WebSocketServerFactory` and plug +that into Spring's `DefaultHandshakeHandler` through your WebSocket Java config: + +[source,java,indent=0] +[subs="verbatim,quotes"] +---- + @Configuration + @EnableWebSocket + public class WebSocketConfig implements WebSocketConfigurer { + + @Override + public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { + registry.addHandler(echoWebSocketHandler(), + "/echo").setHandshakeHandler(this.handshakeHandler); + } + + @Bean + public DefaultHandshakeHandler handshakeHandler() { + + WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); + policy.setInputBufferSize(8192); + policy.setIdleTimeout(600000); + + return new DefaultHandshakeHandler( + new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy))); + } + + } +---- + +or WebSocket XML namespace: + +[source,xml,indent=0] +[subs="verbatim,quotes,attributes"] +---- + + + + + + + + + + + + + + + + + + + + + + + + + + +---- +