[[websocket-stomp-server-config]]
= WebSocket Transport

This section explains how to configure the underlying WebSocket server transport.

For Jakarta WebSocket servers, add a `ServletServerContainerFactoryBean` to your
configuration. For examples, see
xref:web/websocket/server.adoc#websocket-server-runtime-configuration[Configuring the Server]
under the WebSocket section.

For Jetty WebSocket servers, customize the `JettyRequestUpgradeStrategy` as follows:

[source,java,indent=0,subs="verbatim,quotes"]
----
	@Configuration
	@EnableWebSocketMessageBroker
	public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

		@Override
		public void registerStompEndpoints(StompEndpointRegistry registry) {
			registry.addEndpoint("/portfolio").setHandshakeHandler(handshakeHandler());
		}

		@Bean
		public DefaultHandshakeHandler handshakeHandler() {
			JettyRequestUpgradeStrategy strategy = new JettyRequestUpgradeStrategy();
			strategy.addWebSocketConfigurer(configurable -> {
					policy.setInputBufferSize(4 * 8192);
					policy.setIdleTimeout(600000);
			});
			return new DefaultHandshakeHandler(strategy);
		}
	}
----

In addition to WebSocket server properties, there are also STOMP WebSocket transport properties
to customize as follows:

[source,java,indent=0,subs="verbatim,quotes"]
----
	@Configuration
	@EnableWebSocketMessageBroker
	public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

		@Override
		public void configureWebSocketTransport(WebSocketTransportRegistration registry) {
			registry.setMessageSizeLimit(4 * 8192);
			registry.setTimeToFirstMessage(30000);
		}

	}
----
