diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/HandlerParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/HandlerParser.java deleted file mode 100644 index 156972f32a..0000000000 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/HandlerParser.java +++ /dev/null @@ -1,128 +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.config; - -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.BeanDefinitionHolder; -import org.springframework.beans.factory.config.RuntimeBeanReference; -import org.springframework.beans.factory.parsing.BeanComponentDefinition; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.support.ManagedList; -import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.beans.factory.xml.BeanDefinitionParser; -import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.integration.handler.DefaultMessageHandler; -import org.springframework.integration.handler.MessageHandlerChain; -import org.springframework.util.StringUtils; - -/** - * Parser for the <handler/> element. - * - * @author Mark Fisher - */ -public class HandlerParser implements BeanDefinitionParser { - - private static final String HANDLER_CHAIN_ELEMENT = "handler-chain"; - - private static final String HANDLER_ELEMENT = "handler"; - - private static final String HANDLERS_PROPERTY = "handlers"; - - private static final String OBJECT_PROPERTY = "object"; - - private static final String METHOD_NAME_PROPERTY = "methodName"; - - - public BeanDefinition parse(Element element, ParserContext parserContext) { - if (HANDLER_CHAIN_ELEMENT.equals(element.getLocalName())) { - return this.parseHandlerChain(element, parserContext); - } - else if (HANDLER_ELEMENT.equals(element.getLocalName())) { - return this.parseHandler(element, parserContext, null); - } - return null; - } - - private BeanDefinition parseHandlerChain(Element element, ParserContext parserContext) { - RootBeanDefinition beanDefinition = new RootBeanDefinition(MessageHandlerChain.class); - ManagedList handlers = new ManagedList(); - NodeList childNodes = element.getChildNodes(); - for (int i = 0; i < childNodes.getLength(); i++) { - Node child = childNodes.item(i); - if (child.getNodeType() == Node.ELEMENT_NODE) { - String localName = child.getLocalName(); - if (HANDLER_ELEMENT.equals(localName)) { - parseHandler((Element) child, parserContext, handlers); - } - } - } - beanDefinition.getPropertyValues().addPropertyValue(HANDLERS_PROPERTY, handlers); - String id = element.getAttribute("id"); - String beanName = (StringUtils.hasText(id)) ? id : parserContext.getReaderContext().generateBeanName(beanDefinition); - parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, beanName)); - return beanDefinition; - } - - @SuppressWarnings("unchecked") - private BeanDefinition parseHandler(Element element, ParserContext parserContext, ManagedList handlers) { - boolean isInnerHandler = (handlers != null); - String ref = element.getAttribute("ref"); - String method = element.getAttribute("method"); - String id = element.getAttribute("id"); - if (!isInnerHandler && (!StringUtils.hasText(id) || !StringUtils.hasText(ref) || !StringUtils.hasText(method))) { - parserContext.getReaderContext().error("Top-level elements must provide 'id', 'ref', and 'method' attributes.", - parserContext.extractSource(element)); - } - if (isInnerHandler && StringUtils.hasText(id)) { - parserContext.getReaderContext().error("The 'id' attribute is only supported for top-level elements.", - parserContext.extractSource(element)); - } - if (StringUtils.hasText(method)) { - BeanDefinitionHolder bdh = this.parseHandlerAdapter(id, ref, method, parserContext, isInnerHandler); - if (handlers != null) { - handlers.add(bdh.getBeanDefinition()); - return null; - } - return bdh.getBeanDefinition(); - } - if (StringUtils.hasText(id)) { - parserContext.getReaderContext().error("The 'id' attribute is only supported for handler adapters (when 'method' is also provided).", - parserContext.extractSource(element)); - } - if (handlers != null) { - handlers.add(new RuntimeBeanReference(ref)); - } - return null; - } - - private BeanDefinitionHolder parseHandlerAdapter(String id, String handlerRef, String handlerMethod, ParserContext parserContext, boolean isInnerHandler) { - BeanDefinition handlerDef = new RootBeanDefinition(DefaultMessageHandler.class); - handlerDef.getPropertyValues().addPropertyValue(OBJECT_PROPERTY, new RuntimeBeanReference(handlerRef)); - handlerDef.getPropertyValues().addPropertyValue(METHOD_NAME_PROPERTY, handlerMethod); - String handlerBeanName = (StringUtils.hasText(id)) ? id : - BeanDefinitionReaderUtils.generateBeanName(handlerDef, parserContext.getRegistry(), isInnerHandler); - if (!isInnerHandler) { - parserContext.registerBeanComponent(new BeanComponentDefinition(handlerDef, handlerBeanName)); - } - return new BeanDefinitionHolder(handlerDef, handlerBeanName); - } - -} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java index 15b6c69837..297619bdf2 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/IntegrationNamespaceHandler.java @@ -55,8 +55,6 @@ public class IntegrationNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("service-activator", new ServiceActivatorParser()); registerBeanDefinitionParser("channel-adapter", new ChannelAdapterParser()); registerBeanDefinitionParser("gateway", new GatewayParser()); - registerBeanDefinitionParser("handler", new HandlerParser()); - registerBeanDefinitionParser("handler-chain", new HandlerParser()); registerBeanDefinitionParser("selector-chain", new SelectorChainParser()); registerBeanDefinitionParser("router", new RouterParser()); registerBeanDefinitionParser("splitter", new SplitterParser()); diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/EndpointParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/EndpointParserTests.java index b84dc4248a..99ec92e286 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/EndpointParserTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/EndpointParserTests.java @@ -27,7 +27,6 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.channel.MessageChannel; -import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.message.Message; @@ -54,31 +53,6 @@ public class EndpointParserTests { assertEquals("test", handler.getMessageString()); } - @Test - public void testHandlerAdapterEndpoint() throws InterruptedException { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "handlerAdapterEndpointTests.xml", this.getClass()); - context.start(); - MessageChannel channel = (MessageChannel) context.getBean("testChannel"); - TestBean bean = (TestBean) context.getBean("testBean"); - assertNull(bean.getMessage()); - channel.send(new GenericMessage("test")); - bean.getLatch().await(500, TimeUnit.MILLISECONDS); - assertEquals("test", bean.getMessage()); - } - - @Test - public void testHandlerChainEndpoint() throws InterruptedException { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "endpointWithHandlerChainElement.xml", this.getClass()); - MessageChannel channel = (MessageChannel) context.getBean("testChannel"); - PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel"); - channel.send(new StringMessage("test")); - Message reply = replyChannel.receive(500); - assertNotNull(reply); - assertEquals("test-1-2-3", reply.getPayload()); - } - @Test public void testEndpointWithSelectorAccepts() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/HandlerParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/HandlerParserTests.java deleted file mode 100644 index f9831d37e8..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/HandlerParserTests.java +++ /dev/null @@ -1,62 +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.config; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.handler.MessageHandler; -import org.springframework.integration.message.Message; -import org.springframework.integration.message.StringMessage; - -/** - * @author Mark Fisher - */ -public class HandlerParserTests { - - @Test - public void testTopLevelHandlerAdapter() { - ApplicationContext context = new ClassPathXmlApplicationContext( - "handlerAdapterParserTests.xml", HandlerParserTests.class); - MessageHandler adapter = (MessageHandler) context.getBean("handlerAdapter"); - assertNotNull(adapter); - Message reply = adapter.handle(new StringMessage("foo")); - assertNotNull(reply); - assertEquals("bar", reply.getPayload()); - } - - @Test - public void testHandlerChain() { - ApplicationContext context = new ClassPathXmlApplicationContext( - "handlerChainParserTests.xml", HandlerParserTests.class); - TestBean testBean = (TestBean) context.getBean("testBean"); - assertNull(testBean.getMessage()); - MessageHandler handlerChain = (MessageHandler) context.getBean("handlerChain"); - assertNotNull(handlerChain); - Message reply = handlerChain.handle(new StringMessage("test")); - assertNotNull(reply); - assertEquals(0, testBean.getLatch().getCount()); - assertEquals("foo", testBean.getMessage()); - assertEquals("bar", reply.getPayload()); - } - -} diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/endpointWithHandlerChainElement.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/endpointWithHandlerChainElement.xml deleted file mode 100644 index a5282e4693..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/endpointWithHandlerChainElement.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerAdapterEndpointTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerAdapterEndpointTests.xml deleted file mode 100644 index c11ef8e20d..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerAdapterEndpointTests.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerAdapterParserTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerAdapterParserTests.xml deleted file mode 100644 index 6e9148a8a9..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerAdapterParserTests.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerChainParserTests.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerChainParserTests.xml deleted file mode 100644 index a54c85928d..0000000000 --- a/org.springframework.integration/src/test/java/org/springframework/integration/config/handlerChainParserTests.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - -