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 2017/12/26 11:04:46 UTC

[camel] branch master updated (cd11a37 -> 10d218d)

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

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


    from cd11a37  Upgrade Netty Tcnative Boring SSL Static to version 2.0.7.Final
     new 00cb0f2  CAMEL-12094: file/ftp producer fixed so moveExisting works when using temp filename as well.
     new 10d218d  Fixed CS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/component/direct/DirectComponent.java    |  2 +-
 .../camel/component/file/GenericFileProducer.java  | 29 +++++++++++++++++++++-
 .../file/FileProducerMoveExistingTest.java         | 13 ++++++++++
 .../impl/cloud/ServiceCallConfigurationTest.java   |  4 +--
 .../file/remote/FtpProducerMoveExistingTest.java   | 12 +++++++++
 5 files changed, 56 insertions(+), 4 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].

[camel] 01/02: CAMEL-12094: file/ftp producer fixed so moveExisting works when using temp filename as well.

Posted by da...@apache.org.
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

commit 00cb0f2ebc887026a521b41ee614c7d81123bb48
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 26 12:01:53 2017 +0100

    CAMEL-12094: file/ftp producer fixed so moveExisting works when using temp filename as well.
---
 .../camel/component/file/GenericFileProducer.java  | 29 +++++++++++++++++++++-
 .../file/FileProducerMoveExistingTest.java         | 13 ++++++++++
 .../file/remote/FtpProducerMoveExistingTest.java   | 12 +++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
