@@ -229,34 +229,27 @@ Java initialization API. The following example shows how to do so:
229229
230230
231231[[websocket-server-runtime-configuration]]
232- == Server Configuration
232+ == Configuring the Server
233233[.small]#xref:web/webflux-websocket.adoc#webflux-websocket-server-config[See equivalent in the Reactive stack]#
234234
235- Each underlying WebSocket engine exposes configuration properties that control
236- runtime characteristics, such as the size of message buffer sizes, idle timeout,
237- and others.
235+ You can configure of the underlying WebSocket server such as input message buffer size,
236+ idle timeout, and more.
238237
239- For Tomcat, WildFly, and GlassFish , you can add a `ServletServerContainerFactoryBean` to your
240- WebSocket Java config, as the following example shows :
238+ For Jakarta WebSocket servers , you can add a `ServletServerContainerFactoryBean` to your
239+ Java configuration. For example:
241240
242241[source,java,indent=0,subs="verbatim,quotes"]
243242----
244- @Configuration
245- @EnableWebSocket
246- public class WebSocketConfig implements WebSocketConfigurer {
247-
248- @Bean
249- public ServletServerContainerFactoryBean createWebSocketContainer() {
250- ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
251- container.setMaxTextMessageBufferSize(8192);
252- container.setMaxBinaryMessageBufferSize(8192);
253- return container;
254- }
255-
256- }
243+ @Bean
244+ public ServletServerContainerFactoryBean createWebSocketContainer() {
245+ ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
246+ container.setMaxTextMessageBufferSize(8192);
247+ container.setMaxBinaryMessageBufferSize(8192);
248+ return container;
249+ }
257250----
258251
259- The following example shows the XML configuration equivalent of the preceding example :
252+ Or to your XML configuration:
260253
261254[source,xml,indent=0,subs="verbatim,quotes,attributes"]
262255----
@@ -277,10 +270,11 @@ The following example shows the XML configuration equivalent of the preceding ex
277270 </beans>
278271----
279272
280- NOTE: For client-side WebSocket configuration, you should use `WebSocketContainerFactoryBean`
281- (XML) or `ContainerProvider.getWebSocketContainer()` (Java configuration).
273+ NOTE: For client Jakarta WebSocket configuration, use
274+ ContainerProvider.getWebSocketContainer() in Java configuration, or
275+ `WebSocketContainerFactoryBean` in XML.
282276
283- For Jetty, you need to supply a `Consumer` callback to configure the WebSocket server. For example :
277+ For Jetty, you can supply a `Consumer` callback to configure the WebSocket server:
284278
285279[source,java,indent=0,subs="verbatim,quotes"]
286280----
@@ -290,20 +284,25 @@ For Jetty, you need to supply a `Consumer` callback to configure the WebSocket s
290284
291285 @Override
292286 public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
287+ registry.addHandler(echoWebSocketHandler(), "/echo").setHandshakeHandler(handshakeHandler());
288+ }
293289
294- JettyRequestUpgradeStrategy upgradeStrategy = new JettyRequestUpgradeStrategy();
295- upgradeStrategy.addWebSocketConfigurer(configurable -> {
290+ @Bean
291+ public DefaultHandshakeHandler handshakeHandler() {
292+ JettyRequestUpgradeStrategy strategy = new JettyRequestUpgradeStrategy();
293+ strategy.addWebSocketConfigurer(configurable -> {
296294 policy.setInputBufferSize(8192);
297295 policy.setIdleTimeout(600000);
298296 });
299-
300- registry.addHandler(echoWebSocketHandler(),
301- "/echo").setHandshakeHandler(new DefaultHandshakeHandler(upgradeStrategy));
297+ return new DefaultHandshakeHandler(strategy);
302298 }
303299
304300 }
305301----
306302
303+ TIP: When using STOMP over WebSocket, you will also need to configure
304+ xref:web/websocket/stomp/server-config.adoc[STOMP WebSocket transport]
305+ properties.
307306
308307
309308
0 commit comments