svn commit: r642107 - in /activemq/camel/trunk/components/camel-ftp/src: main/java/org/apache/camel/component/file/remote/ test/java/org/apache/camel/component/file/remote/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r642107 - in /activemq/camel/trunk/components/camel-ftp/src: main/java/org/apache/camel/component/file/remote/ test/java/org/apache/camel/component/file/remote/

davsclaus-2
Author: davsclaus
Date: Fri Mar 28 00:10:01 2008
New Revision: 642107

URL: http://svn.apache.org/viewvc?rev=642107&view=rev
Log:
CAMEL-171 and
- fixed throwing an empty RuntimeException
- improved logging a bit
- polished a TODO statement that spanned 7 lines

Modified:
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
    activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java?rev=642107&r1=642106&r2=642107&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java Fri Mar 28 00:10:01 2008
@@ -107,7 +107,8 @@
                     pollDirectory(getFullFileName(ftpFile));
                 }
             } else {
-                throw new RuntimeException("");
+                // TODO: Type can be symbolic link etc. so what should we do?
+                LOG.warn("Unsupported type of FTPFile: " + ftpFile + " not a file or directory");
             }
         }
     }
@@ -117,15 +118,8 @@
     }
 
     private void pollFile(FTPFile ftpFile) throws Exception {
-        if (ftpFile.getTimestamp().getTimeInMillis() > lastPollTime) { // TODO
-                                                                       // do we
-                                                                       // need
-                                                                       // to
-                                                                       // adjust
-                                                                       // the
-                                                                       // TZ?
-                                                                       // can
-                                                                       // we?
+        // TODO do we need to adjust the TZ? can we?
+        if (ftpFile.getTimestamp().getTimeInMillis() > lastPollTime) {
             if (isMatched(ftpFile)) {
                 final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                 client.retrieveFile(ftpFile.getName(), byteArrayOutputStream);

Modified: activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java?rev=642107&r1=642106&r2=642107&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpProducer.java Fri Mar 28 00:10:01 2008
@@ -85,19 +85,20 @@
             if (lastPathIndex != -1) {
                 String directory = fileName.substring(0, lastPathIndex);
                 if (!buildDirectory(client, directory)) {
-                    LOG.warn("Couldn't buildDirectory: " + directory + " (either permissions deny it, or it already exists)");
+                    LOG.warn("Couldn't build directory: " + directory + " (either permissions deny it, or it already exists)");
                 }
             }
 
             final boolean success = client.storeFile(fileName, payload);
             if (!success) {
-                throw new RuntimeCamelException("error sending file");
+                // TODO: Should we not have better exception for this?
+                throw new RuntimeCamelException("Error sending file: " + fileName);
             }
 
             RemoteFileConfiguration config = endpoint.getConfiguration();
             LOG.info("Sent: " + fileName + " to " + config.toString().substring(0, config.toString().indexOf(config.getFile())));
         } finally {
-            if (null != payload) {
+            if (payload != null) {
                 payload.close();
             }
         }
@@ -125,13 +126,21 @@
         boolean atLeastOneSuccess = false;
         final StringBuilder sb = new StringBuilder(dirName.length());
         final String[] dirs = dirName.split("\\/");
+
         for (String dir : dirs) {
             sb.append(dir).append('/');
-            final boolean success = ftpClient.makeDirectory(sb.toString());
+            String directory = sb.toString();
+
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Trying to build directory: " + directory);
+            }
+            final boolean success = ftpClient.makeDirectory(directory);
+
             if (!atLeastOneSuccess && success) {
                 atLeastOneSuccess = true;
             }
         }
+
         return atLeastOneSuccess;
     }
 }

Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java?rev=642107&r1=642106&r2=642107&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java Fri Mar 28 00:10:01 2008
@@ -61,7 +61,7 @@
 
         super.setUp();
 
-        resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");
+        resultEndpoint = getMockEndpoint("mock:result");
     }
 
     @Override