This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 2aaa23a  CAMEL-12337: camel-ftp - ignoreFileNotFoundOrPermissionError 
should also ignore dir not found or list dir permission error.
2aaa23a is described below

commit 2aaa23a52f4c167a3bd4371b59034e48c0fb65da
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat Mar 10 10:40:32 2018 +0100

    CAMEL-12337: camel-ftp - ignoreFileNotFoundOrPermissionError should also 
ignore dir not found or list dir permission error.
---
 components/camel-ftp/src/main/docs/ftp-component.adoc    |  2 +-
 components/camel-ftp/src/main/docs/ftps-component.adoc   |  2 +-
 components/camel-ftp/src/main/docs/sftp-component.adoc   |  2 +-
 .../apache/camel/component/file/remote/FtpConsumer.java  | 16 ++++++++++++----
 .../component/file/remote/RemoteFileConfiguration.java   |  4 ++--
 .../apache/camel/component/file/remote/SftpConsumer.java | 16 ++++++++++++----
 6 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/components/camel-ftp/src/main/docs/ftp-component.adoc 
b/components/camel-ftp/src/main/docs/ftp-component.adoc
index 1744f87..9821eca 100644
--- a/components/camel-ftp/src/main/docs/ftp-component.adoc
+++ b/components/camel-ftp/src/main/docs/ftp-component.adoc
@@ -132,7 +132,7 @@ with the following path and query parameters:
 | *exceptionHandler* (consumer) | To let the consumer use a custom 
ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this 
options is not in use. By default the consumer will deal with exceptions, that 
will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer 
creates an exchange. |  | ExchangePattern
 | *handleDirectoryParser AbsoluteResult* (consumer) | Allows you to set how 
the consumer will handle subfolders and files in the path if the directory 
parser results in with absolute paths The reason for this is that some FTP 
servers may return file names with absolute paths, and if so then the FTP 
component needs to handle this by converting the returned path into a relative 
path. | false | boolean
-| *ignoreFileNotFoundOr PermissionError* (consumer) | Whether to ignore when 
trying to download a file which does not exist or due to permission error. By 
default when a file does not exists or insufficient permission, then an 
exception is thrown. Setting this option to true allows to ignore that instead. 
| false | boolean
+| *ignoreFileNotFoundOr PermissionError* (consumer) | Whether to ignore when 
(trying to list files in directories or when downloading a file), which does 
not exist or due to permission error. By default when a directory or file does 
not exists or insufficient permission, then an exception is thrown. Setting 
this option to true allows to ignore that instead. | false | boolean
 | *inProgressRepository* (consumer) | A pluggable in-progress repository 
org.apache.camel.spi.IdempotentRepository. The in-progress repository is used 
to account the current in progress files being consumed. By default a memory 
based repository is used. |  | String>
 | *localWorkDirectory* (consumer) | When consuming, a local work directory can 
be used to store the remote file content directly in local files, to avoid 
loading the content into memory. This is beneficial, if you consume a very big 
remote file and thus can conserve memory. |  | String
 | *onCompletionException Handler* (consumer) | To use a custom 
org.apache.camel.spi.ExceptionHandler to handle any thrown exceptions that 
happens during the file on completion process where the consumer does either a 
commit or rollback. The default implementation will log any exception at WARN 
level and ignore. |  | ExceptionHandler
diff --git a/components/camel-ftp/src/main/docs/ftps-component.adoc 
b/components/camel-ftp/src/main/docs/ftps-component.adoc
index b50e091..106fd53 100644
--- a/components/camel-ftp/src/main/docs/ftps-component.adoc
+++ b/components/camel-ftp/src/main/docs/ftps-component.adoc
@@ -92,7 +92,7 @@ with the following path and query parameters:
 | *exceptionHandler* (consumer) | To let the consumer use a custom 
ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this 
options is not in use. By default the consumer will deal with exceptions, that 
will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer 
creates an exchange. |  | ExchangePattern
 | *handleDirectoryParser AbsoluteResult* (consumer) | Allows you to set how 
the consumer will handle subfolders and files in the path if the directory 
parser results in with absolute paths The reason for this is that some FTP 
servers may return file names with absolute paths, and if so then the FTP 
component needs to handle this by converting the returned path into a relative 
path. | false | boolean
-| *ignoreFileNotFoundOr PermissionError* (consumer) | Whether to ignore when 
trying to download a file which does not exist or due to permission error. By 
default when a file does not exists or insufficient permission, then an 
exception is thrown. Setting this option to true allows to ignore that instead. 
| false | boolean
+| *ignoreFileNotFoundOr PermissionError* (consumer) | Whether to ignore when 
(trying to list files in directories or when downloading a file), which does 
not exist or due to permission error. By default when a directory or file does 
not exists or insufficient permission, then an exception is thrown. Setting 
this option to true allows to ignore that instead. | false | boolean
 | *inProgressRepository* (consumer) | A pluggable in-progress repository 
org.apache.camel.spi.IdempotentRepository. The in-progress repository is used 
to account the current in progress files being consumed. By default a memory 
based repository is used. |  | String>
 | *localWorkDirectory* (consumer) | When consuming, a local work directory can 
be used to store the remote file content directly in local files, to avoid 
loading the content into memory. This is beneficial, if you consume a very big 
remote file and thus can conserve memory. |  | String
 | *onCompletionException Handler* (consumer) | To use a custom 
