Removing dependencies on ConfigurationException.
This commit is contained in:
@@ -30,7 +30,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.mail.monitor.AsyncMonitoringStrategy;
|
||||
import org.springframework.integration.mail.monitor.MailTransportUtils;
|
||||
import org.springframework.integration.mail.monitor.MonitoringStrategy;
|
||||
@@ -71,10 +70,8 @@ public class DefaultFolderConnection implements Lifecycle, DisposableBean, Folde
|
||||
this.storeUri = new URLName(storeUri);
|
||||
this.monitoringStrategy = monitoringStrategy;
|
||||
this.polling = polling;
|
||||
if (!polling && monitoringStrategy.getClass().isAssignableFrom(AsyncMonitoringStrategy.class)) {
|
||||
throw new ConfigurationException(
|
||||
"Folder connection requires an AsyncMonitoringStrategy if polling is disabled.");
|
||||
}
|
||||
Assert.isTrue(polling || AsyncMonitoringStrategy.class.isAssignableFrom(monitoringStrategy.getClass()),
|
||||
"Folder connection requires an AsyncMonitoringStrategy if polling is disabled.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
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.AbstractOutboundChannelAdapterParser;
|
||||
import org.springframework.integration.config.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.mail.MailSendingMessageConsumer;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -49,13 +49,13 @@ public class MailOutboundChannelAdapterParser extends AbstractOutboundChannelAda
|
||||
String username = element.getAttribute("username");
|
||||
String password = element.getAttribute("password");
|
||||
if (StringUtils.hasText(mailSenderRef)) {
|
||||
if (StringUtils.hasText(host) || StringUtils.hasText(username) || StringUtils.hasText(password)) {
|
||||
throw new ConfigurationException("The 'host', 'username', and 'password' properties " +
|
||||
"should not be provided when using a 'mail-sender' reference.");
|
||||
}
|
||||
Assert.isTrue(!StringUtils.hasText(host) && !StringUtils.hasText(username) && !StringUtils.hasText(password),
|
||||
"The 'host', 'username', and 'password' properties " +
|
||||
"should not be provided when using a 'mail-sender' reference.");
|
||||
builder.addConstructorArgReference(mailSenderRef);
|
||||
}
|
||||
else if (StringUtils.hasText(host)) {
|
||||
else {
|
||||
Assert.hasText(host, "Either a 'mail-sender' reference or 'host' property is required.");
|
||||
BeanDefinitionBuilder mailSenderBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(JavaMailSenderImpl.class);
|
||||
mailSenderBuilder.addPropertyValue("host", host);
|
||||
@@ -74,9 +74,6 @@ public class MailOutboundChannelAdapterParser extends AbstractOutboundChannelAda
|
||||
mailSenderBuilder.getBeanDefinition(), parserContext.getRegistry());
|
||||
builder.addConstructorArgReference(mailSenderBeanName);
|
||||
}
|
||||
else {
|
||||
throw new ConfigurationException("Either a 'mail-sender' reference or 'host' property is required.");
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ import org.w3c.dom.Element;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.mail.DefaultFolderConnection;
|
||||
import org.springframework.integration.mail.PollingMailSource;
|
||||
import org.springframework.integration.mail.monitor.MonitoringStrategy;
|
||||
import org.springframework.integration.mail.monitor.PollingMonitoringStrategy;
|
||||
import org.springframework.integration.mail.monitor.Pop3PollingMonitoringStrategy;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -46,28 +46,24 @@ public class PollingMailSourceParser extends AbstractSingleBeanDefinitionParser
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String mailConvertorRef = element.getAttribute("convertor");
|
||||
String uri = element.getAttribute("store-uri");
|
||||
String propertiesRef = element.getAttribute("javaMailProperties");
|
||||
if (!StringUtils.hasLength(uri)) {
|
||||
throw new ConfigurationException("A store-uri is required");
|
||||
}
|
||||
Assert.hasText(uri, "the 'store-uri' attribute is required");
|
||||
BeanDefinitionBuilder folderConnectionBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(DefaultFolderConnection.class);
|
||||
String storeType = uri.substring(0, 4).toLowerCase();
|
||||
MonitoringStrategy monitoringStrategy = null;
|
||||
|
||||
if (storeType.equals("pop3")) {
|
||||
if (uri.toLowerCase().startsWith("pop3")) {
|
||||
monitoringStrategy = new Pop3PollingMonitoringStrategy();
|
||||
} else if (storeType.equals("imap")) {
|
||||
monitoringStrategy = new PollingMonitoringStrategy();
|
||||
} else {
|
||||
throw new ConfigurationException(
|
||||
"No monitoring strategy for store-uri " + uri);
|
||||
}
|
||||
|
||||
else if (uri.toLowerCase().startsWith("imap")) {
|
||||
monitoringStrategy = new PollingMonitoringStrategy();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"unable to determine monitoring strategy for store-uri [" + uri + "]");
|
||||
}
|
||||
folderConnectionBuilder.addConstructorArgValue(uri);
|
||||
folderConnectionBuilder.addConstructorArgValue(monitoringStrategy);
|
||||
// set polling true
|
||||
@@ -78,16 +74,12 @@ public class PollingMailSourceParser extends AbstractSingleBeanDefinitionParser
|
||||
propertiesRef);
|
||||
}
|
||||
String folderConnectionName = parserContext.getReaderContext()
|
||||
.registerWithGeneratedName(
|
||||
folderConnectionBuilder.getBeanDefinition());
|
||||
|
||||
.registerWithGeneratedName(folderConnectionBuilder.getBeanDefinition());
|
||||
builder.addDependsOn(folderConnectionName);
|
||||
builder.addConstructorArgValue(folderConnectionBuilder
|
||||
.getBeanDefinition());
|
||||
|
||||
builder.addConstructorArgValue(folderConnectionBuilder.getBeanDefinition());
|
||||
if (StringUtils.hasText(mailConvertorRef)) {
|
||||
builder.addPropertyReference("convertor", mailConvertorRef);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
@@ -84,7 +83,7 @@ public class CharacterStreamSource implements MessageSource<String> {
|
||||
return new CharacterStreamSource(new InputStreamReader(System.in, charsetName));
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new ConfigurationException("unsupported encoding: " + charsetName, e);
|
||||
throw new IllegalArgumentException("unsupported encoding: " + charsetName, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.io.Writer;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
@@ -108,7 +107,7 @@ public class CharacterStreamWritingMessageConsumer implements MessageConsumer {
|
||||
return new CharacterStreamWritingMessageConsumer(new OutputStreamWriter(stream, charsetName));
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new ConfigurationException("unsupported encoding: " + charsetName, e);
|
||||
throw new IllegalArgumentException("unsupported encoding: " + charsetName, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
@@ -99,9 +98,9 @@ public class ConsoleInboundChannelAdapterParserTests {
|
||||
beanCreationException = e;
|
||||
}
|
||||
Throwable parentCause = beanCreationException.getCause().getCause();
|
||||
assertEquals(ConfigurationException.class, parentCause.getClass());
|
||||
Throwable configurationExceptionCause = ((ConfigurationException) parentCause).getCause();
|
||||
assertEquals(UnsupportedEncodingException.class, configurationExceptionCause.getClass());
|
||||
assertEquals(IllegalArgumentException.class, parentCause.getClass());
|
||||
Throwable rootCause = ((IllegalArgumentException) parentCause).getCause();
|
||||
assertEquals(UnsupportedEncodingException.class, rootCause.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.stream.CharacterStreamWritingMessageConsumer;
|
||||
|
||||
@@ -110,9 +109,9 @@ public class ConsoleOutboundChannelAdapterParserTests {
|
||||
beanCreationException = e;
|
||||
}
|
||||
Throwable parentCause = beanCreationException.getCause().getCause();
|
||||
assertEquals(ConfigurationException.class, parentCause.getClass());
|
||||
Throwable configurationExceptionCause = ((ConfigurationException) parentCause).getCause();
|
||||
assertEquals(UnsupportedEncodingException.class, configurationExceptionCause.getClass());
|
||||
assertEquals(IllegalArgumentException.class, parentCause.getClass());
|
||||
Throwable rootCause = ((IllegalArgumentException) parentCause).getCause();
|
||||
assertEquals(UnsupportedEncodingException.class, rootCause.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.util.DefaultMethodInvoker;
|
||||
import org.springframework.integration.util.MethodInvoker;
|
||||
import org.springframework.integration.util.MethodValidator;
|
||||
@@ -70,7 +69,7 @@ public class MethodInvokingSource implements MessageSource<Object>, Initializing
|
||||
this.invoker = nrmi;
|
||||
}
|
||||
else {
|
||||
throw new ConfigurationException("either 'method' or 'methodName' is required");
|
||||
throw new IllegalArgumentException("either 'method' or 'methodName' is required");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,9 +100,8 @@ public class MethodInvokingSource implements MessageSource<Object>, Initializing
|
||||
private static class MessageReceivingMethodValidator implements MethodValidator {
|
||||
|
||||
public void validate(Method method) {
|
||||
if (method.getReturnType().equals(void.class)) {
|
||||
throw new ConfigurationException("MethodInvokingSource requires a non-void returning method.");
|
||||
}
|
||||
Assert.isTrue(!method.getReturnType().equals(void.class),
|
||||
"MethodInvokingSource requires a non-void returning method.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.channel.ChannelRegistry;
|
||||
import org.springframework.integration.channel.ChannelRegistryAware;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
@@ -90,7 +89,7 @@ public class MethodInvokingChannelResolver implements ChannelResolver, ChannelRe
|
||||
this.addChannel((String) result, channels);
|
||||
}
|
||||
else {
|
||||
throw new ConfigurationException(
|
||||
throw new IllegalStateException(
|
||||
"router method must return type 'MessageChannel' or 'String'");
|
||||
}
|
||||
return channels;
|
||||
|
||||
Reference in New Issue
Block a user