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 2019/05/16 09:47:18 UTC

[camel] branch camel-2.23.x updated: CAMEL-13542: Fixed camel-catalog would strip out dashes in hostnames when using optimized toD with http components.

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

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


The following commit(s) were added to refs/heads/camel-2.23.x by this push:
     new 3e35412  CAMEL-13542: Fixed camel-catalog would strip out dashes in hostnames when using optimized toD with http components.
3e35412 is described below

commit 3e354128a90d36b82148beca2917de88ad66278b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 16 11:14:18 2019 +0200

    CAMEL-13542: Fixed camel-catalog would strip out dashes in hostnames when using optimized toD with http components.
---
 .../camel/runtimecatalog/AbstractCamelCatalog.java |  5 ++--
 .../apache/camel/catalog/AbstractCamelCatalog.java | 29 ++++++++++++----------
 .../org/apache/camel/catalog/CamelCatalogTest.java | 16 ++++++++++++
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java b/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
index 98dafd6..431072b 100644
--- a/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
+++ b/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
@@ -68,6 +68,7 @@ public abstract class AbstractCamelCatalog {
     // CHECKSTYLE:OFF
 
     private static final Pattern SYNTAX_PATTERN = Pattern.compile("([\\w.]+)");
+    private static final Pattern SYNTAX_DASH_PATTERN = Pattern.compile("([\\w.-]+)");
     private static final Pattern COMPONENT_SYNTAX_PARSER = Pattern.compile("([^\\w-]*)([\\w-]+)");
 
     private SuggestionStrategy suggestionStrategy;
@@ -953,7 +954,7 @@ public abstract class AbstractCamelCatalog {
             // oh darn some options is missing, so we need a complex way of building the uri
 
             // the tokens between the options in the path
-            String[] tokens = syntax.split("[\\w.]+");
+            String[] tokens = SYNTAX_DASH_PATTERN.split(syntax);
 
             // parse the syntax into each options
             Matcher matcher = SYNTAX_PATTERN.matcher(originalSyntax);
@@ -969,7 +970,7 @@ public abstract class AbstractCamelCatalog {
             syntax = syntax.replaceAll("\\}\\}", "ENDCAMELPLACEHOLDER");
 
             // parse the syntax into each options
-            Matcher matcher2 = SYNTAX_PATTERN.matcher(syntax);
+            Matcher matcher2 = SYNTAX_DASH_PATTERN.matcher(syntax);
             List<String> options2 = new ArrayList<>();
             while (matcher2.find()) {
                 String s = matcher2.group(1);
diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
index 99f5fbd..64a69a9 100644
--- a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
+++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
@@ -68,6 +68,7 @@ public abstract class AbstractCamelCatalog {
     // CHECKSTYLE:OFF
 
     private static final Pattern SYNTAX_PATTERN = Pattern.compile("([\\w.]+)");
+    private static final Pattern SYNTAX_DASH_PATTERN = Pattern.compile("([\\w.-]+)");
     private static final Pattern COMPONENT_SYNTAX_PARSER = Pattern.compile("([^\\w-]*)([\\w-]+)");
 
     private SuggestionStrategy suggestionStrategy;
@@ -759,17 +760,19 @@ public abstract class AbstractCamelCatalog {
             boolean multiValued = isPropertyMultiValue(rows, key);
             if (multiValued) {
                 String prefix = getPropertyPrefix(rows, key);
-                // extra all the multi valued options
-                Map<String, Object> values = URISupport.extractProperties(parameters, prefix);
-                // build a string with the extra multi valued options with the prefix and & as separator
-                CollectionStringBuffer csb = new CollectionStringBuffer("&");
-                for (Map.Entry<String, Object> multi : values.entrySet()) {
-                    String line = prefix + multi.getKey() + "=" + (multi.getValue() != null ? multi.getValue().toString() : "");
-                    csb.append(line);
-                }
-                // append the extra multi-values to the existing (which contains the first multi value)
-                if (!csb.isEmpty()) {
-                    value = value + "&" + csb.toString();
+                if (prefix != null) {
+                    // extra all the multi valued options
+                    Map<String, Object> values = URISupport.extractProperties(parameters, prefix);
+                    // build a string with the extra multi valued options with the prefix and & as separator
+                    CollectionStringBuffer csb = new CollectionStringBuffer("&");
+                    for (Map.Entry<String, Object> multi : values.entrySet()) {
+                        String line = prefix + multi.getKey() + "=" + (multi.getValue() != null ? multi.getValue().toString() : "");
+                        csb.append(line);
+                    }
+                    // append the extra multi-values to the existing (which contains the first multi value)
+                    if (!csb.isEmpty()) {
+                        value = value + "&" + csb.toString();
+                    }
                 }
             }
 
@@ -951,7 +954,7 @@ public abstract class AbstractCamelCatalog {
             // oh darn some options is missing, so we need a complex way of building the uri
 
             // the tokens between the options in the path
-            String[] tokens = syntax.split("[\\w.]+");
+            String[] tokens = SYNTAX_DASH_PATTERN.split(syntax);
 
             // parse the syntax into each options
             Matcher matcher = SYNTAX_PATTERN.matcher(originalSyntax);
@@ -967,7 +970,7 @@ public abstract class AbstractCamelCatalog {
             syntax = syntax.replaceAll("\\}\\}", "ENDCAMELPLACEHOLDER");
 
             // parse the syntax into each options
-            Matcher matcher2 = SYNTAX_PATTERN.matcher(syntax);
+            Matcher matcher2 = SYNTAX_DASH_PATTERN.matcher(syntax);
             List<String> options2 = new ArrayList<>();
             while (matcher2.find()) {
                 String s = matcher2.group(1);
diff --git a/platforms/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java b/platforms/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index ceb036e..84a5c43 100644
--- a/platforms/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -1191,6 +1191,22 @@ public class CamelCatalogTest {
     }
 
     @Test
+    public void testNetty4Http4DynamicToIssueHost() throws Exception {
+        String uri = "netty4-http:http://a-b-c.hostname.tld:8080/anything";
+        Map<String, String> params = catalog.endpointProperties(uri);
+        assertEquals("http", params.get("protocol"));
+        assertEquals("a-b-c.hostname.tld", params.get("host"));
+        assertEquals("8080", params.get("port"));
+        assertEquals("anything", params.get("path"));
+
+        // remove path
+        params.remove("path");
+
+        String resolved = catalog.asEndpointUri("netty4-http", params, false);
+        assertEquals("netty4-http:http:a-b-c.hostname.tld:8080", resolved);
+    }
+
+    @Test
     public void testJSonSchemaHelper() throws Exception {
         String json = loadText(new FileInputStream("src/test/resources/org/foo/camel/dummy.json"));
         assertNotNull(json);