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/01/16 11:27:58 UTC

[2/2] camel git commit: camel-catalog - improve endpoint validation around lenient vs non lenient components.

camel-catalog - improve endpoint validation around lenient vs non lenient components.


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

Branch: refs/heads/camel-2.18.x
Commit: bb2264d8f45143c80b05f9793bc3255c3323a84e
Parents: a35771d
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jan 16 12:23:50 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 16 12:27:49 2017 +0100

----------------------------------------------------------------------
 .../camel/catalog/DefaultCamelCatalog.java      | 29 +++++++++++++-------
 .../camel/catalog/EndpointValidationResult.java | 14 ++++++++++
 .../apache/camel/catalog/CamelCatalogTest.java  | 25 +++++++++++++++++
 3 files changed, 58 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bb2264d8/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 b00bf73..766a2a1 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
@@ -998,9 +998,13 @@ public class DefaultCamelCatalog implements CamelCatalog {
             }
 
             rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
-            // only enable lenient properties if we should not ignore
-            lenientProperties = !ignoreLenientProperties && isComponentLenientProperties(rows);
-
+            if (consumerOnly) {
+                // lenient properties is not support in consumer only mode
+                lenientProperties = false;
+            } else {
+                // only enable lenient properties if we should not ignore
+                lenientProperties = !ignoreLenientProperties && isComponentLenientProperties(rows);
+            }
             rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
             properties = endpointProperties(uri);
         } catch (URISyntaxException e) {
@@ -1054,13 +1058,18 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
                 // only add as error if the component is not lenient properties, or not stub component
                 // and the name is not a property placeholder for one or more values
-                // as if we are lenient then the option is a dynamic extra option which we cannot validate
-                if (!namePlaceholder && !lenientProperties && !"stub".equals(scheme)) {
-                    result.addUnknown(name);
-                    if (suggestionStrategy != null) {
-                        String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name);
-                        if (suggestions != null) {
-                            result.addUnknownSuggestions(name, suggestions);
+                if (!namePlaceholder && !"stub".equals(scheme)) {
+                    if (lenientProperties) {
+                        // as if we are lenient then the option is a dynamic extra option which we cannot validate
+                        result.addLenient(name);
+                    } else {
+                        // its unknown
+                        result.addUnknown(name);
+                        if (suggestionStrategy != null) {
+                            String[] suggestions = suggestionStrategy.suggestEndpointOptions(getNames(rows), name);
+                            if (suggestions != null) {
+                                result.addUnknownSuggestions(name, suggestions);
+                            }
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/bb2264d8/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
index fa2515e..11e2c5e 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
@@ -41,6 +41,7 @@ public class EndpointValidationResult implements Serializable {
     // options
     private Set<String> unknown;
     private Map<String, String[]> unknownSuggestions;
+    private Set<String> lenient;
     private Set<String> notConsumerOnly;
     private Set<String> notProducerOnly;
     private Set<String> required;
@@ -110,6 +111,15 @@ public class EndpointValidationResult implements Serializable {
         unknownSuggestions.put(name, suggestions);
     }
 
+    public void addLenient(String name) {
+        if (lenient == null) {
+            lenient = new LinkedHashSet<String>();
+        }
+        if (!lenient.contains(name)) {
+            lenient.add(name);
+        }
+    }
+
     public void addRequired(String name) {
         if (required == null) {
             required = new LinkedHashSet<String>();
@@ -223,6 +233,10 @@ public class EndpointValidationResult implements Serializable {
         return unknown;
     }
 
+    public Set<String> getLenient() {
+        return lenient;
+    }
+
     public Map<String, String[]> getUnknownSuggestions() {
         return unknownSuggestions;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/bb2264d8/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 acddd83..c8d890c 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
@@ -599,6 +599,31 @@ public class CamelCatalogTest {
         assertFalse(result.isSuccess());
         assertTrue(result.getUnknown().contains("foo"));
 
+        // lenient off consumer only
+        result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", false, true, false);
+        assertFalse(result.isSuccess());
+        // consumer should still fail because we cannot use lenient option in consumer mode
+        assertEquals("foo", result.getUnknown().iterator().next());
+        assertNull(result.getLenient());
+        // lenient off producer only
+        result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", false, false, true);
+        assertTrue(result.isSuccess());
+        // foo is the lenient option
+        assertEquals(1, result.getLenient().size());
+        assertEquals("foo", result.getLenient().iterator().next());
+
+        // lenient on consumer only
+        result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", true, true, false);
+        assertFalse(result.isSuccess());
+        // consumer should still fail because we cannot use lenient option in consumer mode
+        assertEquals("foo", result.getUnknown().iterator().next());
+        assertNull(result.getLenient());
+        // lenient on producer only
+        result = catalog.validateEndpointProperties("netty4-http:http://myserver?foo=bar", true, false, true);
+        assertFalse(result.isSuccess());
+        assertEquals("foo", result.getUnknown().iterator().next());
+        assertNull(result.getLenient());
+
         // data format
         result = catalog.validateEndpointProperties("dataformat:string:marshal?charset=utf-8", true);
         assertTrue(result.isSuccess());