From f8e7bdf3c2b73c486dddcb0c8053cbbbba13ac11 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 7 Jul 2008 11:58:12 +0000 Subject: [PATCH] Setting ChannelRegistry in MessageBusAwareBeanPostProcessor and avoiding potential NPE in ConcurrencyInterceptor (when ChannelRegistry has not been set). --- .../bus/MessageBusAwareBeanPostProcessor.java | 18 +++++++++++------- .../interceptor/ConcurrencyInterceptor.java | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAwareBeanPostProcessor.java b/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAwareBeanPostProcessor.java index 064b1fddcd..4f47b5f8fc 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAwareBeanPostProcessor.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAwareBeanPostProcessor.java @@ -18,6 +18,7 @@ package org.springframework.integration.bus; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.integration.channel.ChannelRegistryAware; import org.springframework.util.Assert; /** @@ -25,7 +26,7 @@ import org.springframework.util.Assert; * reference to the {@link MessageBus}. * * @author Marius Bogoevici - * + * @author Mark Fisher */ public class MessageBusAwareBeanPostProcessor implements BeanPostProcessor { @@ -37,18 +38,21 @@ public class MessageBusAwareBeanPostProcessor implements BeanPostProcessor { } public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof MessageBusAware) { - ((MessageBusAware) bean).setMessageBus(messageBus); - } - return bean; + return postProcessIfNecessary(bean); } public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + return postProcessIfNecessary(bean); + } + + private Object postProcessIfNecessary(Object bean) { if (bean instanceof MessageBusAware) { - ((MessageBusAware) bean).setMessageBus(messageBus); + ((MessageBusAware) bean).setMessageBus(this.messageBus); + } + if (bean instanceof ChannelRegistryAware) { + ((ChannelRegistryAware) bean).setChannelRegistry(this.messageBus); } return bean; } - } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/interceptor/ConcurrencyInterceptor.java b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/interceptor/ConcurrencyInterceptor.java index 2e635d7050..a536ec8b63 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/interceptor/ConcurrencyInterceptor.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/endpoint/interceptor/ConcurrencyInterceptor.java @@ -92,7 +92,7 @@ public class ConcurrencyInterceptor extends EndpointInterceptorAdapter } public void afterPropertiesSet() throws Exception { - if (this.errorHandler == null) { + if (this.errorHandler == null && this.channelRegistry != null) { MessageChannel errorChannel = this.channelRegistry.lookupChannel( ChannelRegistry.ERROR_CHANNEL_NAME); if (errorChannel != null) {