org.apache.camel.spi.ExceptionHandler to handle any thrown exceptions that 
happens during the file on completion process where the consumer does either a 
commit or rollback. The default implementation will log any exception at WARN 
level and ignore. |  | ExceptionHandler
diff --git a/components/camel-ftp/src/main/docs/sftp-component.adoc 
b/components/camel-ftp/src/main/docs/sftp-component.adoc
index c525adc..9743837 100644
--- a/components/camel-ftp/src/main/docs/sftp-component.adoc
+++ b/components/camel-ftp/src/main/docs/sftp-component.adoc
@@ -77,7 +77,7 @@ with the following path and query parameters:
 | *download* (consumer) | Whether the FTP consumer should download the file. 
If this option is set to false, then the message body will be null, but the 
consumer will still trigger a Camel Exchange that has details about the file 
such as file name, file size, etc. It's just that the file will not be 
downloaded. | false | boolean
 | *exceptionHandler* (consumer) | To let the consumer use a custom 
ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this 
options is not in use. By default the consumer will deal with exceptions, that 
will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer 
creates an exchange. |  | ExchangePattern
-| *ignoreFileNotFoundOr PermissionError* (consumer) | Whether to ignore when 
trying to download a file which does not exist or due to permission error. By 
default when a file does not exists or insufficient permission, then an 
exception is thrown. Setting this option to true allows to ignore that instead. 
| false | boolean
+| *ignoreFileNotFoundOr PermissionError* (consumer) | Whether to ignore when 
(trying to list files in directories or when downloading a file), which does 
not exist or due to permission error. By default when a directory or file does 
not exists or insufficient permission, then an exception is thrown. Setting 
this option to true allows to ignore that instead. | false | boolean
 | *inProgressRepository* (consumer) | A pluggable in-progress repository 
org.apache.camel.spi.IdempotentRepository. The in-progress repository is used 
to account the current in progress files being consumed. By default a memory 
based repository is used. |  | String>
 | *localWorkDirectory* (consumer) | When consuming, a local work directory can 
be used to store the remote file content directly in local files, to avoid 
loading the content into memory. This is beneficial, if you consume a very big 
remote file and thus can conserve memory. |  | String
 | *onCompletionException Handler* (consumer) | To use a custom 
org.apache.camel.spi.ExceptionHandler to handle any thrown exceptions that 
happens during the file on completion process where the consumer does either a 
commit or rollback. The default implementation will log any exception at WARN 
level and ignore. |  | ExceptionHandler
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
index c4c5b72..24a4637 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java
@@ -130,10 +130,18 @@ public class FtpConsumer extends 
RemoteFileConsumer<FTPFile> {
         log.trace("Polling directory: {}", dir);
         List<FTPFile> files = null;
         if (isUseList()) {
-            if (isStepwise()) {
-                files = operations.listFiles();
-            } else {
-                files = operations.listFiles(dir);
+            try {
+                if (isStepwise()) {
+                    files = operations.listFiles();
+                } else {
+                    files = operations.listFiles(dir);
+                }
+            } catch (GenericFileOperationFailedException e) {
+                if (ignoreCannotRetrieveFile(null, null, e)) {
+                    log.debug("Cannot list files in directory {} due directory 
does not exists or file permission error.", dir);
+                } else {
+                    throw e;
+                }
             }
         } else {
             // we cannot use the LIST command(s) so we can only poll a named 
file
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
index 31883a7..0fad6d1 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java
@@ -369,9 +369,9 @@ public abstract class RemoteFileConfiguration extends 
GenericFileConfiguration {
     }
 
     /**
-     * Whether to ignore when trying to download a file which does not exist 
or due to permission error.
+     * Whether to ignore when (trying to list files in directories or when 
downloading a file), which does not exist or due to permission error.
      * <p/>
-     * By default when a file does not exists or insufficient permission, then 
an exception is thrown.
+     * By default when a directory or file does not exists or insufficient 
permission, then an exception is thrown.
      * Setting this option to <tt>true</tt> allows to ignore that instead.
      */
     public void setIgnoreFileNotFoundOrPermissionError(boolean 
ignoreFileNotFoundOrPermissionError) {
diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
index c7a4a44..6a92015 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java
@@ -120,10 +120,18 @@ public class SftpConsumer extends 
RemoteFileConsumer<SftpRemoteFile> {
         log.trace("Polling directory: {}", dir);
         List<SftpRemoteFile> files = null;
         if (isUseList()) {
-            if (isStepwise()) {
-                files = operations.listFiles();
-            } else {
-                files = operations.listFiles(dir);
+            try {
+                if (isStepwise()) {
+                    files = operations.listFiles();
+                } else {
+                    files = operations.listFiles(dir);
+                }
+            } catch (GenericFileOperationFailedException e) {
+                if (ignoreCannotRetrieveFile(null, null, e)) {
+                    log.debug("Cannot list files in directory {} due directory 
does not exists or file permission error.", dir);
+                } else {
+                    throw e;
+                }
             }
         } else {
             // we cannot use the LIST command(s) so we can only poll a named 
file

-- 
To stop receiving notification emails like this one, please contact
davscl...@apache.org.

Reply via email to