-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TcpConnectionInterceptorSupport.addNewConnection() is no longer called #3713
Comments
The workaround I posted is not valid; investigating... |
This is a behavior change; here is a work around in the context of one of the test cases: private void senderCalledForDeadConnectionClient(AbstractClientConnectionFactory client) throws InterruptedException {
CountDownLatch adds = new CountDownLatch(2);
CountDownLatch removes = new CountDownLatch(2);
CountDownLatch interceptorAddCalled = new CountDownLatch(1);
TcpConnectionInterceptorFactoryChain chain = new TcpConnectionInterceptorFactoryChain();
chain.setInterceptor(new HelloWorldInterceptorFactory() {
@Override
public TcpConnectionInterceptorSupport getInterceptor() {
return new TcpConnectionInterceptorSupport() {
private List<TcpSender> interceptedSenders;
private boolean realSender;
@Override
public void addNewConnection(TcpConnection connection) {
interceptorAddCalled.countDown();
this.interceptedSenders.forEach(sender -> sender.addNewConnection(connection));
}
@Override
public void removeDeadConnection(TcpConnection connection) {
this.interceptedSenders.forEach(sender -> sender.removeDeadConnection(connection));
}
@Override
public void registerSenders(List<TcpSender> sendersToRegister) {
this.interceptedSenders = sendersToRegister;
if (sendersToRegister.size() > 0) {
if (!(sendersToRegister.get(0) instanceof TcpConnectionInterceptorSupport)) {
this.realSender = true;
}
else {
this.realSender = ((TcpConnectionInterceptorSupport) this.interceptedSenders.get(0))
.hasRealSender();
}
}
super.registerSenders(Collections.singletonList(this));
}
@Override
protected boolean hasRealSender() {
return this.realSender;
}
};
}
});
client.setInterceptorFactoryChain(chain);
client.registerSender(new TcpSender() {
@Override
public void addNewConnection(TcpConnection connection) {
adds.countDown();
}
@Override
public void removeDeadConnection(TcpConnection connection) {
removes.countDown();
}
});
client.setSingleUse(true);
client.afterPropertiesSet();
client.start();
TcpConnectionSupport conn = client.getConnection();
assertThat(((TcpConnectionInterceptorSupport) conn).hasRealSender()).isTrue();
conn.close();
conn = client.getConnection();
assertThat(adds.await(10, TimeUnit.SECONDS)).isTrue();
conn.close();
client.stop();
assertThat(removes.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(interceptorAddCalled.await(10, TimeUnit.SECONDS)).isTrue();
} |
That seems quite confusing. So I need to do I hate to say it, but I think I'm going to stick with 5.3.10.RELEASE for now (the last release where the Interceptor actually intercepted things) and maybe I'll follow up later to see if things get changed back. Would you assume that my code in my original post will never work again, post-5.3? Thanks! |
Yes, this will be fixed in 5.5.9. |
Oh, fabulous! Definitely the best answer I could've hoped for! Thank you! |
Resolves spring-projects#3713 spring-projects#3326 added support for multiple `TcpSenders`. However, when connections are intercepted, the sender list was not properly chained through the interceptors. - override `registerSenders` and properly capture the real senders in the last interceptor and intermediate interceptors - this ensures that `addNewConnection` is called on each interceptor - when removing dead connections, use the (possibly intercepted) connection sender list insted of the factory's raw sender list. **cherry-pick to 5.5.x**
Resolves spring-projects#3713 spring-projects#3326 added support for multiple `TcpSenders`. However, when connections are intercepted, the sender list was not properly chained through the interceptors. - override `registerSenders` and properly capture the real senders in the last interceptor and intermediate interceptors - this ensures that `addNewConnection` is called on each interceptor - when removing dead connections, use the connection sender list insted of the factory's raw sender list; detect if the connection is an interceptor and call its remove method instead. **cherry-pick to 5.5.x**
Resolves #3713 #3326 added support for multiple `TcpSenders`. However, when connections are intercepted, the sender list was not properly chained through the interceptors. - override `registerSenders` and properly capture the real senders in the last interceptor and intermediate interceptors - this ensures that `addNewConnection` is called on each interceptor - when removing dead connections, use the connection sender list insted of the factory's raw sender list; detect if the connection is an interceptor and call its remove method instead. **cherry-pick to 5.5.x**
Resolves #3713 #3326 added support for multiple `TcpSenders`. However, when connections are intercepted, the sender list was not properly chained through the interceptors. - override `registerSenders` and properly capture the real senders in the last interceptor and intermediate interceptors - this ensures that `addNewConnection` is called on each interceptor - when removing dead connections, use the connection sender list insted of the factory's raw sender list; detect if the connection is an interceptor and call its remove method instead. **cherry-pick to 5.5.x**
In what version(s) of Spring Integration are you seeing this issue?
5.5.8
Describe the bug
In 5.2.8.RELEASE, the following code worked:
However, in 5.5.8 -- and I assume ever since this change -- the
addNewConnection()
method above is no longer called.This is because the old code called
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport.registerSender(TcpSender)
with aMyInterceptor
instance. This calledthis.theConnection.registerSender(this)
which eventually calledaddNewConnection()
on the interceptor.But the new code calls
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport.registerSenders(List)
. It then walks through the list of senders and callsaddNewConnection()
on them directly, and those senders are theTcpSendingMessageHandler
Bean(s) that were returned from theoutbound
ServiceActivator(s) above.Let me know if this is clear, or, if not, if I should make working and non-working samples.
Or, alternately, let me know if I'm misreading the documentation and am setting up interceptors wrong!
Thank you so much!
Dave
The text was updated successfully, but these errors were encountered: