camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r979953 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/test/java/org/apache/camel/component/file/ components/camel-ftp/src/main/java/org/apache/camel/co...
Date Wed, 28 Jul 2010 05:50:45 GMT
Author: davsclaus
Date: Wed Jul 28 05:50:44 2010
New Revision: 979953

URL: http://svn.apache.org/viewvc?rev=979953&view=rev
Log:
CAMEL-2999: Added options startingDirectoryMustExist and directoryMustExist to file component.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/FailedToCreateConsumerException.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/FailedToCreateConsumerException.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/FailedToCreateConsumerException.java?rev=979953&r1=979952&r2=979953&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/FailedToCreateConsumerException.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/FailedToCreateConsumerException.java
Wed Jul 28 05:50:44 2010
@@ -31,11 +31,6 @@ public class FailedToCreateConsumerExcep
         this.uri = endpoint.getEndpointUri();
     }
 
-    public FailedToCreateConsumerException(Endpoint endpoint, String message) {
-        super("Failed to create Consumer for endpoint: " + endpoint + ". Reason: " + message);
-        this.uri = endpoint.getEndpointUri();
-    }
-
     public FailedToCreateConsumerException(Endpoint endpoint, String message, Throwable cause)
{
         super("Failed to create Consumer for endpoint: " + endpoint + ". Reason: " + message,
cause);
         this.uri = endpoint.getEndpointUri();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java?rev=979953&r1=979952&r2=979953&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileConsumer.java
Wed Jul 28 05:50:44 2010
@@ -45,6 +45,9 @@ public class FileConsumer extends Generi
             if (log.isDebugEnabled()) {
                 log.debug("Cannot poll as directory does not exists or its not a directory:
" + directory);
             }
+            if (getEndpoint().isDirectoryMustExist()) {
+                throw new GenericFileOperationFailedException("Directory does not exist:
" + directory);
+            }
             return true;
         }
 
@@ -159,4 +162,9 @@ public class FileConsumer extends Generi
         answer.setBody(file);
         return answer;
     }
+
+    @Override
+    public FileEndpoint getEndpoint() {
+        return (FileEndpoint) super.getEndpoint();
+    }
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java?rev=979953&r1=979952&r2=979953&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileEndpoint.java
Wed Jul 28 05:50:44 2010
@@ -17,9 +17,11 @@
 package org.apache.camel.component.file;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 
 import org.apache.camel.Component;
 import org.apache.camel.Exchange;
+import org.apache.camel.FailedToCreateConsumerException;
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.processor.idempotent.MemoryIdempotentRepository;
@@ -62,6 +64,8 @@ public class FileEndpoint extends Generi
                 }
                 boolean absolute = FileUtil.isAbsolute(file);
                 operations.buildDirectory(file.getPath(), absolute);
+            } else if (isStartingDirectoryMustExist()) {
+                throw new FileNotFoundException("Starting directory does not exist: " + file);
             }
         }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java?rev=979953&r1=979952&r2=979953&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
Wed Jul 28 05:50:44 2010
@@ -56,6 +56,8 @@ public abstract class GenericFileEndpoin
     protected IdempotentRepository<String> inProgressRepository = new MemoryIdempotentRepository();
     protected String localWorkDirectory;
     protected boolean autoCreate = true;
+    protected boolean startingDirectoryMustExist;
+    protected boolean directoryMustExist;
     protected int bufferSize = 128 * 1024;
     protected GenericFileExist fileExist = GenericFileExist.Override;
     protected boolean noop;
@@ -421,6 +423,22 @@ public abstract class GenericFileEndpoin
         this.autoCreate = autoCreate;
     }
 
+    public boolean isStartingDirectoryMustExist() {
+        return startingDirectoryMustExist;
+    }
+
+    public void setStartingDirectoryMustExist(boolean startingDirectoryMustExist) {
+        this.startingDirectoryMustExist = startingDirectoryMustExist;
+    }
+
+    public boolean isDirectoryMustExist() {
+        return directoryMustExist;
+    }
+
+    public void setDirectoryMustExist(boolean directoryMustExist) {
+        this.directoryMustExist = directoryMustExist;
+    }
+
     public GenericFileProcessStrategy<T> getProcessStrategy() {
         return processStrategy;
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java?rev=979953&r1=979952&r2=979953&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerAutoCreateDirectoryTest.java
Wed Jul 28 05:50:44 2010
@@ -17,6 +17,7 @@
 package org.apache.camel.component.file;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.ContextTestSupport;
@@ -87,5 +88,25 @@ public class FileConsumerAutoCreateDirec
         assertFalse("Directory should NOT be created", dir.exists());
     }
 
+    public void testStartingDirectoryMustExistDirectory() throws Exception {
+        deleteDirectory("target/file/foo");
+
+        Endpoint endpoint = context.getEndpoint("file://target/file/foo?autoCreate=false&startingDirectoryMustExist=true");
+        try {
+            endpoint.createConsumer(new Processor() {
+                public void process(Exchange exchange) throws Exception {
+                    // noop
+                }
+            });
+            fail("Should have thrown an exception");
+        } catch (FileNotFoundException e) {
+            assertEquals("Starting directory does not exist: target/file/foo", e.getMessage());
+        }
+
+        // the directory should NOT exists
+        File dir = new File("target/file/foo").getAbsoluteFile();
+        assertFalse("Directory should NOT be created", dir.exists());
+    }
+
 
 }

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=979953&r1=979952&r2=979953&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
(original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
Wed Jul 28 05:50:44 2010
@@ -19,7 +19,6 @@ package org.apache.camel.component.file.
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.component.file.GenericFile;
-import org.apache.camel.component.file.GenericFileConfiguration;
 import org.apache.camel.component.file.GenericFileEndpoint;
 import org.apache.camel.component.file.GenericFileProducer;
 import org.apache.camel.impl.DefaultExchange;



Mime
View raw message