Update after RSocket changes in Spring Framework

Spring Framework recently removed the `MessageHandlerAcceptor` (which is
a sub-class of `RSocketMessageHandler`).
Instead of implementing directly the `SocketAcceptor` contract, it now
exposes them through `clientAcceptor()` and `serverAcceptor()` methods.

See gh-17280
pull/17285/head
Brian Clozel 5 years ago
parent 62c70140c6
commit 7857dd2d72

@ -25,9 +25,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.rsocket.MessageHandlerAcceptor;
import org.springframework.messaging.rsocket.RSocketRequester;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.util.ClassUtils;
import org.springframework.web.util.pattern.PathPatternParser;
import org.springframework.web.util.pattern.PathPatternRouteMatcher;
@ -48,15 +48,15 @@ public class RSocketMessagingAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public MessageHandlerAcceptor messageHandlerAcceptor(RSocketStrategies rSocketStrategies) {
MessageHandlerAcceptor acceptor = new MessageHandlerAcceptor();
acceptor.setRSocketStrategies(rSocketStrategies);
public RSocketMessageHandler messageHandler(RSocketStrategies rSocketStrategies) {
RSocketMessageHandler messageHandler = new RSocketMessageHandler();
messageHandler.setRSocketStrategies(rSocketStrategies);
if (ClassUtils.isPresent(PATHPATTERN_ROUTEMATCHER_CLASS, null)) {
PathPatternParser parser = new PathPatternParser();
parser.setSeparator('.');
acceptor.setRouteMatcher(new PathPatternRouteMatcher(parser));
messageHandler.setRouteMatcher(new PathPatternRouteMatcher(parser));
}
return acceptor;
return messageHandler;
}
}

