Browse Source

Avoid duplicate RSocket endpoint for WebSocket

Prior to this commit, choosing a "websocket" transport for your RSocket
endpoint with `spring.rsocket.server.port` would not only expose the
endpoint on that specific port, but also on the main server.

This commit refines the auto-configuration condition to only add a route
on the main server if the separate port is not chosen.

Fixes gh-49592
pull/49591/head
Brian Clozel 5 days ago
parent
commit
c366ddaca0
  1. 2
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java
  2. 11
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java

2
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfiguration.java

@ -148,7 +148,7 @@ public class RSocketServerAutoConfiguration { @@ -148,7 +148,7 @@ public class RSocketServerAutoConfiguration {
}
@ConditionalOnProperty(name = "spring.rsocket.server.port", matchIfMissing = true)
@ConditionalOnProperty(name = "spring.rsocket.server.port", havingValue = "false", matchIfMissing = true)
static class HasNoPortConfigured {
}

11
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java

@ -84,6 +84,17 @@ class RSocketServerAutoConfigurationTests { @@ -84,6 +84,17 @@ class RSocketServerAutoConfigurationTests {
.run((context) -> assertThat(context).hasSingleBean(RSocketWebSocketNettyRouteProvider.class));
}
@Test
void shouldNotCreateWebSocketRouteProviderWhenDedicatedPortIsSet() {
reactiveWebContextRunner()
.withPropertyValues("spring.rsocket.server.port=0", "spring.rsocket.server.transport=websocket",
"spring.rsocket.server.mapping-path=/rsocket")
.run((context) -> {
assertThat(context).hasSingleBean(RSocketServerFactory.class);
assertThat(context).doesNotHaveBean(RSocketWebSocketNettyRouteProvider.class);
});
}
@Test
void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
reactiveWebContextRunner().withPropertyValues("spring.rsocket.server.port=0")

Loading…
Cancel
Save