diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java
index c900076b43..9631cf5067 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistoryConfigurer.java
@@ -154,8 +154,8 @@ public class MessageHistoryConfigurer implements SmartLifecycle, BeanFactoryAwar
component.setShouldTrack(shouldTrack);
if (shouldTrack) {
this.currentlyTrackedComponents.add(component);
- if (this.LOGGER.isInfoEnabled()) {
- this.LOGGER.info("Enabling MessageHistory tracking for component '" + componentName + "'");
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("Enabling MessageHistory tracking for component '" + componentName + "'");
}
}
}
@@ -217,8 +217,8 @@ public class MessageHistoryConfigurer implements SmartLifecycle, BeanFactoryAwar
if (this.running) {
this.currentlyTrackedComponents.forEach(component -> {
component.setShouldTrack(false);
- if (this.LOGGER.isInfoEnabled()) {
- this.LOGGER.info("Disabling MessageHistory tracking for component '"
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("Disabling MessageHistory tracking for component '"
+ component.getComponentName() + "'");
}
});
diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java
index a2eb620934..703b6e4f08 100644
--- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java
+++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java
@@ -35,20 +35,20 @@ import org.springframework.util.MimeTypeUtils;
* A base connector container for common RSocket client and server functionality.
*
* It accepts {@link IntegrationRSocketEndpoint} instances for mapping registration via an internal
- * {@link IntegrationRSocketAcceptor} or performs an auto-detection otherwise, when all bean are ready
+ * {@link IntegrationRSocketMessageHandler} or performs an auto-detection otherwise, when all bean are ready
* in the application context.
*
* @author Artem Bilan
*
* @since 5.2
*
- * @see IntegrationRSocketAcceptor
+ * @see IntegrationRSocketMessageHandler
*/
public abstract class AbstractRSocketConnector
implements ApplicationContextAware, InitializingBean, DisposableBean, SmartInitializingSingleton,
SmartLifecycle {
- protected final IntegrationRSocketAcceptor rsocketAcceptor; // NOSONAR - final
+ protected final IntegrationRSocketMessageHandler rSocketMessageHandler; // NOSONAR - final
private MimeType dataMimeType = MimeTypeUtils.TEXT_PLAIN;
@@ -65,8 +65,8 @@ public abstract class AbstractRSocketConnector
private volatile boolean running;
- protected AbstractRSocketConnector(IntegrationRSocketAcceptor rsocketAcceptor) {
- this.rsocketAcceptor = rsocketAcceptor;
+ protected AbstractRSocketConnector(IntegrationRSocketMessageHandler rSocketMessageHandler) {
+ this.rSocketMessageHandler = rSocketMessageHandler;
}
/**
@@ -126,25 +126,25 @@ public abstract class AbstractRSocketConnector
* @param endpoint the {@link IntegrationRSocketEndpoint} to map.
*/
public void addEndpoint(IntegrationRSocketEndpoint endpoint) {
- this.rsocketAcceptor.addEndpoint(endpoint);
+ this.rSocketMessageHandler.addEndpoint(endpoint);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- this.rsocketAcceptor.setApplicationContext(applicationContext);
+ this.rSocketMessageHandler.setApplicationContext(applicationContext);
}
@Override
public void afterPropertiesSet() {
- this.rsocketAcceptor.setDefaultDataMimeType(this.dataMimeType);
- this.rsocketAcceptor.setDefaultMetadataMimeType(this.metadataMimeType);
- this.rsocketAcceptor.setRSocketStrategies(this.rsocketStrategies);
- this.rsocketAcceptor.afterPropertiesSet();
+ this.rSocketMessageHandler.setDefaultDataMimeType(this.dataMimeType);
+ this.rSocketMessageHandler.setDefaultMetadataMimeType(this.metadataMimeType);
+ this.rSocketMessageHandler.setRSocketStrategies(this.rsocketStrategies);
+ this.rSocketMessageHandler.afterPropertiesSet();
}
@Override
public void afterSingletonsInstantiated() {
- this.rsocketAcceptor.detectEndpoints();
+ this.rSocketMessageHandler.detectEndpoints();
}
public void setAutoStartup(boolean autoStartup) {
diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ClientRSocketConnector.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ClientRSocketConnector.java
index 4886c9c765..c8b014f3b9 100644
--- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ClientRSocketConnector.java
+++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ClientRSocketConnector.java
@@ -37,7 +37,8 @@ import reactor.core.publisher.Mono;
* A client {@link AbstractRSocketConnector} extension to the RSocket server.
*
* Note: the {@link RSocketFactory.ClientRSocketFactory#acceptor(java.util.function.Function)}
- * in the provided {@link #factoryConfigurer} is overridden with an internal {@link IntegrationRSocketAcceptor}
+ * in the provided {@link #factoryConfigurer} is overridden with an internal
+ * {@link IntegrationRSocketMessageHandler#clientAcceptor()}
* for the proper Spring Integration channel adapter mappings.
*
* @author Artem Bilan
@@ -85,7 +86,7 @@ public class ClientRSocketConnector extends AbstractRSocketConnector {
* @param clientTransport the {@link ClientTransport} to use.
*/
public ClientRSocketConnector(ClientTransport clientTransport) {
- super(new IntegrationRSocketAcceptor());
+ super(new IntegrationRSocketMessageHandler());
Assert.notNull(clientTransport, "'clientTransport' must not be null");
this.clientTransport = clientTransport;
}
@@ -125,7 +126,7 @@ public class ClientRSocketConnector extends AbstractRSocketConnector {
.dataMimeType(getDataMimeType().toString())
.metadataMimeType(getMetadataMimeType().toString());
this.factoryConfigurer.accept(clientFactory);
- clientFactory.acceptor(this.rsocketAcceptor);
+ clientFactory.acceptor(this.rSocketMessageHandler.clientAcceptor());
Payload connectPayload = EmptyPayload.INSTANCE;
if (this.connectRoute != null) {
connectPayload = DefaultPayload.create(this.connectData, this.connectRoute);
@@ -136,7 +137,7 @@ public class ClientRSocketConnector extends AbstractRSocketConnector {
@Override
public void afterSingletonsInstantiated() {
- this.autoConnect = this.rsocketAcceptor.detectEndpoints();
+ this.autoConnect = this.rSocketMessageHandler.detectEndpoints();
}
@Override
diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocket.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocket.java
index d3f9a65a9d..c1af1a0f46 100644
--- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocket.java
+++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocket.java
@@ -46,6 +46,7 @@ import org.springframework.util.RouteMatcher;
import io.netty.buffer.ByteBuf;
import io.rsocket.AbstractRSocket;
+import io.rsocket.ConnectionSetupPayload;
import io.rsocket.Payload;
import io.rsocket.metadata.CompositeMetadata;
import reactor.core.publisher.Flux;
@@ -109,8 +110,23 @@ class IntegrationRSocket extends AbstractRSocket {
this.bufferFactory = bufferFactory;
}
- public RSocketRequester getRequester() {
- return this.requester;
+ /**
+ * Wrap the {@link ConnectionSetupPayload} with a {@link Message} and
+ * delegate to {@link #handle(Payload)} for handling.
+ * @param payload the connection payload
+ * @return completion handle for success or error
+ */
+ Mono> handleConnectionSetupPayload(ConnectionSetupPayload payload) {
+ String destination = getDestination(payload);
+ MessageHeaders headers = createHeaders(destination, null);
+ DataBuffer dataBuffer = retainDataAndReleasePayload(payload);
+ int refCount = refCount(dataBuffer);
+ return Mono.just(MessageBuilder.createMessage(dataBuffer, headers))
+ .doFinally(s -> {
+ if (refCount(dataBuffer) == refCount) {
+ DataBufferUtils.release(dataBuffer);
+ }
+ });
}
@Override
diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocketAcceptor.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocketMessageHandler.java
similarity index 74%
rename from spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocketAcceptor.java
rename to spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocketMessageHandler.java
index 58d4c4eeda..a160731041 100644
--- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocketAcceptor.java
+++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocketMessageHandler.java
@@ -31,7 +31,6 @@ import org.springframework.messaging.handler.DestinationPatternsMessageCondition
import org.springframework.messaging.handler.invocation.reactive.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.invocation.reactive.SyncHandlerMethodArgumentResolver;
import org.springframework.messaging.rsocket.RSocketRequester;
-import org.springframework.messaging.rsocket.RSocketStrategies;
import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler;
import org.springframework.util.Assert;
import org.springframework.util.MimeType;
@@ -45,20 +44,15 @@ import io.rsocket.RSocket;
/**
* The {@link RSocketMessageHandler} extension for Spring Integration needs.
*
- * The most of logic is copied from {@link org.springframework.messaging.rsocket.MessageHandlerAcceptor}.
- * That cannot be extended because it is {@link final}.
- *
- * This class adds an {@link IntegrationRSocketEndpoint} beans detection and registration functionality,
- * as well as serves as a container over an internal {@link IntegrationRSocket} implementation.
+ * This class adds an {@link IntegrationRSocketEndpoint} beans detection and registration functionality.
*
* @author Artem Bilan
*
* @since 5.2
*
- * @see org.springframework.messaging.rsocket.MessageHandlerAcceptor
+ * @see RSocketMessageHandler
*/
-class IntegrationRSocketAcceptor extends RSocketMessageHandler
- implements BiFunction {
+class IntegrationRSocketMessageHandler extends RSocketMessageHandler {
private static final Method HANDLE_MESSAGE_METHOD =
ReflectionUtils.findMethod(ReactiveMessageHandler.class, "handleMessage", Message.class);
@@ -68,7 +62,7 @@ class IntegrationRSocketAcceptor extends RSocketMessageHandler
private MimeType defaultMetadataMimeType = IntegrationRSocket.COMPOSITE_METADATA;
- IntegrationRSocketAcceptor() {
+ IntegrationRSocketMessageHandler() {
setHandlerPredicate((clazz) -> false);
}
@@ -84,6 +78,7 @@ class IntegrationRSocketAcceptor extends RSocketMessageHandler
this.defaultDataMimeType = defaultDataMimeType;
}
+
/**
* Configure the default {@code MimeType} for payload data if the
* {@code SETUP} frame did not specify one.
@@ -96,6 +91,11 @@ class IntegrationRSocketAcceptor extends RSocketMessageHandler
this.defaultMetadataMimeType = mimeType;
}
+ @Override
+ public BiFunction clientAcceptor() {
+ return this::createRSocket;
+ }
+
public boolean detectEndpoints() {
ApplicationContext applicationContext = getApplicationContext();
if (applicationContext != null && getHandlerMethods().isEmpty()) {
@@ -122,27 +122,19 @@ class IntegrationRSocketAcceptor extends RSocketMessageHandler
return Collections.singletonList(new MessageHandlerMethodArgumentResolver());
}
- @Override
- public RSocket apply(ConnectionSetupPayload setupPayload, RSocket sendingRSocket) {
- return createRSocket(setupPayload, sendingRSocket);
- }
-
protected IntegrationRSocket createRSocket(ConnectionSetupPayload setupPayload, RSocket rsocket) {
- RSocketStrategies rsocketStrategies = getRSocketStrategies();
- MimeType dataMimeType =
- StringUtils.hasText(setupPayload.dataMimeType())
- ? MimeTypeUtils.parseMimeType(setupPayload.dataMimeType())
- : this.defaultDataMimeType;
- Assert.notNull(dataMimeType, "No `dataMimeType` in the ConnectionSetupPayload and no default value");
+ String s = setupPayload.dataMimeType();
+ MimeType dataMimeType = StringUtils.hasText(s) ? MimeTypeUtils.parseMimeType(s) : this.defaultDataMimeType;
+ Assert.notNull(dataMimeType, "No `dataMimeType` in ConnectionSetupPayload and no default value");
- MimeType metadataMimeType =
- StringUtils.hasText(setupPayload.metadataMimeType())
- ? MimeTypeUtils.parseMimeType(setupPayload.metadataMimeType())
- : this.defaultMetadataMimeType;
- Assert.notNull(dataMimeType, "No `metadataMimeType` in the ConnectionSetupPayload and no default value");
- return new IntegrationRSocket(this, getRouteMatcher(),
- RSocketRequester.wrap(rsocket, dataMimeType, metadataMimeType, rsocketStrategies),
- dataMimeType, metadataMimeType, rsocketStrategies.dataBufferFactory());
+ s = setupPayload.metadataMimeType();
+ MimeType metaMimeType = StringUtils.hasText(s) ? MimeTypeUtils.parseMimeType(s) : this.defaultMetadataMimeType;
+ Assert.notNull(dataMimeType, "No `metadataMimeType` in ConnectionSetupPayload and no default value");
+
+ RSocketRequester requester = RSocketRequester.wrap(rsocket, dataMimeType, metaMimeType, getRSocketStrategies());
+
+ return new IntegrationRSocket(this, getRouteMatcher(), requester, dataMimeType, metaMimeType,
+ getRSocketStrategies().dataBufferFactory());
}
private static final class MessageHandlerMethodArgumentResolver implements SyncHandlerMethodArgumentResolver {
diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/RSocketConnectedEvent.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/RSocketConnectedEvent.java
index e65323af0b..a117e32774 100644
--- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/RSocketConnectedEvent.java
+++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/RSocketConnectedEvent.java
@@ -31,7 +31,7 @@ import org.springframework.messaging.rsocket.RSocketRequester;
*
* @since 5.2
*
- * @see IntegrationRSocketAcceptor
+ * @see IntegrationRSocketMessageHandler
*/
@SuppressWarnings("serial")
public class RSocketConnectedEvent extends IntegrationEvent {
diff --git a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ServerRSocketConnector.java b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ServerRSocketConnector.java
index 558a7a9baa..a5cf00f6c4 100644
--- a/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ServerRSocketConnector.java
+++ b/spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ServerRSocketConnector.java
@@ -28,17 +28,18 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.lang.Nullable;
+import org.springframework.messaging.MessageHeaders;
+import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
import org.springframework.messaging.rsocket.RSocketRequester;
+import org.springframework.messaging.rsocket.annotation.support.RSocketRequesterMethodArgumentResolver;
import org.springframework.util.Assert;
+import org.springframework.util.RouteMatcher;
-import io.rsocket.Closeable;
-import io.rsocket.ConnectionSetupPayload;
-import io.rsocket.RSocket;
import io.rsocket.RSocketFactory;
import io.rsocket.SocketAcceptor;
import io.rsocket.transport.ServerTransport;
+import io.rsocket.transport.netty.server.CloseableChannel;
import io.rsocket.transport.netty.server.TcpServerTransport;
import io.rsocket.transport.netty.server.WebsocketServerTransport;
import reactor.core.Disposable;
@@ -49,7 +50,8 @@ import reactor.netty.http.server.HttpServer;
* A server {@link AbstractRSocketConnector} extension to accept and manage client RSocket connections.
*
* Note: the {@link RSocketFactory.ServerRSocketFactory#acceptor(SocketAcceptor)}
- * in the provided {@link #factoryConfigurer} is overridden with an internal {@link IntegrationRSocketAcceptor}
+ * in the provided {@link #factoryConfigurer} is overridden with an internal
+ * {@link ServerRSocketMessageHandler#serverAcceptor()}
* for the proper Spring Integration channel adapter mappings.
*
* @author Artem Bilan
@@ -61,11 +63,11 @@ import reactor.netty.http.server.HttpServer;
public class ServerRSocketConnector extends AbstractRSocketConnector
implements ApplicationEventPublisherAware {
- private final ServerTransport extends Closeable> serverTransport;
+ private final ServerTransport serverTransport;
private Consumer factoryConfigurer = (serverRSocketFactory) -> { };
- private Mono extends Closeable> serverMono;
+ private Mono serverMono;
/**
* Instantiate a server connector based on the {@link TcpServerTransport}.
@@ -90,8 +92,8 @@ public class ServerRSocketConnector extends AbstractRSocketConnector
* Instantiate a server connector based on the provided {@link ServerTransport}.
* @param serverTransport the {@link ServerTransport} to make server based on.
*/
- public ServerRSocketConnector(ServerTransport extends Closeable> serverTransport) {
- super(new ServerRSocketAcceptor());
+ public ServerRSocketConnector(ServerTransport serverTransport) {
+ super(new ServerRSocketMessageHandler());
Assert.notNull(serverTransport, "'serverTransport' must not be null");
this.serverTransport = serverTransport;
}
@@ -112,12 +114,12 @@ public class ServerRSocketConnector extends AbstractRSocketConnector
*/
public void setClientRSocketKeyStrategy(BiFunction clientRSocketKeyStrategy) {
Assert.notNull(clientRSocketKeyStrategy, "'clientRSocketKeyStrategy' must not be null");
- serverRSocketAcceptor().clientRSocketKeyStrategy = clientRSocketKeyStrategy;
+ serverRSocketMessageHandler().clientRSocketKeyStrategy = clientRSocketKeyStrategy;
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
- serverRSocketAcceptor().applicationEventPublisher = applicationEventPublisher;
+ serverRSocketMessageHandler().applicationEventPublisher = applicationEventPublisher;
}
@Override
@@ -125,25 +127,31 @@ public class ServerRSocketConnector extends AbstractRSocketConnector
super.afterPropertiesSet();
RSocketFactory.ServerRSocketFactory serverFactory = RSocketFactory.receive();
this.factoryConfigurer.accept(serverFactory);
+
this.serverMono =
serverFactory
- .acceptor(serverRSocketAcceptor())
+ .acceptor(serverRSocketMessageHandler().serverAcceptor())
.transport(this.serverTransport)
.start()
.cache();
}
public Map