Using Asserts with IllegalArgumentException/IllegalStateException instead of ConfigurationException.

This commit is contained in:
Mark Fisher
2008-09-29 13:49:47 +00:00
parent c76daa497d
commit c78e7e67ad
5 changed files with 21 additions and 36 deletions

View File

@@ -20,7 +20,6 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.channel.ChannelRegistry;
@@ -80,23 +79,18 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
String inputChannelName = (String) AnnotationUtils.getValue(annotation, INPUT_CHANNEL_ATTRIBUTE);
if (StringUtils.hasText(inputChannelName)) {
MessageChannel inputChannel = this.messageBus.lookupChannel(inputChannelName);
if (inputChannel == null) {
throw new ConfigurationException("unable to resolve inputChannel '" + inputChannelName + "'");
}
Assert.notNull(inputChannel, "unable to resolve inputChannel '" + inputChannelName + "'");
if (endpoint instanceof AbstractMessageConsumingEndpoint) {
AbstractMessageConsumingEndpoint consumingEndpoint = (AbstractMessageConsumingEndpoint) endpoint;
if (pollerAnnotation != null) {
if (inputChannel instanceof PollableChannel) {
IntervalTrigger trigger = new IntervalTrigger(
pollerAnnotation.interval(), pollerAnnotation.timeUnit());
trigger.setInitialDelay(pollerAnnotation.initialDelay(), pollerAnnotation.timeUnit());
trigger.setFixedRate(pollerAnnotation.fixedRate());
consumingEndpoint.setTrigger(trigger);
consumingEndpoint.setMaxMessagesPerPoll(pollerAnnotation.maxMessagesPerPoll());
}
else {
throw new ConfigurationException("The @Poller annotation should only be provided for a PollableChannel");
}
if (pollerAnnotation != null) {
Assert.isInstanceOf(PollableChannel.class, inputChannel,
"The @Poller annotation should only be provided for a PollableChannel");
IntervalTrigger trigger = new IntervalTrigger(
pollerAnnotation.interval(), pollerAnnotation.timeUnit());
trigger.setInitialDelay(pollerAnnotation.initialDelay(), pollerAnnotation.timeUnit());
trigger.setFixedRate(pollerAnnotation.fixedRate());
consumingEndpoint.setTrigger(trigger);
consumingEndpoint.setMaxMessagesPerPoll(pollerAnnotation.maxMessagesPerPoll());
}
consumingEndpoint.setInputChannel(inputChannel);
}
@@ -104,9 +98,7 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
String outputChannelName = (String) AnnotationUtils.getValue(annotation, OUTPUT_CHANNEL_ATTRIBUTE);
if (StringUtils.hasText(outputChannelName)) {
MessageChannel outputChannel = this.messageBus.lookupChannel(outputChannelName);
if (outputChannel == null) {
throw new ConfigurationException("unable to resolve outputChannel '" + outputChannelName + "'");
}
Assert.notNull(outputChannel, "unable to resolve outputChannel '" + outputChannelName + "'");
((AbstractMessageHandlingEndpoint) endpoint).setOutputChannel(outputChannel);
}
}

View File

@@ -20,16 +20,16 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.aggregator.AggregatorEndpoint;
import org.springframework.integration.aggregator.MethodInvokingAggregator;
import org.springframework.integration.aggregator.CompletionStrategyAdapter;
import org.springframework.integration.aggregator.MethodInvokingAggregator;
import org.springframework.integration.annotation.Aggregator;
import org.springframework.integration.annotation.CompletionStrategy;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.bus.MessageBus;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -67,9 +67,7 @@ public class AggregatorAnnotationPostProcessor extends AbstractMethodAnnotationP
String discardChannelName = annotation.discardChannel();
if (StringUtils.hasText(discardChannelName)) {
MessageChannel discardChannel = this.getChannelRegistry().lookupChannel(discardChannelName);
if (discardChannel == null) {
throw new ConfigurationException("unable to resolve discardChannel '" + discardChannelName + "'");
}
Assert.notNull(discardChannel, "unable to resolve discardChannel '" + discardChannelName + "'");
aggregatorEndpoint.setDiscardChannel(discardChannel);
}
aggregatorEndpoint.setSendTimeout(annotation.sendTimeout());

View File

@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.annotation.ChannelAdapter;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.bus.MessageBus;
@@ -80,8 +79,9 @@ public class ChannelAdapterAnnotationPostProcessor implements MethodAnnotationPo
endpoint = this.createOutboundChannelAdapter(consumer, channel, pollerAnnotation);
}
else {
throw new ConfigurationException("The @ChannelAdapter can only be applied to methods that accept no arguments but have"
+ " a return value (inbound) or methods that have no return value but do accept arguments (outbound)");
throw new IllegalArgumentException("The @ChannelAdapter can only be applied to methods"
+ " that accept no arguments but have a return value (inbound) or methods that"
+ " have no return value but do accept arguments (outbound)");
}
if (endpoint != null) {
String annotationName = ClassUtils.getShortNameAsProperty(annotation.annotationType());
@@ -92,10 +92,8 @@ public class ChannelAdapterAnnotationPostProcessor implements MethodAnnotationPo
}
private SourcePollingChannelAdapter createInboundChannelAdapter(MethodInvokingSource source, MessageChannel channel, Poller pollerAnnotation) {
if (pollerAnnotation == null) {
throw new ConfigurationException("The @Poller annotation is required (at method-level) "
Assert.notNull(pollerAnnotation, "The @Poller annotation is required (at method-level) "
+ "when using the @ChannelAdapter annotation with a no-arg method.");
}
Trigger trigger = this.createTrigger(pollerAnnotation);
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setSource(source);

View File

@@ -37,7 +37,6 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.annotation.Aggregator;
import org.springframework.integration.annotation.ChannelAdapter;
import org.springframework.integration.annotation.Router;
@@ -135,7 +134,7 @@ public class MessagingAnnotationPostProcessor implements BeanPostProcessor, Bean
continue;
}
if (proxyFactory.isInterfaceProxied(iface)) {
throw new ConfigurationException("interface [" + iface + "] is already proxied");
throw new IllegalStateException("interface [" + iface + "] is already proxied");
}
shouldProxy = true;
}

View File

@@ -18,7 +18,6 @@ package org.springframework.integration.config.annotation;
import java.lang.reflect.Method;
import org.springframework.integration.ConfigurationException;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.annotation.Router;
import org.springframework.integration.bus.MessageBus;
@@ -26,6 +25,7 @@ import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.router.MethodInvokingChannelResolver;
import org.springframework.integration.router.RouterEndpoint;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
@@ -59,9 +59,7 @@ public class RouterAnnotationPostProcessor extends AbstractMethodAnnotationPostP
String defaultOutputChannelName = annotation.defaultOutputChannel();
if (StringUtils.hasText(defaultOutputChannelName)) {
MessageChannel defaultOutputChannel = this.getChannelRegistry().lookupChannel(defaultOutputChannelName);
if (defaultOutputChannel == null) {
throw new ConfigurationException("unable to resolve defaultOutputChannel '" + defaultOutputChannelName + "'");
}
Assert.notNull(defaultOutputChannel, "unable to resolve defaultOutputChannel '" + defaultOutputChannelName + "'");
((RouterEndpoint) endpoint).setDefaultOutputChannel(defaultOutputChannel);
}
}