INT-1897: Refactoring for ChannelInterceptors
JIRA: https://jira.springsource.org/browse/INT-1897 INT-1897: Introduce `ChannelInterceptorAware` Upgrade to SF 4.0.1 JIRA: https://jira.springsource.org/browse/INT-3255
This commit is contained in:
committed by
Gary Russell
parent
062e7bc9d2
commit
2b888b7a76
@@ -62,7 +62,7 @@ subprojects { subproject ->
|
||||
h2Version = '1.3.172'
|
||||
activeMqVersion = '5.8.0'
|
||||
|
||||
springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.0.1.BUILD-SNAPSHOT'
|
||||
springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.0.1.RELEASE'
|
||||
|
||||
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.3.0.BUILD-SNAPSHOT'
|
||||
|
||||
|
||||
@@ -46,8 +46,10 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public abstract class AbstractMessageChannel extends IntegrationObjectSupport implements MessageChannel, TrackableComponent {
|
||||
public abstract class AbstractMessageChannel extends IntegrationObjectSupport
|
||||
implements MessageChannel, TrackableComponent, ChannelInterceptorAware {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
@@ -94,6 +96,7 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
*
|
||||
* @param interceptors The list of interceptors.
|
||||
*/
|
||||
@Override
|
||||
public void setInterceptors(List<ChannelInterceptor> interceptors) {
|
||||
Collections.sort(interceptors, new OrderComparator());
|
||||
this.interceptors.set(interceptors);
|
||||
@@ -104,10 +107,22 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
*
|
||||
* @param interceptor The interceptor.
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptor(ChannelInterceptor interceptor) {
|
||||
this.interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a channel interceptor to the specified index of the list.
|
||||
*
|
||||
* @param index The index to add interceptor.
|
||||
* @param interceptor The interceptor.
|
||||
*/
|
||||
@Override
|
||||
public void addInterceptor(int index, ChannelInterceptor interceptor) {
|
||||
this.interceptors.add(index, interceptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the {@link ConversionService} to use when trying to convert to
|
||||
* one of this channel's supported datatypes for a Message whose payload
|
||||
@@ -124,6 +139,14 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
super.setConversionService(conversionService);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a read-only list of the configured interceptors.
|
||||
*/
|
||||
@Override
|
||||
public List<ChannelInterceptor> getChannelInterceptors() {
|
||||
return this.interceptors.getInterceptors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exposes the interceptor list for subclasses.
|
||||
*
|
||||
@@ -261,6 +284,10 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
return this.interceptors.add(interceptor);
|
||||
}
|
||||
|
||||
public void add(int index, ChannelInterceptor interceptor) {
|
||||
this.interceptors.add(index, interceptor);
|
||||
}
|
||||
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("preSend on channel '" + channel + "', message: " + message);
|
||||
@@ -310,5 +337,9 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public List<ChannelInterceptor> getInterceptors() {
|
||||
return Collections.unmodifiableList(this.interceptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.channel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
|
||||
/**
|
||||
* A marker interface providing the ability to configure {@link ChannelInterceptor}s
|
||||
* on {@link org.springframework.messaging.MessageChannel} implementations.
|
||||
* <p>
|
||||
* Typically useful when the target {@link org.springframework.messaging.MessageChannel}
|
||||
* is an AOP Proxy.
|
||||
* *
|
||||
* @author Artem Bilan
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface ChannelInterceptorAware {
|
||||
|
||||
void setInterceptors(List<ChannelInterceptor> interceptors);
|
||||
|
||||
void addInterceptor(ChannelInterceptor interceptor);
|
||||
|
||||
void addInterceptor(int index, ChannelInterceptor interceptor);
|
||||
|
||||
List<ChannelInterceptor> getChannelInterceptors();
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -25,16 +25,12 @@ import java.util.Set;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.NotReadablePropertyException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.core.OrderComparator;
|
||||
import org.springframework.integration.channel.ChannelInterceptorAware;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -43,6 +39,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
final class GlobalChannelInterceptorBeanPostProcessor implements BeanPostProcessor, InitializingBean {
|
||||
@@ -83,11 +80,11 @@ final class GlobalChannelInterceptorBeanPostProcessor implements BeanPostProcess
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof MessageChannel) {
|
||||
if (bean instanceof ChannelInterceptorAware && bean instanceof MessageChannel) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Applying global interceptors on channel '" + beanName + "'");
|
||||
}
|
||||
this.addMatchingInterceptors((MessageChannel) bean, beanName);
|
||||
this.addMatchingInterceptors((ChannelInterceptorAware) bean, beanName);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
@@ -95,67 +92,34 @@ final class GlobalChannelInterceptorBeanPostProcessor implements BeanPostProcess
|
||||
/**
|
||||
* Adds any interceptor whose pattern matches against the channel's name.
|
||||
*/
|
||||
private void addMatchingInterceptors(MessageChannel channel, String beanName) {
|
||||
List<ChannelInterceptor> interceptors = this.getExistingInterceptors(channel);
|
||||
if (interceptors != null) {
|
||||
List<GlobalChannelInterceptorWrapper> tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>();
|
||||
for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.positiveOrderInterceptors) {
|
||||
String[] patterns = globalChannelInterceptorWrapper.getPatterns();
|
||||
patterns = StringUtils.trimArrayElements(patterns);
|
||||
if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
|
||||
tempInterceptors.add(globalChannelInterceptorWrapper);
|
||||
}
|
||||
}
|
||||
Collections.sort(tempInterceptors, this.comparator);
|
||||
for (GlobalChannelInterceptorWrapper next : tempInterceptors) {
|
||||
interceptors.add(next.getChannelInterceptor());
|
||||
}
|
||||
tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>();
|
||||
for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.negativeOrderInterceptors) {
|
||||
String[] patterns = globalChannelInterceptorWrapper.getPatterns();
|
||||
patterns = StringUtils.trimArrayElements(patterns);
|
||||
if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
|
||||
tempInterceptors.add(globalChannelInterceptorWrapper);
|
||||
}
|
||||
}
|
||||
Collections.sort(tempInterceptors, comparator);
|
||||
if (!tempInterceptors.isEmpty()) {
|
||||
for (int i = tempInterceptors.size() - 1; i >= 0; i--) {
|
||||
interceptors.add(0, tempInterceptors.get(i).getChannelInterceptor());
|
||||
}
|
||||
private void addMatchingInterceptors(ChannelInterceptorAware channel, String beanName) {
|
||||
List<GlobalChannelInterceptorWrapper> tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>();
|
||||
for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.positiveOrderInterceptors) {
|
||||
String[] patterns = globalChannelInterceptorWrapper.getPatterns();
|
||||
patterns = StringUtils.trimArrayElements(patterns);
|
||||
if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
|
||||
tempInterceptors.add(globalChannelInterceptorWrapper);
|
||||
}
|
||||
}
|
||||
else if (logger.isDebugEnabled()) {
|
||||
logger.debug("Global Channel interceptors will not be applied to Channel: " + beanName);
|
||||
Collections.sort(tempInterceptors, this.comparator);
|
||||
for (GlobalChannelInterceptorWrapper next : tempInterceptors) {
|
||||
channel.addInterceptor(next.getChannelInterceptor());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<ChannelInterceptor> getExistingInterceptors(MessageChannel channel) {
|
||||
try {
|
||||
MessageChannel targetChannel = channel;
|
||||
if (AopUtils.isAopProxy(channel)) {
|
||||
Object target = ((Advised) channel).getTargetSource().getTarget();
|
||||
if (target instanceof MessageChannel) {
|
||||
targetChannel = (MessageChannel) target;
|
||||
}
|
||||
}
|
||||
DirectFieldAccessor channelAccessor = new DirectFieldAccessor(targetChannel);
|
||||
Object interceptorListWrapper = channelAccessor.getPropertyValue("interceptors");
|
||||
if (interceptorListWrapper != null) {
|
||||
return (List<ChannelInterceptor>) new DirectFieldAccessor(interceptorListWrapper).getPropertyValue("interceptors");
|
||||
tempInterceptors.clear();
|
||||
for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.negativeOrderInterceptors) {
|
||||
String[] patterns = globalChannelInterceptorWrapper.getPatterns();
|
||||
patterns = StringUtils.trimArrayElements(patterns);
|
||||
if (PatternMatchUtils.simpleMatch(patterns, beanName)) {
|
||||
tempInterceptors.add(globalChannelInterceptorWrapper);
|
||||
}
|
||||
}
|
||||
catch (NotReadablePropertyException e) {
|
||||
// Channel doesn't support interceptors - null return logged by caller
|
||||
}
|
||||
catch (Exception e) {
|
||||
// interceptors not supported, will return null
|
||||
if (logger.isDebugEnabled() && channel != null) {
|
||||
logger.debug("interceptors not supported by channel '" + channel + "'", e);
|
||||
Collections.sort(tempInterceptors, comparator);
|
||||
if (!tempInterceptors.isEmpty()) {
|
||||
for (int i = tempInterceptors.size() - 1; i >= 0; i--) {
|
||||
channel.addInterceptor(0, tempInterceptors.get(i).getChannelInterceptor());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -20,22 +20,25 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
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.ChannelInterceptorAware;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -43,6 +46,7 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class ChannelInterceptorTests {
|
||||
|
||||
@@ -162,14 +166,11 @@ public class ChannelInterceptorTests {
|
||||
@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);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<PreSendReturnsMessageInterceptor> interceptorList =
|
||||
(List<PreSendReturnsMessageInterceptor>) iAccessor.getPropertyValue("interceptors");
|
||||
String foo = interceptorList.get(0).getFoo();
|
||||
ChannelInterceptorAware channel = ac.getBean("input", AbstractMessageChannel.class);
|
||||
List<ChannelInterceptor> interceptors = channel.getChannelInterceptors();
|
||||
ChannelInterceptor channelInterceptor = interceptors.get(0);
|
||||
assertThat(channelInterceptor, Matchers.instanceOf(PreSendReturnsMessageInterceptor.class));
|
||||
String foo = ((PreSendReturnsMessageInterceptor) channelInterceptor).getFoo();
|
||||
assertTrue(StringUtils.hasText(foo));
|
||||
assertEquals("foo", foo);
|
||||
}
|
||||
|
||||
@@ -14,22 +14,22 @@
|
||||
<ref bean="channelInterceptor"/>
|
||||
</int:interceptors>
|
||||
</int:channel>
|
||||
|
||||
|
||||
<int:channel id="inputB">
|
||||
<int:queue capacity="1"/>
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="inpuC"/>
|
||||
|
||||
<int:publish-subscribe-channel id="foo"/>
|
||||
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="inputC"/>
|
||||
|
||||
<int:publish-subscribe-channel id="foo"/>
|
||||
|
||||
<int:channel id="bar">
|
||||
<int:interceptors>
|
||||
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="eight"/>
|
||||
<ref bean="channelInterceptor"/>
|
||||
</int:interceptors>
|
||||
</int:channel>
|
||||
|
||||
|
||||
<int:channel id="baz"/>
|
||||
|
||||
<int:channel-interceptor pattern="input*, foo" order="3">
|
||||
@@ -38,22 +38,22 @@
|
||||
<int:channel-interceptor pattern="input*, foo, object" order="1">
|
||||
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="four"/>
|
||||
</int:channel-interceptor>
|
||||
|
||||
|
||||
<int:channel-interceptor pattern="inputA, foo">
|
||||
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="five"/>
|
||||
</int:channel-interceptor>
|
||||
<int:channel-interceptor pattern="inputA">
|
||||
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="six"/>
|
||||
</int:channel-interceptor>
|
||||
|
||||
|
||||
<int:channel-interceptor>
|
||||
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="ten"/>
|
||||
</int:channel-interceptor>
|
||||
|
||||
|
||||
<int:channel-interceptor pattern="*" ref="eleven"/>
|
||||
|
||||
|
||||
<bean id="eleven" class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="eleven"/>
|
||||
|
||||
|
||||
<int:channel-interceptor pattern="input*, foo" order="-3">
|
||||
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="two"/>
|
||||
</int:channel-interceptor>
|
||||
@@ -61,16 +61,16 @@
|
||||
<bean class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="three"/>
|
||||
</int:channel-interceptor>
|
||||
|
||||
|
||||
|
||||
<bean id="channelInterceptor" class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests$SampleInterceptor" p:testIdentifier="seven"/>
|
||||
|
||||
|
||||
<int:channel id="inputWithProxy"/>
|
||||
|
||||
|
||||
<aop:config>
|
||||
<aop:pointcut id="testPointcut" expression="bean(inputWithProxy)"/>
|
||||
<aop:advisor advice-ref="testInterceptor" pointcut-ref="testPointcut"/>
|
||||
</aop:config>
|
||||
|
||||
|
||||
<bean id="testInterceptor" class="org.springframework.integration.channel.interceptor.GlobalChannelInterceptorTests.TestInterceptor"/>
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -26,13 +26,12 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.channel.ChannelInterceptorAware;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
@@ -42,27 +41,31 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author David Turanski
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class GlobalChannelInterceptorTests {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inputC")
|
||||
ChannelInterceptorAware inputCChannel;
|
||||
|
||||
|
||||
@Test
|
||||
public void validateGlobalInterceptor() throws Exception{
|
||||
Map<String, MessageChannel> channels = applicationContext.getBeansOfType(MessageChannel.class);
|
||||
Map<String, ChannelInterceptorAware> channels = applicationContext.getBeansOfType(ChannelInterceptorAware.class);
|
||||
for (String channelName : channels.keySet()) {
|
||||
MessageChannel channel = channels.get(channelName);
|
||||
ChannelInterceptorAware channel = channels.get(channelName);
|
||||
if (channelName.equals("nullChannel")){
|
||||
continue;
|
||||
}
|
||||
if (AopUtils.isAopProxy(channel)){
|
||||
channel = (MessageChannel) ((Advised)channel).getTargetSource().getTarget();
|
||||
}
|
||||
List<?> interceptorList = TestUtils.getPropertyValue(channel, "interceptors.interceptors", List.class);
|
||||
ChannelInterceptor[] interceptors = interceptorList.toArray(new ChannelInterceptor[] {});
|
||||
|
||||
ChannelInterceptor[] interceptors = channel.getChannelInterceptors().toArray(new ChannelInterceptor[channel.getChannelInterceptors().size()]);
|
||||
if (channelName.equals("inputA")){ // 328741
|
||||
Assert.assertTrue(interceptors.length ==10);
|
||||
Assert.assertEquals("interceptor-three", interceptors[0].toString());
|
||||
@@ -111,17 +114,12 @@ public class GlobalChannelInterceptorTests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inpuC")
|
||||
MessageChannel inpuCchannel;
|
||||
@Test
|
||||
public void testWildCardPatternMatch() {
|
||||
|
||||
List<?> interceptorList = TestUtils.getPropertyValue(inpuCchannel, "interceptors.interceptors", List.class);
|
||||
List<ChannelInterceptor> channelInterceptors = this.inputCChannel.getChannelInterceptors();
|
||||
List<String> interceptorNames = new ArrayList<String>();
|
||||
for (Object interceptor : interceptorList) {
|
||||
for (ChannelInterceptor interceptor : channelInterceptors) {
|
||||
interceptorNames.add(interceptor.toString());
|
||||
}
|
||||
Assert.assertTrue(interceptorNames.contains("interceptor-ten"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -27,12 +27,15 @@ import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.channel.ChannelInterceptorAware;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public class GlobalChannelInterceptorTests {
|
||||
@@ -42,12 +45,11 @@ public class GlobalChannelInterceptorTests {
|
||||
ActiveMqTestUtils.prepare();
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class);
|
||||
AbstractMessageChannel jmsChannel = context.getBean("jmsChannel", AbstractMessageChannel.class);
|
||||
Object interceptors = TestUtils.getPropertyValue((TestUtils.getPropertyValue(jmsChannel, "interceptors")), "interceptors");
|
||||
ChannelInterceptorAware jmsChannel = context.getBean("jmsChannel", AbstractMessageChannel.class);
|
||||
List<ChannelInterceptor> interceptors = jmsChannel.getChannelInterceptors();
|
||||
assertNotNull(interceptors);
|
||||
assertTrue(interceptors instanceof List);
|
||||
assertEquals(1, ((List<?>) interceptors).size());
|
||||
assertTrue(((List<?>) interceptors).get(0) instanceof SampleInterceptor);
|
||||
assertEquals(1, interceptors.size());
|
||||
assertTrue(interceptors.get(0) instanceof SampleInterceptor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2013 the original author or authors.
|
||||
* Copyright 2009-2014 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. You may obtain a copy of the License at
|
||||
@@ -13,8 +13,10 @@
|
||||
package org.springframework.integration.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -22,18 +24,23 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.ChannelInterceptorAware;
|
||||
import org.springframework.integration.channel.interceptor.WireTap;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
*/
|
||||
public class MessageChannelsMonitorIntegrationTests {
|
||||
@@ -185,6 +192,10 @@ public class MessageChannelsMonitorIntegrationTests {
|
||||
int sends = messageChannelsMonitor.getChannelSendRate("" + channel).getCount();
|
||||
assertEquals("No statistics for input channel", 1, sends, 0.01);
|
||||
|
||||
assertThat(channel, Matchers.instanceOf(ChannelInterceptorAware.class));
|
||||
List<ChannelInterceptor> channelInterceptors = ((ChannelInterceptorAware) channel).getChannelInterceptors();
|
||||
assertEquals(1, channelInterceptors.size());
|
||||
assertThat(channelInterceptors.get(0), Matchers.instanceOf(WireTap.class));
|
||||
}
|
||||
finally {
|
||||
context.close();
|
||||
@@ -223,7 +234,7 @@ public class MessageChannelsMonitorIntegrationTests {
|
||||
}
|
||||
|
||||
@Aspect
|
||||
public static class ChannelInterceptor {
|
||||
public static class TestChannelInterceptor {
|
||||
@Before("execution(* *..MessageChannel+.send(*)) && args(input)")
|
||||
public void around(Message<?> input) {
|
||||
logger.debug("Handling: " + input);
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
<int:channel id="anonymous" />
|
||||
|
||||
<int:wire-tap channel="nullChannel"/>
|
||||
|
||||
<int:service-activator input-channel="anonymous" ref="service" />
|
||||
|
||||
<bean id="service" class="org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests$Service" />
|
||||
|
||||
@@ -8,15 +8,17 @@
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<import resource="common-context.xml" />
|
||||
|
||||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
<int:channel id="anonymous" />
|
||||
|
||||
<int:wire-tap channel="nullChannel"/>
|
||||
|
||||
<int:service-activator input-channel="anonymous" ref="service" />
|
||||
|
||||
<bean id="service" class="org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests$Service" />
|
||||
|
||||
<bean id="interceptor" class="org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests$ChannelInterceptor" />
|
||||
<bean id="interceptor" class="org.springframework.integration.monitor.MessageChannelsMonitorIntegrationTests$TestChannelInterceptor" />
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user