diff --git a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java index 0146b76b53..0e7604f6a5 100644 --- a/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java +++ b/org.springframework.integration.adapter/src/main/java/org/springframework/integration/adapter/file/FileSource.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.util.Map; import org.springframework.beans.factory.InitializingBean; +import org.springframework.core.io.Resource; +import org.springframework.integration.ConfigurationException; import org.springframework.integration.message.MessageCreator; import org.springframework.integration.message.MessageDeliveryAware; import org.springframework.integration.message.MessagingException; @@ -46,14 +48,23 @@ public class FileSource extends AbstractDirectorySource implements Source messageCreator) { + public FileSource(Resource directory, MessageCreator messageCreator) { super(messageCreator); Assert.notNull(directory, "The directory must not be null"); - this.directory = directory; + try { + this.directory = directory.getFile(); + if (!this.directory.isDirectory()) { + throw new ConfigurationException("The FileSource can't be instantiated because " + + this.directory.getAbsolutePath() + " is not a directory."); + } + } + catch (IOException e) { + throw new ConfigurationException("The FileSource can't be instantiated", e); + } } @@ -87,7 +98,7 @@ public class FileSource extends AbstractDirectorySource implements Source snapshot) throws IOException { - File[] files = null; + File[] files; if (this.fileFilter != null) { files = this.directory.listFiles(this.fileFilter); } @@ -100,10 +111,10 @@ public class FileSource extends AbstractDirectorySource implements Source 0); + } + } + } diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml index 8086603fc2..2191daf6f4 100644 --- a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceParserTests.xml @@ -30,6 +30,4 @@ - - diff --git a/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithFileDirectory.xml b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithFileDirectory.xml new file mode 100644 index 0000000000..1319e65f7a --- /dev/null +++ b/org.springframework.integration.adapter/src/test/java/org/springframework/integration/adapter/file/config/fileSourceWithFileDirectory.xml @@ -0,0 +1,15 @@ + + + + + +