Upgrade to RSocket 1.0.0-RC7
This commit upgrades to RSocket 1.0.0-RC7. This new RC brings API changes we have to adapt to. As of this commit, we're introducing a new `RSocketServerCustomizer` which replaces the now deprecated `ServerRSocketFactoryProcessor`. Closes gh-21046
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.rsocket;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.rsocket.RSocketFactory;
|
||||
import io.rsocket.core.RSocketServer;
|
||||
import io.rsocket.frame.decoder.PayloadDecoder;
|
||||
import io.rsocket.transport.netty.server.TcpServerTransport;
|
||||
import reactor.netty.http.server.HttpServer;
|
||||
@@ -36,6 +36,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.rsocket.context.RSocketServerBootstrap;
|
||||
import org.springframework.boot.rsocket.netty.NettyRSocketServerFactory;
|
||||
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
|
||||
import org.springframework.boot.rsocket.server.RSocketServerFactory;
|
||||
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -57,7 +58,7 @@ import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHa
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ConditionalOnClass({ RSocketFactory.class, RSocketStrategies.class, HttpServer.class, TcpServerTransport.class })
|
||||
@ConditionalOnClass({ RSocketServer.class, RSocketStrategies.class, HttpServer.class, TcpServerTransport.class })
|
||||
@ConditionalOnBean(RSocketMessageHandler.class)
|
||||
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
|
||||
@EnableConfigurationProperties(RSocketProperties.class)
|
||||
@@ -69,10 +70,12 @@ public class RSocketServerAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@SuppressWarnings("deprecation")
|
||||
RSocketWebSocketNettyRouteProvider rSocketWebsocketRouteProvider(RSocketProperties properties,
|
||||
RSocketMessageHandler messageHandler, ObjectProvider<ServerRSocketFactoryProcessor> processors) {
|
||||
RSocketMessageHandler messageHandler, ObjectProvider<ServerRSocketFactoryProcessor> processors,
|
||||
ObjectProvider<RSocketServerCustomizer> customizers) {
|
||||
return new RSocketWebSocketNettyRouteProvider(properties.getServer().getMappingPath(),
|
||||
messageHandler.responder(), processors.orderedStream());
|
||||
messageHandler.responder(), processors.orderedStream(), customizers.orderedStream());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,14 +92,17 @@ public class RSocketServerAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@SuppressWarnings("deprecation")
|
||||
RSocketServerFactory rSocketServerFactory(RSocketProperties properties, ReactorResourceFactory resourceFactory,
|
||||
ObjectProvider<ServerRSocketFactoryProcessor> processors) {
|
||||
ObjectProvider<ServerRSocketFactoryProcessor> processors,
|
||||
ObjectProvider<RSocketServerCustomizer> customizers) {
|
||||
NettyRSocketServerFactory factory = new NettyRSocketServerFactory();
|
||||
factory.setResourceFactory(resourceFactory);
|
||||
factory.setTransport(properties.getServer().getTransport());
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
map.from(properties.getServer().getAddress()).to(factory::setAddress);
|
||||
map.from(properties.getServer().getPort()).to(factory::setPort);
|
||||
factory.setRSocketServerCustomizers(customizers.orderedStream().collect(Collectors.toList()));
|
||||
factory.setSocketFactoryProcessors(processors.orderedStream().collect(Collectors.toList()));
|
||||
return factory;
|
||||
}
|
||||
@@ -109,13 +115,12 @@ public class RSocketServerAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
ServerRSocketFactoryProcessor frameDecoderServerFactoryCustomizer(RSocketMessageHandler rSocketMessageHandler) {
|
||||
return (serverRSocketFactory) -> {
|
||||
RSocketServerCustomizer frameDecoderRSocketServerCustomizer(RSocketMessageHandler rSocketMessageHandler) {
|
||||
return (server) -> {
|
||||
if (rSocketMessageHandler.getRSocketStrategies()
|
||||
.dataBufferFactory() instanceof NettyDataBufferFactory) {
|
||||
return serverRSocketFactory.frameDecoder(PayloadDecoder.ZERO_COPY);
|
||||
server.payloadDecoder(PayloadDecoder.ZERO_COPY);
|
||||
}
|
||||
return serverRSocketFactory;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,10 +22,12 @@ import java.util.stream.Stream;
|
||||
|
||||
import io.rsocket.RSocketFactory;
|
||||
import io.rsocket.SocketAcceptor;
|
||||
import io.rsocket.core.RSocketServer;
|
||||
import io.rsocket.transport.ServerTransport;
|
||||
import io.rsocket.transport.netty.server.WebsocketRouteTransport;
|
||||
import reactor.netty.http.server.HttpServerRoutes;
|
||||
|
||||
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
|
||||
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
|
||||
import org.springframework.boot.web.embedded.netty.NettyRouteProvider;
|
||||
|
||||
@@ -34,6 +36,7 @@ import org.springframework.boot.web.embedded.netty.NettyRouteProvider;
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
|
||||
|
||||
private final String mappingPath;
|
||||
@@ -42,21 +45,24 @@ class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
|
||||
|
||||
private final List<ServerRSocketFactoryProcessor> processors;
|
||||
|
||||
private final List<RSocketServerCustomizer> customizers;
|
||||
|
||||
RSocketWebSocketNettyRouteProvider(String mappingPath, SocketAcceptor socketAcceptor,
|
||||
Stream<ServerRSocketFactoryProcessor> processors) {
|
||||
Stream<ServerRSocketFactoryProcessor> processors, Stream<RSocketServerCustomizer> customizers) {
|
||||
this.mappingPath = mappingPath;
|
||||
this.socketAcceptor = socketAcceptor;
|
||||
this.processors = processors.collect(Collectors.toList());
|
||||
this.customizers = customizers.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpServerRoutes apply(HttpServerRoutes httpServerRoutes) {
|
||||
RSocketFactory.ServerRSocketFactory server = RSocketFactory.receive();
|
||||
for (ServerRSocketFactoryProcessor processor : this.processors) {
|
||||
server = processor.process(server);
|
||||
}
|
||||
ServerTransport.ConnectionAcceptor acceptor = server.acceptor(this.socketAcceptor).toConnectionAcceptor();
|
||||
return httpServerRoutes.ws(this.mappingPath, WebsocketRouteTransport.newHandler(acceptor));
|
||||
RSocketServer server = RSocketServer.create(this.socketAcceptor);
|
||||
RSocketFactory.ServerRSocketFactory factory = new RSocketFactory.ServerRSocketFactory(server);
|
||||
this.processors.forEach((processor) -> processor.process(factory));
|
||||
this.customizers.forEach((customizer) -> customizer.customize(server));
|
||||
ServerTransport.ConnectionAcceptor connectionAcceptor = server.asConnectionAcceptor();
|
||||
return httpServerRoutes.ws(this.mappingPath, WebsocketRouteTransport.newHandler(connectionAcceptor));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.security.rsocket;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
|
||||
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.rsocket.EnableRSocketSecurity;
|
||||
@@ -29,6 +29,7 @@ import org.springframework.security.rsocket.core.SecuritySocketAcceptorIntercept
|
||||
* server.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @author Brian Clozel
|
||||
* @since 2.2.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -37,8 +38,8 @@ import org.springframework.security.rsocket.core.SecuritySocketAcceptorIntercept
|
||||
public class RSocketSecurityAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
ServerRSocketFactoryProcessor springSecurityRSocketSecurity(SecuritySocketAcceptorInterceptor interceptor) {
|
||||
return (factory) -> factory.addSocketAcceptorPlugin(interceptor);
|
||||
RSocketServerCustomizer springSecurityRSocketSecurity(SecuritySocketAcceptorInterceptor interceptor) {
|
||||
return (server) -> server.interceptors((registry) -> registry.forSocketAcceptor(interceptor));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user