From 1c1ca9c6afc199f14af2497e8e78afb2c728bab0 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 4 Jun 2011 14:34:20 -0400 Subject: [PATCH] INT-1928 WireTap now refuses to intercept its own channel --- .../integration/channel/interceptor/WireTap.java | 8 +++++++- .../integration/channel/interceptor/WireTapTests.java | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java index b7a23c7d05..20a8d5e3ab 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java @@ -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) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java index 6cf9cf5ee2..093534d702 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/WireTapTests.java @@ -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 {