[CAMEL-10505] FILE component - resolved FileNotFountException in Generic File Rename Exclusive Read Lock Strategy in case of work file is locked by another application
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b2b62d06 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b2b62d06 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b2b62d06 Branch: refs/heads/camel-2.17.x Commit: b2b62d06bb22c00186824ee6956751ce342cac2b Parents: b430437 Author: [email protected] <[email protected]> Authored: Tue Nov 22 15:39:11 2016 +0300 Committer: Claus Ibsen <[email protected]> Committed: Tue Nov 22 20:43:47 2016 +0100 ---------------------------------------------------------------------- .../GenericFileRenameExclusiveReadLockStrategy.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b2b62d06/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java index 976c965..ef5fdb1 100644 --- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/GenericFileRenameExclusiveReadLockStrategy.java @@ -16,11 +16,14 @@ */ package org.apache.camel.component.file.strategy; +import java.io.FileNotFoundException; + import org.apache.camel.Exchange; import org.apache.camel.LoggingLevel; import org.apache.camel.component.file.GenericFile; import org.apache.camel.component.file.GenericFileEndpoint; import org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy; +import org.apache.camel.component.file.GenericFileOperationFailedException; import org.apache.camel.component.file.GenericFileOperations; import org.apache.camel.util.CamelLogger; import org.apache.camel.util.StopWatch; @@ -70,7 +73,15 @@ public class GenericFileRenameExclusiveReadLockStrategy<T> implements GenericFil } } - exclusive = operations.renameFile(file.getAbsoluteFilePath(), newFile.getAbsoluteFilePath()); + try { + exclusive = operations.renameFile(file.getAbsoluteFilePath(), newFile.getAbsoluteFilePath()); + } catch (GenericFileOperationFailedException ex) { + if (ex.getCause() != null && ex.getCause() instanceof FileNotFoundException) { + exclusive = false; + } else { + throw ex; + } + } if (exclusive) { LOG.trace("Acquired exclusive read lock to file: {}", file); // rename it back so we can read it
