You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/07/23 11:28:45 UTC

svn commit: r679046 - in /servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src: main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java test/java/org/apache/servicemix/ftp/FtpPollerEndpointTest.java

Author: gertv
Date: Wed Jul 23 02:28:45 2008
New Revision: 679046

URL: http://svn.apache.org/viewvc?rev=679046&view=rev
Log:
SM-1458: Allow servicemix-ftp to interact with GuildFTPd -- cwd into directory before listing it

Added:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/FtpPollerEndpointTest.java
Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java?rev=679046&r1=679045&r2=679046&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java Wed Jul 23 02:28:45 2008
@@ -57,6 +57,7 @@
     private FileFilter filter;  
     private boolean deleteFile = true;
     private boolean recursive = true;
+    private boolean changeWorkingDirectory;
     private FileMarshaler marshaler = new DefaultFileMarshaler();
     private LockManager lockManager;
     private QName targetOperation;
@@ -85,6 +86,9 @@
         if (uri != null && getClientPool() != null && getClientPool().getHost() != null) {
             throw new DeploymentException("Properties uri and clientPool.host can not be configured at the same time");
         }
+        if (changeWorkingDirectory && recursive) {
+            throw new DeploymentException("changeWorkingDirectory='true' can not be set when recursive='true'");
+        }
     }
     
     public void start() throws Exception {
@@ -195,6 +199,9 @@
 
     public void setTargetOperation(QName targetOperation) { this.targetOperation = targetOperation; }
 
+    public void setChangeWorkingDirectory(boolean changeWorkingDirectory) {
+        this.changeWorkingDirectory = changeWorkingDirectory;
+    }
     // Implementation methods
     //-------------------------------------------------------------------------
 
@@ -210,7 +217,7 @@
     }
 
     protected void pollFileOrDirectory(FTPClient ftp, String fileOrDirectory, boolean processDir) throws Exception {
-        FTPFile[] files = ftp.listFiles(fileOrDirectory);
+        FTPFile[] files = listFiles(ftp, fileOrDirectory);
         for (int i = 0; i < files.length; i++) {
             String name = files[i].getName();
             if (".".equals(name) || "..".equals(name)) {
@@ -236,6 +243,15 @@
         }
     }
 
+    private FTPFile[] listFiles(FTPClient ftp, String directory) throws IOException {
+        if (changeWorkingDirectory) {
+            ftp.changeWorkingDirectory(directory);
+            return ftp.listFiles("");
+        } else {
+            return ftp.listFiles(directory);
+        }
+    }
+
     protected void pollFile(final String file) {
         if (logger.isDebugEnabled()) {
             logger.debug("Scheduling file " + file + " for processing");
@@ -341,5 +357,6 @@
             }
         }
     }
+
     
 }

Added: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/FtpPollerEndpointTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/FtpPollerEndpointTest.java?rev=679046&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/FtpPollerEndpointTest.java (added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/FtpPollerEndpointTest.java Wed Jul 23 02:28:45 2008
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.ftp;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.jbi.management.DeploymentException;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link FtpPollerEndpoint} 
+ */
+public class FtpPollerEndpointTest extends TestCase {
+
+    public void testValidateNoCwdWhenRecursive() throws URISyntaxException {
+        FtpPollerEndpoint endpoint = new FtpPollerEndpoint();
+        endpoint.setUri(new URI("ftp://anonymous@just.a.server/test"));
+        endpoint.setTargetService(new QName("test", "service"));
+        endpoint.setChangeWorkingDirectory(true);
+        try {
+            endpoint.validate();
+            fail("validate() should throw exception when changeWorkingDirectory='true' and recursive='true'");
+        } catch (DeploymentException e) {
+            //this is what we expect
+            System.out.println(e);
+        }
+    }
+}
\ No newline at end of file