From 292aa90599757e43edda27d26578795d5749638d Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 17 Jan 2012 09:23:35 -0500 Subject: [PATCH] INT-2404 Fix Auto-Created Channel; Event, TCP, UDP The AbstractChannelAdapterParser creates an implicit DirectChannel if the adapter has no 'channel' attribute. The Event, TCP, and UDP channel adapter parsers did not bind this channel to the adapter and AC initialization failed with 'outputChannel is required'. Further, the event schema marked the channel as being 'required', precluding this feature. INT-2407 Remove Channel use="required" Parsers automatically generate the channel when none is provided. - JMX - JDBC - SFTP - Redis - Feed - XMPP - Mail - FTP - HTTP --- .../EventInboundChannelAdapterParser.java | 9 +++-- .../config/spring-integration-event-2.0.xsd | 2 +- .../config/spring-integration-event-2.1.xsd | 2 +- ...boundChannelAdapterParserTests-context.xml | 4 ++ ...EventInboundChannelAdapterParserTests.java | 14 ++++++- .../config/spring-integration-feed-2.1.xsd | 2 +- ...AdapterParserTests-autoChannel-context.xml | 17 +++++++++ .../FeedInboundChannelAdapterParserTests.java | 12 ++++++ .../ftp/config/spring-integration-ftp-2.1.xsd | 2 +- ...boundChannelAdapterParserTests-context.xml | 9 +++++ .../FtpInboundChannelAdapterParserTests.java | 14 ++++++- .../config/HttpInboundEndpointParser.java | 31 +++++++++++++-- .../config/spring-integration-http-2.1.xsd | 4 +- ...boundChannelAdapterParserTests-context.xml | 9 +++++ .../HttpInboundChannelAdapterParserTests.java | 14 ++++++- .../TcpInboundChannelAdapterParser.java | 11 ++---- .../UdpInboundChannelAdapterParser.java | 15 +++----- .../ip/config/ParserUnitTests-context.xml | 8 ++++ .../ip/config/ParserUnitTests.java | 23 ++++++++++- .../config/spring-integration-jdbc-2.1.xsd | 8 ++-- .../JdbcPollingChannelAdapterParserTests.java | 19 +++++++++- ...dProcPollingChannelAdapterParserTests.java | 25 ++++++++---- ...llingChannelAdapterParserTests-context.xml | 18 +++++++++ ...redProcPollingChannelAdapterParserTest.xml | 21 +++++++++- ...ficationListeningChannelAdapterParser.java | 30 ++++++--------- .../jmx/config/spring-integration-jmx-2.1.xsd | 2 +- ...llingChannelAdapterParserTests-context.xml | 9 +++++ ...ibutePollingChannelAdapterParserTests.java | 18 ++++++++- ...eningChannelAdapterParserTests-context.xml | 5 +++ ...ionListeningChannelAdapterParserTests.java | 15 ++++++++ .../config/ImapIdleChannelAdapterParser.java | 38 ++++++------------- .../config/spring-integration-mail-2.1.xsd | 2 +- ...pIdleChannelAdapterParserTests-context.xml | 8 ++++ .../ImapIdleChannelAdapterParserTests.java | 13 +++++++ ...boundChannelAdapterParserTests-context.xml | 5 +++ .../InboundChannelAdapterParserTests.java | 20 ++++++++-- .../RedisInboundChannelAdapterParser.java | 4 +- .../config/spring-integration-redis-2.1.xsd | 2 +- ...boundChannelAdapterParserTests-context.xml | 6 +++ ...RedisInboundChannelAdapterParserTests.java | 24 +++++++++--- .../config/spring-integration-sftp-2.1.xsd | 2 +- ...boundChannelAdapterParserTests-context.xml | 13 ++++++- .../InboundChannelAdapterParserTests.java | 15 +++++++- ...stractXmppInboundChannelAdapterParser.java | 26 +++++++------ .../config/spring-integration-xmpp-2.1.xsd | 2 +- ...boundChannelAdapterParserTests-context.xml | 13 +++++-- ...ssageInboundChannelAdapterParserTests.java | 22 ++++++++--- 47 files changed, 457 insertions(+), 130 deletions(-) create mode 100644 spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests-autoChannel-context.xml create mode 100644 spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/autoChannelJdbcPollingChannelAdapterParserTests-context.xml diff --git a/spring-integration-event/src/main/java/org/springframework/integration/event/config/EventInboundChannelAdapterParser.java b/spring-integration-event/src/main/java/org/springframework/integration/event/config/EventInboundChannelAdapterParser.java index 772b32f6bf..c747dd338d 100644 --- a/spring-integration-event/src/main/java/org/springframework/integration/event/config/EventInboundChannelAdapterParser.java +++ b/spring-integration-event/src/main/java/org/springframework/integration/event/config/EventInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -23,6 +23,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer; /** * @author Oleg Zhurakousky @@ -34,9 +35,9 @@ public class EventInboundChannelAdapterParser extends AbstractChannelAdapterPars @Override protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { - BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder.rootBeanDefinition( - "org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(adapterBuilder, element, "channel", "outputChannel"); + BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder + .rootBeanDefinition(ApplicationEventListeningMessageProducer.class); + adapterBuilder.addPropertyReference("outputChannel", channelName); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(adapterBuilder, element, "error-channel", "errorChannel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "event-types"); IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "payload-expression"); diff --git a/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd b/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd index 2f14520520..b8b32777a7 100644 --- a/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd +++ b/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd @@ -25,7 +25,7 @@ - + diff --git a/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.1.xsd b/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.1.xsd index df96a6dfbf..27a0005d24 100644 --- a/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.1.xsd +++ b/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.1.xsd @@ -25,7 +25,7 @@ - + diff --git a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests-context.xml b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests-context.xml index a70ea3de3d..9de4ac2bb9 100644 --- a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests-context.xml @@ -38,6 +38,10 @@ + + + + diff --git a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java index aaed912127..d59fd2b54c 100644 --- a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java +++ b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -19,6 +19,7 @@ package org.springframework.integration.event.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.util.Properties; @@ -31,6 +32,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.event.ContextRefreshedEvent; @@ -60,6 +62,12 @@ public class EventInboundChannelAdapterParserTests { @Autowired MessageChannel errorChannel; + @Autowired + MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + ApplicationEventListeningMessageProducer eventListener; + @Test public void validateEventParser() { Object adapter = context.getBean("eventAdapterSimple"); @@ -126,6 +134,10 @@ public class EventInboundChannelAdapterParserTests { Assert.assertEquals("source + '-test'", expression.getExpressionString()); } + @Test + public void testAutoCreateChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(eventListener, "outputChannel")); + } @SuppressWarnings("serial") public static class SampleEvent extends ApplicationEvent { diff --git a/spring-integration-feed/src/main/resources/org/springframework/integration/feed/config/spring-integration-feed-2.1.xsd b/spring-integration-feed/src/main/resources/org/springframework/integration/feed/config/spring-integration-feed-2.1.xsd index 1cce09172f..9831c0df12 100644 --- a/spring-integration-feed/src/main/resources/org/springframework/integration/feed/config/spring-integration-feed-2.1.xsd +++ b/spring-integration-feed/src/main/resources/org/springframework/integration/feed/config/spring-integration-feed-2.1.xsd @@ -30,7 +30,7 @@ - + diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests-autoChannel-context.xml b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests-autoChannel-context.xml new file mode 100644 index 0000000000..fe10c0640e --- /dev/null +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests-autoChannel-context.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java index cbae2bf856..4d04bbb92f 100644 --- a/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/config/FeedInboundChannelAdapterParserTests.java @@ -18,6 +18,7 @@ package org.springframework.integration.feed.config; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertSame; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; @@ -36,6 +37,7 @@ import org.mockito.Mockito; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; import org.springframework.integration.MessagingException; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.core.MessageHandler; @@ -52,6 +54,7 @@ import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher; /** * @author Oleg Zhurakousky * @author Mark Fisher + * @author Gary Russell * @since 2.0 */ public class FeedInboundChannelAdapterParserTests { @@ -154,6 +157,15 @@ public class FeedInboundChannelAdapterParserTests { verify(handler, atLeast(3)).handleMessage(Mockito.any(Message.class)); } + @Test + public void testAutoChannel() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "FeedInboundChannelAdapterParserTests-autoChannel-context.xml", this.getClass()); + MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class); + SourcePollingChannelAdapter adapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class); + assertSame(autoChannel, TestUtils.getPropertyValue(adapter, "outputChannel")); + context.destroy(); + } public static class SampleService { diff --git a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.1.xsd b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.1.xsd index 6a41e6f757..cc428587de 100644 --- a/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.1.xsd +++ b/spring-integration-ftp/src/main/resources/org/springframework/integration/ftp/config/spring-integration-ftp-2.1.xsd @@ -388,7 +388,7 @@ - + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml index a559a0c6bc..c5b39ac817 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests-context.xml @@ -60,4 +60,13 @@ + + + + + + diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java index 886032a641..7049eee7d3 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -33,6 +34,7 @@ import org.junit.Test; import org.springframework.beans.factory.FactoryBean; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.MessageChannel; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.file.remote.session.CachingSessionFactory; import org.springframework.integration.file.remote.session.Session; @@ -45,6 +47,7 @@ import org.springframework.integration.test.util.TestUtils; /** * @author Oleg Zhurakousky * @author Mark Fisher + * @author Gary Russell */ public class FtpInboundChannelAdapterParserTests { @@ -105,6 +108,15 @@ public class FtpInboundChannelAdapterParserTests { assertNotNull(adapter); } + @Test + public void testAutoChannel() { + ApplicationContext context = + new ClassPathXmlApplicationContext("FtpInboundChannelAdapterParserTests-context.xml", this.getClass()); + // Auto-created channel + MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class); + SourcePollingChannelAdapter autoChannelAdapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class); + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } public static class TestSessionFactoryBean implements FactoryBean { diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java index 8a648d0816..65b315a0e7 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -19,6 +19,7 @@ package org.springframework.integration.http.config; import java.util.List; import org.springframework.beans.factory.BeanDefinitionStoreException; +import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; @@ -26,6 +27,7 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.config.ExpressionFactoryBean; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.util.CollectionUtils; @@ -41,6 +43,7 @@ import org.w3c.dom.Element; * * @author Mark Fisher * @author Oleg Zhurakousky + * @author Gary Russell */ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParser { @@ -65,11 +68,16 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse String id = super.resolveId(element, definition, parserContext); if (!StringUtils.hasText(id)) { id = element.getAttribute("name"); + } else { + if (!element.hasAttribute(getInputChannelAttributeName())) { + // the created channel will get the 'id', so the adapter's bean name includes a suffix + id = id + ".adapter"; + } } if (!StringUtils.hasText(id)) { id = BeanDefinitionReaderUtils.generateBeanName(definition, parserContext.getRegistry()); } - + return id; } @@ -79,8 +87,12 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse String inputChannelAttributeName = this.getInputChannelAttributeName(); String inputChannelRef = element.getAttribute(inputChannelAttributeName); if (!StringUtils.hasText(inputChannelRef)) { - parserContext.getReaderContext().error( - "a '" + inputChannelAttributeName + "' reference is required", element); + if (this.expectReply) { + parserContext.getReaderContext().error( + "a '" + inputChannelAttributeName + "' reference is required", element); + } else { + inputChannelRef = createDirectChannel(element, parserContext); + } } builder.addPropertyReference("requestChannel", inputChannelRef); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel"); @@ -158,4 +170,15 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse return this.expectReply ? "request-channel" : "channel"; } + private String createDirectChannel(Element element, ParserContext parserContext) { + String channelId = element.getAttribute("id"); + if (!StringUtils.hasText(channelId)) { + parserContext.getReaderContext().error("The channel-adapter's 'id' attribute is required when no 'channel' " + + "reference has been provided, because that 'id' would be used for the created channel.", element); + } + BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); + BeanDefinitionHolder holder = new BeanDefinitionHolder(channelBuilder.getBeanDefinition(), channelId); + BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry()); + return channelId; + } } diff --git a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd index 4d4a0c1a08..a385c2b797 100644 --- a/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd +++ b/spring-integration-http/src/main/resources/org/springframework/integration/http/config/spring-integration-http-2.1.xsd @@ -32,7 +32,7 @@ - + @@ -284,7 +284,7 @@ The String "HTTP_REQUEST_HEADERS" will match against any of the standard HTTP Re - + diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml index dff2dee5a0..5ffa7f9453 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests-context.xml @@ -50,4 +50,13 @@
+ +
+ + + + diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java index 79dba5ae36..2f38007eb3 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -19,6 +19,7 @@ package org.springframework.integration.http.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; @@ -40,6 +41,7 @@ import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.http.MockHttpServletRequest; @@ -56,6 +58,7 @@ import org.springframework.util.MultiValueMap; /** * @author Mark Fisher * @author Oleg Zhurakousky + * @author Gary Russell */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @@ -90,6 +93,11 @@ public class HttpInboundChannelAdapterParserTests { @Autowired private HttpRequestHandlingController inboundController; + @Autowired + private MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + private HttpRequestHandlingMessagingGateway autoChannelAdapter; @Test @SuppressWarnings("unchecked") @@ -259,6 +267,10 @@ public class HttpInboundChannelAdapterParserTests { assertEquals("oops", errorCode); } + @Test + public void testAutoChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "requestChannel")); + } @SuppressWarnings("serial") private static class TestObject implements Serializable { diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpInboundChannelAdapterParser.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpInboundChannelAdapterParser.java index a70b4d2770..d58c7a253a 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpInboundChannelAdapterParser.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/TcpInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -21,6 +21,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter; import org.w3c.dom.Element; /** @@ -31,15 +32,11 @@ import org.w3c.dom.Element; */ public class TcpInboundChannelAdapterParser extends AbstractChannelAdapterParser { - private static final String BASE_PACKAGE = "org.springframework.integration.ip.tcp"; - protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BASE_PACKAGE + - ".TcpReceivingChannelAdapter"); + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(TcpReceivingChannelAdapter.class); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, IpAdapterParserUtils.TCP_CONNECTION_FACTORY); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, - element, "channel", "outputChannel"); + builder.addPropertyReference("outputChannel", channelName); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel", "errorChannel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/UdpInboundChannelAdapterParser.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/UdpInboundChannelAdapterParser.java index 127774e1d1..096dc48046 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/UdpInboundChannelAdapterParser.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/config/UdpInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -21,6 +21,8 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.integration.ip.udp.MulticastReceivingChannelAdapter; +import org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter; import org.springframework.util.StringUtils; import org.w3c.dom.Element; @@ -32,8 +34,6 @@ import org.w3c.dom.Element; */ public class UdpInboundChannelAdapterParser extends AbstractChannelAdapterParser { - private static final String BASE_PACKAGE = "org.springframework.integration.ip.udp"; - protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { BeanDefinitionBuilder builder = parseUdp(element, parserContext); IpAdapterParserUtils.addCommonSocketOptions(builder, element); @@ -41,8 +41,7 @@ public class UdpInboundChannelAdapterParser extends AbstractChannelAdapterParser IpAdapterParserUtils.RECEIVE_BUFFER_SIZE); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IpAdapterParserUtils.POOL_SIZE); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, - element, "channel", "outputChannel"); + builder.addPropertyReference("outputChannel", channelName); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel", "errorChannel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, @@ -72,12 +71,10 @@ public class UdpInboundChannelAdapterParser extends AbstractChannelAdapterParser BeanDefinitionBuilder builder; String multicast = IpAdapterParserUtils.getMulticast(element); if (multicast.equals("false")) { - builder = BeanDefinitionBuilder.genericBeanDefinition(BASE_PACKAGE + - ".UnicastReceivingChannelAdapter"); + builder = BeanDefinitionBuilder.genericBeanDefinition(UnicastReceivingChannelAdapter.class); } else { - builder = BeanDefinitionBuilder.genericBeanDefinition(BASE_PACKAGE + - ".MulticastReceivingChannelAdapter"); + builder = BeanDefinitionBuilder.genericBeanDefinition(MulticastReceivingChannelAdapter.class); String mcAddress = element .getAttribute(IpAdapterParserUtils.MULTICAST_ADDRESS); if (!StringUtils.hasText(mcAddress)) { diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests-context.xml b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests-context.xml index 705e0fc76f..998c9eb771 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests-context.xml +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests-context.xml @@ -331,4 +331,12 @@ + + + + + + + + \ No newline at end of file diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java index ebb5e9ed4b..26f5536cb0 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -195,6 +195,18 @@ public class ParserUnitTests { @Qualifier(value="org.springframework.integration.ip.tcp.TcpSendingMessageHandler#3") TcpSendingMessageHandler tcpOutClientMode; + @Autowired + MessageChannel tcpAutoChannel; + + @Autowired + MessageChannel udpAutoChannel; + + @Autowired @Qualifier("tcpAutoChannel.adapter") + TcpReceivingChannelAdapter tcpAutoAdapter; + + @Autowired @Qualifier("udpAutoChannel.adapter") + UnicastReceivingChannelAdapter udpAutoAdapter; + @Test public void testInUdp() { DirectFieldAccessor dfa = new DirectFieldAccessor(udpIn); @@ -518,4 +530,13 @@ public class ParserUnitTests { assertEquals(125000L, dfa.getPropertyValue("retryInterval")); } + @Test + public void testAutoTcp() { + assertSame(tcpAutoChannel, TestUtils.getPropertyValue(tcpAutoAdapter, "outputChannel")); + } + + @Test + public void testAutoUdp() { + assertSame(udpAutoChannel, TestUtils.getPropertyValue(udpAutoAdapter, "outputChannel")); + } } diff --git a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd index 0beea9e102..c44b8296a4 100644 --- a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd +++ b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd @@ -178,7 +178,7 @@ - + @@ -267,7 +267,7 @@ - + @@ -681,7 +681,7 @@ - + @@ -1096,7 +1096,7 @@ - + Channel to which polled messages will be send. If the stored diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParserTests.java index e618fd1fc9..f7d53c217a 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParserTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -19,6 +19,7 @@ package org.springframework.integration.jdbc.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.util.List; @@ -32,8 +33,10 @@ import org.junit.Test; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; import org.springframework.integration.core.MessagingTemplate; import org.springframework.integration.core.PollableChannel; +import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.test.util.TestUtils; import org.springframework.jdbc.core.JdbcTemplate; @@ -43,6 +46,12 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; +/** + * @author David Syer + * @author Gary Russell + * @since 2.0 + * + */ // Not transactional because the poller threads need access to the data // @Transactional public class JdbcPollingChannelAdapterParserTests { @@ -149,6 +158,14 @@ public class JdbcPollingChannelAdapterParserTests { } } + @Test + public void testAutoChannel() { + setUp("autoChannelJdbcPollingChannelAdapterParserTests-context.xml", getClass()); + MessageChannel autoChannel = appCtx.getBean("autoChannel", MessageChannel.class); + SourcePollingChannelAdapter autoChannelAdapter = appCtx.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class); + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } + @After public void tearDown() { if (appCtx != null) { diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java index 4743a021bb..0b1971f62e 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/StoredProcPollingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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 @@ -13,6 +13,12 @@ package org.springframework.integration.jdbc.config; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import java.sql.Types; import java.util.List; import java.util.Map; @@ -20,25 +26,22 @@ import java.util.Map.Entry; import org.junit.After; import org.junit.Test; - import org.springframework.beans.DirectFieldAccessor; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.MessageChannel; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.jdbc.storedproc.PrimeMapper; import org.springframework.integration.jdbc.storedproc.ProcedureParameter; +import org.springframework.integration.test.util.TestUtils; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SqlInOutParameter; import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlParameter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - /** * @author Gunnar Hillert + * @author Gary Russell * @since 2.1 * */ @@ -185,6 +188,14 @@ public class StoredProcPollingChannelAdapterParserTests { } + @Test + public void testAutoChannel() throws Exception { + setUp("storedProcPollingChannelAdapterParserTest.xml", getClass()); + MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class); + SourcePollingChannelAdapter autoChannelAdapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class); + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } + @After public void tearDown(){ if(context != null){ diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/autoChannelJdbcPollingChannelAdapterParserTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/autoChannelJdbcPollingChannelAdapterParserTests-context.xml new file mode 100644 index 0000000000..9d2c0d2018 --- /dev/null +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/autoChannelJdbcPollingChannelAdapterParserTests-context.xml @@ -0,0 +1,18 @@ + + + + + + + + + + diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/storedProcPollingChannelAdapterParserTest.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/storedProcPollingChannelAdapterParserTest.xml index 59bb1c0cc5..deb68e566c 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/storedProcPollingChannelAdapterParserTest.xml +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/storedProcPollingChannelAdapterParserTest.xml @@ -19,7 +19,7 @@ - + @@ -29,4 +29,23 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParser.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParser.java index 06bdfe53a8..df0dc8d74d 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParser.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -16,19 +16,20 @@ package org.springframework.integration.jmx.config; -import org.w3c.dom.Element; - +import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.xml.AbstractChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; -import org.springframework.util.StringUtils; +import org.springframework.integration.jmx.NotificationListeningMessageProducer; +import org.w3c.dom.Element; /** * @author Mark Fisher + * @author Gary Russell * @since 2.0 */ -public class NotificationListeningChannelAdapterParser extends AbstractSimpleBeanDefinitionParser { +public class NotificationListeningChannelAdapterParser extends AbstractChannelAdapterParser { @Override protected boolean shouldGenerateIdAsFallback() { @@ -36,23 +37,16 @@ public class NotificationListeningChannelAdapterParser extends AbstractSimpleBea } @Override - protected String getBeanClassName(Element element) { - return "org.springframework.integration.jmx.NotificationListeningMessageProducer"; - } - - @Override - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - Object source = parserContext.extractSource(element); - String channel = element.getAttribute("channel"); - if (!StringUtils.hasText(channel)) { - parserContext.getReaderContext().error("The 'channel' attribute is required.", source); - } - builder.addPropertyReference("outputChannel", channel); + protected AbstractBeanDefinition doParse(Element element, + ParserContext parserContext, String channelName) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(NotificationListeningMessageProducer.class); + builder.addPropertyReference("outputChannel", channelName); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "server"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "notification-filter", "filter"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "handback"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "object-name"); + return builder.getBeanDefinition(); } } diff --git a/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.1.xsd b/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.1.xsd index ea3ebea259..310736d3d6 100644 --- a/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.1.xsd +++ b/spring-integration-jmx/src/main/resources/org/springframework/integration/jmx/config/spring-integration-jmx-2.1.xsd @@ -149,7 +149,7 @@ - + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests-context.xml index a393f0ad92..ba38340cc8 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests-context.xml @@ -30,4 +30,13 @@ + + + + + + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java index 26ea48543f..11229ce02c 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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,19 +18,23 @@ package org.springframework.integration.jmx.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; import org.junit.Test; import org.junit.runner.RunWith; - import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; +import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Fisher + * @author Gary Russell * @since 2.0 */ @ContextConfiguration @@ -46,6 +50,11 @@ public class AttributePollingChannelAdapterParserTests { @Autowired private TestBean testBean; + @Autowired + private MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + private SourcePollingChannelAdapter autoChannelAdapter; @Test public void pollForAttribute() throws Exception { @@ -56,4 +65,9 @@ public class AttributePollingChannelAdapterParserTests { assertEquals("foo", result.getPayload()); } + @Test + public void testAutoChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } + } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests-context.xml b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests-context.xml index 27a9a1d92c..9f4f7fa54b 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests-context.xml +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests-context.xml @@ -26,4 +26,9 @@ + + + + diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java index 5cff64a9b9..6c0ed7e581 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java @@ -19,14 +19,19 @@ package org.springframework.integration.jmx.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import javax.management.Notification; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.Message; +import org.springframework.integration.MessageChannel; import org.springframework.integration.core.PollableChannel; +import org.springframework.integration.jmx.NotificationListeningMessageProducer; +import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -44,6 +49,11 @@ public class NotificationListeningChannelAdapterParserTests { @Autowired private TestPublisher testPublisher; + @Autowired + private MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + private NotificationListeningMessageProducer autoChannelAdapter; @Test public void receiveNotification() throws Exception { @@ -55,4 +65,9 @@ public class NotificationListeningChannelAdapterParserTests { assertEquals("ABC", ((Notification) message.getPayload()).getMessage()); } + @Test + public void testAutoChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } + } diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java index 567f3e83bd..ac8b83b003 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -16,16 +16,17 @@ package org.springframework.integration.mail.config; -import org.w3c.dom.Element; - import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.xml.AbstractChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; -import org.springframework.util.Assert; +import org.springframework.integration.mail.ImapIdleChannelAdapter; +import org.springframework.integration.mail.ImapMailReceiver; import org.springframework.util.StringUtils; +import org.w3c.dom.Element; /** * Parser for the <imap-idle-channel-adapter> element in the 'mail' namespace. @@ -35,34 +36,19 @@ import org.springframework.util.StringUtils; * @author Oleg Zhurakousky * @author Gary Russell */ -public class ImapIdleChannelAdapterParser extends AbstractSingleBeanDefinitionParser { +public class ImapIdleChannelAdapterParser extends AbstractChannelAdapterParser { - private static final String BASE_PACKAGE = "org.springframework.integration.mail"; - - - protected String getBeanClassName(Element element) { - return BASE_PACKAGE + ".ImapIdleChannelAdapter"; - } - - protected boolean shouldGenerateId() { - return false; - } - - protected boolean shouldGenerateIdAsFallback() { - return true; - } - - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - String channel = element.getAttribute("channel"); - Assert.hasText(channel, "the 'channel' attribute is required"); + protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ImapIdleChannelAdapter.class); builder.addConstructorArgValue(this.parseImapMailReceiver(element, parserContext)); - builder.addPropertyReference("outputChannel", channel); + builder.addPropertyReference("outputChannel", channelName); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel", "errorChannel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); + return builder.getBeanDefinition(); } private BeanDefinition parseImapMailReceiver(Element element, ParserContext parserContext) { - BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(BASE_PACKAGE + ".ImapMailReceiver"); + BeanDefinitionBuilder receiverBuilder = BeanDefinitionBuilder.genericBeanDefinition(ImapMailReceiver.class); Object source = parserContext.extractSource(element); String uri = element.getAttribute("store-uri"); if (StringUtils.hasText(uri)) { diff --git a/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.1.xsd b/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.1.xsd index 2bbbf0f1d1..18fe4825f3 100644 --- a/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.1.xsd +++ b/spring-integration-mail/src/main/resources/org/springframework/integration/mail/config/spring-integration-mail-2.1.xsd @@ -135,7 +135,7 @@ - + Reference for the MessageChannel to which this adapter will send Messages. diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml index 0336122b98..02dc65116f 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests-context.xml @@ -71,4 +71,12 @@ + + + + \ No newline at end of file diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java index 4a99d2024f..33721cb21b 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java @@ -28,9 +28,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; +import org.springframework.integration.MessageChannel; import org.springframework.integration.mail.ImapIdleChannelAdapter; import org.springframework.integration.mail.ImapMailReceiver; +import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -46,6 +49,11 @@ public class ImapIdleChannelAdapterParserTests { @Autowired private ApplicationContext context; + @Autowired + private MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + private ImapIdleChannelAdapter autoChannelAdapter; @Test public void simpleAdapter() { @@ -140,4 +148,9 @@ public class ImapIdleChannelAdapterParserTests { assertEquals("bar", properties.getProperty("foo")); assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("shouldDeleteMessages")); } + + @Test + public void testAutoChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } } diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml index ab5f299125..f02d36a6da 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests-context.xml @@ -98,6 +98,11 @@ + + + + + diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java index b3ca495135..a7a8d1e89a 100644 --- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java +++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/InboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -27,19 +28,22 @@ import javax.mail.Authenticator; import org.junit.Test; import org.junit.runner.RunWith; -import org.xml.sax.SAXParseException; - import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.MessageChannel; +import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.mail.AbstractMailReceiver; import org.springframework.integration.mail.ImapIdleChannelAdapter; import org.springframework.integration.mail.ImapMailReceiver; import org.springframework.integration.mail.Pop3MailReceiver; +import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.xml.sax.SAXParseException; /** * @author Mark Fisher @@ -53,6 +57,11 @@ public class InboundChannelAdapterParserTests { @Autowired private ApplicationContext context; + @Autowired + private MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + private SourcePollingChannelAdapter autoChannelAdapter; //==================== INT-982 ===================== @@ -283,4 +292,9 @@ public class InboundChannelAdapterParserTests { return (AbstractMailReceiver) new DirectFieldAccessor(target).getPropertyValue("mailReceiver"); } + @Test + public void testAutoChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } + } diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java index 6de909eff2..8e84e01fec 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java @@ -16,7 +16,6 @@ package org.springframework.integration.redis.config; -import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; @@ -28,6 +27,7 @@ import org.w3c.dom.Element; /** * @author Oleg Zhurakousky * @author Mark Fisher + * @author Gary Russell * @since 2.1 */ public class RedisInboundChannelAdapterParser extends AbstractChannelAdapterParser { @@ -41,7 +41,7 @@ public class RedisInboundChannelAdapterParser extends AbstractChannelAdapterPars connectionFactory = "redisConnectionFactory"; } builder.addConstructorArgReference(connectionFactory); - builder.addPropertyValue("outputChannel", new RuntimeBeanReference(channelName)); + builder.addPropertyReference("outputChannel", channelName); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "topics"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter"); diff --git a/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-2.1.xsd b/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-2.1.xsd index 2e0cb7049e..27473801f1 100644 --- a/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-2.1.xsd +++ b/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-2.1.xsd @@ -173,7 +173,7 @@ - + Channel to which Messages will be sent. diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml index 7b0ddbcea3..31a60b9c33 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml @@ -23,4 +23,10 @@ + + + + diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java index 9b1a025d00..12ba56ce3b 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -16,26 +16,30 @@ package org.springframework.integration.redis.config; +import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertSame; + import org.junit.Test; import org.junit.runner.RunWith; - import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; +import org.springframework.integration.MessageChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.redis.inbound.RedisInboundChannelAdapter; import org.springframework.integration.redis.rules.RedisAvailable; import org.springframework.integration.redis.rules.RedisAvailableTests; import org.springframework.integration.support.converter.SimpleMessageConverter; +import org.springframework.integration.test.util.TestUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static junit.framework.Assert.assertEquals; - /** * @author Oleg Zhurakousky * @author Mark Fisher + * @author Gary Russell */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -43,7 +47,12 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests{ @Autowired private ApplicationContext context; - + + @Autowired + private MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + private RedisInboundChannelAdapter autoChannelAdapter; @Test @RedisAvailable @@ -72,6 +81,11 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests{ assertEquals("Hello Redis from bar", receiveChannel.receive(1000).getPayload()); } + @Test + @RedisAvailable + public void testAutoChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } @SuppressWarnings("unused") private static class TestMessageConverter extends SimpleMessageConverter { diff --git a/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.1.xsd b/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.1.xsd index c0cf8beb98..7ac343233f 100644 --- a/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.1.xsd +++ b/spring-integration-sftp/src/main/resources/org/springframework/integration/sftp/config/spring-integration-sftp-2.1.xsd @@ -389,7 +389,7 @@ - + diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests-context.xml b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests-context.xml index 3da9bb86c6..e59cdf71a3 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests-context.xml +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests-context.xml @@ -93,5 +93,16 @@ - + + + + + + diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests.java index 0dbe86111e..5b03ba4c4f 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/config/InboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -20,6 +20,7 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertSame; import java.io.File; import java.util.Comparator; @@ -33,6 +34,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.MessageChannel; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizer; @@ -41,6 +43,7 @@ import org.springframework.integration.test.util.TestUtils; /** * @author Oleg Zhurakousky + * @author Gary Russell */ public class InboundChannelAdapterParserTests { @@ -82,6 +85,16 @@ public class InboundChannelAdapterParserTests { assertNotNull(requestChannel.receive(2000)); } + @Test + public void testAutoChannel() { + ApplicationContext context = + new ClassPathXmlApplicationContext("InboundChannelAdapterParserTests-context.xml", this.getClass()); + // Auto-created channel + MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class); + SourcePollingChannelAdapter autoChannelAdapter = context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class); + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } + @Test(expected=BeanDefinitionStoreException.class) //exactly one of 'filename-pattern' or 'filter' is allowed on SFTP inbound adapter public void testFailWithFilePatternAndFilter() throws Exception{ diff --git a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/AbstractXmppInboundChannelAdapterParser.java b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/AbstractXmppInboundChannelAdapterParser.java index 25c290f9fe..f27c215d61 100644 --- a/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/AbstractXmppInboundChannelAdapterParser.java +++ b/spring-integration-xmpp/src/main/java/org/springframework/integration/xmpp/config/AbstractXmppInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -16,23 +16,24 @@ package org.springframework.integration.xmpp.config; -import org.w3c.dom.Element; - import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.xml.AbstractChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.integration.xmpp.support.DefaultXmppHeaderMapper; import org.springframework.util.StringUtils; +import org.w3c.dom.Element; /** * Base class for XMPP inbound parsers * * @author Oleg Zhurakousky + * @author Gary Russell * @since 2.0.1 */ -public abstract class AbstractXmppInboundChannelAdapterParser extends AbstractSingleBeanDefinitionParser { +public abstract class AbstractXmppInboundChannelAdapterParser extends AbstractChannelAdapterParser { @Override protected boolean shouldGenerateId() { @@ -44,13 +45,15 @@ public abstract class AbstractXmppInboundChannelAdapterParser extends AbstractSi return true; } - @Override - protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - + protected abstract String getBeanClassName(Element element); + + protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(getBeanClassName(element)); + IntegrationNamespaceUtils.configureHeaderMapper(element, builder, parserContext, DefaultXmppHeaderMapper.class, null); - + String connectionName = element.getAttribute("xmpp-connection"); - + if (StringUtils.hasText(connectionName)){ builder.addConstructorArgReference(connectionName); } @@ -62,10 +65,11 @@ public abstract class AbstractXmppInboundChannelAdapterParser extends AbstractSi "'xmpp-connection' attribute or have default XMPP connection bean registered under the name 'xmppConnection'" + "(e.g., ). If 'id' is not provided the default will be 'xmppConnection'."); } - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel", "outputChannel"); + builder.addPropertyReference("outputChannel", channelName); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel"); this.postProcess(element, parserContext, builder); + return builder.getBeanDefinition(); } protected void postProcess(Element element, ParserContext parserContext, BeanDefinitionBuilder builder){ diff --git a/spring-integration-xmpp/src/main/resources/org/springframework/integration/xmpp/config/spring-integration-xmpp-2.1.xsd b/spring-integration-xmpp/src/main/resources/org/springframework/integration/xmpp/config/spring-integration-xmpp-2.1.xsd index 60102fe825..8072dc6af0 100644 --- a/spring-integration-xmpp/src/main/resources/org/springframework/integration/xmpp/config/spring-integration-xmpp-2.1.xsd +++ b/spring-integration-xmpp/src/main/resources/org/springframework/integration/xmpp/config/spring-integration-xmpp-2.1.xsd @@ -161,7 +161,7 @@ - + diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests-context.xml b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests-context.xml index 61b8af51b1..9ea6995ef4 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests-context.xml @@ -21,14 +21,21 @@ - + - + + + + diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests.java index 0ce6b1cafd..2bb7a4b4c7 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageInboundChannelAdapterParserTests.java @@ -16,6 +16,10 @@ package org.springframework.integration.xmpp.config; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static org.junit.Assert.assertSame; + import java.lang.reflect.Field; import org.jivesoftware.smack.Chat; @@ -23,12 +27,11 @@ import org.jivesoftware.smack.ChatManager; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.Message; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; - import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.integration.MessageChannel; import org.springframework.integration.channel.QueueChannel; @@ -38,9 +41,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.ReflectionUtils; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; - /** * @author Oleg Zhurakousky * @author Mark Fisher @@ -51,10 +51,16 @@ public class ChatMessageInboundChannelAdapterParserTests { @Autowired private ApplicationContext context; - + @Autowired private QueueChannel xmppInbound; + @Autowired + private MessageChannel autoChannel; + + @Autowired @Qualifier("autoChannel.adapter") + private ChatMessageListeningEndpoint autoChannelAdapter; + @Test public void testInboundAdapter(){ ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class); @@ -94,4 +100,8 @@ public class ChatMessageInboundChannelAdapterParserTests { assertEquals("oleg", siMessage.getHeaders().get("xmpp_to")); } + @Test + public void testAutoChannel() { + assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")); + } }