Skip to content

Commit 032c8fa

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.
1 parent c4c4e51 commit 032c8fa

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

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

Lines changed: 6 additions & 1 deletion
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

Lines changed: 8 additions & 4 deletions
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.
@@ -328,6 +328,10 @@ public SocketInfo getSocketInfo() {
328328
return this.socketInfo;
329329
}
330330

331+
public String getConnectionFactoryName() {
332+
return this.connectionFactoryName;
333+
}
334+
331335
protected boolean isNoReadErrorOnClose() {
332336
return this.noReadErrorOnClose;
333337
}
@@ -347,19 +351,19 @@ protected final void sendExceptionToListener(Exception e) {
347351

348352
protected void publishConnectionOpenEvent() {
349353
TcpConnectionEvent event = new TcpConnectionOpenEvent(this,
350-
this.connectionFactoryName);
354+
getConnectionFactoryName());
351355
doPublish(event);
352356
}
353357

354358
protected void publishConnectionCloseEvent() {
355359
TcpConnectionEvent event = new TcpConnectionCloseEvent(this,
356-
this.connectionFactoryName);
360+
getConnectionFactoryName());
357361
doPublish(event);
358362
}
359363

360364
protected void publishConnectionExceptionEvent(Throwable t) {
361365
TcpConnectionEvent event = new TcpConnectionExceptionEvent(this,
362-
this.connectionFactoryName, t);
366+
getConnectionFactoryName(), t);
363367
doPublish(event);
364368
}
365369

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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

2225
import org.apache.log4j.Level;
2326
import org.apache.log4j.LogManager;
@@ -27,11 +30,14 @@
2730
import org.junit.runner.RunWith;
2831

2932
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.context.ApplicationListener;
3034
import org.springframework.context.support.AbstractApplicationContext;
3135
import org.springframework.integration.channel.QueueChannel;
3236
import org.springframework.integration.config.ConsumerEndpointFactoryBean;
3337
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
3438
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
39+
import org.springframework.integration.ip.tcp.connection.HelloWorldInterceptor;
40+
import org.springframework.integration.ip.tcp.connection.TcpConnectionOpenEvent;
3541
import org.springframework.integration.ip.util.TestingUtilities;
3642
import org.springframework.integration.support.MessageBuilder;
3743
import org.springframework.messaging.Message;
@@ -58,6 +64,9 @@ public class InterceptedSharedConnectionTests {
5864
@Autowired
5965
AbstractClientConnectionFactory client;
6066

67+
@Autowired
68+
Listener listener;
69+
6170
private static Level existingLogLevel;
6271

6372
// temporary hooks to investigate CI failures
@@ -95,6 +104,21 @@ public void test1() throws Exception {
95104
assertNotNull(message);
96105
assertEquals("Test", message.getPayload());
97106
}
107+
assertThat(this.listener.openEvent, notNullValue());
108+
assertThat(this.listener.openEvent.getConnectionFactoryName(), equalTo("client"));
109+
}
110+
111+
public static class Listener implements ApplicationListener<TcpConnectionOpenEvent> {
112+
113+
private volatile TcpConnectionOpenEvent openEvent;
114+
115+
@Override
116+
public void onApplicationEvent(TcpConnectionOpenEvent event) {
117+
if (event.getSource() instanceof HelloWorldInterceptor) {
118+
this.openEvent = event;
119+
}
120+
}
121+
98122
}
99123

100124
}

0 commit comments

Comments
 (0)