|
|
|
@ -229,34 +229,27 @@ Java initialization API. The following example shows how to do so: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[websocket-server-runtime-configuration]] |
|
|
|
[[websocket-server-runtime-configuration]] |
|
|
|
== Server Configuration |
|
|
|
== Configuring the Server |
|
|
|
[.small]#xref:web/webflux-websocket.adoc#webflux-websocket-server-config[See equivalent in the Reactive stack]# |
|
|
|
[.small]#xref:web/webflux-websocket.adoc#webflux-websocket-server-config[See equivalent in the Reactive stack]# |
|
|
|
|
|
|
|
|
|
|
|
Each underlying WebSocket engine exposes configuration properties that control |
|
|
|
You can configure of the underlying WebSocket server such as input message buffer size, |
|
|
|
runtime characteristics, such as the size of message buffer sizes, idle timeout, |
|
|
|
idle timeout, and more. |
|
|
|
and others. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For Tomcat, WildFly, and GlassFish, you can add a `ServletServerContainerFactoryBean` to your |
|
|
|
For Jakarta WebSocket servers, you can add a `ServletServerContainerFactoryBean` to your |
|
|
|
WebSocket Java config, as the following example shows: |
|
|
|
Java configuration. For example: |
|
|
|
|
|
|
|
|
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
---- |
|
|
|
---- |
|
|
|
@Configuration |
|
|
|
@Bean |
|
|
|
@EnableWebSocket |
|
|
|
public ServletServerContainerFactoryBean createWebSocketContainer() { |
|
|
|
public class WebSocketConfig implements WebSocketConfigurer { |
|
|
|
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); |
|
|
|
|
|
|
|
container.setMaxTextMessageBufferSize(8192); |
|
|
|
@Bean |
|
|
|
container.setMaxBinaryMessageBufferSize(8192); |
|
|
|
public ServletServerContainerFactoryBean createWebSocketContainer() { |
|
|
|
return container; |
|
|
|
ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean(); |
|
|
|
} |
|
|
|
container.setMaxTextMessageBufferSize(8192); |
|
|
|
|
|
|
|
container.setMaxBinaryMessageBufferSize(8192); |
|
|
|
|
|
|
|
return container; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
The following example shows the XML configuration equivalent of the preceding example: |
|
|
|
Or to your XML configuration: |
|
|
|
|
|
|
|
|
|
|
|
[source,xml,indent=0,subs="verbatim,quotes,attributes"] |
|
|
|
[source,xml,indent=0,subs="verbatim,quotes,attributes"] |
|
|
|
---- |
|
|
|
---- |
|
|
|
@ -277,12 +270,11 @@ The following example shows the XML configuration equivalent of the preceding ex |
|
|
|
</beans> |
|
|
|
</beans> |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
NOTE: For client-side WebSocket configuration, you should use `WebSocketContainerFactoryBean` |
|
|
|
NOTE: For client Jakarta WebSocket configuration, use |
|
|
|
(XML) or `ContainerProvider.getWebSocketContainer()` (Java configuration). |
|
|
|
ContainerProvider.getWebSocketContainer() in Java configuration, or |
|
|
|
|
|
|
|
`WebSocketContainerFactoryBean` in XML. |
|
|
|
|
|
|
|
|
|
|
|
For Jetty, you need to supply a pre-configured Jetty `WebSocketServerFactory` and plug |
|
|
|
For Jetty, you can supply a `Consumer` callback to configure the WebSocket server: |
|
|
|
that into Spring's `DefaultHandshakeHandler` through your WebSocket Java config. |
|
|
|
|
|
|
|
The following example shows how to do so: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
[source,java,indent=0,subs="verbatim,quotes"] |
|
|
|
---- |
|
|
|
---- |
|
|
|
@ -298,11 +290,9 @@ The following example shows how to do so: |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public DefaultHandshakeHandler handshakeHandler() { |
|
|
|
public DefaultHandshakeHandler handshakeHandler() { |
|
|
|
|
|
|
|
|
|
|
|
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); |
|
|
|
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); |
|
|
|
policy.setInputBufferSize(8192); |
|
|
|
policy.setInputBufferSize(8192); |
|
|
|
policy.setIdleTimeout(600000); |
|
|
|
policy.setIdleTimeout(600000); |
|
|
|
|
|
|
|
|
|
|
|
return new DefaultHandshakeHandler( |
|
|
|
return new DefaultHandshakeHandler( |
|
|
|
new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy))); |
|
|
|
new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy))); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -349,6 +339,10 @@ The following example shows the XML configuration equivalent of the preceding ex |
|
|
|
</beans> |
|
|
|
</beans> |
|
|
|
---- |
|
|
|
---- |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TIP: When using STOMP over WebSocket, you will also need to configure |
|
|
|
|
|
|
|
xref:web/websocket/stomp/server-config.adoc[STOMP WebSocket transport] |
|
|
|
|
|
|
|
properties. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[websocket-server-allowed-origins]] |
|
|
|
[[websocket-server-allowed-origins]] |
|
|
|
|