Search in sources :

Example 6 with ChannelInterceptorAware

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);
}
Also used : HashMap(java.util.HashMap) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) GlobalChannelInterceptorWrapper(org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper) ChannelInterceptorAware(org.springframework.integration.channel.ChannelInterceptorAware) Test(org.junit.Test)

Example 7 with ChannelInterceptorAware

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);
}
Also used : HashMap(java.util.HashMap) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) GlobalChannelInterceptorWrapper(org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper) ChannelInterceptorAware(org.springframework.integration.channel.ChannelInterceptorAware) Test(org.junit.Test)

Example 8 with ChannelInterceptorAware

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));
}
Also used : GlobalChannelInterceptorWrapper(org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper) Properties(java.util.Properties) IntegrationProperties(org.springframework.integration.context.IntegrationProperties) ChannelInterceptorAware(org.springframework.integration.channel.ChannelInterceptorAware)

Example 9 with ChannelInterceptorAware

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();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) CountDownLatch(java.util.concurrent.CountDownLatch) WireTap(org.springframework.integration.channel.interceptor.WireTap) ChannelInterceptorAware(org.springframework.integration.channel.ChannelInterceptorAware)

Example 10 with ChannelInterceptorAware

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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) ChannelInterceptorAware(org.springframework.integration.channel.ChannelInterceptorAware) Test(org.junit.Test)

Aggregations

ChannelInterceptorAware (org.springframework.integration.channel.ChannelInterceptorAware)10 ChannelInterceptor (org.springframework.messaging.support.ChannelInterceptor)8 Test (org.junit.Test)7 GlobalChannelInterceptorWrapper (org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper)5 HashMap (java.util.HashMap)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 WireTap (org.springframework.integration.channel.interceptor.WireTap)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 IntegrationProperties (org.springframework.integration.context.IntegrationProperties)1 ExecutorChannelInterceptor (org.springframework.messaging.support.ExecutorChannelInterceptor)1