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 2020/07/19 08:49:23 UTC

[camel] branch camel-3.4.x updated: CAMEL-15282: camel-catalog tooling should deal with endpoint properties validation if uri context path contains env or jvm system property functions for placeholders.

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

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


The following commit(s) were added to refs/heads/camel-3.4.x by this push:
     new 9daeb32  CAMEL-15282: camel-catalog tooling should deal with endpoint properties validation if uri context path contains env or jvm system property functions for placeholders.
9daeb32 is described below

commit 9daeb3208176f9ff6d5de5ddb6f9544851f39ea7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Jul 19 10:42:07 2020 +0200

    CAMEL-15282: camel-catalog tooling should deal with endpoint properties validation if uri context path contains env or jvm system property functions for placeholders.
---
 .../src/test/java/org/apache/camel/catalog/CamelCatalogTest.java | 9 +++++++++
 .../java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java | 7 ++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index b7b4a4f..ade74e4 100644
--- a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -1500,4 +1500,13 @@ public class CamelCatalogTest {
         assertTrue(result.isSuccess());
     }
 
+    @Test
+    public void validateEnvVariableInSyntax() throws Exception {
+        EndpointValidationResult result = catalog.validateEndpointProperties("netty-http:http://foo-bar.{{env:NAMESPACE}}.svc.cluster.local/samples");
+        assertTrue(result.isSuccess());
+
+        result = catalog.validateEndpointProperties("netty-http:http://foo-bar/?requestTimeout={{env:TIMEOUT}}");
+        assertTrue(result.isSuccess());
+    }
+
 }
diff --git a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
index 1ad77e4..c9d03af 100644
--- a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
+++ b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
@@ -62,6 +62,7 @@ public abstract class AbstractCamelCatalog {
     // CHECKSTYLE:OFF
 
     private static final Pattern SYNTAX_PATTERN = Pattern.compile("([\\w.]+)");
+    private static final Pattern ENV_OR_SYS_PATTERN = Pattern.compile("\\{\\{(env|sys):\\w+\\}\\}");
     private static final Pattern SYNTAX_DASH_PATTERN = Pattern.compile("([\\w.-]+)");
     private static final Pattern COMPONENT_SYNTAX_PARSER = Pattern.compile("([^\\w-]*)([\\w-]+)");
 
@@ -445,6 +446,10 @@ public abstract class AbstractCamelCatalog {
         uri = CatalogHelper.after(uri, ":");
         String uriPath = URISupport.stripQuery(uri);
 
+        // the uri path may use {{env:xxx}} or {{sys:xxx}} placeholders so ignore those
+        Matcher matcher = ENV_OR_SYS_PATTERN.matcher(uriPath);
+        uriPath = matcher.replaceAll("");
+
         // strip user info from uri path
         if (!userInfoOptions.isEmpty()) {
             int idx = uriPath.indexOf('@');
@@ -459,7 +464,7 @@ public abstract class AbstractCamelCatalog {
         }
 
         // parse the syntax and find the names of each option
-        Matcher matcher = SYNTAX_PATTERN.matcher(syntax);
+        matcher = SYNTAX_PATTERN.matcher(syntax);
         List<String> word = new ArrayList<>();
         while (matcher.find()) {
             String s = matcher.group(1);