@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.rsocket;
import java.util.stream.Collectors;
import io.rsocket.RSocketFactory;
import io.rsocket.SocketAcceptor;
import io.rsocket.transport.netty.server.TcpServerTransport;
import reactor.netty.http.server.HttpServer;
@ -42,8 +41,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.reactive.ReactorResourceFactory;
import org.springframework.messaging.rsocket.MessageHandlerAcceptor;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
/**
* {@link EnableAutoConfiguration Auto-configuration} for RSocket servers. In the case of
@ -57,7 +56,7 @@ import org.springframework.messaging.rsocket.RSocketStrategies;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ RSocketFactory.class, RSocketStrategies.class, HttpServer.class, TcpServerTransport.class })
@ConditionalOnBean(MessageHandlerAcceptor.class)
@ConditionalOnBean(RSocketMessageHandler.class)
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
@EnableConfigurationProperties(RSocketProperties.class)
public class RSocketServerAutoConfiguration {
@ -68,9 +67,9 @@ public class RSocketServerAutoConfiguration {
@Bean
public RSocketWebSocketNettyRouteProvider rSocketWebsocketRouteProvider(RSocketProperties properties,
MessageHandlerAcceptor messageHandlerAcceptor) {
RSocketMessageHandler messageHandler) {
return new RSocketWebSocketNettyRouteProvider(properties.getServer().getMappingPath(),
messageHandlerAcceptor);
messageHandler.serverAcceptor());
}
}
@ -100,8 +99,8 @@ public class RSocketServerAutoConfiguration {
@Bean
public RSocketServerBootstrap rSocketServerBootstrap(RSocketServerFactory rSocketServerFactory,
SocketAcceptor socketAcceptor) {
return new RSocketServerBootstrap(rSocketServerFactory, socketAcceptor);
RSocketMessageHandler rSocketMessageHandler) {
return new RSocketServerBootstrap(rSocketServerFactory, rSocketMessageHandler.serverAcceptor());
}
}

@ -17,12 +17,12 @@
package org.springframework.boot.autoconfigure.rsocket;
import io.rsocket.RSocketFactory;
import io.rsocket.SocketAcceptor;
import io.rsocket.transport.ServerTransport;
import io.rsocket.transport.netty.server.WebsocketRouteTransport;
import reactor.netty.http.server.HttpServerRoutes;
import org.springframework.boot.web.embedded.netty.NettyRouteProvider;
import org.springframework.messaging.rsocket.MessageHandlerAcceptor;
/**
* {@link NettyRouteProvider} that configures an RSocket Websocket endpoint.
@ -33,16 +33,16 @@ class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
private final String mappingPath;
private final MessageHandlerAcceptor messageHandlerAcceptor;
private final SocketAcceptor socketAcceptor;
RSocketWebSocketNettyRouteProvider(String mappingPath, MessageHandlerAcceptor messageHandlerAcceptor) {
RSocketWebSocketNettyRouteProvider(String mappingPath, SocketAcceptor socketAcceptor) {
this.mappingPath = mappingPath;
this.messageHandlerAcceptor = messageHandlerAcceptor;
this.socketAcceptor = socketAcceptor;
}
@Override
public HttpServerRoutes apply(HttpServerRoutes httpServerRoutes) {
ServerTransport.ConnectionAcceptor acceptor = RSocketFactory.receive().acceptor(this.messageHandlerAcceptor)
ServerTransport.ConnectionAcceptor acceptor = RSocketFactory.receive().acceptor(this.socketAcceptor)
.toConnectionAcceptor();
return httpServerRoutes.ws(this.mappingPath, WebsocketRouteTransport.newHandler(acceptor));
}

@ -24,8 +24,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.messaging.rsocket.MessageHandlerAcceptor;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.web.util.pattern.PathPatternRouteMatcher;
import static org.assertj.core.api.Assertions.assertThat;
@ -44,8 +44,8 @@ class RSocketMessagingAutoConfigurationTests {
@Test
void shouldCreateDefaultBeans() {
this.contextRunner.run((context) -> {
assertThat(context).getBeans(MessageHandlerAcceptor.class).hasSize(1);
assertThat(context.getBean(MessageHandlerAcceptor.class).getRouteMatcher())
assertThat(context).getBeans(RSocketMessageHandler.class).hasSize(1);
assertThat(context.getBean(RSocketMessageHandler.class).getRouteMatcher())
.isInstanceOf(PathPatternRouteMatcher.class);
});
}
@ -61,10 +61,9 @@ class RSocketMessagingAutoConfigurationTests {
}
@Test
void shouldUseCustomMessageHandlerAcceptor() {
this.contextRunner.withUserConfiguration(CustomMessageHandlerAcceptor.class)
.run((context) -> assertThat(context).getBeanNames(MessageHandlerAcceptor.class)
.containsOnly("customMessageHandlerAcceptor"));
void shouldUseCustomSocketAcceptor() {
this.contextRunner.withUserConfiguration(CustomMessageHandler.class).run((context) -> assertThat(context)
.getBeanNames(RSocketMessageHandler.class).containsOnly("customMessageHandler"));
}
@Configuration(proxyBeanMethods = false)
@ -79,15 +78,15 @@ class RSocketMessagingAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
static class CustomMessageHandlerAcceptor {
static class CustomMessageHandler {
@Bean
public MessageHandlerAcceptor customMessageHandlerAcceptor() {
MessageHandlerAcceptor acceptor = new MessageHandlerAcceptor();
public RSocketMessageHandler customMessageHandler() {
RSocketMessageHandler messageHandler = new RSocketMessageHandler();
RSocketStrategies strategies = RSocketStrategies.builder().encoder(CharSequenceEncoder.textPlainOnly())
.decoder(StringDecoder.textPlainOnly()).build();
acceptor.setRSocketStrategies(strategies);
return acceptor;
messageHandler.setRSocketStrategies(strategies);
return messageHandler;
}
}

@ -28,8 +28,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.codec.CharSequenceEncoder;
import org.springframework.core.codec.StringDecoder;
import org.springframework.messaging.rsocket.MessageHandlerAcceptor;
import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import static org.assertj.core.api.Assertions.assertThat;
@ -91,11 +91,11 @@ class RSocketServerAutoConfigurationTests {
static class BaseConfiguration {
@Bean
public MessageHandlerAcceptor messageHandlerAcceptor() {
MessageHandlerAcceptor messageHandlerAcceptor = new MessageHandlerAcceptor();
messageHandlerAcceptor.setRSocketStrategies(RSocketStrategies.builder()
.encoder(CharSequenceEncoder.textPlainOnly()).decoder(StringDecoder.textPlainOnly()).build());
return messageHandlerAcceptor;
public RSocketMessageHandler messageHandler() {
RSocketMessageHandler messageHandler = new RSocketMessageHandler();
messageHandler.setRSocketStrategies(RSocketStrategies.builder().encoder(CharSequenceEncoder.textPlainOnly())
.decoder(StringDecoder.textPlainOnly()).build());
return messageHandler;
}
}

Loading…
Cancel
Save