diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java index 3d471d3661..bd70333b0d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java @@ -130,7 +130,7 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean adviceChain; @@ -48,6 +51,14 @@ public class PollerMetadata { public Trigger getTrigger() { return this.trigger; } + + public ErrorHandler getErrorHandler() { + return errorHandler; + } + + public void setErrorHandler(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } /** * Set the maximum number of messages to receive for each poll. diff --git a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd index a0e77dd259..458f42c2a5 100644 --- a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd +++ b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd @@ -1242,6 +1242,15 @@ endpoint itself is a Polling Consumer for a channel with a queue. + + + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannel-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannel-context.xml index e0fe737657..3b30bfa697 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannel-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannel-context.xml @@ -9,22 +9,30 @@ - + - + channel="serviceChannel" auto-startup="false"> + - + channel="serviceChannel" auto-startup="false"> + + + + + + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannel.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannelTests.java similarity index 65% rename from spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannel.java rename to spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannelTests.java index 46538be584..6c51377f88 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannel.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/PollerWithErrorChannelTests.java @@ -16,34 +16,49 @@ package org.springframework.integration.config.xml; import static junit.framework.Assert.assertNotNull; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import org.junit.Ignore; import org.junit.Test; +import org.mockito.Mockito; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.Message; +import org.springframework.integration.core.MessageHandler; import org.springframework.integration.core.PollableChannel; +import org.springframework.integration.core.SubscribableChannel; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; /** * @author Oleg Zhurakousky * */ -public class PollerWithErrorChannel { +public class PollerWithErrorChannelTests { @Test - @Ignore + /* + * Although adapter configuration specifies header-enricher pointing to the 'eChannel' as errorChannel + * the ErrorMessage will still be forwarded to the 'errorChannel' since exception occurs on + * receive() and not on send() + */ public void testWithErrorChannelAsHeader() throws Exception{ ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = ac.getBean("withErrorHeader", SourcePollingChannelAdapter.class); + + SubscribableChannel errorChannel = ac.getBean("errorChannel", SubscribableChannel.class); + MessageHandler handler = mock(MessageHandler.class); + errorChannel.subscribe(handler); adapter.start(); - PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class); - assertNotNull(errorChannel.receive(1000)); + Thread.sleep(1000); + verify(handler, atLeastOnce()).handleMessage(Mockito.any(Message.class)); adapter.stop(); } @Test - @Ignore public void testWithErrorChannel() throws Exception{ ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannel", SourcePollingChannelAdapter.class); @@ -54,11 +69,21 @@ public class PollerWithErrorChannel { } @Test - @Ignore public void testWithErrorChannelAndHeader() throws Exception{ ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeader", SourcePollingChannelAdapter.class); adapter.start(); + PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class); + assertNotNull(errorChannel.receive(1000)); + adapter.stop(); + } + + @Test + // config the same as above but the error wil come from the send + public void testWithErrorChannelAndHeaderWithSendFailure() throws Exception{ + ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass()); + SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeaderErrorOnSend", SourcePollingChannelAdapter.class); + adapter.start(); PollableChannel errorChannel = ac.getBean("errChannel", PollableChannel.class); assertNotNull(errorChannel.receive(1000)); adapter.stop();