Using Asserts with IllegalArgumentException/IllegalStateException instead of ConfigurationException.
This commit is contained in:
@@ -23,12 +23,12 @@ import org.w3c.dom.Element;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.config.AbstractPollingInboundChannelAdapterParser;
|
||||
import org.springframework.integration.file.AcceptOnceFileListFilter;
|
||||
import org.springframework.integration.file.CompositeFileListFilter;
|
||||
import org.springframework.integration.file.PatternMatchingFileListFilter;
|
||||
import org.springframework.integration.file.PollableFileSource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -52,9 +52,8 @@ public class FileInboundChannelAdapterParser extends AbstractPollingInboundChann
|
||||
}
|
||||
String filenamePattern = element.getAttribute("filename-pattern");
|
||||
if (StringUtils.hasText(filenamePattern)) {
|
||||
if (StringUtils.hasText(filter)) {
|
||||
throw new ConfigurationException("at most one of 'filter' and 'filename-pattern' may be provided");
|
||||
}
|
||||
Assert.isTrue(!StringUtils.hasText(filter),
|
||||
"at most one of 'filter' and 'filename-pattern' may be provided");
|
||||
AcceptOnceFileListFilter acceptOnceFilter = new AcceptOnceFileListFilter();
|
||||
Pattern pattern = Pattern.compile(filenamePattern);
|
||||
PatternMatchingFileListFilter patternFilter = new PatternMatchingFileListFilter(pattern);
|
||||
|
||||
@@ -20,10 +20,10 @@ import javax.jms.ConnectionFactory;
|
||||
import javax.jms.Destination;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.MessageHeaderMapper;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base class for adapters that delegate to a {@link JmsTemplate}.
|
||||
@@ -104,10 +104,10 @@ public abstract class AbstractJmsTemplateBasedAdapter implements InitializingBea
|
||||
return;
|
||||
}
|
||||
if (this.jmsTemplate == null) {
|
||||
if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) {
|
||||
throw new ConfigurationException("Either a 'jmsTemplate' or " +
|
||||
"*both* 'connectionFactory' and 'destination' (or 'destination-name') are required.");
|
||||
}
|
||||
Assert.isTrue(this.connectionFactory != null
|
||||
&& (this.destination != null || this.destinationName != null),
|
||||
"Either a 'jmsTemplate' or *both* 'connectionFactory' and"
|
||||
+ " 'destination' (or 'destination-name') are required.");
|
||||
this.jmsTemplate = this.createDefaultJmsTemplate();
|
||||
}
|
||||
MessageConverter converter = this.jmsTemplate.getMessageConverter();
|
||||
|
||||
@@ -23,7 +23,6 @@ import javax.jms.Session;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.gateway.SimpleMessagingGateway;
|
||||
import org.springframework.jms.listener.AbstractMessageListenerContainer;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
@@ -147,10 +146,10 @@ public class JmsGateway extends SimpleMessagingGateway implements Lifecycle, Dis
|
||||
}
|
||||
|
||||
private AbstractMessageListenerContainer createDefaultContainer() {
|
||||
if (this.connectionFactory == null || (this.destination == null && this.destinationName == null)) {
|
||||
throw new ConfigurationException("If a 'container' reference is not provided, then "
|
||||
+ "'connectionFactory' and 'destination' (or 'destinationName') are required.");
|
||||
}
|
||||
Assert.isTrue(this.connectionFactory != null
|
||||
&& (this.destination != null || this.destinationName != null),
|
||||
"If a 'container' reference is not provided, then 'connectionFactory'"
|
||||
+ " and 'destination' (or 'destinationName') are required.");
|
||||
DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
|
||||
dmlc.setConcurrentConsumers(this.concurrentConsumers);
|
||||
dmlc.setMaxConcurrentConsumers(this.maxConcurrentConsumers);
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -30,6 +29,7 @@ import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.Subscribable;
|
||||
import org.springframework.integration.scheduling.IntervalTrigger;
|
||||
import org.springframework.integration.scheduling.Trigger;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* The base class for Message Endpoint implementations that consume Messages.
|
||||
@@ -104,16 +104,13 @@ public abstract class AbstractMessageConsumingEndpoint extends AbstractEndpoint
|
||||
if (!this.initialized) {
|
||||
this.afterPropertiesSet();
|
||||
}
|
||||
if (this.inputChannel == null) {
|
||||
throw new ConfigurationException("failed to start endpoint, inputChannel is required");
|
||||
}
|
||||
Assert.notNull(this.inputChannel, "failed to start endpoint, inputChannel is required");
|
||||
if (this.inputChannel instanceof Subscribable) {
|
||||
((Subscribable) inputChannel).subscribe(this);
|
||||
}
|
||||
else if (this.inputChannel instanceof PollableChannel) {
|
||||
if (this.getTaskScheduler() == null) {
|
||||
throw new ConfigurationException("failed to start endpoint, no taskScheduler available");
|
||||
}
|
||||
Assert.notNull(this.getTaskScheduler(),
|
||||
"failed to start endpoint, no taskScheduler available");
|
||||
this.pollerFuture = this.getTaskScheduler().schedule(this.poller, this.poller.getTrigger());
|
||||
}
|
||||
this.running = true;
|
||||
|
||||
Reference in New Issue
Block a user