Skip to content

Commit 6ef0798

Browse files
authored
Fix Websocket dynamic registration mapping order (#3580)
Related to https://stackoverflow.com/questions/67923303/dynamic-registration-of-websocket-output-adapter-is-not-working By default the `AbstractHandlerMapping` comes with the `order = Ordered.LOWEST_PRECEDENCE` which sorts added mappings to the end of chain. At the same time Spring Boot registers a `SimpleUrlHandlerMapping` as a fallback for all not handled requests leaving our own mapping behind consideration * Add `order = 0` to the `IntegrationDynamicWebSocketHandlerMapping` bean registration to let it to be consulted before `SimpleUrlHandlerMapping` * Add a note into `web-sockets.adoc` that `@EnableWebsocket` would disable Spring Integration dynamic WebSocket endpoints
1 parent e28bdc8 commit 6ef0798

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/WebSocketIntegrationConfigurationInitializer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ private void registerEnableWebSocketIfNecessary(BeanDefinitionRegistry registry)
9999

100100
BeanDefinitionReaderUtils.registerWithGeneratedName(
101101
new RootBeanDefinition(IntegrationDynamicWebSocketHandlerMapping.class,
102-
IntegrationDynamicWebSocketHandlerMapping::new),
102+
() -> {
103+
IntegrationDynamicWebSocketHandlerMapping dynamicWebSocketHandlerMapping =
104+
new IntegrationDynamicWebSocketHandlerMapping();
105+
dynamicWebSocketHandlerMapping.setOrder(0);
106+
return dynamicWebSocketHandlerMapping;
107+
}),
103108
registry);
104109

105110
BeanDefinitionBuilder enableWebSocketBuilder =

src/reference/asciidoc/web-sockets.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,6 @@ dynamicServerFlow.destroy();
429429
====
430430

431431
NOTE: It is important to call `.addBean(serverWebSocketContainer)` on the dynamic flow registration to add the instance of `ServerWebSocketContainer` into an `ApplicationContext` for endpoint registration.
432-
When a dynamic flow registration is destroyed, the associated `ServerWebSocketContainer` instance is destroyed, too, as well as the respective endpoint registration, including URL path mappings.
432+
When a dynamic flow registration is destroyed, the associated `ServerWebSocketContainer` instance is destroyed, too, as well as the respective endpoint registration, including URL path mappings.
433+
434+
IMPORTANT: The dynamic Websocket endpoints can only be registered via Spring Integration mechanism: when regular Spring `@EnableWebsocket` is used, Spring Integration configuration backs off and no infrastructure for dynamic endpoints is registered.

0 commit comments

Comments
 (0)