diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAware.java b/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAware.java deleted file mode 100644 index 645a6aebec..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAware.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2002-2008 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.bus; - -/** - * Interface to be implemented by classes which need access to the {@link MessageBus}. - * - * @author Marius Bogoevici - */ -public interface MessageBusAware { - - public void setMessageBus(MessageBus messageBus); - -} 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 deleted file mode 100644 index 1e5ba5ab8d..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/bus/MessageBusAwareBeanPostProcessor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2002-2008 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.bus; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.util.Assert; - -/** - * A bean post processor which injects all {@link MessageBusAware} beans with a - * reference to the {@link MessageBus}. - * - * @author Marius Bogoevici - * @author Mark Fisher - */ -public class MessageBusAwareBeanPostProcessor implements BeanPostProcessor { - - private final MessageBus messageBus; - - - public MessageBusAwareBeanPostProcessor(MessageBus messageBus) { - Assert.notNull(messageBus, "'messageBus' must not be null"); - this.messageBus = messageBus; - } - - - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - 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(this.messageBus); - } - return bean; - } - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MessageBusParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MessageBusParser.java index 70d24c26f8..37643c5a8c 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MessageBusParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MessageBusParser.java @@ -24,7 +24,6 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; -import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; @@ -36,7 +35,6 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.core.task.TaskExecutor; import org.springframework.integration.bus.ApplicationContextMessageBus; import org.springframework.integration.bus.MessageBus; -import org.springframework.integration.bus.MessageBusAwareBeanPostProcessor; import org.springframework.integration.channel.MessagePublishingErrorHandler; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor; @@ -58,9 +56,6 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser { public static final String TASK_SCHEDULER_BEAN_NAME = "taskScheduler"; - public static final String MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME = - "internal.MessageBusAwareBeanPostProcessor"; - private static final String MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME = "internal.MessagingAnnotationPostProcessor"; @@ -150,24 +145,16 @@ public class MessageBusParser extends AbstractSimpleBeanDefinitionParser { * Adds extra post-processors to the context, to inject the objects configured by the MessageBus */ private void addPostProcessors(Element element, ParserContext parserContext) { - this.registerMessageBusAwarePostProcessor(parserContext); if ("true".equals(element.getAttribute("enable-annotations").toLowerCase())) { this.registerMessagingAnnotationPostProcessor(parserContext); } } - private void registerMessageBusAwarePostProcessor(ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessageBusAwareBeanPostProcessor.class); - builder.addConstructorArgReference(MessageBusParser.MESSAGE_BUS_BEAN_NAME); - builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); - parserContext.getRegistry().registerBeanDefinition(MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME, builder.getBeanDefinition()); - } - private void registerMessagingAnnotationPostProcessor(ParserContext parserContext) { - BeanDefinition bd = new RootBeanDefinition(MessagingAnnotationPostProcessor.class); - BeanComponentDefinition bcd = new BeanComponentDefinition( - bd, MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME); - parserContext.registerBeanComponent(bcd); + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessagingAnnotationPostProcessor.class); + builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + parserContext.getRegistry().registerBeanDefinition( + MESSAGING_ANNOTATION_POST_PROCESSOR_BEAN_NAME, builder.getBeanDefinition()); } } diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java index 9c4133d7e5..89a1a04924 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/bus/ApplicationContextMessageBusTests.java @@ -297,13 +297,6 @@ public class ApplicationContextMessageBusTests { messageBus.resolveChannelName("noSuchChannel"); } - @Test - public void messageBusAware() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("messageBusTests.xml", this.getClass()); - TestMessageBusAwareImpl messageBusAwareBean = (TestMessageBusAwareImpl) context.getBean("messageBusAwareBean"); - assertTrue(messageBusAwareBean.getMessageBus() == context.getBean("bus")); - } - private static class FailingSource implements MessageSource { diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/bus/TestMessageBusAwareImpl.java b/org.springframework.integration/src/test/java/org/springframework/integration/bus/TestMessageBusAwareImpl.java deleted file mode 100644 index 68585167d2..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/bus/TestMessageBusAwareImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2002-2008 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.bus; - -/** - * @author Marius Bogoevici - */ -public class TestMessageBusAwareImpl implements MessageBusAware { - - private MessageBus messageBus; - - public void setMessageBus(MessageBus messageBus) { - this.messageBus = messageBus; - } - - public MessageBus getMessageBus() { - return messageBus; - } - -} \ No newline at end of file diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml index 4dd8035451..eb0c31bab2 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml +++ b/org.springframework.integration/src/test/java/org/springframework/integration/bus/messageBusTests.xml @@ -29,10 +29,4 @@ - - - - - - diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/MessageBusParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/MessageBusParserTests.java index d776e20707..b3c8b97018 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/MessageBusParserTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/MessageBusParserTests.java @@ -33,7 +33,6 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.integration.bus.ApplicationContextMessageBus; import org.springframework.integration.bus.MessageBus; -import org.springframework.integration.bus.TestMessageBusAwareImpl; import org.springframework.integration.bus.MessageBusEventTests.TestMessageBusListener; import org.springframework.integration.config.xml.MessageBusParser; import org.springframework.integration.core.MessageChannel; @@ -85,12 +84,8 @@ public class MessageBusParserTests { } catch (BeanCreationException e) { exceptionThrown = true; - // an exception is thrown when creating the post-processor, which - // tries to get a reference to the message bus - assertEquals(BeanCreationException.class, e.getCause().getClass()); - assertEquals(e.getBeanName(), MessageBusParser.MESSAGE_BUS_AWARE_POST_PROCESSOR_BEAN_NAME); - assertEquals(IllegalStateException.class, (e.getCause()).getCause().getClass()); - assertEquals(((BeanCreationException) e.getCause()).getBeanName(), MessageBusParser.MESSAGE_BUS_BEAN_NAME); + assertEquals(IllegalStateException.class, e.getCause().getClass()); + assertEquals(e.getBeanName(), MessageBusParser.MESSAGE_BUS_BEAN_NAME); } assertTrue(exceptionThrown); } @@ -104,14 +99,6 @@ public class MessageBusParserTests { bus.stop(); } - @Test - public void testMessageBusAwareAutomaticallyAddedByNamespace() { - ApplicationContext context = new ClassPathXmlApplicationContext( - "messageBusWithMessageBusAware.xml", this.getClass()); - TestMessageBusAwareImpl messageBusAware = (TestMessageBusAwareImpl) context.getBean("messageBusAwareBean"); - assertTrue(messageBusAware.getMessageBus() == context.getBean(MessageBusParser.MESSAGE_BUS_BEAN_NAME)); - } - @Test public void testMulticasterIsSyncByDefault() { ApplicationContext context = new ClassPathXmlApplicationContext(