Skip to content

Commit d2fb79e

Browse files
garyrussellartembilan
authored andcommitted
INT-4378: TCP Fix CF Name in Intercepted Events
JIRA: https://jira.spring.io/browse/INT-4378 Events (e.g. `TcpConnectionOpenEvent` from intercepted connections contain an 'unknown' connection factory name. Delegate to the underlying connection's factory name. # Conflicts: # spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/InterceptedSharedConnectionTests.java
1 parent 9c890ea commit d2fb79e

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionInterceptorSupport.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -106,6 +106,11 @@ public SocketInfo getSocketInfo() {
106106
return this.theConnection.getSocketInfo();
107107
}
108108

109+
@Override
110+
public String getConnectionFactoryName() {
111+
return this.theConnection.getConnectionFactoryName();
112+
}
113+
109114
@Override
110115
public void run() {
111116
this.theConnection.run();

spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpConnectionSupport.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2001-2016 the original author or authors.
2+
* Copyright 2001-2018 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.
@@ -336,6 +336,10 @@ public SocketInfo getSocketInfo() {
336336
return this.socketInfo;
337337
}
338338

339+
public String getConnectionFactoryName() {
340+
return this.connectionFactoryName;
341+
}
342+
339343
protected boolean isNoReadErrorOnClose() {
340344
return this.noReadErrorOnClose;
341345
}
@@ -355,19 +359,19 @@ protected final void sendExceptionToListener(Exception e) {
355359

356360
protected void publishConnectionOpenEvent() {
357361
TcpConnectionEvent event = new TcpConnectionOpenEvent(this,
358-
this.connectionFactoryName);
362+
getConnectionFactoryName());
359363
doPublish(event);
360364
}
361365

362366
protected void publishConnectionCloseEvent() {
363367
TcpConnectionEvent event = new TcpConnectionCloseEvent(this,
364-
this.connectionFactoryName);
368+
getConnectionFactoryName());
365369
doPublish(event);
366370
}
367371

368372
protected void publishConnectionExceptionEvent(Throwable t) {
369373
TcpConnectionEvent event = new TcpConnectionExceptionEvent(this,
370-
this.connectionFactoryName, t);
374+
getConnectionFactoryName(), t);
371375
doPublish(event);
372376
}
373377

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/InterceptedSharedConnectionTests-context.xml

+2
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@
7171

7272
<int:channel id="loop" />
7373

74+
<bean class="org.springframework.integration.ip.tcp.InterceptedSharedConnectionTests$Listener" />
75+
7476
</beans>

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/InterceptedSharedConnectionTests.java

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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,8 +16,11 @@
1616

1717
package org.springframework.integration.ip.tcp;
1818

19+
import static org.hamcrest.CoreMatchers.equalTo;
20+
import static org.hamcrest.CoreMatchers.notNullValue;
1921
import static org.junit.Assert.assertEquals;
2022
import static org.junit.Assert.assertNotNull;
23+
import static org.junit.Assert.assertThat;
2124
import static org.junit.Assert.fail;
2225

2326
import org.apache.log4j.Level;
@@ -29,8 +32,11 @@
2932

3033
import org.springframework.beans.factory.annotation.Autowired;
3134
import org.springframework.beans.factory.annotation.Qualifier;
35+
import org.springframework.context.ApplicationListener;
3236
import org.springframework.context.support.AbstractApplicationContext;
3337
import org.springframework.integration.channel.QueueChannel;
38+
import org.springframework.integration.ip.tcp.connection.HelloWorldInterceptor;
39+
import org.springframework.integration.ip.tcp.connection.TcpConnectionOpenEvent;
3440
import org.springframework.integration.support.MessageBuilder;
3541
import org.springframework.messaging.Message;
3642
import org.springframework.messaging.MessageChannel;
@@ -52,6 +58,9 @@ public class InterceptedSharedConnectionTests {
5258
@Qualifier(value = "inboundServer")
5359
TcpReceivingChannelAdapter listener;
5460

61+
@Autowired
62+
Listener testListener;
63+
5564
private static Level existingLogLevel;
5665

5766
// temporary hooks to investigate CI failures
@@ -73,8 +82,6 @@ public static void tearDown() {
7382
* for the outbound adapter that's sharing the connections. The response
7483
* comes back to an inbound adapter that is sharing the client's
7584
* connection and we verify we get the echo back as expected.
76-
*
77-
* @throws Exception
7885
*/
7986
@Test
8087
public void test1() throws Exception {
@@ -93,6 +100,21 @@ public void test1() throws Exception {
93100
assertNotNull(message);
94101
assertEquals("Test", message.getPayload());
95102
}
103+
assertThat(this.testListener.openEvent, notNullValue());
104+
assertThat(this.testListener.openEvent.getConnectionFactoryName(), equalTo("client"));
105+
}
106+
107+
public static class Listener implements ApplicationListener<TcpConnectionOpenEvent> {
108+
109+
private volatile TcpConnectionOpenEvent openEvent;
110+
111+
@Override
112+
public void onApplicationEvent(TcpConnectionOpenEvent event) {
113+
if (event.getSource() instanceof HelloWorldInterceptor) {
114+
this.openEvent = event;
115+
}
116+
}
117+
96118
}
97119

98120
}

0 commit comments

Comments
 (0)