Skip to content

Commit 985c8f7

Browse files
committed
Polish RSocket support
1 parent 704b5fb commit 985c8f7

File tree

9 files changed

+28
-48
lines changed

9 files changed

+28
-48
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
4545
public class RSocketMessagingAutoConfiguration {
4646

47-
private static String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher";
47+
private static final String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher";
4848

4949
@Bean
5050
@ConditionalOnMissingBean

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Server getServer() {
3535
return this.server;
3636
}
3737

38-
static class Server {
38+
public static class Server {
3939

4040
/**
4141
* Server port.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class RSocketRequesterAutoConfiguration {
4848
@Bean
4949
@Scope("prototype")
5050
@ConditionalOnMissingBean
51-
public RSocketRequester.Builder rsocketRequesterBuilder(RSocketStrategies strategies) {
51+
public RSocketRequester.Builder rSocketRequesterBuilder(RSocketStrategies strategies) {
5252
return RSocketRequester.builder().rsocketStrategies(strategies);
5353
}
5454

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static class EmbeddedServerAutoConfiguration {
8181

8282
@Bean
8383
@ConditionalOnMissingBean
84-
public ReactorResourceFactory reactorServerResourceFactory() {
84+
public ReactorResourceFactory reactorResourceFactory() {
8585
return new ReactorResourceFactory();
8686
}
8787

@@ -109,7 +109,7 @@ public RSocketServerBootstrap rSocketServerBootstrap(RSocketServerFactory rSocke
109109
static class OnRSocketWebServerCondition extends AllNestedConditions {
110110

111111
OnRSocketWebServerCondition() {
112-
super(ConfigurationPhase.REGISTER_BEAN);
112+
super(ConfigurationPhase.PARSE_CONFIGURATION);
113113
}
114114

115115
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected static class JacksonCborStrategyConfiguration {
7676
@Bean
7777
@Order(0)
7878
@ConditionalOnBean(Jackson2ObjectMapperBuilder.class)
79-
public RSocketStrategiesCustomizer jacksonCborStrategyCustomizer(Jackson2ObjectMapperBuilder builder) {
79+
public RSocketStrategiesCustomizer jacksonCborRSocketStrategyCustomizer(Jackson2ObjectMapperBuilder builder) {
8080
return (strategy) -> {
8181
ObjectMapper objectMapper = builder.factory(new CBORFactory()).build();
8282
strategy.decoder(new Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES));
@@ -96,7 +96,7 @@ protected static class JacksonJsonStrategyConfiguration {
9696
@Bean
9797
@Order(1)
9898
@ConditionalOnBean(ObjectMapper.class)
99-
public RSocketStrategiesCustomizer jacksonJsonStrategyCustomizer(ObjectMapper objectMapper) {
99+
public RSocketStrategiesCustomizer jacksonJsonRSocketStrategyCustomizer(ObjectMapper objectMapper) {
100100
return (strategy) -> {
101101
strategy.decoder(new Jackson2JsonDecoder(objectMapper, SUPPORTED_TYPES));
102102
strategy.encoder(new Jackson2JsonEncoder(objectMapper, SUPPORTED_TYPES));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
class RSocketMessagingAutoConfigurationTests {
3939

40-
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
40+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
4141
.withConfiguration(AutoConfigurations.of(RSocketMessagingAutoConfiguration.class))
4242
.withUserConfiguration(BaseConfiguration.class);
4343

@@ -67,7 +67,7 @@ void shouldUseCustomMessageHandlerAcceptor() {
6767
.containsOnly("customMessageHandlerAcceptor"));
6868
}
6969

70-
@Configuration
70+
@Configuration(proxyBeanMethods = false)
7171
static class BaseConfiguration {
7272

7373
@Bean
@@ -78,7 +78,7 @@ public RSocketStrategies rSocketStrategies() {
7878

7979
}
8080

81-
@Configuration
81+
@Configuration(proxyBeanMethods = false)
8282
static class CustomMessageHandlerAcceptor {
8383

8484
@Bean

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
class RSocketRequesterAutoConfigurationTests {
3636

37-
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
37+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
3838
AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class, RSocketRequesterAutoConfiguration.class));
3939

4040
@Test

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,20 @@ class RSocketServerAutoConfigurationTests {
4242

4343
@Test
4444
void shouldNotCreateBeansByDefault() {
45-
ApplicationContextRunner contextRunner = createContextRunner();
46-
contextRunner.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
45+
contextRunner().run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
4746
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
4847
}
4948

5049
@Test
5150
void shouldNotCreateDefaultBeansForReactiveWebAppWithoutMapping() {
52-
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
53-
contextRunner.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
54-
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
51+
reactiveWebContextRunner()
52+
.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
53+
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
5554
}
5655

5756
@Test
5857
void shouldNotCreateDefaultBeansForReactiveWebAppWithWrongTransport() {
59-
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
60-
contextRunner
58+
reactiveWebContextRunner()
6159
.withPropertyValues("spring.rsocket.server.transport=tcp",
6260
"spring.rsocket.server.mapping-path=/rsocket")
6361
.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
@@ -66,31 +64,30 @@ void shouldNotCreateDefaultBeansForReactiveWebAppWithWrongTransport() {
6664

6765
@Test
6866
void shouldCreateDefaultBeansForReactiveWebApp() {
69-
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
70-
contextRunner
67+
reactiveWebContextRunner()
7168
.withPropertyValues("spring.rsocket.server.transport=websocket",
7269
"spring.rsocket.server.mapping-path=/rsocket")
7370
.run((context) -> assertThat(context).hasSingleBean(RSocketWebSocketNettyRouteProvider.class));
7471
}
7572

7673
@Test
7774
void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
78-
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner();
79-
contextRunner.withPropertyValues("spring.rsocket.server.port=0").run((context) -> assertThat(context)
80-
.hasSingleBean(RSocketServerFactory.class).hasSingleBean(RSocketServerBootstrap.class));
75+
reactiveWebContextRunner().withPropertyValues("spring.rsocket.server.port=0")
76+
.run((context) -> assertThat(context).hasSingleBean(RSocketServerFactory.class)
77+
.hasSingleBean(RSocketServerBootstrap.class));
8178
}
8279

83-
private ApplicationContextRunner createContextRunner() {
80+
private ApplicationContextRunner contextRunner() {
8481
return new ApplicationContextRunner().withUserConfiguration(BaseConfiguration.class)
8582
.withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));
8683
}
8784

88-
private ReactiveWebApplicationContextRunner createReactiveWebContextRunner() {
85+
private ReactiveWebApplicationContextRunner reactiveWebContextRunner() {
8986
return new ReactiveWebApplicationContextRunner().withUserConfiguration(BaseConfiguration.class)
9087
.withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));
9188
}
9289

93-
@Configuration
90+
@Configuration(proxyBeanMethods = false)
9491
static class BaseConfiguration {
9592

9693
@Bean

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package org.springframework.boot.autoconfigure.rsocket;
1818

19-
import com.fasterxml.jackson.databind.ObjectMapper;
2019
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.boot.autoconfigure.AutoConfigurations;
22+
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
2323
import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer;
2424
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2525
import org.springframework.context.annotation.Bean;
@@ -32,7 +32,6 @@
3232
import org.springframework.http.codec.cbor.Jackson2CborEncoder;
3333
import org.springframework.http.codec.json.Jackson2JsonDecoder;
3434
import org.springframework.http.codec.json.Jackson2JsonEncoder;
35-
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3635
import org.springframework.messaging.rsocket.RSocketStrategies;
3736

3837
import static org.assertj.core.api.Assertions.assertThat;
@@ -44,9 +43,8 @@
4443
*/
4544
class RSocketStrategiesAutoConfigurationTests {
4645

47-
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
48-
.withUserConfiguration(BaseConfiguration.class)
49-
.withConfiguration(AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class));
46+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
47+
AutoConfigurations.of(JacksonAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class));
5048

5149
@Test
5250
void shouldCreateDefaultBeans() {
@@ -82,22 +80,7 @@ void shouldUseStrategiesCustomizer() {
8280
});
8381
}
8482

85-
@Configuration
86-
static class BaseConfiguration {
87-
88-
@Bean
89-
public ObjectMapper objectMapper() {
90-
return new ObjectMapper();
91-
}
92-
93-
@Bean
94-
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
95-
return new Jackson2ObjectMapperBuilder();
96-
}
97-
98-
}
99-
100-
@Configuration
83+
@Configuration(proxyBeanMethods = false)
10184
static class UserStrategies {
10285

10386
@Bean
@@ -108,7 +91,7 @@ public RSocketStrategies customRSocketStrategies() {
10891

10992
}
11093

111-
@Configuration
94+
@Configuration(proxyBeanMethods = false)
11295
static class StrategiesCustomizer {
11396

11497
@Bean

0 commit comments

Comments
 (0)