Skip to content

Commit 90a751e

Browse files
TYsewynartembilan
authored andcommitted
GH-2346: Fix Java DSL TCP Factory
Fixes #2346 * Fixed issue where the Java DSL will always create NIO connection factories regardless of which type you specified. * Deprecated the 2 static booleans
1 parent 3530e76 commit 90a751e

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/dsl/Tcp.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,28 @@
2323
* Factory methods for TCP.
2424
*
2525
* @author Gary Russell
26+
* @author Tim Ysewyn
2627
* @since 5.0
2728
*
2829
*/
2930
public final class Tcp {
3031

3132
/**
3233
* Boolean indicating the connection factory should use NIO.
34+
*
35+
* @deprecated This isn't used anymore within the framework and will be removed in a future release.
3336
*/
37+
@Deprecated
3438
public static final boolean NIO = true;
3539

3640
/**
3741
* Boolean indicating the connection factory should not use NIO
3842
* (default).
43+
*
44+
* @deprecated This isn't used anymore within the framework and will be removed in a future release.
3945
*/
40-
public static final boolean NET = true;
46+
@Deprecated
47+
public static final boolean NET = false;
4148

4249
private Tcp() {
4350
super();
@@ -49,7 +56,7 @@ private Tcp() {
4956
* @return the spec.
5057
*/
5158
public static TcpServerConnectionFactorySpec nioServer(int port) {
52-
return new TcpServerConnectionFactorySpec(port, NIO);
59+
return new TcpServerConnectionFactorySpec(port, true);
5360
}
5461

5562
/**
@@ -58,7 +65,7 @@ public static TcpServerConnectionFactorySpec nioServer(int port) {
5865
* @return the spec.
5966
*/
6067
public static TcpServerConnectionFactorySpec netServer(int port) {
61-
return new TcpServerConnectionFactorySpec(port, NET);
68+
return new TcpServerConnectionFactorySpec(port, false);
6269
}
6370

6471
/**
@@ -68,7 +75,7 @@ public static TcpServerConnectionFactorySpec netServer(int port) {
6875
* @return the spec.
6976
*/
7077
public static TcpClientConnectionFactorySpec nioClient(String host, int port) {
71-
return new TcpClientConnectionFactorySpec(host, port, NIO);
78+
return new TcpClientConnectionFactorySpec(host, port, true);
7279
}
7380

7481
/**
@@ -78,7 +85,7 @@ public static TcpClientConnectionFactorySpec nioClient(String host, int port) {
7885
* @return the spec.
7986
*/
8087
public static TcpClientConnectionFactorySpec netClient(String host, int port) {
81-
return new TcpClientConnectionFactorySpec(host, port, NET);
88+
return new TcpClientConnectionFactorySpec(host, port, false);
8289
}
8390

8491
/**

spring-integration-ip/src/test/java/org/springframework/integration/ip/dsl/ConnectionFacforyTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@
2828
import org.springframework.context.ApplicationEventPublisher;
2929
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
3030
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
31+
import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
32+
import org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory;
33+
import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
34+
import org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory;
3135
import org.springframework.integration.ip.util.TestingUtilities;
3236
import org.springframework.integration.transformer.ObjectToStringTransformer;
3337
import org.springframework.messaging.Message;
3438
import org.springframework.messaging.support.GenericMessage;
3539

3640
/**
3741
* @author Gary Russell
42+
* @author Tim Ysewyn
3843
* @since 5.0
3944
*
4045
*/
@@ -66,4 +71,22 @@ public void test() throws Exception {
6671
server.stop();
6772
}
6873

74+
@Test
75+
public void shouldReturnNioFlavor() throws Exception {
76+
AbstractServerConnectionFactory server = Tcp.nioServer(0).get();
77+
assertTrue(server instanceof TcpNioServerConnectionFactory);
78+
79+
AbstractClientConnectionFactory client = Tcp.nioClient("localhost", server.getPort()).get();
80+
assertTrue(client instanceof TcpNioClientConnectionFactory);
81+
}
82+
83+
@Test
84+
public void shouldReturnNetFlavor() throws Exception {
85+
AbstractServerConnectionFactory server = Tcp.netServer(0).get();
86+
assertTrue(server instanceof TcpNetServerConnectionFactory);
87+
88+
AbstractClientConnectionFactory client = Tcp.netClient("localhost", server.getPort()).get();
89+
assertTrue(client instanceof TcpNetClientConnectionFactory);
90+
}
91+
6992
}

0 commit comments

Comments
 (0)