Skip to content

Commit dac6247

Browse files
committed
Merge branch '2.2.x'
Closes gh-21208
2 parents 71565a1 + a63ab46 commit dac6247

File tree

11 files changed

+150
-49
lines changed

11 files changed

+150
-49
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818

1919
import java.util.stream.Collectors;
2020

21-
import io.rsocket.RSocketFactory;
21+
import io.rsocket.core.RSocketServer;
2222
import io.rsocket.frame.decoder.PayloadDecoder;
2323
import io.rsocket.transport.netty.server.TcpServerTransport;
2424
import reactor.netty.http.server.HttpServer;
@@ -36,6 +36,7 @@
3636
import org.springframework.boot.context.properties.PropertyMapper;
3737
import org.springframework.boot.rsocket.context.RSocketServerBootstrap;
3838
import org.springframework.boot.rsocket.netty.NettyRSocketServerFactory;
39+
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
3940
import org.springframework.boot.rsocket.server.RSocketServerFactory;
4041
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
4142
import org.springframework.context.annotation.Bean;
@@ -57,7 +58,7 @@
5758
* @since 2.2.0
5859
*/
5960
@Configuration(proxyBeanMethods = false)
60-
@ConditionalOnClass({ RSocketFactory.class, RSocketStrategies.class, HttpServer.class, TcpServerTransport.class })
61+
@ConditionalOnClass({ RSocketServer.class, RSocketStrategies.class, HttpServer.class, TcpServerTransport.class })
6162
@ConditionalOnBean(RSocketMessageHandler.class)
6263
@AutoConfigureAfter(RSocketStrategiesAutoConfiguration.class)
6364
@EnableConfigurationProperties(RSocketProperties.class)
@@ -69,10 +70,12 @@ static class WebFluxServerAutoConfiguration {
6970

7071
@Bean
7172
@ConditionalOnMissingBean
73+
@SuppressWarnings("deprecation")
7274
RSocketWebSocketNettyRouteProvider rSocketWebsocketRouteProvider(RSocketProperties properties,
73-
RSocketMessageHandler messageHandler, ObjectProvider<ServerRSocketFactoryProcessor> processors) {
75+
RSocketMessageHandler messageHandler, ObjectProvider<ServerRSocketFactoryProcessor> processors,
76+
ObjectProvider<RSocketServerCustomizer> customizers) {
7477
return new RSocketWebSocketNettyRouteProvider(properties.getServer().getMappingPath(),
75-
messageHandler.responder(), processors.orderedStream());
78+
messageHandler.responder(), processors.orderedStream(), customizers.orderedStream());
7679
}
7780

