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 2021/12/31 10:07:04 UTC

[camel] branch main updated: CAMEL-17389: ToD using file endpoints windows path issue.

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 0962cc2  CAMEL-17389: ToD using file endpoints windows path issue.
0962cc2 is described below

commit 0962cc28e756d239c649ce9396a8c1f2f467fa3c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Dec 31 11:01:36 2021 +0100

    CAMEL-17389: ToD using file endpoints windows path issue.
---
 .../file/GenericFileSendDynamicAware.java          |  9 +++--
 .../camel/issues/ToDWindowsFilePathIssueTest.java  | 42 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java
index 0ca4dbf..57ad5bc 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileSendDynamicAware.java
@@ -38,6 +38,11 @@ public abstract class GenericFileSendDynamicAware extends SendDynamicAwareSuppor
 
     @Override
     public String resolveStaticUri(Exchange exchange, DynamicAwareEntry entry) throws Exception {
+        String uri = entry.getUri();
+        // windows path problems such as C:\temp was by simple language evaluated \t as a tab character
+        // which should then be reversed
+        uri = uri.replaceAll("\t", "\\\\t");
+
         boolean fileName = entry.getProperties().containsKey("fileName");
         boolean tempFileName = entry.getProperties().containsKey("tempFileName");
         boolean idempotentKey = entry.getProperties().containsKey("idempotentKey");
@@ -94,9 +99,9 @@ public abstract class GenericFileSendDynamicAware extends SendDynamicAwareSuppor
                 }
             }
 
-            return asEndpointUri(exchange, entry.getUri(), params);
+            return asEndpointUri(exchange, uri, params);
         } else {
-            return entry.getUri();
+            return uri;
         }
     }
 
diff --git a/core/camel-core/src/test/java/org/apache/camel/issues/ToDWindowsFilePathIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/issues/ToDWindowsFilePathIssueTest.java
new file mode 100644
index 0000000..8fbb55e
--- /dev/null
+++ b/core/camel-core/src/test/java/org/apache/camel/issues/ToDWindowsFilePathIssueTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+@Disabled("CAMEL-17389: Manual test")
+public class ToDWindowsFilePathIssueTest extends ContextTestSupport {
+
+    @Test
+    public void testWindows() throws Exception {
+        template.sendBody("direct:start", "Hello Windows");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                        .toD("file:C:\\temp");
+            }
+        };
+    }
+}