use of org.springframework.integration.channel.ChannelInterceptorAware in project spring-integration by spring-projects.
the class GlobalChannelInterceptorProcessorTests method testProcessorWithInterceptorMatchingPattern.
@Test
public void testProcessorWithInterceptorMatchingPattern() {
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
Map<String, ChannelInterceptorAware> channels = new HashMap<>();
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor);
ChannelInterceptorAware channel = Mockito.mock(ChannelInterceptorAware.class);
globalChannelInterceptorWrapper.setPatterns(new String[] { "Te*" });
interceptors.put("Test-1", globalChannelInterceptorWrapper);
channels.put("Test-1", channel);
when(this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class)).thenReturn(interceptors);
when(this.beanFactory.getBeansOfType(ChannelInterceptorAware.class)).thenReturn(channels);
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
verify(channel).addInterceptor(channelInterceptor);
}
use of org.springframework.integration.channel.ChannelInterceptorAware in project spring-integration by spring-projects.
the class GlobalChannelInterceptorProcessorTests method testProcessorWithInterceptorMatchingNegativePattern.
@Test
public void testProcessorWithInterceptorMatchingNegativePattern() {
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
Map<String, ChannelInterceptorAware> channels = new HashMap<>();
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor);
ChannelInterceptorAware channel = Mockito.mock(ChannelInterceptorAware.class);
globalChannelInterceptorWrapper.setPatterns(new String[] { "!te*", "!Te*" });
interceptors.put("Test-1", globalChannelInterceptorWrapper);
channels.put("Test-1", channel);
when(this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class)).thenReturn(interceptors);
when(this.beanFactory.getBeansOfType(ChannelInterceptorAware.class)).thenReturn(channels);
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
verify(channel, Mockito.never()).addInterceptor(channelInterceptor);
}
use of org.springframework.integration.channel.ChannelInterceptorAware in project spring-integration by spring-projects.
the class GlobalChannelInterceptorProcessor method afterSingletonsInstantiated.
@Override
public void afterSingletonsInstantiated() {
Collection<GlobalChannelInterceptorWrapper> interceptors = this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class).values();
if (CollectionUtils.isEmpty(interceptors)) {
logger.debug("No global channel interceptors.");
} else {
for (GlobalChannelInterceptorWrapper channelInterceptor : interceptors) {
if (channelInterceptor.getOrder() >= 0) {
this.positiveOrderInterceptors.add(channelInterceptor);
} else {
this.negativeOrderInterceptors.add(channelInterceptor);
}
}
Map<String, ChannelInterceptorAware> channels = this.beanFactory.getBeansOfType(ChannelInterceptorAware.class);
for (Entry<String, ChannelInterceptorAware> entry : channels.entrySet()) {
addMatchingInterceptors(entry.getValue(), entry.getKey());
}
}
// TODO Remove this logic in 5.1
Properties integrationProperties = IntegrationContextUtils.getIntegrationProperties(this.beanFactory);
this.singletonsInstantiated = Boolean.parseBoolean(integrationProperties.getProperty(IntegrationProperties.POST_PROCESS_DYNAMIC_BEANS));
}
use of org.springframework.integration.channel.ChannelInterceptorAware in project spring-integration by spring-projects.
the class MessageChannelsMonitorIntegrationTests method doTest.
private void doTest(String config, String channelName) throws Exception {
ClassPathXmlApplicationContext context = createContext(config, channelName);
try {
int before = service.getCounter();
CountDownLatch latch = new CountDownLatch(1);
service.setLatch(latch);
channel.send(new GenericMessage<String>("bar"));
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(before + 1, service.getCounter());
// The handler monitor is registered under the endpoint id (since it is explicit)
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();
}
}
use of org.springframework.integration.channel.ChannelInterceptorAware in project spring-integration by spring-projects.
the class GlobalChannelInterceptorTests method testJmsChannel.
@Test
public void testJmsChannel() {
ActiveMqTestUtils.prepare();
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class);
ChannelInterceptorAware jmsChannel = context.getBean("jmsChannel", AbstractMessageChannel.class);
List<ChannelInterceptor> interceptors = jmsChannel.getChannelInterceptors();
assertNotNull(interceptors);
assertEquals(1, interceptors.size());
assertTrue(interceptors.get(0) instanceof SampleInterceptor);
context.close();
}
Aggregations