Using Asserts with IllegalArgumentException/IllegalStateException instead of ConfigurationException.

This commit is contained in:
Mark Fisher
2008-09-29 15:06:27 +00:00
parent 6cda0b8e7c
commit 039679b173
4 changed files with 16 additions and 21 deletions

View File

@@ -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();

View File

@@ -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);