camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: Camel catalog - Add api to validate endpoint uri
Date Sun, 20 Dec 2015 08:17:21 GMT
Repository: camel
Updated Branches:
  refs/heads/master 624d98160 -> 15e17fbce


Camel catalog - Add api to validate endpoint uri


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/15e17fbc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/15e17fbc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/15e17fbc

Branch: refs/heads/master
Commit: 15e17fbcec59c2bf7e1d7b706dfeefed97378726
Parents: 624d981
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Dec 20 09:17:12 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Dec 20 09:17:12 2015 +0100

----------------------------------------------------------------------
 .../org/apache/camel/catalog/CamelCatalog.java  |  2 +-
 .../camel/catalog/DefaultCamelCatalog.java      | 28 ++++++++++++++------
 .../apache/camel/catalog/ValidationResult.java  | 24 ++++++++++++++++-
 .../apache/camel/catalog/CamelCatalogTest.java  |  5 ++++
 4 files changed, 49 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/15e17fbc/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index ac01b51..f3ce3a1 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -175,7 +175,7 @@ public interface CamelCatalog {
      * @param uri  the endpoint uri
      * @return validation result
      */
-    ValidationResult validateProperties(String uri) throws URISyntaxException;
+    ValidationResult validateProperties(String uri);
 
     /**
      * Returns the component name from the given endpoint uri

http://git-wip-us.apache.org/repos/asf/camel/blob/15e17fbc/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index f0e4c3c..2725ffa 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -646,17 +646,29 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
-    public ValidationResult validateProperties(String uri) throws URISyntaxException {
+    public ValidationResult validateProperties(String uri) {
         ValidationResult result = new ValidationResult();
 
-        // parse the uri
-        URI u = normalizeUri(uri);
-        String scheme = u.getScheme();
-        String json = componentJSonSchema(scheme);
-        List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("properties",
json, true);
+        Map<String, String> properties;
+        List<Map<String, String>> rows;
+
+        try {
+            // parse the uri
+            URI u = normalizeUri(uri);
+            String scheme = u.getScheme();
+            String json = componentJSonSchema(scheme);
+            if (json == null) {
+                result.addUnknownComponent(scheme);
+                return result;
+            }
+            rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
+            properties = endpointProperties(uri);
+        } catch (URISyntaxException e) {
+            result.addSyntaxError(e.getMessage());
+            return result;
+        }
 
-        // parse into a map of properties of the uri, and look for options that are invalid
-        Map<String, String> properties = endpointProperties(uri);
+        // validate all the options
         for (Map.Entry<String, String> property : properties.entrySet()) {
             String name = property.getKey();
             String value = property.getValue();

http://git-wip-us.apache.org/repos/asf/camel/blob/15e17fbc/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
index 2ea9528..1c8dc4e 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/ValidationResult.java
@@ -22,6 +22,11 @@ import java.util.Set;
 
 public class ValidationResult implements Serializable {
 
+    // component
+    private String syntaxError;
+    private String unknownComponent;
+
+    // options
     private Set<String> unknown;
     private Set<String> required;
     private Set<String> invalidEnum;
@@ -30,10 +35,19 @@ public class ValidationResult implements Serializable {
     private Set<String> invalidNumber;
 
     public boolean isSuccess() {
-        return unknown == null && required == null && invalidEnum == null
+        return syntaxError == null && unknownComponent == null
+                && unknown == null && required == null && invalidEnum
== null
                 && invalidBoolean == null && invalidInteger == null &&
invalidNumber == null;
     }
 
+    public void addSyntaxError(String syntaxError) {
+        this.syntaxError = syntaxError;
+    }
+
+    public void addUnknownComponent(String name) {
+        this.unknownComponent = name;
+    }
+
     public void addUnknown(String name) {
         if (unknown == null) {
             unknown = new LinkedHashSet<String>();
@@ -76,10 +90,18 @@ public class ValidationResult implements Serializable {
         invalidNumber.add(name);
     }
 
+    public String getSyntaxError() {
+        return syntaxError;
+    }
+
     public Set<String> getUnknown() {
         return unknown;
     }
 
+    public String getUnknownComponent() {
+        return unknownComponent;
+    }
+
     public Set<String> getRequired() {
         return required;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/15e17fbc/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index 59ec112..f1fd778 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -423,6 +423,11 @@ public class CamelCatalogTest {
         result = catalog.validateProperties("mqtt:myqtt?reconnectBackOffMultiplier=five");
         assertFalse(result.isSuccess());
         assertTrue(result.getInvalidNumber().contains("reconnectBackOffMultiplier"));
+
+        // unknown component
+        result = catalog.validateProperties("foo:bar?me=you");
+        assertFalse(result.isSuccess());
+        assertTrue(result.getUnknownComponent().equals("foo"));
     }
 
     @Test


Mime
View raw message