CAMEL-7999: apt plugin should generate component properties also, which currently are assumed as getter/setter pairs as we do not have annotations for those.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2cfecd68 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2cfecd68 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2cfecd68 Branch: refs/heads/master Commit: 2cfecd6880ba403bcba3cf1b363e4e2d8ed52f4d Parents: 714f3e5 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Feb 6 17:08:15 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Feb 6 17:08:15 2015 +0100 ---------------------------------------------------------------------- .../java/org/apache/camel/CamelContext.java | 11 +- .../mbean/ManagedCamelContextMBean.java | 9 ++ .../apache/camel/impl/DefaultCamelContext.java | 140 +++++++++++++++++++ .../management/mbean/ManagedCamelContext.java | 4 + .../management/ManagedCamelContextTest.java | 31 +++- 5 files changed, 188 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/2cfecd68/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 e66d132..28e83e9 100644 --- a/camel-core/src/main/java/org/apache/camel/CamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java @@ -1413,7 +1413,7 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration { 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 component and 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 */ @@ -1450,6 +1450,15 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration { String explainEipJson(String nameOrId, boolean includeAllOptions); /** + * Returns a JSON schema representation of the component parameters (not endpoint parameters) for the given component by its id. + * + * @param componentName the name of the component. + * @param includeAllOptions whether to include non configured options also (eg default options) + * @return the json or <tt>null</tt> if the component was not found + */ + String explainComponentJson(String componentName, boolean includeAllOptions); + + /** * Returns a JSON schema representation of the endpoint parameters for the given endpoint uri. * * @param uri the endpoint uri http://git-wip-us.apache.org/repos/asf/camel/blob/2cfecd68/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java index c803cdf..ac8d4af 100644 --- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java @@ -308,6 +308,15 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean String explainEipJson(String nameOrId, boolean includeAllOptions); /** + * Returns a JSON schema representation of the component parameters (not endpoint parameters) for the given component by its id. + * + * @param componentName the id of the component + * @param includeAllOptions whether to include non configured options also (eg default options) + */ + @ManagedOperation(description = " Returns a JSON schema representation of the component parameters for the given component by its id") + String explainComponentJson(String componentName, boolean includeAllOptions) throws Exception; + + /** * Returns a JSON schema representation of the endpoint parameters for the given endpoint uri * * @param uri the endpoint uri http://git-wip-us.apache.org/repos/asf/camel/blob/2cfecd68/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 0226067..c9060e4 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 @@ -1488,6 +1488,146 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon } } + public String explainComponentJson(String componentName, boolean includeAllOptions) { + try { + String json = getComponentParameterJsonSchema(componentName); + if (json == null) { + return null; + } + + List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("componentProperties", json, true); + + // selected rows to use for answer + Map<String, String[]> selected = new LinkedHashMap<String, String[]>(); + + // insert values from component + Component component = getComponent(componentName); + Map<String, Object> options = new HashMap<String, Object>(); + IntrospectionSupport.getProperties(component, options, null); + + 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); + + // find type and description from the json schema + String type = null; + String kind = null; + String required = null; + String javaType = null; + String deprecated = null; + String defaultValue = null; + String description = null; + for (Map<String, String> row : rows) { + if (name.equals(row.get("name"))) { + type = row.get("type"); + kind = row.get("kind"); + required = row.get("required"); + javaType = row.get("javaType"); + deprecated = row.get("deprecated"); + defaultValue = row.get("defaultValue"); + description = row.get("description"); + break; + } + } + + // add as selected row + selected.put(name, new String[]{name, kind, required, type, javaType, deprecated, value, defaultValue, description}); + } + + // include other rows + for (Map<String, String> row : rows) { + String name = row.get("name"); + String kind = row.get("kind"); + String required = row.get("required"); + String value = row.get("value"); + String defaultValue = row.get("defaultValue"); + String type = row.get("type"); + String javaType = row.get("javaType"); + String deprecated = row.get("deprecated"); + value = URISupport.sanitizePath(value); + String description = row.get("description"); + + // always include path options + if (includeAllOptions) { + // add as selected row + if (!selected.containsKey(name)) { + selected.put(name, new String[]{name, kind, required, type, javaType, deprecated, value, defaultValue, description}); + } + } + } + + json = ObjectHelper.before(json, " \"componentProperties\": {"); + + StringBuilder buffer = new StringBuilder(" \"componentProperties\": {"); + + boolean first = true; + for (String[] row : selected.values()) { + if (first) { + first = false; + } else { + buffer.append(","); + } + buffer.append("\n "); + + String name = row[0]; + String kind = row[1]; + String required = row[2]; + String type = row[3]; + String javaType = row[4]; + String deprecated = row[5]; + String value = row[6]; + String defaultValue = row[7]; + String description = row[8]; + + // add json of the option + buffer.append(doubleQuote(name)).append(": { "); + CollectionStringBuffer csb = new CollectionStringBuffer(); + if (kind != null) { + csb.append("\"kind\": \"" + kind + "\""); + } + if (required != null) { + csb.append("\"required\": \"" + required + "\""); + } + if (type != null) { + csb.append("\"type\": \"" + type + "\""); + } + if (javaType != null) { + csb.append("\"javaType\": \"" + javaType + "\""); + } + if (deprecated != null) { + csb.append("\"deprecated\": \"" + deprecated + "\""); + } + if (value != null) { + csb.append("\"value\": \"" + value + "\""); + } + if (defaultValue != null) { + csb.append("\"defaultValue\": \"" + defaultValue + "\""); + } + if (description != null) { + csb.append("\"description\": \"" + description + "\""); + } + if (!csb.isEmpty()) { + buffer.append(csb.toString()); + } + buffer.append(" }"); + } + + buffer.append("\n }\n}\n"); + + // insert the original first part of the json into the start of the buffer + buffer.insert(0, json); + return buffer.toString(); + + } catch (Exception e) { + // ignore and return empty response + return null; + } + } + public String explainEndpointJson(String uri, boolean includeAllOptions) { try { URI u = new URI(uri); http://git-wip-us.apache.org/repos/asf/camel/blob/2cfecd68/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java index c74d391..a967fa0 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java @@ -623,6 +623,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti return context.explainEipJson(nameOrId, includeAllOptions); } + public String explainComponentJson(String componentName, boolean includeAllOptions) throws Exception { + return context.explainComponentJson(componentName, includeAllOptions); + } + public String explainEndpointJson(String uri, boolean includeAllOptions) throws Exception { return context.explainEndpointJson(uri, includeAllOptions); } http://git-wip-us.apache.org/repos/asf/camel/blob/2cfecd68/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 8dc4d32..7bbe295 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 @@ -244,11 +244,11 @@ public class ManagedCamelContextTest extends ManagementTestSupport { new String[]{"java.lang.String", "boolean"}); assertNotNull(json); - assertEquals(7, StringHelper.countChar(json, '{')); - assertEquals(7, StringHelper.countChar(json, '}')); + assertEquals(8, StringHelper.countChar(json, '{')); + assertEquals(8, StringHelper.countChar(json, '}')); assertTrue(json.contains("\"scheme\": \"log\"")); - assertTrue(json.contains("\"description\": \"The Log Component to log message exchanges to the underlying logging mechanism.\"")); + assertTrue(json.contains("\"description\": \"The Log Component is for logging message exchanges via the underlying logging mechanism.\"")); assertTrue(json.contains("\"label\": \"core,monitoring\"")); assertTrue(json.contains("\"groupDelay\": { \"kind\": \"parameter\", \"type\": \"integer\", \"javaType\": \"java.lang.Long\", \"deprecated\": \"false\", \"value\": \"2000\"," @@ -275,11 +275,11 @@ public class ManagedCamelContextTest extends ManagementTestSupport { new String[]{"java.lang.String", "boolean"}); assertNotNull(json); - assertEquals(14, StringHelper.countChar(json, '{')); - assertEquals(14, StringHelper.countChar(json, '}')); + assertEquals(15, StringHelper.countChar(json, '{')); + assertEquals(15, StringHelper.countChar(json, '}')); assertTrue(json.contains("\"scheme\": \"log\"")); - assertTrue(json.contains("\"description\": \"The Log Component to log message exchanges to the underlying logging mechanism.\"")); + assertTrue(json.contains("\"description\": \"The Log Component is for logging message exchanges via the underlying logging mechanism.\"")); assertTrue(json.contains("\"label\": \"core,monitoring\"")); assertTrue(json.contains("\"groupDelay\": { \"kind\": \"parameter\", \"type\": \"integer\", \"javaType\": \"java.lang.Long\", \"deprecated\": \"false\", \"value\": \"2000\"," @@ -352,6 +352,25 @@ public class ManagedCamelContextTest extends ManagementTestSupport { assertTrue(json.contains("\"discardOnCompletionTimeout\": { \"kind\": \"attribute\", \"required\": \"false\", \"type\": \"boolean\"")); } + public void testManagedCamelContextExplainComponentModel() throws Exception { + // JMX tests dont work well on AIX CI servers (hangs them) + if (isPlatform("aix")) { + return; + } + + MBeanServer mbeanServer = getMBeanServer(); + ObjectName on = ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\""); + + // get the json + String json = (String) mbeanServer.invoke(on, "explainComponentJson", new Object[]{"seda", false}, new String[]{"java.lang.String", "boolean"}); + assertNotNull(json); + + assertTrue(json.contains("\"description\": \"The SEDA Component is for asynchronous SEDA exchanges on a BlockingQueue within a CamelContext\"")); + assertTrue(json.contains("\"label\": \"core,endpoint\"")); + assertTrue(json.contains("\"concurrentConsumers\": { \"value\": \"1\" }")); + assertTrue(json.contains("\"queueSize\": { \"kind\": \"property\", \"type\": \"integer\", \"javaType\": \"int\", \"deprecated\": \"false\", \"value\": \"0\" }")); + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() {