INT-1708, INT-1709 undid the changes made with regard to adding error-channel to SourcePollingChannelAdapter in favor of adding it to the poller

This commit is contained in:
Oleg Zhurakousky
2011-01-20 08:33:40 -05:00
parent 8ee0af309f
commit 21b5809057
7 changed files with 5 additions and 98 deletions

View File

@@ -1,40 +0,0 @@
/*
* Copyright 2002-2011 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;
/**
* @author Oleg Zhurakousky
* @since 2.0.2
*/
@SuppressWarnings("serial")
public class MessageSourceReceiveException extends MessageHandlingException {
private volatile Object errorChannel;
public void setErrorChannel(Object errorChannel) {
this.errorChannel = errorChannel;
}
public MessageSourceReceiveException(Object errorChannel, Throwable t) {
super(null, t);
this.errorChannel = errorChannel;
}
public Object getErrorChannel() {
return errorChannel;
}
}

View File

@@ -23,7 +23,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessageSourceReceiveException;
import org.springframework.integration.MessagingException;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.message.ErrorMessage;
@@ -31,7 +30,6 @@ import org.springframework.integration.support.channel.BeanFactoryChannelResolve
import org.springframework.integration.support.channel.ChannelResolver;
import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler;
import org.springframework.util.StringUtils;
/**
* {@link ErrorHandler} implementation that sends an {@link ErrorMessage} to a
@@ -114,20 +112,6 @@ public class MessagePublishingErrorHandler implements ErrorHandler, BeanFactoryA
IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
}
if (t instanceof MessageSourceReceiveException){
Object errorChannel = ((MessageSourceReceiveException)t).getErrorChannel();
if (errorChannel != null){
if (errorChannel instanceof MessageChannel){
return (MessageChannel) errorChannel;
}
else if (errorChannel instanceof String && StringUtils.hasText((String)errorChannel)){
return this.channelResolver.resolveChannelName((String) errorChannel);
}
else {
throw new MessagingException("Failed to resolve 'errorChannel' - " + errorChannel);
}
}
}
if (failedMessage == null || failedMessage.getHeaders().getErrorChannel() == null) {
return this.defaultErrorChannel;
}

View File

@@ -30,7 +30,6 @@ import org.springframework.integration.core.MessageSource;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.scheduling.PollerMetadata;
import org.springframework.util.Assert;
import org.springframework.util.ErrorHandler;
/**
* FactoryBean for creating a SourcePollingChannelAdapter instance.
@@ -60,13 +59,6 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean<Sourc
private volatile boolean initialized;
private final Object initializationMonitor = new Object();
private volatile ErrorHandler errorHandler;
public void setErrorHandler(ErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
public void setSource(MessageSource<?> source) {
this.source = source;
@@ -127,7 +119,6 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean<Sourc
SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter();
spca.setSource(this.source);
spca.setOutputChannel(this.outputChannel);
spca.setErrorHandler(errorHandler);
if (this.pollerMetadata == null) {
this.pollerMetadata = IntegrationContextUtils.getDefaultPollerMetadata(this.beanFactory);
Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '"

View File

@@ -22,7 +22,6 @@ import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
@@ -47,14 +46,6 @@ public abstract class AbstractPollingInboundChannelAdapterParser extends Abstrac
IntegrationNamespaceUtils.configurePollerMetadata(pollerElement, adapterBuilder, parserContext);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(adapterBuilder, element, "auto-startup");
String errorChannel = element.getAttribute("error-channel");
if (StringUtils.hasText(errorChannel)){
BeanDefinitionBuilder errorHandler = BeanDefinitionBuilder.genericBeanDefinition(
"org.springframework.integration.channel.MessagePublishingErrorHandler");
errorHandler.addPropertyReference("defaultErrorChannel", errorChannel);
adapterBuilder.addPropertyValue("errorHandler", errorHandler.getBeanDefinition());
}
return adapterBuilder.getBeanDefinition();
}

View File

@@ -22,8 +22,6 @@ import java.util.Map;
import org.springframework.expression.Expression;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHeaders;
import org.springframework.integration.MessageSourceReceiveException;
import org.springframework.integration.MessagingException;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.support.MessageBuilder;
@@ -47,22 +45,10 @@ public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluat
@SuppressWarnings("unchecked")
public final Message<T> receive() {
Message<T> message = null;
Object result = null;
Object result = this.doReceive();
Map<String, Object> headers = this.evaluateHeaders();
if (headers.containsKey(MessageHeaders.ERROR_CHANNEL)){
try {
result = this.doReceive();
}
catch (Exception e) {
throw new MessageSourceReceiveException((String) headers.get(MessageHeaders.ERROR_CHANNEL), e);
}
}
else {
result = this.doReceive();
}
if (result instanceof Message<?>) {
try {
message = (Message<T>) result;

View File

@@ -694,15 +694,6 @@
</xsd:sequence>
<xsd:attributeGroup ref="methodInvokingOrExpressionEvaluatingAttributes" />
<xsd:attributeGroup ref="channelAdapterAttributes" />
<xsd:attribute name="error-channel" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Identifies channel that error messages will be sent to if a failure occurs in this
adapter's invocation. To completely suppress Exceptions, provide a
reference to the "nullChannel" here.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

View File

@@ -17,6 +17,7 @@ package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertNotNull;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
@@ -31,6 +32,7 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
public class PollerWithErrorChannel {
@Test
@Ignore
public void testWithErrorChannelAsHeader() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorHeader", SourcePollingChannelAdapter.class);
@@ -41,6 +43,7 @@ public class PollerWithErrorChannel {
}
@Test
@Ignore
public void testWithErrorChannel() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannel", SourcePollingChannelAdapter.class);
@@ -51,6 +54,7 @@ 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);