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
This commit is contained in:
Gary Russell
2018-01-14 14:59:13 -05:00
committed by Artem Bilan
parent 9c890ea02d
commit d2fb79e846
4 changed files with 41 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,6 +106,11 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo
return this.theConnection.getSocketInfo();
}
@Override
public String getConnectionFactoryName() {
return this.theConnection.getConnectionFactoryName();
}
@Override
public void run() {
this.theConnection.run();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2016 the original author or authors.
* Copyright 2001-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -336,6 +336,10 @@ public abstract class TcpConnectionSupport implements TcpConnection {
return this.socketInfo;
}
public String getConnectionFactoryName() {
return this.connectionFactoryName;
}
protected boolean isNoReadErrorOnClose() {
return this.noReadErrorOnClose;
}
@@ -355,19 +359,19 @@ public abstract class TcpConnectionSupport implements TcpConnection {
protected void publishConnectionOpenEvent() {
TcpConnectionEvent event = new TcpConnectionOpenEvent(this,
this.connectionFactoryName);
getConnectionFactoryName());
doPublish(event);
}
protected void publishConnectionCloseEvent() {
TcpConnectionEvent event = new TcpConnectionCloseEvent(this,
this.connectionFactoryName);
getConnectionFactoryName());
doPublish(event);
}
protected void publishConnectionExceptionEvent(Throwable t) {
TcpConnectionEvent event = new TcpConnectionExceptionEvent(this,
this.connectionFactoryName, t);
getConnectionFactoryName(), t);
doPublish(event);
}

View File

@@ -71,4 +71,6 @@
<int:channel id="loop" />
<bean class="org.springframework.integration.ip.tcp.InterceptedSharedConnectionTests$Listener" />
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,11 @@
package org.springframework.integration.ip.tcp;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.apache.log4j.Level;
@@ -29,8 +32,11 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.ip.tcp.connection.HelloWorldInterceptor;
import org.springframework.integration.ip.tcp.connection.TcpConnectionOpenEvent;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
@@ -52,6 +58,9 @@ public class InterceptedSharedConnectionTests {
@Qualifier(value = "inboundServer")
TcpReceivingChannelAdapter listener;
@Autowired
Listener testListener;
private static Level existingLogLevel;
// temporary hooks to investigate CI failures
@@ -73,8 +82,6 @@ public class InterceptedSharedConnectionTests {
* for the outbound adapter that's sharing the connections. The response
* comes back to an inbound adapter that is sharing the client's
* connection and we verify we get the echo back as expected.
*
* @throws Exception
*/
@Test
public void test1() throws Exception {
@@ -93,6 +100,21 @@ public class InterceptedSharedConnectionTests {
assertNotNull(message);
assertEquals("Test", message.getPayload());
}
assertThat(this.testListener.openEvent, notNullValue());
assertThat(this.testListener.openEvent.getConnectionFactoryName(), equalTo("client"));
}
public static class Listener implements ApplicationListener<TcpConnectionOpenEvent> {
private volatile TcpConnectionOpenEvent openEvent;
@Override
public void onApplicationEvent(TcpConnectionOpenEvent event) {
if (event.getSource() instanceof HelloWorldInterceptor) {
this.openEvent = event;
}
}
}
}