List of usage examples for org.springframework.integration.channel AbstractMessageChannel addInterceptor
@Override public void addInterceptor(ChannelInterceptor interceptor)
From source file:org.opencredo.esper.integration.config.xml.EsperWireTapChannelsBeanPostProcessor.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private void addMatchingWireTaps(AbstractMessageChannel channel) { Assert.notNull(channel.getComponentName(), "channel name must not be null"); Set<Entry> patternWireTapEntries = this.channelPatternMappings.entrySet(); for (Entry patternWireTapEntry : patternWireTapEntries) { if (((Pattern) patternWireTapEntry.getKey()).matcher(channel.getComponentName()).matches()) { channel.addInterceptor((EsperWireTap) patternWireTapEntry.getValue()); }//from ww w .j a v a2 s. co m } }
From source file:com.qpark.eip.core.spring.EipWsChannelInterceptorInitializer.java
/** * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() *///w ww. jav a 2 s . c om @Override public void afterPropertiesSet() throws Exception { this.logger.debug("+afterPropertiesSet"); int i = 0; String[] channelNames = this.applicationContext.getBeanNamesForType(AbstractMessageChannel.class); String[] interceptorNames = this.applicationContext.getBeanNamesForType(EipWsChannelInterceptor.class); List<EipWsChannelInterceptor> interceptors = new ArrayList<EipWsChannelInterceptor>( interceptorNames.length); Object proxy; for (String interceptorName : interceptorNames) { proxy = this.applicationContext.getBean(interceptorName); interceptors.add(this.getTargetObject(proxy, EipWsChannelInterceptor.class)); } AbstractMessageChannel channel; for (String channelName : channelNames) { if (channelName.startsWith("eip") && (channelName.endsWith("WsChannelRequest") || channelName.endsWith("WsChannelResponse"))) { try { proxy = this.applicationContext.getBean(channelName); channel = this.getTargetObject(proxy, AbstractMessageChannel.class); for (EipWsChannelInterceptor interceptor : interceptors) { channel.addInterceptor(interceptor); } i++; } catch (RuntimeException e) { this.logger.error(e.getMessage()); } catch (Exception e) { this.logger.error(e.getMessage()); } catch (Throwable e) { this.logger.error(e.getMessage()); } } } this.logger.debug( "-afterPropertiesSet AbstractMessageChannels {}, EipWsChannnelInterceptors {}, channels changed {}", channelNames.length, interceptorNames.length, i); }
From source file:org.springframework.cloud.stream.binding.MessageConverterConfigurer.java
/** * Setup data-type and message converters for the given message channel. * * @param channel message channel to set the data-type and message converters * @param channelName the channel name/*from w w w .j a va 2 s . com*/ * @param inbound inbound (i.e., "input") or outbound channel */ private void configureMessageChannel(MessageChannel channel, String channelName, boolean inbound) { Assert.isAssignable(AbstractMessageChannel.class, channel.getClass()); AbstractMessageChannel messageChannel = (AbstractMessageChannel) channel; BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(channelName); String contentType = bindingProperties.getContentType(); ProducerProperties producerProperties = bindingProperties.getProducer(); if (!inbound && producerProperties != null && producerProperties.isPartitioned()) { messageChannel.addInterceptor(new PartitioningInterceptor(bindingProperties, getPartitionKeyExtractorStrategy(producerProperties), getPartitionSelectorStrategy(producerProperties))); } ConsumerProperties consumerProperties = bindingProperties.getConsumer(); if (this.isNativeEncodingNotSet(producerProperties, consumerProperties, inbound)) { if (inbound) { messageChannel.addInterceptor(new InboundContentTypeConvertingInterceptor(contentType, this.compositeMessageConverterFactory)); } else { messageChannel.addInterceptor(new OutboundContentTypeConvertingInterceptor(contentType, this.compositeMessageConverterFactory.getMessageConverterForAllRegistered())); } } }
From source file:org.springframework.integration.test.coverage.AbstractChannelCoverageTests.java
private void findAndInterceptChannels() { if (_ctx == null) { fail("No application context loaded - be sure to use @ContextConfiguration and @RunWith(SpringJUnit4ClassRunner.class)"); }/*from w w w .ja v a2s . co m*/ Map<String, MessageChannel> channels = _ctx.getBeansOfType(MessageChannel.class); for (String channelName : channels.keySet()) { MessageChannel channel = channels.get(channelName); if (channel instanceof AbstractMessageChannel) { AbstractMessageChannel abstractChannel = (AbstractMessageChannel) channel; DirectFieldAccessor dfa = new DirectFieldAccessor(abstractChannel); dfa = new DirectFieldAccessor(dfa.getPropertyValue("interceptors")); @SuppressWarnings("unchecked") List<ChannelInterceptor> interceptors = (List<ChannelInterceptor>) dfa .getPropertyValue("interceptors"); if (interceptors.size() < 1 || !(interceptors.get(interceptors.size() - 1) instanceof ChannelTraversalInterceptor)) { abstractChannel.addInterceptor(new ChannelTraversalInterceptor()); } } } }