From 5c8eeeafdcf64be4af5eb575fbcd8cc16bce5513 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 26 Mar 2010 21:24:33 +0000 Subject: [PATCH] INT-1046, fixed the ChannelInterceptorParser and added test --- .../config/xml/ChannelInterceptorParser.java | 5 +++- .../ChannelInterceptorTests-context.xml | 16 ++++++++++ .../interceptor/ChannelInterceptorTests.java | 30 ++++++++++++++++++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests-context.xml diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java index 1979fd22d7..63fde33198 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/ChannelInterceptorParser.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.ManagedList; +import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; /** @@ -56,7 +57,9 @@ public class ChannelInterceptorParser { Element childElement = (Element) child; String localName = child.getLocalName(); if ("bean".equals(localName)) { - BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(childElement); + BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); + BeanDefinitionHolder holder = delegate.parseBeanDefinitionElement(childElement); + holder = delegate.decorateBeanDefinitionIfRequired(childElement, holder); parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); interceptors.add(new RuntimeBeanReference(holder.getBeanName())); } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests-context.xml new file mode 100644 index 0000000000..31779426fc --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests.java index 4a4d447f80..90ed7693e5 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/channel/interceptor/ChannelInterceptorTests.java @@ -22,16 +22,23 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests.SampleInterceptor; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.StringMessage; +import org.springframework.util.StringUtils; /** * @author Mark Fisher @@ -151,9 +158,23 @@ public class ChannelInterceptorTests { assertEquals(2, invokedCount.get()); assertEquals(1, messageCount.get()); } + @Test + public void testInterceptorBeanWithPnamespace(){ + ApplicationContext ac = new ClassPathXmlApplicationContext("ChannelInterceptorTests-context.xml", ChannelInterceptorTests.class); + AbstractMessageChannel channel = ac.getBean("input", AbstractMessageChannel.class); + DirectFieldAccessor cAccessor = new DirectFieldAccessor(channel); + Object iList = cAccessor.getPropertyValue("interceptors"); + DirectFieldAccessor iAccessor = new DirectFieldAccessor(iList); + List interceptoList = + (List) iAccessor.getPropertyValue("interceptors"); + String foo = interceptoList.get(0).getFoo(); + assertTrue(StringUtils.hasText(foo)); + assertEquals("foo", foo); + } - private static class PreSendReturnsMessageInterceptor extends ChannelInterceptorAdapter { + public static class PreSendReturnsMessageInterceptor extends ChannelInterceptorAdapter { + private String foo; private static AtomicInteger counter = new AtomicInteger(); @@ -164,6 +185,13 @@ public class ChannelInterceptorTests { .setHeader(this.getClass().getSimpleName(), counter.incrementAndGet()).build(); return reply; } + public String getFoo() { + return foo; + } + + public void setFoo(String foo) { + this.foo = foo; + } }