index 5876cb1..ee40b91 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileProducer.java
@@ -117,7 +117,7 @@ public class GenericFileProducer<T> extends DefaultProducer {
             boolean writeAsTempAndRename = ObjectHelper.isNotEmpty(endpoint.getTempFileName());
             String tempTarget = null;
             // remember if target exists to avoid checking twice
-            Boolean targetExists = null;
+            Boolean targetExists;
             if (writeAsTempAndRename) {
                 // compute temporary name with the temp prefix
                 tempTarget = createTempFileName(exchange, target);
@@ -142,6 +142,9 @@ public class GenericFileProducer<T> extends DefaultProducer {
                             return;
                         } else if (endpoint.getFileExist() == GenericFileExist.Fail) {
                             throw new GenericFileOperationFailedException("File already exist: " + target + ". Cannot write new file.");
+                        } else if (endpoint.getFileExist() == GenericFileExist.Move) {
+                            // move any existing file first
+                            doMoveExistingFile(target);
                         } else if (endpoint.isEagerDeleteTargetFile() && endpoint.getFileExist() == GenericFileExist.Override) {
                             // we override the target so we do this by deleting it so the temp file can be renamed later
                             // with success as the existing target file have been deleted
@@ -231,6 +234,30 @@ public class GenericFileProducer<T> extends DefaultProducer {
         postWriteCheck(exchange);
     }
 
+    private void doMoveExistingFile(String fileName) throws GenericFileOperationFailedException {
+        // need to evaluate using a dummy and simulate the file first, to have access to all the file attributes
+        // create a dummy exchange as Exchange is needed for expression evaluation
+        // we support only the following 3 tokens.
+        Exchange dummy = endpoint.createExchange();
+        String parent = FileUtil.onlyPath(fileName);
+        String onlyName = FileUtil.stripPath(fileName);
+        dummy.getIn().setHeader(Exchange.FILE_NAME, fileName);
+        dummy.getIn().setHeader(Exchange.FILE_NAME_ONLY, onlyName);
+        dummy.getIn().setHeader(Exchange.FILE_PARENT, parent);
+
+        String to = endpoint.getMoveExisting().evaluate(dummy, String.class);
+        // we must normalize it (to avoid having both \ and / in the name which confuses java.io.File)
+        to = FileUtil.normalizePath(to);
+        if (ObjectHelper.isEmpty(to)) {
+            throw new GenericFileOperationFailedException("moveExisting evaluated as empty String, cannot move existing file: " + fileName);
+        }
+
+        boolean renamed = operations.renameFile(fileName, to);
+        if (!renamed) {
+            throw new GenericFileOperationFailedException("Cannot rename file from: " + fileName + " to: " + to);
+        }
+    }
+
     /**
      * If we fail writing out a file, we will call this method. This hook is
      * provided to disconnect from servers or clean up files we created (if needed).
diff --git a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java
index 947c868..a3f833e 100644
--- a/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/file/FileProducerMoveExistingTest.java
@@ -54,6 +54,19 @@ public class FileProducerMoveExistingTest extends ContextTestSupport {
         assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, new File("target/file/renamed-hello.txt")));
     }
 
+    public void testExistingFileExistsTempFileName() throws Exception {
+        template.sendBodyAndHeader("file://target/file?tempFileName=${file:onlyname}.temp&fileExist=Move&moveExisting=${file:parent}/renamed-${file:onlyname}",
+                "Hello World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader("file://target/file?tempFileName=${file:onlyname}.temp&fileExist=Move&moveExisting=${file:parent}/renamed-${file:onlyname}",
+                "Bye World", Exchange.FILE_NAME, "hello.txt");
+
+        assertFileExists("target/file/hello.txt");
+        assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, new File("target/file/hello.txt")));
+
+        assertFileExists("target/file/renamed-hello.txt");
+        assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, new File("target/file/renamed-hello.txt")));
+    }
+
     public void testExistingFileExistsMoveSubDir() throws Exception {
         template.sendBodyAndHeader("file://target/file?fileExist=Move&moveExisting=backup", "Hello World", Exchange.FILE_NAME, "hello.txt");
         template.sendBodyAndHeader("file://target/file?fileExist=Move&moveExisting=backup", "Bye World", Exchange.FILE_NAME, "hello.txt");
diff --git a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerMoveExistingTest.java b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerMoveExistingTest.java
index 2e3201a..f610b0b 100644
--- a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerMoveExistingTest.java
+++ b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerMoveExistingTest.java
@@ -53,6 +53,18 @@ public class FtpProducerMoveExistingTest extends FtpServerTestSupport {
     }
 
     @Test
+    public void testExistingFileExistsTempFilename() throws Exception {
+        template.sendBodyAndHeader(getFtpUrl() + "&tempFileName=${file:onlyname}.temp&moveExisting=${file:parent}/renamed-${file:onlyname}", "Hello World", Exchange.FILE_NAME, "hello.txt");
+        template.sendBodyAndHeader(getFtpUrl() + "&tempFileName=${file:onlyname}.temp&moveExisting=${file:parent}/renamed-${file:onlyname}", "Bye World", Exchange.FILE_NAME, "hello.txt");
+
+        assertFileExists(FTP_ROOT_DIR + "/move/hello.txt");
+        assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, new File(FTP_ROOT_DIR + "/move/hello.txt")));
+
+        assertFileExists(FTP_ROOT_DIR + "/move/renamed-hello.txt");
+        assertEquals("Hello World", context.getTypeConverter().convertTo(String.class, new File(FTP_ROOT_DIR + "/move/renamed-hello.txt")));
+    }
+
+    @Test
     public void testExistingFileExistsMoveSubDir() throws Exception {
         template.sendBodyAndHeader(getFtpUrl() + "&moveExisting=backup", "Hello World", Exchange.FILE_NAME, "hello.txt");
         template.sendBodyAndHeader(getFtpUrl() + "&moveExisting=backup", "Bye World", Exchange.FILE_NAME, "hello.txt");

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.

[camel] 02/02: Fixed CS

Posted by da...@apache.org.
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

commit 10d218dd3dc1174ce07c64b50d9eaeb1b64c8ff5
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 26 12:03:22 2017 +0100

    Fixed CS
---
 .../main/java/org/apache/camel/component/direct/DirectComponent.java  | 2 +-
 .../org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java b/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java
index e1dee25..acf0d8f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/direct/DirectComponent.java
@@ -35,7 +35,7 @@ public class DirectComponent extends UriEndpointComponent {
     // later in case the DirectEndpoint was re-created due the old was evicted from the endpoints LRUCache
     // on DefaultCamelContext
     private final Map<String, DirectConsumer> consumers = new HashMap<String, DirectConsumer>();
-    @Metadata(label = "producer", defaultValue = "true" )
+    @Metadata(label = "producer", defaultValue = "true")
     private boolean block = true;
     @Metadata(label = "producer", defaultValue = "30000")
     private long timeout = 30000L;
diff --git a/camel-core/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java b/camel-core/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java
index 94763fe..fd84be6 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/cloud/ServiceCallConfigurationTest.java
@@ -43,8 +43,8 @@ public class ServiceCallConfigurationTest {
     @Test
     public void testDynamicUri() throws Exception {
         StaticServiceDiscovery sd = new StaticServiceDiscovery();
-        sd.addServer("scall","127.0.0.1", 8080);
-        sd.addServer("scall","127.0.0.1", 8081);
+        sd.addServer("scall", "127.0.0.1", 8080);
+        sd.addServer("scall", "127.0.0.1", 8081);
 
         ServiceCallConfigurationDefinition conf = new ServiceCallConfigurationDefinition();
         conf.setServiceDiscovery(sd);

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.