INT-1046, fixed the ChannelInterceptorParser and added test
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:p="http://www.springframework.org/schema/p">
|
||||
|
||||
|
||||
<int:channel id="input">
|
||||
<int:interceptors>
|
||||
<bean class="org.springframework.integration.channel.interceptor.ChannelInterceptorTests$PreSendReturnsMessageInterceptor"
|
||||
p:foo="foo"/>
|
||||
</int:interceptors>
|
||||
</int:channel>
|
||||
</beans>
|
||||
@@ -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<PreSendReturnsMessageInterceptor> interceptoList =
|
||||
(List<PreSendReturnsMessageInterceptor>) 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user