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

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-2017 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 org.apache.log4j.Level;
import org.apache.log4j.LogManager;
@@ -27,11 +30,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.ConsumerEndpointFactoryBean;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.tcp.connection.HelloWorldInterceptor;
import org.springframework.integration.ip.tcp.connection.TcpConnectionOpenEvent;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
@@ -58,6 +64,9 @@ public class InterceptedSharedConnectionTests {
@Autowired
AbstractClientConnectionFactory client;
@Autowired
Listener listener;
private static Level existingLogLevel;
// temporary hooks to investigate CI failures
@@ -95,6 +104,21 @@ public class InterceptedSharedConnectionTests {
assertNotNull(message);
assertEquals("Test", message.getPayload());
}
assertThat(this.listener.openEvent, notNullValue());
assertThat(this.listener.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;
}
}
}
}