@@ -229,34 +229,27 @@ Java initialization API. The following example shows how to do so:
229
229
230
230
231
231
[[websocket-server-runtime-configuration]]
232
- == Server Configuration
232
+ == Configuring the Server
233
233
[.small]#xref:web/webflux-websocket.adoc#webflux-websocket-server-config[See equivalent in the Reactive stack]#
234
234
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.
238
237
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:
241
240
242
241
[source,java,indent=0,subs="verbatim,quotes"]
243
242
----
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
+ }
257
250
----
258
251
259
- The following example shows the XML configuration equivalent of the preceding example :
252
+ Or to your XML configuration:
260
253
261
254
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
262
255
----
@@ -277,10 +270,11 @@ The following example shows the XML configuration equivalent of the preceding ex
277
270
</beans>
278
271
----
279
272
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.
282
276
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:
284
278
285
279
[source,java,indent=0,subs="verbatim,quotes"]
286
280
----
@@ -290,20 +284,25 @@ For Jetty, you need to supply a `Consumer` callback to configure the WebSocket s
290
284
291
285
@Override
292
286
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
287
+ registry.addHandler(echoWebSocketHandler(), "/echo").setHandshakeHandler(handshakeHandler());
288
+ }
293
289
294
- JettyRequestUpgradeStrategy upgradeStrategy = new JettyRequestUpgradeStrategy();
295
- upgradeStrategy.addWebSocketConfigurer(configurable -> {
290
+ @Bean
291
+ public DefaultHandshakeHandler handshakeHandler() {
292
+ JettyRequestUpgradeStrategy strategy = new JettyRequestUpgradeStrategy();
293
+ strategy.addWebSocketConfigurer(configurable -> {
296
294
policy.setInputBufferSize(8192);
297
295
policy.setIdleTimeout(600000);
298
296
});
299
-
300
- registry.addHandler(echoWebSocketHandler(),
301
- "/echo").setHandshakeHandler(new DefaultHandshakeHandler(upgradeStrategy));
297
+ return new DefaultHandshakeHandler(strategy);
302
298
}
303
299
304
300
}
305
301
----
306
302
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.
307
306
308
307
309
308
0 commit comments