Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6D071104D9 for ; Fri, 13 Sep 2013 16:05:39 +0000 (UTC) Received: (qmail 33104 invoked by uid 500); 13 Sep 2013 12:53:22 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 33004 invoked by uid 500); 13 Sep 2013 12:53:19 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 32932 invoked by uid 99); 13 Sep 2013 12:53:16 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Sep 2013 12:53:16 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 128B782253B; Fri, 13 Sep 2013 12:53:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 13 Sep 2013 12:53:16 -0000 Message-Id: <10c8087cf38e4a3091c427f567f30c4e@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] git commit: CAMEL-6745: sftp consumer - Option ignoreFileNotFound should be used for ignoring file permission errors as well CAMEL-6745: sftp consumer - Option ignoreFileNotFound should be used for ignoring file permission errors as well Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/71b21652 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/71b21652 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/71b21652 Branch: refs/heads/master Commit: 71b216526e8b3e5e6d63010aa49d6b41fcd2d4b0 Parents: f9760f7 Author: Claus Ibsen Authored: Fri Sep 13 14:52:40 2013 +0200 Committer: Claus Ibsen Committed: Fri Sep 13 14:52:40 2013 +0200 ---------------------------------------------------------------------- .../component/file/GenericFileConsumer.java | 23 +++++++++++++++----- .../component/file/remote/FtpConsumer.java | 6 ++--- .../file/remote/RemoteFileConfiguration.java | 14 ++++++------ .../component/file/remote/SftpConsumer.java | 12 ++++++++++ .../file/remote/FromFtpUseListFalseTest.java | 2 +- .../FtpConsumerTemplateUseListFalseTest.java | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/71b21652/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java index 3a3fc59..c8452fd 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java @@ -297,9 +297,10 @@ public abstract class GenericFileConsumer extends ScheduledBatchPollingConsum * * @param name the file name * @param exchange the exchange + * @param cause optional exception occurred during retrieving file * @return true to ignore, false is the default. */ - protected boolean ignoreCannotRetrieveFile(String name, Exchange exchange) { + protected boolean ignoreCannotRetrieveFile(String name, Exchange exchange, Exception cause) { return false; } @@ -355,10 +356,18 @@ public abstract class GenericFileConsumer extends ScheduledBatchPollingConsum log.trace("Retrieving file: {} from: {}", name, endpoint); // retrieve the file and check it was a success - boolean retrieved = operations.retrieveFile(name, exchange); + boolean retrieved; + Exception cause = null; + try { + retrieved = operations.retrieveFile(name, exchange); + } catch (Exception e) { + retrieved = false; + cause = e; + } + if (!retrieved) { - if (ignoreCannotRetrieveFile(name, exchange)) { - log.trace("Cannot retrieve file {} maybe it does not exists. Ignorning.", name); + if (ignoreCannotRetrieveFile(name, exchange, cause)) { + log.trace("Cannot retrieve file {} maybe it does not exists. Ignoring.", name); // remove file from the in progress list as we could not retrieve it, but should ignore endpoint.getInProgressRepository().remove(absoluteFileName); return false; @@ -366,7 +375,11 @@ public abstract class GenericFileConsumer extends ScheduledBatchPollingConsum // throw exception to handle the problem with retrieving the file // then if the method return false or throws an exception is handled the same in here // as in both cases an exception is being thrown - throw new GenericFileOperationFailedException("Cannot retrieve file: " + file + " from: " + endpoint); + if (cause != null && cause instanceof GenericFileOperationFailedException) { + throw cause; + } else { + throw new GenericFileOperationFailedException("Cannot retrieve file: " + file + " from: " + endpoint, cause); + } } } http://git-wip-us.apache.org/repos/asf/camel/blob/71b21652/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConsumer.java ---------------------------------------------------------------------- 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 5d7dca5..fff8e93 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 @@ -165,15 +165,15 @@ public class FtpConsumer extends RemoteFileConsumer { } @Override - protected boolean ignoreCannotRetrieveFile(String name, Exchange exchange) { - if (getEndpoint().getConfiguration().isIgnoreFileNotFound()) { + protected boolean ignoreCannotRetrieveFile(String name, Exchange exchange, Exception cause) { + if (getEndpoint().getConfiguration().isIgnoreFileNotFoundOrPermissionError()) { // error code 550 is file not found int code = exchange.getIn().getHeader(FtpConstants.FTP_REPLY_CODE, 0, int.class); if (code == 550) { return true; } } - return super.ignoreCannotRetrieveFile(name, exchange); + return super.ignoreCannotRetrieveFile(name, exchange, cause); } private RemoteFile asRemoteFile(String absolutePath, FTPFile file) { http://git-wip-us.apache.org/repos/asf/camel/blob/71b21652/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConfiguration.java ---------------------------------------------------------------------- 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 bbe0a18..56cd66c 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 @@ -51,7 +51,7 @@ public abstract class RemoteFileConfiguration extends GenericFileConfiguration { private PathSeparator separator = PathSeparator.Auto; private boolean streamDownload; private boolean useList = true; - private boolean ignoreFileNotFound; + private boolean ignoreFileNotFoundOrPermissionError; public RemoteFileConfiguration() { } @@ -292,18 +292,18 @@ public abstract class RemoteFileConfiguration extends GenericFileConfiguration { this.useList = useList; } - public boolean isIgnoreFileNotFound() { - return ignoreFileNotFound; + public boolean isIgnoreFileNotFoundOrPermissionError() { + return ignoreFileNotFoundOrPermissionError; } /** - * Whether to ignore when trying to download a file which does not exist. + * 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, then an exception is thrown. + * 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. */ - public void setIgnoreFileNotFound(boolean ignoreFileNotFound) { - this.ignoreFileNotFound = ignoreFileNotFound; + public void setIgnoreFileNotFoundOrPermissionError(boolean ignoreFileNotFoundOrPermissionError) { + this.ignoreFileNotFoundOrPermissionError = ignoreFileNotFoundOrPermissionError; } /** http://git-wip-us.apache.org/repos/asf/camel/blob/71b21652/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpConsumer.java ---------------------------------------------------------------------- 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 765aac4..0d0906b 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 @@ -19,6 +19,7 @@ package org.apache.camel.component.file.remote; import java.util.List; import com.jcraft.jsch.ChannelSftp; +import com.jcraft.jsch.SftpException; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.component.file.GenericFile; @@ -147,6 +148,17 @@ public class SftpConsumer extends RemoteFileConsumer { return false; } + @Override + protected boolean ignoreCannotRetrieveFile(String name, Exchange exchange, Exception cause) { + if (getEndpoint().getConfiguration().isIgnoreFileNotFoundOrPermissionError()) { + SftpException sftp = ObjectHelper.getException(SftpException.class, cause); + if (sftp != null) { + return sftp.id == ChannelSftp.SSH_FX_NO_SUCH_FILE || sftp.id == ChannelSftp.SSH_FX_PERMISSION_DENIED; + } + } + return super.ignoreCannotRetrieveFile(name, exchange, cause); + } + private RemoteFile asRemoteFile(String absolutePath, ChannelSftp.LsEntry file) { RemoteFile answer = new RemoteFile(); http://git-wip-us.apache.org/repos/asf/camel/blob/71b21652/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpUseListFalseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpUseListFalseTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpUseListFalseTest.java index afd2763..4013d57 100644 --- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpUseListFalseTest.java +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpUseListFalseTest.java @@ -31,7 +31,7 @@ public class FromFtpUseListFalseTest extends FtpServerTestSupport { private String getFtpUrl() { return "ftp://admin@localhost:" + getPort() + "/nolist/?password=admin" - + "&stepwise=false&useList=false&ignoreFileNotFound=true&fileName=report.txt&delete=true"; + + "&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&fileName=report.txt&delete=true"; } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/71b21652/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerTemplateUseListFalseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerTemplateUseListFalseTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerTemplateUseListFalseTest.java index 6554e62..63a5712 100644 --- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerTemplateUseListFalseTest.java +++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerTemplateUseListFalseTest.java @@ -29,7 +29,7 @@ public class FtpConsumerTemplateUseListFalseTest extends FtpServerTestSupport { private String getFtpUrl() { return "ftp://admin@localhost:" + getPort() + "/nolist/?password=admin" - + "&stepwise=false&useList=false&ignoreFileNotFound=true&delete=true"; + + "&stepwise=false&useList=false&ignoreFileNotFoundOrPermissionError=true&delete=true"; } @Override