INT-1928 WireTap now refuses to intercept its own channel

This commit is contained in:
Mark Fisher
2011-06-04 14:34:20 -04:00
parent 73bf93c229
commit 1c1ca9c6af
2 changed files with 15 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -111,6 +111,12 @@ public class WireTap extends ChannelInterceptorAdapter implements Lifecycle {
*/
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
if (this.channel.equals(channel)) {
if (logger.isDebugEnabled()) {
logger.debug("WireTap is refusing to intercept its own channel '" + this.channel + "'");
}
return message;
}
if (this.running && (this.selector == null || this.selector.accept(message))) {
boolean sent = (this.timeout >= 0)
? this.channel.send(message, this.timeout)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2011 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.
@@ -109,6 +109,13 @@ public class WireTapTests {
assertEquals(originalAttribute, interceptedAttribute);
}
@Test
public void wireTapDoesNotInterceptItsOwnChannel() {
QueueChannel wireTapChannel = new QueueChannel();
wireTapChannel.addInterceptor(new WireTap(wireTapChannel));
// would throw a StackOverflowException if not working:
wireTapChannel.send(MessageBuilder.withPayload("test").build());
}
private static class TestSelector implements MessageSelector {