7881
}
@@ -89,14 +92,17 @@ ReactorResourceFactory reactorResourceFactory() {
8992

9093
@Bean
9194
@ConditionalOnMissingBean
95+
@SuppressWarnings("deprecation")
9296
RSocketServerFactory rSocketServerFactory(RSocketProperties properties, ReactorResourceFactory resourceFactory,
93-
ObjectProvider<ServerRSocketFactoryProcessor> processors) {
97+
ObjectProvider<ServerRSocketFactoryProcessor> processors,
98+
ObjectProvider<RSocketServerCustomizer> customizers) {
9499
NettyRSocketServerFactory factory = new NettyRSocketServerFactory();
95100
factory.setResourceFactory(resourceFactory);
96101
factory.setTransport(properties.getServer().getTransport());
97102
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
98103
map.from(properties.getServer().getAddress()).to(factory::setAddress);
99104
map.from(properties.getServer().getPort()).to(factory::setPort);
105+
factory.setRSocketServerCustomizers(customizers.orderedStream().collect(Collectors.toList()));
100106
factory.setSocketFactoryProcessors(processors.orderedStream().collect(Collectors.toList()));
101107
return factory;
102108
}
@@ -109,13 +115,12 @@ RSocketServerBootstrap rSocketServerBootstrap(RSocketServerFactory rSocketServer
109115
}
110116

111117
@Bean
112-
ServerRSocketFactoryProcessor frameDecoderServerFactoryCustomizer(RSocketMessageHandler rSocketMessageHandler) {
113-
return (serverRSocketFactory) -> {
118+
RSocketServerCustomizer frameDecoderRSocketServerCustomizer(RSocketMessageHandler rSocketMessageHandler) {
119+
return (server) -> {
114120
if (rSocketMessageHandler.getRSocketStrategies()
115121
.dataBufferFactory() instanceof NettyDataBufferFactory) {
116-
return serverRSocketFactory.frameDecoder(PayloadDecoder.ZERO_COPY);
122+
server.payloadDecoder(PayloadDecoder.ZERO_COPY);
117123
}
118-
return serverRSocketFactory;
119124
};
120125
}
121126

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,10 +22,12 @@
2222

2323
import io.rsocket.RSocketFactory;
2424
import io.rsocket.SocketAcceptor;
25+
import io.rsocket.core.RSocketServer;
2526
import io.rsocket.transport.ServerTransport;
2627
import io.rsocket.transport.netty.server.WebsocketRouteTransport;
2728
import reactor.netty.http.server.HttpServerRoutes;
2829

30+
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
2931
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
3032
import org.springframework.boot.web.embedded.netty.NettyRouteProvider;
3133

@@ -34,6 +36,7 @@
3436
*
3537
* @author Brian Clozel
3638
*/
39+
@SuppressWarnings("deprecation")
3740
class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
3841

3942
private final String mappingPath;
@@ -42,21 +45,24 @@ class RSocketWebSocketNettyRouteProvider implements NettyRouteProvider {
4245

4346
private final List<ServerRSocketFactoryProcessor> processors;
4447

48+
private final List<RSocketServerCustomizer> customizers;
49+
4550
RSocketWebSocketNettyRouteProvider(String mappingPath, SocketAcceptor socketAcceptor,
46-
Stream<ServerRSocketFactoryProcessor> processors) {
51+
Stream<ServerRSocketFactoryProcessor> processors, Stream<RSocketServerCustomizer> customizers) {
4752
this.mappingPath = mappingPath;
4853
this.socketAcceptor = socketAcceptor;
4954
this.processors = processors.collect(Collectors.toList());
55+
this.customizers = customizers.collect(Collectors.toList());
5056
}
5157

5258
@Override
5359
public HttpServerRoutes apply(HttpServerRoutes httpServerRoutes) {
54-
RSocketFactory.ServerRSocketFactory server = RSocketFactory.receive();
55-
for (ServerRSocketFactoryProcessor processor : this.processors) {
56-
server = processor.process(server);
57-
}
58-
ServerTransport.ConnectionAcceptor acceptor = server.acceptor(this.socketAcceptor).toConnectionAcceptor();
59-
return httpServerRoutes.ws(this.mappingPath, WebsocketRouteTransport.newHandler(acceptor));
60+
RSocketServer server = RSocketServer.create(this.socketAcceptor);
61+
RSocketFactory.ServerRSocketFactory factory = new RSocketFactory.ServerRSocketFactory(server);
62+
this.processors.forEach((processor) -> processor.process(factory));
63+
this.customizers.forEach((customizer) -> customizer.customize(server));
64+
ServerTransport.ConnectionAcceptor connectionAcceptor = server.asConnectionAcceptor();
65+
return httpServerRoutes.ws(this.mappingPath, WebsocketRouteTransport.newHandler(connectionAcceptor));
6066
}
6167

6268
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818

1919
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2020
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
21-
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
21+
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
2222
import org.springframework.context.annotation.Bean;
2323
import org.springframework.context.annotation.Configuration;
2424
import org.springframework.security.config.annotation.rsocket.EnableRSocketSecurity;
@@ -29,6 +29,7 @@
2929
* server.
3030
*
3131
* @author Madhura Bhave
32+
* @author Brian Clozel
3233
* @since 2.2.0
3334
*/
3435
@Configuration(proxyBeanMethods = false)
@@ -37,8 +38,8 @@
3738
public class RSocketSecurityAutoConfiguration {
3839

3940
@Bean
40-
ServerRSocketFactoryProcessor springSecurityRSocketSecurity(SecuritySocketAcceptorInterceptor interceptor) {
41-
return (factory) -> factory.addSocketAcceptorPlugin(interceptor);
41+
RSocketServerCustomizer springSecurityRSocketSecurity(SecuritySocketAcceptorInterceptor interceptor) {
42+
return (server) -> server.interceptors((registry) -> registry.forSocketAcceptor(interceptor));
4243
}
4344

4445
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@
2121
import org.springframework.boot.autoconfigure.AutoConfigurations;
2222
import org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer;
2323
import org.springframework.boot.rsocket.context.RSocketServerBootstrap;
24+
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
2425
import org.springframework.boot.rsocket.server.RSocketServerFactory;
25-
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
2626
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2727
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
2828
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
@@ -78,17 +78,15 @@ void shouldCreateDefaultBeansForReactiveWebApp() {
7878
void shouldCreateDefaultBeansForRSocketServerWhenPortIsSet() {
7979
reactiveWebContextRunner().withPropertyValues("spring.rsocket.server.port=0")
8080
.run((context) -> assertThat(context).hasSingleBean(RSocketServerFactory.class)
81-
.hasSingleBean(RSocketServerBootstrap.class)
82-
.hasSingleBean(ServerRSocketFactoryProcessor.class));
81+
.hasSingleBean(RSocketServerBootstrap.class).hasSingleBean(RSocketServerCustomizer.class));
8382
}
8483

8584
@Test
8685
void shouldSetLocalServerPortWhenRSocketServerPortIsSet() {
8786
reactiveWebContextRunner().withPropertyValues("spring.rsocket.server.port=0")
8887
.withInitializer(new RSocketPortInfoApplicationContextInitializer()).run((context) -> {
8988
assertThat(context).hasSingleBean(RSocketServerFactory.class)
90-
.hasSingleBean(RSocketServerBootstrap.class)
91-
.hasSingleBean(ServerRSocketFactoryProcessor.class);
89+
.hasSingleBean(RSocketServerBootstrap.class).hasSingleBean(RSocketServerCustomizer.class);
9290
assertThat(context.getEnvironment().getProperty("local.rsocket.server.port")).isNotNull();
9391
});
9492
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,28 +16,26 @@
1616

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

19-
import io.rsocket.RSocketFactory;
19+
import io.rsocket.core.RSocketServer;
2020
import org.junit.jupiter.api.Test;
21-
import org.mockito.ArgumentCaptor;
2221

2322
import org.springframework.boot.autoconfigure.AutoConfigurations;
2423
import org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration;
2524
import org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration;
2625
import org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration;
27-
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
26+
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
2827
import org.springframework.boot.test.context.FilteredClassLoader;
2928
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
3029
import org.springframework.security.config.annotation.rsocket.RSocketSecurity;
3130
import org.springframework.security.rsocket.core.SecuritySocketAcceptorInterceptor;
3231

3332
import static org.assertj.core.api.Assertions.assertThat;
34-
import static org.mockito.Mockito.mock;
35-
import static org.mockito.Mockito.verify;
3633

3734
/**
3835
* Tests for {@link RSocketSecurityAutoConfiguration}.
3936
*
4037
* @author Madhura Bhave
38+
* @author Brian Clozel
4139
*/
4240
class RSocketSecurityAutoConfigurationTests {
4341

@@ -58,14 +56,15 @@ void autoConfigurationIsConditionalOnSecuritySocketAcceptorInterceptorClass() {
5856

5957
@Test
6058
void autoConfigurationAddsCustomizerForServerRSocketFactory() {
61-
RSocketFactory.ServerRSocketFactory factory = mock(RSocketFactory.ServerRSocketFactory.class);
62-
ArgumentCaptor<SecuritySocketAcceptorInterceptor> captor = ArgumentCaptor
63-
.forClass(SecuritySocketAcceptorInterceptor.class);
59+
RSocketServer server = RSocketServer.create();
6460
this.contextRunner.run((context) -> {
65-
ServerRSocketFactoryProcessor customizer = context.getBean(ServerRSocketFactoryProcessor.class);
66-
customizer.process(factory);
67-
verify(factory).addSocketAcceptorPlugin(captor.capture());
68-
assertThat(captor.getValue()).isInstanceOf(SecuritySocketAcceptorInterceptor.class);
61+
RSocketServerCustomizer customizer = context.getBean(RSocketServerCustomizer.class);
62+
customizer.customize(server);
63+
server.interceptors((registry) -> registry.forSocketAcceptor((interceptors) -> {
64+
assertThat(interceptors).isNotEmpty();
65+
assertThat(interceptors)
66+
.anyMatch((interceptor) -> interceptor instanceof SecuritySocketAcceptorInterceptor);
67+
}));
6968
});
7069
}
7170

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ bom {
14031403
]
14041404
}
14051405
}
1406-
library("RSocket", "1.0.0-RC6") {
1406+
library("RSocket", "1.0.0-RC7") {
14071407
group("io.rsocket") {
14081408
imports = [
14091409
"rsocket-bom"

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/rsocket/netty/NettyRSocketServerFactory.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737

3838
import org.springframework.boot.rsocket.server.ConfigurableRSocketServerFactory;
3939
import org.springframework.boot.rsocket.server.RSocketServer;
40+
import org.springframework.boot.rsocket.server.RSocketServerCustomizer;
4041
import org.springframework.boot.rsocket.server.RSocketServerFactory;
4142
import org.springframework.boot.rsocket.server.ServerRSocketFactoryProcessor;
4243
import org.springframework.http.client.reactive.ReactorResourceFactory;
@@ -63,6 +64,8 @@ public class NettyRSocketServerFactory implements RSocketServerFactory, Configur
6364

6465
private List<ServerRSocketFactoryProcessor> socketFactoryProcessors = new ArrayList<>();
6566

67+
private List<RSocketServerCustomizer> rSocketServerCustomizers = new ArrayList<>();
68+
6669
@Override
6770
public void setPort(int port) {
6871
this.port = port;
@@ -91,7 +94,10 @@ public void setResourceFactory(ReactorResourceFactory resourceFactory) {
9194
* {@link ServerRSocketFactory} while building the server. Calling this method will
9295
* replace any existing processors.
9396
* @param socketFactoryProcessors processors to apply before the server starts
97+
* @deprecated in favor of {@link #setRSocketServerCustomizers(Collection)} as of
98+
* 2.2.7
9499
*/
100+
@Deprecated
95101
public void setSocketFactoryProcessors(
96102
Collection<? extends ServerRSocketFactoryProcessor> socketFactoryProcessors) {
97103
Assert.notNull(socketFactoryProcessors, "SocketFactoryProcessors must not be null");
@@ -102,12 +108,38 @@ public void setSocketFactoryProcessors(
102108
* Add {@link ServerRSocketFactoryProcessor}s that should be called to process the
103109
* {@link ServerRSocketFactory} while building the server.
104110
* @param socketFactoryProcessors processors to apply before the server starts
111+
* @deprecated in favor of
112+
* {@link #addRSocketServerCustomizers(RSocketServerCustomizer...)} as of 2.2.7
105113
*/
114+
@Deprecated
106115
public void addSocketFactoryProcessors(ServerRSocketFactoryProcessor... socketFactoryProcessors) {
107116
Assert.notNull(socketFactoryProcessors, "SocketFactoryProcessors must not be null");
108117
this.socketFactoryProcessors.addAll(Arrays.asList(socketFactoryProcessors));
109118
}
110119

120+
/**
121+
* Set {@link RSocketServerCustomizer}s that should be called to configure the
122+
* {@link io.rsocket.core.RSocketServer} while building the server. Calling this
123+
* method will replace any existing customizers.
124+
* @param rSocketServerCustomizers customizers to apply before the server starts
125+
* @since 2.2.7
126+
*/
127+
public void setRSocketServerCustomizers(Collection<? extends RSocketServerCustomizer> rSocketServerCustomizers) {
128+
Assert.notNull(rSocketServerCustomizers, "RSocketServerCustomizers must not be null");
129+
this.rSocketServerCustomizers = new ArrayList<>(rSocketServerCustomizers);
130+
}
131+
132+
/**
133+
* Add {@link RSocketServerCustomizer}s that should be called to configure the
134+
* {@link io.rsocket.core.RSocketServer}.
135+
* @param rSocketServerCustomizers customizers to apply before the server starts
136+
* @since 2.2.7
137+
*/
138+
public void addRSocketServerCustomizers(RSocketServerCustomizer... rSocketServerCustomizers) {
139+
Assert.notNull(rSocketServerCustomizers, "RSocketServerCustomizers must not be null");
140+
this.rSocketServerCustomizers.addAll(Arrays.asList(rSocketServerCustomizers));
141+
}
142+
111143
/**
112144
* Set the maximum amount of time that should be waited when starting or stopping the
113145
* server.
@@ -118,13 +150,14 @@ public void setLifecycleTimeout(Duration lifecycleTimeout) {
118150
}
119151

120152
@Override
153+
@SuppressWarnings("deprecation")
121154
public NettyRSocketServer create(SocketAcceptor socketAcceptor) {
122155
ServerTransport<CloseableChannel> transport = createTransport();
123-
RSocketFactory.ServerRSocketFactory factory = RSocketFactory.receive();
124-
for (ServerRSocketFactoryProcessor processor : this.socketFactoryProcessors) {
125-
factory = processor.process(factory);
126-
}
127-
Mono<CloseableChannel> starter = factory.acceptor(socketAcceptor).transport(transport).start();
156+
io.rsocket.core.RSocketServer server = io.rsocket.core.RSocketServer.create(socketAcceptor);
157+
RSocketFactory.ServerRSocketFactory factory = new ServerRSocketFactory(server);
158+
this.rSocketServerCustomizers.forEach((customizer) -> customizer.customize(server));
159+
this.socketFactoryProcessors.forEach((processor) -> processor.process(factory));
160+
Mono<CloseableChannel> starter = server.bind(transport);
128161
return new NettyRSocketServer(starter, this.lifecycleTimeout);
129162
}
130163

0 commit comments

Comments
 (0)