diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java index e866a634f1..2ff7c34bd9 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/AbstractOutboundChannelAdapterParser.java @@ -46,6 +46,7 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann IntegrationNamespaceUtils.configurePollerMetadata(pollerElement, builder, parserContext); } builder.addPropertyValue("inputChannelName", channelName); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); return builder.getBeanDefinition(); } @@ -60,6 +61,10 @@ public abstract class AbstractOutboundChannelAdapterParser extends AbstractChann parserContext.getReaderContext().error( "Consumer parsing must return a BeanDefinition.", element); } + String order = element.getAttribute("order"); + if (StringUtils.hasText(order)) { + definition.getPropertyValues().addPropertyValue("order", order); + } return BeanDefinitionReaderUtils.registerWithGeneratedName( definition, parserContext.getRegistry()); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParser.java index 29809e7909..7790249e5e 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParser.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -50,6 +50,10 @@ public class MethodInvokingOutboundChannelAdapterParser extends AbstractOutbound IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.MethodInvokingMessageHandler"); invokerBuilder.addConstructorArgReference(element.getAttribute("ref")); invokerBuilder.addConstructorArgValue(element.getAttribute("method")); + String order = element.getAttribute("order"); + if (StringUtils.hasText(order)) { + invokerBuilder.addPropertyValue("order", order); + } return invokerBuilder.getBeanDefinition(); } diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java index 85cedddc71..a72ac07aa0 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -18,6 +18,7 @@ package org.springframework.integration.handler; import java.lang.reflect.Method; +import org.springframework.core.Ordered; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessagingException; import org.springframework.integration.message.MessageHandler; @@ -28,7 +29,10 @@ import org.springframework.util.Assert; * * @author Mark Fisher */ -public class MethodInvokingMessageHandler extends MessageMappingMethodInvoker implements MessageHandler { +public class MethodInvokingMessageHandler extends MessageMappingMethodInvoker implements MessageHandler, Ordered { + + private volatile int order = Ordered.LOWEST_PRECEDENCE; + public MethodInvokingMessageHandler(Object object, Method method) { super(object, method); @@ -41,6 +45,14 @@ public class MethodInvokingMessageHandler extends MessageMappingMethodInvoker im } + public void setOrder(int order) { + this.order = order; + } + + public int getOrder() { + return this.order; + } + public void handleMessage(Message message) { Object result = this.invokeMethod(message); if (result != null) { diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd index 53eba8384c..e9d7b87e33 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-1.0.xsd @@ -26,13 +26,9 @@ - Defines the ApplicationEventMulticaster to use - for this - ApplicationContext. The "task-executor" reference is - optional. - If not provided, an instance of ThreadPoolTaskExecutor - will be - created by default. + Defines the ApplicationEventMulticaster to use for this ApplicationContext. + The "task-executor" reference is optional. If not provided, an instance of + ThreadPoolTaskExecutor will be created by default. @@ -273,14 +269,27 @@ - + - Defines a Channel Adapter that receives from a - MessageChannel and sends to - a MessageConsumer. + Defines a Channel Adapter that receives from a MessageChannel and sends to + a method-invoking MessageHandler. + + + + + + + Specifies the order for invocation when this endpoint is connected as a + subscriber to a SubscribableChannel. + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParserTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParserTests-context.xml new file mode 100644 index 0000000000..85998bb675 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParserTests-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParserTests.java new file mode 100644 index 0000000000..e06a4240c0 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/MethodInvokingOutboundChannelAdapterParserTests.java @@ -0,0 +1,61 @@ +/* + * Copyright 2002-2009 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.config.xml; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.junit.runner.RunWith; + +import org.springframework.beans.DirectFieldAccessor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.handler.MethodInvokingMessageHandler; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class MethodInvokingOutboundChannelAdapterParserTests { + + @Autowired + private ApplicationContext context; + + + @Test + public void checkConfig() { + Object adapter = context.getBean("adapter"); + DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); + Object handler = adapterAccessor.getPropertyValue("handler"); + assertEquals(MethodInvokingMessageHandler.class, handler.getClass()); + DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler); + assertEquals(99, handlerAccessor.getPropertyValue("order")); + assertEquals(Boolean.FALSE, adapterAccessor.getPropertyValue("autoStartup")); + } + + + static class TestBean { + + public void out(Object o) { + } + + } +}