This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-2.21.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit d38c5cb1e429c00620406da488cda3ca713aa564 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Mar 12 15:49:48 2018 +0100 CAMEL-12337: camel-ftp - ignoreFileNotFoundOrPermissionError should also ignore dir not found or list dir permission error. --- .../camel/component/file/remote/FtpConsumer.java | 69 +++++++++++----------- .../camel/component/file/remote/SftpConsumer.java | 49 +++++++-------- 2 files changed, 59 insertions(+), 59 deletions(-) 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 24a4637..09e6742 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 @@ -5,9 +5,9 @@ * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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. @@ -43,7 +43,7 @@ import org.apache.commons.net.ftp.FTPFile; public class FtpConsumer extends RemoteFileConsumer<FTPFile> { protected String endpointPath; - + private transient String ftpConsumerToString; public FtpConsumer(RemoteFileEndpoint<FTPFile> endpoint, Processor processor, RemoteFileOperations<FTPFile> fileOperations) { @@ -71,7 +71,7 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> { } catch (GenericFileOperationFailedException e) { // log a WARN as we want to start the consumer. log.warn("Error auto creating directory: " + endpoint.getConfiguration().getDirectory() - + " due " + e.getMessage() + ". This exception is ignored.", e); + + " due " + e.getMessage() + ". This exception is ignored.", e); } } } finally { @@ -119,40 +119,40 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> { dirName = FileUtil.stripTrailingSeparator(dirName); // compute dir depending on stepwise is enabled or not - String dir; - if (isStepwise()) { - dir = ObjectHelper.isNotEmpty(dirName) ? dirName : absolutePath; - operations.changeCurrentDirectory(dir); - } else { - dir = absolutePath; - } - - log.trace("Polling directory: {}", dir); + String dir = null; List<FTPFile> files = null; - if (isUseList()) { - try { + try { + if (isStepwise()) { + dir = ObjectHelper.isNotEmpty(dirName) ? dirName : absolutePath; + operations.changeCurrentDirectory(dir); + } else { + dir = absolutePath; + } + + log.trace("Polling directory: {}", dir); + if (isUseList()) { 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 + // so created a pseudo file with that name + FTPFile file = new FTPFile(); + file.setType(FTPFile.FILE_TYPE); + fileExpressionResult = evaluateFileExpression(); + if (fileExpressionResult != null) { + file.setName(fileExpressionResult); + files = new ArrayList<FTPFile>(1); + files.add(file); } } - } else { - // we cannot use the LIST command(s) so we can only poll a named file - // so created a pseudo file with that name - FTPFile file = new FTPFile(); - file.setType(FTPFile.FILE_TYPE); - fileExpressionResult = evaluateFileExpression(); - if (fileExpressionResult != null) { - file.setName(fileExpressionResult); - files = new ArrayList<FTPFile>(1); - files.add(file); + } 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; } } @@ -164,8 +164,7 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> { // we found some files log.trace("Found {} in directory: {}", files.size(), dir); } - - + if (getEndpoint().isPreSort()) { Collections.sort(files, (a, b) -> a.getName().compareTo(b.getName())); } @@ -262,10 +261,10 @@ public class FtpConsumer extends RemoteFileConsumer<FTPFile> { // create a pseudo absolute name String dir = FileUtil.stripTrailingSeparator(absolutePath); String fileName = file.getName(); - if (((FtpConfiguration)endpoint.getConfiguration()).isHandleDirectoryParserAbsoluteResult()) { + if (((FtpConfiguration) endpoint.getConfiguration()).isHandleDirectoryParserAbsoluteResult()) { fileName = FtpUtils.extractDirNameFromAbsolutePath(file.getName()); } - String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + fileName); + String absoluteFileName = FileUtil.stripLeadingSeparator(dir + "/" + fileName); // if absolute start with a leading separator otherwise let it be relative if (absolute) { absoluteFileName = "/" + absoluteFileName; 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 6a92015..fc8fc36 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 @@ -108,39 +108,40 @@ public class SftpConsumer extends RemoteFileConsumer<SftpRemoteFile> { // remove trailing / dirName = FileUtil.stripTrailingSeparator(dirName); - // compute dir depending on stepwise is enabled or not - String dir; - if (isStepwise()) { - dir = ObjectHelper.isNotEmpty(dirName) ? dirName : absolutePath; - operations.changeCurrentDirectory(dir); - } else { - dir = absolutePath; - } - log.trace("Polling directory: {}", dir); + // compute dir depending on stepwise is enabled or not + String dir = null; List<SftpRemoteFile> files = null; - if (isUseList()) { - try { + try { + if (isStepwise()) { + dir = ObjectHelper.isNotEmpty(dirName) ? dirName : absolutePath; + operations.changeCurrentDirectory(dir); + } else { + dir = absolutePath; + } + + log.trace("Polling directory: {}", dir); + if (isUseList()) { 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 + // so created a pseudo file with that name + fileExpressionResult = evaluateFileExpression(); + if (fileExpressionResult != null) { + SftpRemoteFile file = new SftpRemoteFileSingle(fileExpressionResult); + files = new ArrayList<SftpRemoteFile>(1); + files.add(file); } } - } else { - // we cannot use the LIST command(s) so we can only poll a named file - // so created a pseudo file with that name - fileExpressionResult = evaluateFileExpression(); - if (fileExpressionResult != null) { - SftpRemoteFile file = new SftpRemoteFileSingle(fileExpressionResult); - files = new ArrayList<SftpRemoteFile>(1); - files.add(file); + } 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; } } -- To stop receiving notification emails like this one, please contact davscl...@apache.org.