Commit 985c8f75 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish RSocket support

parent 704b5fb2
...@@ -44,7 +44,7 @@ import org.springframework.web.util.pattern.PathPatternRouteMatcher; ...@@ -44,7 +44,7 @@ import org.springframework.web.util.pattern.PathPatternRouteMatcher;
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class) @AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
public class RSocketMessagingAutoConfiguration { public class RSocketMessagingAutoConfiguration {
private static String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher"; private static final String PATHPATTERN_ROUTEMATCHER_CLASS = "org.springframework.web.util.pattern.PathPatternRouteMatcher";
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
......
...@@ -35,7 +35,7 @@ public class RSocketProperties { ...@@ -35,7 +35,7 @@ public class RSocketProperties {
return this.server; return this.server;
} }
static class Server { public static class Server {
/** /**
* Server port. * Server port.
......
...@@ -48,7 +48,7 @@ public class RSocketRequesterAutoConfiguration { ...@@ -48,7 +48,7 @@ public class RSocketRequesterAutoConfiguration {
@Bean @Bean
@Scope("prototype") @Scope("prototype")
@ConditionalOnMissingBean @ConditionalOnMissingBean
public RSocketRequester.Builder rsocketRequesterBuilder(RSocketStrategies strategies) { public RSocketRequester.Builder rSocketRequesterBuilder(RSocketStrategies strategies) {
return RSocketRequester.builder().rsocketStrategies(strategies); return RSocketRequester.builder().rsocketStrategies(strategies);
} }
......
...@@ -81,7 +81,7 @@ public class RSocketServerAutoConfiguration { ...@@ -81,7 +81,7 @@ public class RSocketServerAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ReactorResourceFactory reactorServerResourceFactory() { public ReactorResourceFactory reactorResourceFactory() {
return new ReactorResourceFactory(); return new ReactorResourceFactory();
} }
...@@ -109,7 +109,7 @@ public class RSocketServerAutoConfiguration { ...@@ -109,7 +109,7 @@ public class RSocketServerAutoConfiguration {
static class OnRSocketWebServerCondition extends AllNestedConditions { static class OnRSocketWebServerCondition extends AllNestedConditions {
OnRSocketWebServerCondition() { OnRSocketWebServerCondition() {
super(ConfigurationPhase.REGISTER_BEAN); super(ConfigurationPhase.PARSE_CONFIGURATION);
} }
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
......
...@@ -76,7 +76,7 @@ public class RSocketStrategiesAutoConfiguration { ...@@ -76,7 +76,7 @@ public class RSocketStrategiesAutoConfiguration {
@Bean @Bean
@Order(0) @Order(0)
@ConditionalOnBean(Jackson2ObjectMapperBuilder.class) @ConditionalOnBean(Jackson2ObjectMapperBuilder.class)
public RSocketStrategiesCustomizer jacksonCborStrategyCustomizer(Jackson2ObjectMapperBuilder builder) { public RSocketStrategiesCustomizer jacksonCborRSocketStrategyCustomizer(Jackson2ObjectMapperBuilder builder) {
return (strategy) -> { return (strategy) -> {
ObjectMapper objectMapper = builder.factory(new CBORFactory()).build(); ObjectMapper objectMapper = builder.factory(new CBORFactory()).build();
strategy.decoder(new Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES)); strategy.decoder(new Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES));
...@@ -96,7 +96,7 @@ public class RSocketStrategiesAutoConfiguration { ...@@ -96,7 +96,7 @@ public class RSocketStrategiesAutoConfiguration {
@Bean @Bean
@Order(1) @Order(1)
@ConditionalOnBean(ObjectMapper.class) @ConditionalOnBean(ObjectMapper.class)
public RSocketStrategiesCustomizer jacksonJsonStrategyCustomizer(ObjectMapper objectMapper) { public RSocketStrategiesCustomizer jacksonJsonRSocketStrategyCustomizer(ObjectMapper objectMapper) {
return (strategy) -> { return (strategy) -> {
strategy.decoder(new Jackson2JsonDecoder(objectMapper, SUPPORTED_TYPES)); strategy.decoder(new Jackson2JsonDecoder(objectMapper, SUPPORTED_TYPES));
strategy.encoder(new Jackson2JsonEncoder(objectMapper, SUPPORTED_TYPES)); strategy.encoder(new Jackson2JsonEncoder(objectMapper, SUPPORTED_TYPES));
......
...@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
class RSocketMessagingAutoConfigurationTests { class RSocketMessagingAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(RSocketMessagingAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(RSocketMessagingAutoConfiguration.class))
.withUserConfiguration(BaseConfiguration.class); .withUserConfiguration(BaseConfiguration.class);
...@@ -67,7 +67,7 @@ class RSocketMessagingAutoConfigurationTests { ...@@ -67,7 +67,7 @@ class RSocketMessagingAutoConfigurationTests {
.containsOnly("customMessageHandlerAcceptor")); .containsOnly("customMessageHandlerAcceptor"));
} }
@Configuration @Configuration(proxyBeanMethods = false)
static class BaseConfiguration { static class BaseConfiguration {
@Bean @Bean
...@@ -78,7 +78,7 @@ class RSocketMessagingAutoConfigurationTests { ...@@ -78,7 +78,7 @@ class RSocketMessagingAutoConfigurationTests {
} }
@Configuration @Configuration(proxyBeanMethods = false)
static class CustomMessageHandlerAcceptor { static class CustomMessageHandlerAcceptor {
@Bean @Bean
......
...@@ -34,7 +34,7 @@ import static org.mockito.Mockito.mock; ...@@ -34,7 +34,7 @@ import static org.mockito.Mockito.mock;
*/ */
class RSocketRequesterAutoConfigurationTests { class RSocketRequesterAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration( private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class, RSocketRequesterAutoConfiguration.class)); AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class, RSocketRequesterAutoConfiguration.class));
@Test @Test
......
...@@ -42,22 +42,20 @@ class RSocketServerAutoConfigurationTests { ...@@ -42,22 +42,20 @@ class RSocketServerAutoConfigurationTests {
@Test @Test
void shouldNotCreateBeansByDefault() { void shouldNotCreateBeansByDefault() {
ApplicationContextRunner contextRunner = createContextRunner(); contextRunner().run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
contextRunner.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class)); .doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
} }
@Test @Test
void shouldNotCreateDefaultBeansForReactiveWebAppWithoutMapping() { void shouldNotCreateDefaultBeansForReactiveWebAppWithoutMapping() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner(); reactiveWebContextRunner()
contextRunner.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class) .run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
.doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class)); .doesNotHaveBean(RSocketServerFactory.class).doesNotHaveBean(RSocketServerBootstrap.class));
} }
@Test @Test
void shouldNotCreateDefaultBeansForReactiveWebAppWithWrongTransport() { void shouldNotCreateDefaultBeansForReactiveWebAppWithWrongTransport() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner(); reactiveWebContextRunner()
contextRunner
.withPropertyValues("spring.rsocket.server.transport=tcp", .withPropertyValues("spring.rsocket.server.transport=tcp",
"spring.rsocket.server.mapping-path=/rsocket") "spring.rsocket.server.mapping-path=/rsocket")
.run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class) .run((context) -> assertThat(context).doesNotHaveBean(WebServerFactoryCustomizer.class)
...@@ -66,8 +64,7 @@ class RSocketServerAutoConfigurationTests { ...@@ -66,8 +64,7 @@ class RSocketServerAutoConfigurationTests {
@Test @Test
void shouldCreateDefaultBeansForReactiveWebApp() { void shouldCreateDefaultBeansForReactiveWebApp() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner(); reactiveWebContextRunner()
contextRunner
.withPropertyValues("spring.rsocket.server.transport=websocket", .withPropertyValues("spring.rsocket.server.transport=websocket",
"spring.rsocket.server.mapping-path=/rsocket") "spring.rsocket.server.mapping-path=/rsocket")
.run((context) -> assertThat(context).hasSingleBean(RSocketWebSocketNettyRouteProvider.class)); .run((context) -> assertThat(context).hasSingleBean(RSocketWebSocketNettyRouteProvider.class));
...@@ -75,22 +72,22 @@ class RSocketServerAutoConfigurationTests { ...@@ -75,22 +72,22 @@ class RSocketServerAutoConfigurationTests {
@Test @Test
void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() { void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
ReactiveWebApplicationContextRunner contextRunner = createReactiveWebContextRunner(); reactiveWebContextRunner().withPropertyValues("spring.rsocket.server.port=0")
contextRunner.withPropertyValues("spring.rsocket.server.port=0").run((context) -> assertThat(context) .run((context) -> assertThat(context).hasSingleBean(RSocketServerFactory.class)
.hasSingleBean(RSocketServerFactory.class).hasSingleBean(RSocketServerBootstrap.class)); .hasSingleBean(RSocketServerBootstrap.class));
} }
private ApplicationContextRunner createContextRunner() { private ApplicationContextRunner contextRunner() {
return new ApplicationContextRunner().withUserConfiguration(BaseConfiguration.class) return new ApplicationContextRunner().withUserConfiguration(BaseConfiguration.class)
.withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));
} }
private ReactiveWebApplicationContextRunner createReactiveWebContextRunner() { private ReactiveWebApplicationContextRunner reactiveWebContextRunner() {
return new ReactiveWebApplicationContextRunner().withUserConfiguration(BaseConfiguration.class) return new ReactiveWebApplicationContextRunner().withUserConfiguration(BaseConfiguration.class)
.withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(RSocketServerAutoConfiguration.class));
} }
@Configuration @Configuration(proxyBeanMethods = false)
static class BaseConfiguration { static class BaseConfiguration {
@Bean @Bean
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
package org.springframework.boot.autoconfigure.rsocket; package org.springframework.boot.autoconfigure.rsocket;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer; import org.springframework.boot.rsocket.messaging.RSocketStrategiesCustomizer;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -32,7 +32,6 @@ import org.springframework.http.codec.cbor.Jackson2CborDecoder; ...@@ -32,7 +32,6 @@ import org.springframework.http.codec.cbor.Jackson2CborDecoder;
import org.springframework.http.codec.cbor.Jackson2CborEncoder; import org.springframework.http.codec.cbor.Jackson2CborEncoder;
import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonDecoder;
import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.messaging.rsocket.RSocketStrategies; import org.springframework.messaging.rsocket.RSocketStrategies;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -44,9 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -44,9 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
class RSocketStrategiesAutoConfigurationTests { class RSocketStrategiesAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner().withConfiguration(
.withUserConfiguration(BaseConfiguration.class) AutoConfigurations.of(JacksonAutoConfiguration.class, RSocketStrategiesAutoConfiguration.class));
.withConfiguration(AutoConfigurations.of(RSocketStrategiesAutoConfiguration.class));
@Test @Test
void shouldCreateDefaultBeans() { void shouldCreateDefaultBeans() {
...@@ -82,22 +80,7 @@ class RSocketStrategiesAutoConfigurationTests { ...@@ -82,22 +80,7 @@ class RSocketStrategiesAutoConfigurationTests {
}); });
} }
@Configuration @Configuration(proxyBeanMethods = false)
static class BaseConfiguration {
@Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
}
@Bean
public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() {
return new Jackson2ObjectMapperBuilder();
}
}
@Configuration
static class UserStrategies { static class UserStrategies {
@Bean @Bean
...@@ -108,7 +91,7 @@ class RSocketStrategiesAutoConfigurationTests { ...@@ -108,7 +91,7 @@ class RSocketStrategiesAutoConfigurationTests {
} }
@Configuration @Configuration(proxyBeanMethods = false)
static class StrategiesCustomizer { static class StrategiesCustomizer {
@Bean @Bean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment