You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/09/13 14:53:17 UTC
[3/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/ed6e772b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ed6e772b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ed6e772b
Branch: refs/heads/camel-2.12.x
Commit: ed6e772b0b6e2a6444b334c80a066a7dca803ada
Parents: 78de11e
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Sep 13 14:52:40 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 13 14:52:59 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/ed6e772b/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<T> extends ScheduledBatchPollingConsum
*
* @param name the file name
* @param exchange the exchange
+ * @param cause optional exception occurred during retrieving file
* @return <tt>true</tt> to ignore, <tt>false</tt> 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<T> 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<T> 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/ed6e772b/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<FTPFile> {
}
@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<FTPFile> asRemoteFile(String absolutePath, FTPFile file) {
http://git-wip-us.apache.org/repos/asf/camel/blob/ed6e772b/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.
* <p/>
- * 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 <tt>true</tt> 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/ed6e772b/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<ChannelSftp.LsEntry> {
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<ChannelSftp.LsEntry> asRemoteFile(String absolutePath, ChannelSftp.LsEntry file) {
RemoteFile<ChannelSftp.LsEntry> answer = new RemoteFile<ChannelSftp.LsEntry>();
http://git-wip-us.apache.org/repos/asf/camel/blob/ed6e772b/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/ed6e772b/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