Changed the json schema slightly to alwyas include the javaType as well.

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

Branch: refs/heads/master
Commit: fa7ad2c3196669a02b974ed34d64faed67ad08a2
Parents: 83562e2
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Nov 7 12:04:11 2014 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Nov 7 13:25:21 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     |  11 +-
 .../apache/camel/impl/DefaultCamelContext.java  | 176 ++++++++++---------
 ...ponentConfigurationAndDocumentationTest.java |   3 +-
 ...ponentConfigurationAndDocumentationTest.java |   3 +-
 .../management/ManagedCamelContextTest.java     |   7 +-
 .../camel/karaf/commands/EndpointList.java      |   1 +
 6 files changed, 108 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fa7ad2c3/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java 
b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index c8d6ff5..1c33d3f 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -1347,21 +1347,26 @@ public interface CamelContext extends 
SuspendableService, RuntimeConfiguration {
 
     /**
      * Returns the HTML documentation for the given Camel component
+     *
+     * @return the HTML or <tt>null</tt> if the component is <b>not</b> built 
with HTML document included.
      */
     String getComponentDocumentation(String componentName) throws IOException;
 
     /**
-     * Returns the JSON schema representation of the endpoint parameters for 
the given component name
+     * Returns the JSON schema representation of the endpoint parameters for 
the given component name.
+     *
+     * @return the json or <tt>null</tt> if the component is <b>not</b> built 
with JSon schema support
      */
     String getComponentParameterJsonSchema(String componentName) throws 
IOException;
 
     /**
-     * Returns a JSON schema representation of the endpoint parameters for the 
given endpoint uri
+     * Returns a JSON schema representation of the endpoint parameters for the 
given endpoint uri.
      *
      * @param uri the endpoint uri
      * @param includeAllOptions whether to include non configured options also 
(eg default options)
+     * @return the json or <tt>null</tt> if uri parameters is invalid, or the 
component is <b>not</b> built with JSon schema support
      */
-    String explainEndpointJson(String uri, boolean includeAllOptions) throws 
Exception;
+    String explainEndpointJson(String uri, boolean includeAllOptions);
 
     /**
      * Creates a JSON representation of all the <b>static</b> and 
<b>dynamic</b> configured endpoints defined in the given route(s).

http://git-wip-us.apache.org/repos/asf/camel/blob/fa7ad2c3/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index e2d665a..a91d176 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -1130,109 +1130,115 @@ public class DefaultCamelContext extends 
ServiceSupport implements ModelCamelCon
         return componentName.replaceAll("-", "");
     }
 
-    public String explainEndpointJson(String uri, boolean includeAllOptions) 
throws Exception {
-        URI u = new URI(uri);
-
-        String json = getComponentParameterJsonSchema(u.getScheme());
-        if (json == null) {
-            return null;
-        }
+    public String explainEndpointJson(String uri, boolean includeAllOptions) {
+        try {
+            URI u = new URI(uri);
 
-        List<Map<String, String>> rows = 
JsonSchemaHelper.parseJsonSchema(json);
+            String json = getComponentParameterJsonSchema(u.getScheme());
+            if (json == null) {
+                return null;
+            }
 
-        // selected rows to use for answer
-        Map<String, String[]> selected = new LinkedHashMap<>();
+            List<Map<String, String>> rows = 
JsonSchemaHelper.parseJsonSchema(json);
 
-        // insert values from uri
-        Map<String, Object> options = URISupport.parseParameters(u);
+            // selected rows to use for answer
+            Map<String, String[]> selected = new LinkedHashMap<>();
 
-        // extract consumer. prefix options
-        Map<String, Object> consumerOptions = 
IntrospectionSupport.extractProperties(options, "consumer.");
-        // and add back again without the consumer. prefix as that json schema 
omits that
-        options.putAll(consumerOptions);
+            // insert values from uri
+            Map<String, Object> options = URISupport.parseParameters(u);
 
-        for (Map.Entry<String, Object> entry : options.entrySet()) {
-            String name = entry.getKey();
-            String value = "";
-            if (entry.getValue() != null) {
-                value = entry.getValue().toString();
-            }
-            value = URISupport.sanitizePath(value);
+            // extract consumer. prefix options
+            Map<String, Object> consumerOptions = 
IntrospectionSupport.extractProperties(options, "consumer.");
+            // and add back again without the consumer. prefix as that json 
schema omits that
+            options.putAll(consumerOptions);
 
-            // find type and description from the json schema
-            String type = null;
-            String javaType = null;
-            String description = null;
-            for (Map<String, String> row : rows) {
-                if (name.equals(row.get("name"))) {
-                    type = row.get("type");
-                    javaType = row.get("javaType");
-                    description = row.get("description");
-                    break;
+            for (Map.Entry<String, Object> entry : options.entrySet()) {
+                String name = entry.getKey();
+                String value = "";
+                if (entry.getValue() != null) {
+                    value = entry.getValue().toString();
                 }
-            }
-
-            // add as selected row
-            selected.put(name, new String[]{name, type, javaType, value, 
description});
-        }
-
-        if (includeAllOptions) {
-            // include other rows
-            for (Map<String, String> row : rows) {
-                String name = row.get("name");
-                String value = row.get("value");
-                String type = row.get("type");
-                String javaType = row.get("javaType");
                 value = URISupport.sanitizePath(value);
-                String description = row.get("description");
+
+                // find type and description from the json schema
+                String type = null;
+                String javaType = null;
+                String description = null;
+                for (Map<String, String> row : rows) {
+                    if (name.equals(row.get("name"))) {
+                        type = row.get("type");
+                        javaType = row.get("javaType");
+                        description = row.get("description");
+                        break;
+                    }
+                }
 
                 // add as selected row
-                if (!selected.containsKey(name)) {
-                    selected.put(name, new String[]{name, type, javaType, 
value, description});
+                selected.put(name, new String[]{name, type, javaType, value, 
description});
+            }
+
+            if (includeAllOptions) {
+                // include other rows
+                for (Map<String, String> row : rows) {
+                    String name = row.get("name");
+                    String value = row.get("value");
+                    String type = row.get("type");
+                    String javaType = row.get("javaType");
+                    value = URISupport.sanitizePath(value);
+                    String description = row.get("description");
+
+                    // add as selected row
+                    if (!selected.containsKey(name)) {
+                        selected.put(name, new String[]{name, type, javaType, 
value, description});
+                    }
                 }
             }
-        }
 
-        StringBuilder buffer = new StringBuilder("{\n  \"properties\": {");
+            StringBuilder buffer = new StringBuilder("{\n  \"properties\": {");
 
-        boolean first = true;
-        for (String[] row : selected.values()) {
-            if (first) {
-                first = false;
-            } else {
-                buffer.append(",");
+            boolean first = true;
+            for (String[] row : selected.values()) {
+                if (first) {
+                    first = false;
+                } else {
+                    buffer.append(",");
+                }
+                buffer.append("\n    ");
+
+                String name = row[0];
+                String type = row[1];
+                String javaType = row[2];
+                String value = row[3];
+                String description = row[4];
+
+                // add json of the option
+                buffer.append(doubleQuote(name) + ": { ");
+                CollectionStringBuffer csb = new CollectionStringBuffer();
+                if (type != null) {
+                    csb.append("\"type\": \"" + type + "\"");
+                }
+                if (javaType != null) {
+                    csb.append("\"javaType\": \"" + javaType + "\"");
+                }
+                if (value != null) {
+                    csb.append("\"value\": \"" + value + "\"");
+                }
+                if (description != null) {
+                    csb.append("\"description\": \"" + description + "\"");
+                }
+                if (!csb.isEmpty()) {
+                    buffer.append(csb.toString());
+                }
+                buffer.append(" }");
             }
-            buffer.append("\n    ");
 
-            String name = row[0];
-            String type = row[1];
-            String javaType = row[2];
-            String value = row[3];
-            String description = row[4];
+            buffer.append("\n  }\n}\n");
+            return buffer.toString();
 
-            // add json of the option
-            buffer.append(doubleQuote(name) + ": { ");
-            CollectionStringBuffer csb = new CollectionStringBuffer();
-            if (type != null) {
-                csb.append("\"type\": \"" + type + "\"");
-            }
-            if (javaType != null) {
-                csb.append("\"javaType\": \"" + javaType + "\"");
-            }
-            if (value != null) {
-                csb.append("\"value\": \"" + value + "\"");
-            }
-            if (description != null) {
-                csb.append("\"description\": \"" + description + "\"");
-            }
-            if (!csb.isEmpty()) {
-                buffer.append(csb.toString());
-            }
-            buffer.append(" }");
+        } catch (Exception e) {
+            // ignore and return empty response
+            return null;
         }
-
-        buffer.append("\n  }\n}\n");
-        return buffer.toString();
     }
 
     public String createRouteStaticEndpointJson(String routeId) {

http://git-wip-us.apache.org/repos/asf/camel/blob/fa7ad2c3/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
 
b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
index 15d9109..b410ce1 100644
--- 
a/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/component/dataset/DataSetComponentConfigurationAndDocumentationTest.java
@@ -43,7 +43,8 @@ public class 
DataSetComponentConfigurationAndDocumentationTest extends ContextTe
 
         assertTrue(json.contains("\"preloadSize\": { \"type\": \"integer\""));
         assertTrue(json.contains("\"minRate\": { \"type\": \"integer\""));
-        assertTrue(json.contains("\"exchangePattern\": { \"type\": \"string\", 
\"enum\":"));
+        assertTrue(json.contains("\"exchangePattern\": { \"type\": \"string\", 
\"javaType\": \"org.apache.camel.ExchangePattern\""
+                + ", \"enum\": [ \"InOnly\", \"RobustInOnly\", \"InOut\", 
\"InOptionalOut\", \"OutOnly\", \"RobustOutOnly\", \"OutIn\", \"OutOptionalIn\" 
]"));
         assertTrue(json.contains("\"InOut\""));
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/fa7ad2c3/camel-core/src/test/java/org/apache/camel/component/direct/DirectComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/component/direct/DirectComponentConfigurationAndDocumentationTest.java
 
b/camel-core/src/test/java/org/apache/camel/component/direct/DirectComponentConfigurationAndDocumentationTest.java
index b17bb5a..2e8be16 100644
--- 
a/camel-core/src/test/java/org/apache/camel/component/direct/DirectComponentConfigurationAndDocumentationTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/component/direct/DirectComponentConfigurationAndDocumentationTest.java
@@ -60,7 +60,8 @@ public class DirectComponentConfigurationAndDocumentationTest 
extends ContextTes
         log.info(json);
 
         // should include javadoc
-        assertTrue("Should include javadoc", json.contains("\"timeout\": { 
\"type\": \"integer\", \"description\": \"The timeout value to use if block is 
enabled. Is by default 30000.\" }"));
+        assertTrue("Should include javadoc", json.contains("\"timeout\": { 
\"type\": \"integer\", \"javaType\": \"long\","
+                + " \"description\": \"The timeout value to use if block is 
enabled. Is by default 30000.\" },"));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/fa7ad2c3/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
index 85ef9f7..0c2fae0 100644
--- 
a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
@@ -240,12 +240,13 @@ public class ManagedCamelContextTest extends 
ManagementTestSupport {
         String json = (String) mbeanServer.invoke(on, "explainEndpointJson", 
new Object[]{"log:foo?groupDelay=2000&groupSize=5", false},
                 new String[]{"java.lang.String", "boolean"});
         assertNotNull(json);
-        System.out.println(json);
 
         assertEquals(4, StringHelper.countChar(json, '{'));
         assertEquals(4, StringHelper.countChar(json, '}'));
-        assertTrue(json.contains("\"groupDelay\": { \"value\": \"2000\", 
\"description\": \"Set the initial delay for stats in millis\" },"));
-        assertTrue(json.contains("\"groupSize\": { \"value\": \"5\", 
\"description\": \"An integer that specifies a group size for throughput 
logging.\" }"));
+        assertTrue(json.contains("\"groupDelay\": { \"type\": \"integer\", 
\"javaType\": \"java.lang.Long\", \"value\": \"2000\","
+                + " \"description\": \"Set the initial delay for stats in 
millis\" },"));
+        assertTrue(json.contains("\"groupSize\": { \"type\": \"integer\", 
\"javaType\": \"java.lang.Integer\", \"value\": \"5\","
+                + " \"description\": \"An integer that specifies a group size 
for throughput logging.\" }"));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/fa7ad2c3/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
----------------------------------------------------------------------
diff --git 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
index 467d6bc..2ec9d6c 100644
--- 
a/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
+++ 
b/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/EndpointList.java
@@ -127,6 +127,7 @@ public class EndpointList extends CamelCommandSupport {
                                 out.println(String.format(rowFormat, "", "\t" 
+ displayType, ""));
                             }
                             if (desc != null) {
+                                // TODO: split desc in multi lines so it does 
not overflow
                                 out.println(String.format(rowFormat, "", "\t" 
+ desc, ""));
                             }
                             out.println();

Reply via email to