From ec8a747261e42115ca0f435188ca96376b1ca36c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Dias?= Date: Wed, 26 May 2021 16:28:10 +0100 Subject: [PATCH] GH-3509: Fix regression in TcpNetServerConnectionFactory Related to https://github.com/spring-projects/spring-integration/issues/3509 * Fix intercepted connection cleanup tests * Add missing logic to call `setSenders()` on wrapped connection **Cherry-pick to `5.4.x`** --- .../ip/tcp/connection/TcpNetServerConnectionFactory.java | 7 ++++++- .../integration/ip/tcp/TcpSendingMessageHandlerTests.java | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java index b16d61075e..18f6f58ae0 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java @@ -35,6 +35,7 @@ import org.springframework.util.Assert; * * @author Gary Russell * @author Artem Bilan + * @author Mário Dias * * @since 2.0 * @@ -180,7 +181,11 @@ public class TcpNetServerConnectionFactory extends AbstractServerConnectionFacto setSocketAttributes(socket); TcpConnectionSupport connection = this.tcpNetConnectionSupport.createNewConnection(socket, true, isLookupHost(), getApplicationEventPublisher(), getComponentName()); - connection = wrapConnection(connection); + TcpConnectionSupport wrapped = wrapConnection(connection); + if (!wrapped.equals(connection)) { + connection.setSenders(getSenders()); + connection = wrapped; + } initializeConnection(connection, socket); getTaskExecutor().execute(connection); harvestClosedConnections(); diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java index 4191e395c8..3c8fb0a64f 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java @@ -1199,7 +1199,6 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest } } - @SuppressWarnings("unchecked") @Test public void testInterceptedConnection() throws Exception { final CountDownLatch latch = new CountDownLatch(1); @@ -1229,7 +1228,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest socket.close(); assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); assertThat(connection.get()).isInstanceOf(HelloWorldInterceptor.class); - await().untilAsserted(() -> handler.getConnections().isEmpty()); + await().untilAsserted(() -> assertThat(handler.getConnections()).isEmpty()); scf.stop(); } @@ -1258,7 +1257,7 @@ public class TcpSendingMessageHandlerTests extends AbstractTcpChannelAdapterTest Socket socket = SocketFactory.getDefault().createSocket("localhost", port); socket.close(); assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); - await().untilAsserted(() -> handler.getConnections().isEmpty()); + await().untilAsserted(() -> assertThat(handler.getConnections()).isEmpty()); scf.stop(); }