Require RSocket 1.0+
This commit removes the previously deprecated classes in Spring Framework 5.2.x. By doing so, Spring Framework now requires RSocket 1.0+. Closes gh-25548
This commit is contained in:
parent
2087f3586c
commit
5bdbbdfcfb
|
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-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.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.messaging.rsocket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Strategy to apply configuration to a client side {@code RSocketFactory}.
|
|
||||||
* that's being prepared by {@link RSocketRequester.Builder} to connect
|
|
||||||
* to a server.
|
|
||||||
*
|
|
||||||
* @author Rossen Stoyanchev
|
|
||||||
* @since 5.2
|
|
||||||
* @deprecated as of 5.2.6 following the deprecation of
|
|
||||||
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory RSocketFactory.ClientRSocketFactory}
|
|
||||||
* in RSocket 1.0 RC7. Please, use {@link RSocketConnectorConfigurer}.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
@Deprecated
|
|
||||||
public interface ClientRSocketFactoryConfigurer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply configuration to the given {@code ClientRSocketFactory}.
|
|
||||||
*/
|
|
||||||
void configure(io.rsocket.RSocketFactory.ClientRSocketFactory rsocketFactory);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -89,9 +89,6 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
|
||||||
|
|
||||||
private List<RSocketConnectorConfigurer> rsocketConnectorConfigurers = new ArrayList<>();
|
private List<RSocketConnectorConfigurer> rsocketConnectorConfigurers = new ArrayList<>();
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private List<ClientRSocketFactoryConfigurer> rsocketFactoryConfigurers = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RSocketRequester.Builder dataMimeType(@Nullable MimeType mimeType) {
|
public RSocketRequester.Builder dataMimeType(@Nullable MimeType mimeType) {
|
||||||
|
|
@ -144,13 +141,6 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public RSocketRequester.Builder rsocketFactory(ClientRSocketFactoryConfigurer configurer) {
|
|
||||||
this.rsocketFactoryConfigurers.add(configurer);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RSocketRequester.Builder apply(Consumer<RSocketRequester.Builder> configurer) {
|
public RSocketRequester.Builder apply(Consumer<RSocketRequester.Builder> configurer) {
|
||||||
configurer.accept(this);
|
configurer.accept(this);
|
||||||
|
|
@ -180,7 +170,7 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
|
||||||
Mono<Payload> setupPayload = getSetupPayload(dataMimeType, metaMimeType, strategies);
|
Mono<Payload> setupPayload = getSetupPayload(dataMimeType, metaMimeType, strategies);
|
||||||
|
|
||||||
RSocketConnector connector = initConnector(
|
RSocketConnector connector = initConnector(
|
||||||
this.rsocketConnectorConfigurers, this.rsocketFactoryConfigurers,
|
this.rsocketConnectorConfigurers,
|
||||||
metaMimeType, dataMimeType, setupPayload, strategies);
|
metaMimeType, dataMimeType, setupPayload, strategies);
|
||||||
|
|
||||||
return new DefaultRSocketRequester(
|
return new DefaultRSocketRequester(
|
||||||
|
|
@ -214,7 +204,7 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
|
||||||
Mono<Payload> setupPayload = getSetupPayload(dataMimeType, metaMimeType, rsocketStrategies);
|
Mono<Payload> setupPayload = getSetupPayload(dataMimeType, metaMimeType, rsocketStrategies);
|
||||||
|
|
||||||
RSocketConnector connector = initConnector(
|
RSocketConnector connector = initConnector(
|
||||||
this.rsocketConnectorConfigurers, this.rsocketFactoryConfigurers,
|
this.rsocketConnectorConfigurers,
|
||||||
metaMimeType, dataMimeType, setupPayload, rsocketStrategies);
|
metaMimeType, dataMimeType, setupPayload, rsocketStrategies);
|
||||||
|
|
||||||
return connector.connect(transport).map(rsocket ->
|
return connector.connect(transport).map(rsocket ->
|
||||||
|
|
@ -304,19 +294,12 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder {
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private RSocketConnector initConnector(List<RSocketConnectorConfigurer> connectorConfigurers,
|
private RSocketConnector initConnector(List<RSocketConnectorConfigurer> connectorConfigurers,
|
||||||
List<ClientRSocketFactoryConfigurer> factoryConfigurers,
|
|
||||||
MimeType metaMimeType, MimeType dataMimeType, Mono<Payload> setupPayloadMono,
|
MimeType metaMimeType, MimeType dataMimeType, Mono<Payload> setupPayloadMono,
|
||||||
RSocketStrategies rsocketStrategies) {
|
RSocketStrategies rsocketStrategies) {
|
||||||
|
|
||||||
RSocketConnector connector = RSocketConnector.create();
|
RSocketConnector connector = RSocketConnector.create();
|
||||||
connectorConfigurers.forEach(c -> c.configure(connector));
|
connectorConfigurers.forEach(c -> c.configure(connector));
|
||||||
|
|
||||||
if (!factoryConfigurers.isEmpty()) {
|
|
||||||
io.rsocket.RSocketFactory.ClientRSocketFactory factory =
|
|
||||||
new io.rsocket.RSocketFactory.ClientRSocketFactory(connector);
|
|
||||||
factoryConfigurers.forEach(c -> c.configure(factory));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rsocketStrategies.dataBufferFactory() instanceof NettyDataBufferFactory) {
|
if (rsocketStrategies.dataBufferFactory() instanceof NettyDataBufferFactory) {
|
||||||
connector.payloadDecoder(PayloadDecoder.ZERO_COPY);
|
connector.payloadDecoder(PayloadDecoder.ZERO_COPY);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,12 +184,12 @@ final class MetadataEncoder {
|
||||||
CompositeByteBuf composite = this.allocator.compositeBuffer();
|
CompositeByteBuf composite = this.allocator.compositeBuffer();
|
||||||
try {
|
try {
|
||||||
if (this.route != null) {
|
if (this.route != null) {
|
||||||
io.rsocket.metadata.CompositeMetadataFlyweight.encodeAndAddMetadata(composite, this.allocator,
|
io.rsocket.metadata.CompositeMetadataCodec.encodeAndAddMetadata(composite, this.allocator,
|
||||||
WellKnownMimeType.MESSAGE_RSOCKET_ROUTING, encodeRoute());
|
WellKnownMimeType.MESSAGE_RSOCKET_ROUTING, encodeRoute());
|
||||||
}
|
}
|
||||||
entries.forEach(entry -> {
|
entries.forEach(entry -> {
|
||||||
Object value = entry.value();
|
Object value = entry.value();
|
||||||
io.rsocket.metadata.CompositeMetadataFlyweight.encodeAndAddMetadata(
|
io.rsocket.metadata.CompositeMetadataCodec.encodeAndAddMetadata(
|
||||||
composite, this.allocator, entry.mimeType().toString(),
|
composite, this.allocator, entry.mimeType().toString(),
|
||||||
value instanceof ByteBuf ? (ByteBuf) value : PayloadUtils.asByteBuf(encodeEntry(entry)));
|
value instanceof ByteBuf ? (ByteBuf) value : PayloadUtils.asByteBuf(encodeEntry(entry)));
|
||||||
});
|
});
|
||||||
|
|
@ -219,9 +219,8 @@ final class MetadataEncoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private ByteBuf encodeRoute() {
|
private ByteBuf encodeRoute() {
|
||||||
return io.rsocket.metadata.TaggingMetadataFlyweight.createRoutingMetadata(
|
return io.rsocket.metadata.TaggingMetadataCodec.createRoutingMetadata(
|
||||||
this.allocator, Collections.singletonList(this.route)).getContent();
|
this.allocator, Collections.singletonList(this.route)).getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -215,29 +215,6 @@ public interface RSocketRequester {
|
||||||
*/
|
*/
|
||||||
RSocketRequester.Builder rsocketConnector(RSocketConnectorConfigurer configurer);
|
RSocketRequester.Builder rsocketConnector(RSocketConnectorConfigurer configurer);
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback to configure the {@code ClientRSocketFactory} directly.
|
|
||||||
* <ul>
|
|
||||||
* <li>The data and metadata mime types cannot be set directly
|
|
||||||
* on the {@code ClientRSocketFactory} and will be overridden. Use the
|
|
||||||
* shortcuts {@link #dataMimeType(MimeType)} and
|
|
||||||
* {@link #metadataMimeType(MimeType)} on this builder instead.
|
|
||||||
* <li>The frame decoder also cannot be set directly and instead is set
|
|
||||||
* to match the configured {@code DataBufferFactory}.
|
|
||||||
* <li>For the
|
|
||||||
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory#setupPayload(Payload)
|
|
||||||
* setupPayload}, consider using methods on this builder to specify the
|
|
||||||
* route, other metadata, and data as Object values to be encoded.
|
|
||||||
* <li>To configure client side responding, see
|
|
||||||
* {@link RSocketMessageHandler#clientResponder(RSocketStrategies, Object...)}.
|
|
||||||
* </ul>
|
|
||||||
* @deprecated as of 5.2.6 following the deprecation of
|
|
||||||
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory RSocketFactory.ClientRSocketFactory}
|
|
||||||
* in RSocket 1.0 RC7. Please, use {@link #rsocketConnector(RSocketConnectorConfigurer)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
RSocketRequester.Builder rsocketFactory(ClientRSocketFactoryConfigurer configurer);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure this builder through a {@code Consumer}. This enables
|
* Configure this builder through a {@code Consumer}. This enables
|
||||||
* libraries such as Spring Security to provide shortcuts for applying
|
* libraries such as Spring Security to provide shortcuts for applying
|
||||||
|
|
|
||||||
|
|
@ -330,8 +330,8 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
|
||||||
|
|
||||||
List<MessageCondition<?>> conditions = composite.getMessageConditions();
|
List<MessageCondition<?>> conditions = composite.getMessageConditions();
|
||||||
Assert.isTrue(conditions.size() == 2 &&
|
Assert.isTrue(conditions.size() == 2 &&
|
||||||
conditions.get(0) instanceof RSocketFrameTypeMessageCondition &&
|
conditions.get(0) instanceof RSocketFrameTypeMessageCondition &&
|
||||||
conditions.get(1) instanceof DestinationPatternsMessageCondition,
|
conditions.get(1) instanceof DestinationPatternsMessageCondition,
|
||||||
"Unexpected message condition types");
|
"Unexpected message condition types");
|
||||||
|
|
||||||
if (conditions.get(0) != RSocketFrameTypeMessageCondition.EMPTY_CONDITION) {
|
if (conditions.get(0) != RSocketFrameTypeMessageCondition.EMPTY_CONDITION) {
|
||||||
|
|
@ -394,7 +394,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
|
||||||
* Return an RSocket {@link SocketAcceptor} backed by this
|
* Return an RSocket {@link SocketAcceptor} backed by this
|
||||||
* {@code RSocketMessageHandler} instance that can be plugged in as a
|
* {@code RSocketMessageHandler} instance that can be plugged in as a
|
||||||
* {@link io.rsocket.core.RSocketConnector#acceptor(SocketAcceptor) client} or
|
* {@link io.rsocket.core.RSocketConnector#acceptor(SocketAcceptor) client} or
|
||||||
* {@link io.rsocket.core.RSocketServer#acceptor(SocketAcceptor) server}
|
* {@link io.rsocket.core.RSocketServer#acceptor(SocketAcceptor) server}
|
||||||
* RSocket responder.
|
* RSocket responder.
|
||||||
* <p>The initial {@link ConnectionSetupPayload} is handled through
|
* <p>The initial {@link ConnectionSetupPayload} is handled through
|
||||||
* {@link ConnectMapping @ConnectionMapping} methods that can be asynchronous
|
* {@link ConnectMapping @ConnectionMapping} methods that can be asynchronous
|
||||||
|
|
@ -494,45 +494,4 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler {
|
||||||
return handler.responder();
|
return handler.responder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Static factory method for a configurer of a client side responder with
|
|
||||||
* annotated handler methods. This is intended to be passed into
|
|
||||||
* {@link org.springframework.messaging.rsocket.RSocketRequester.Builder#rsocketFactory}.
|
|
||||||
* <p>In effect a shortcut to create and initialize
|
|
||||||
* {@code RSocketMessageHandler} with the given strategies and handlers.
|
|
||||||
* Use {@link #responder()} to obtain the responder and plug that into
|
|
||||||
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory ClientRSocketFactory}.
|
|
||||||
* For more advanced scenarios, e.g. discovering handlers through a custom
|
|
||||||
* stereotype annotation, consider declaring {@code RSocketMessageHandler}
|
|
||||||
* as a bean, and then obtain the responder from it.
|
|
||||||
* @param strategies the strategies to set on the created
|
|
||||||
* {@code RSocketMessageHandler}
|
|
||||||
* @param candidateHandlers a list of Objects and/or Classes with annotated
|
|
||||||
* handler methods; used to call {@link #setHandlers(List)} on the created
|
|
||||||
* {@code RSocketMessageHandler}
|
|
||||||
* @return a configurer that may be passed into
|
|
||||||
* {@link org.springframework.messaging.rsocket.RSocketRequester.Builder#rsocketFactory}
|
|
||||||
* @deprecated as of 5.2.6 following the deprecation of
|
|
||||||
* {@link io.rsocket.RSocketFactory.ClientRSocketFactory RSocketFactory.ClientRSocketFactory}
|
|
||||||
* in RSocket 1.0 RC7
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static org.springframework.messaging.rsocket.ClientRSocketFactoryConfigurer clientResponder(
|
|
||||||
RSocketStrategies strategies, Object... candidateHandlers) {
|
|
||||||
|
|
||||||
Assert.notEmpty(candidateHandlers, "No handlers");
|
|
||||||
List<Object> handlers = new ArrayList<>(candidateHandlers.length);
|
|
||||||
for (Object obj : candidateHandlers) {
|
|
||||||
handlers.add(obj instanceof Class ? BeanUtils.instantiateClass((Class<?>) obj) : obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
return factory -> {
|
|
||||||
RSocketMessageHandler handler = new RSocketMessageHandler();
|
|
||||||
handler.setHandlers(handlers);
|
|
||||||
handler.setRSocketStrategies(strategies);
|
|
||||||
handler.afterPropertiesSet();
|
|
||||||
factory.acceptor(handler.responder());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,20 +79,17 @@ public class DefaultRSocketRequesterBuilderTests {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings({"unchecked", "deprecation"})
|
@SuppressWarnings("unchecked")
|
||||||
public void rsocketConnectorConfigurer() {
|
public void rsocketConnectorConfigurer() {
|
||||||
ClientRSocketFactoryConfigurer factoryConfigurer = mock(ClientRSocketFactoryConfigurer.class);
|
|
||||||
Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock(Consumer.class);
|
Consumer<RSocketStrategies.Builder> strategiesConfigurer = mock(Consumer.class);
|
||||||
RSocketRequester.builder()
|
RSocketRequester.builder()
|
||||||
.rsocketConnector(this.connectorConfigurer)
|
.rsocketConnector(this.connectorConfigurer)
|
||||||
.rsocketFactory(factoryConfigurer)
|
|
||||||
.rsocketStrategies(strategiesConfigurer)
|
.rsocketStrategies(strategiesConfigurer)
|
||||||
.transport(this.transport);
|
.transport(this.transport);
|
||||||
|
|
||||||
// RSocketStrategies and RSocketConnector configurers should have been called
|
// RSocketStrategies and RSocketConnector configurers should have been called
|
||||||
|
|
||||||
verify(strategiesConfigurer).accept(any(RSocketStrategies.Builder.class));
|
verify(strategiesConfigurer).accept(any(RSocketStrategies.Builder.class));
|
||||||
verify(factoryConfigurer).configure(any(io.rsocket.RSocketFactory.ClientRSocketFactory.class));
|
|
||||||
assertThat(this.connectorConfigurer.connector()).isNotNull();
|
assertThat(this.connectorConfigurer.connector()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue