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 2015/10/11 11:08:55 UTC
[1/4] camel git commit: CAMEL-9213: CamelContext -
explainEndpointJson should not include component properties
Repository: camel
Updated Branches:
refs/heads/camel-2.16.x 4cc3552bd -> 62b4310a8
refs/heads/master fcb6e6b87 -> 5c034c845
CAMEL-9213: CamelContext - explainEndpointJson should not include component properties
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/da2729a3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/da2729a3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/da2729a3
Branch: refs/heads/master
Commit: da2729a31855b5b6a5b378d818ebdde5638fc032
Parents: fcb6e6b
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Oct 11 09:24:06 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Oct 11 09:24:06 2015 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/impl/DefaultCamelContext.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/da2729a3/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 5935f52..c03d9a4 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
@@ -2045,8 +2045,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
}
- json = ObjectHelper.before(json, " \"properties\": {");
+ // skip component properties
+ json = ObjectHelper.before(json, " \"componentProperties\": {");
+ // and rewrite properties
StringBuilder buffer = new StringBuilder(" \"properties\": {");
boolean first = true;
[3/4] camel git commit: CAMEL-9213: CamelContext -
explainEndpointJson should not include component properties
Posted by da...@apache.org.
CAMEL-9213: CamelContext - explainEndpointJson should not include component properties
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b410e4cb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b410e4cb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b410e4cb
Branch: refs/heads/camel-2.16.x
Commit: b410e4cb3ede8bb0dfa99b6321f036fe043b2157
Parents: 4cc3552
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Oct 11 09:24:06 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Oct 11 11:10:58 2015 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/impl/DefaultCamelContext.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b410e4cb/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 5935f52..c03d9a4 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
@@ -2045,8 +2045,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
}
- json = ObjectHelper.before(json, " \"properties\": {");
+ // skip component properties
+ json = ObjectHelper.before(json, " \"componentProperties\": {");
+ // and rewrite properties
StringBuilder buffer = new StringBuilder(" \"properties\": {");
boolean first = true;
[4/4] camel git commit: CAMEL-9213: CamelContext - Fixed
explainEndpointJson to deal with uris such as from jms and reuse same logic
as in the catalog
Posted by da...@apache.org.
CAMEL-9213: CamelContext - Fixed explainEndpointJson to deal with uris such as from jms and reuse same logic as in the catalog
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/62b4310a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/62b4310a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/62b4310a
Branch: refs/heads/camel-2.16.x
Commit: 62b4310a81bda44ca39aa54011d4d50971bdc6d0
Parents: b410e4c
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Oct 11 10:09:25 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Oct 11 11:11:04 2015 +0200
----------------------------------------------------------------------
.../apache/camel/impl/DefaultCamelContext.java | 11 +-
.../org/apache/camel/util/EndpointHelper.java | 202 ++++++++++++++++---
.../org/apache/camel/util/JsonSchemaHelper.java | 60 +++++-
.../management/ManagedCamelContextTest.java | 8 +-
...ponentConfigurationAndDocumentationTest.java | 34 ++++
.../camel/catalog/DefaultCamelCatalog.java | 3 +
.../apache/camel/catalog/CamelCatalogTest.java | 6 +
7 files changed, 283 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/62b4310a/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 c03d9a4..50f7060 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
@@ -19,6 +19,7 @@ package org.apache.camel.impl;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -39,6 +40,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.naming.Context;
@@ -1968,7 +1971,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
Map<String, String[]> uriOptions = new LinkedHashMap<String, String[]>();
// insert values from uri
- Map<String, Object> options = URISupport.parseParameters(u);
+ Map<String, Object> options = EndpointHelper.endpointProperties(this, uri);
// extract consumer. prefix options
Map<String, Object> consumerOptions = IntrospectionSupport.extractProperties(options, "consumer.");
@@ -2024,12 +2027,6 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
value = URISupport.sanitizePath(value);
String description = row.get("description");
- if ("path".equals(kind)) {
- // if its the path option then we need to grab the actual value from the uri, which is the remainder path
- value = URISupport.extractRemainderPath(u, false);
- value = URISupport.sanitizePath(value);
- }
-
boolean isUriOption = uriOptions.containsKey(name);
// always include from uri or path options
http://git-wip-us.apache.org/repos/asf/camel/blob/62b4310a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
index 524d8dc..93c2be2 100644
--- a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
@@ -16,14 +16,18 @@
*/
package org.apache.camel.util;
+import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.apache.camel.CamelContext;
@@ -42,13 +46,13 @@ import org.slf4j.LoggerFactory;
/**
* Some helper methods for working with {@link Endpoint} instances
- *
- * @version
*/
public final class EndpointHelper {
private static final Logger LOG = LoggerFactory.getLogger(EndpointHelper.class);
private static final AtomicLong ENDPOINT_COUNTER = new AtomicLong(0);
+ private static final Pattern SYNTAX_PATTERN = Pattern.compile("(\\w+)");
+
private EndpointHelper() {
//Utility Class
@@ -98,10 +102,10 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>exact match, returns true</li>
- * <li>wildcard match (pattern ends with a * and the uri starts with the pattern), returns true</li>
- * <li>regular expression match, returns true</li>
- * <li>otherwise returns false</li>
+ * <li>exact match, returns true</li>
+ * <li>wildcard match (pattern ends with a * and the uri starts with the pattern), returns true</li>
+ * <li>regular expression match, returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param context the Camel context, if <tt>null</tt> then property placeholder resolution is skipped.
@@ -148,8 +152,8 @@ public final class EndpointHelper {
/**
* Matches the endpoint with the given pattern.
- * @see #matchEndpoint(org.apache.camel.CamelContext, String, String)
*
+ * @see #matchEndpoint(org.apache.camel.CamelContext, String, String)
* @deprecated use {@link #matchEndpoint(org.apache.camel.CamelContext, String, String)} instead.
*/
@Deprecated
@@ -162,10 +166,10 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>exact match, returns true</li>
- * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
- * <li>regular expression match, returns true</li>
- * <li>otherwise returns false</li>
+ * <li>exact match, returns true</li>
+ * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
+ * <li>regular expression match, returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param name the name
@@ -199,8 +203,8 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
- * <li>otherwise returns false</li>
+ * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param name the name
@@ -220,8 +224,8 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>regular expression match, returns true</li>
- * <li>otherwise returns false</li>
+ * <li>regular expression match, returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param name the name
@@ -312,7 +316,7 @@ public final class EndpointHelper {
* @param value reference parameter value.
* @param type type of object to lookup.
* @return lookup result (or <code>null</code> only if
- * <code>mandatory</code> is <code>false</code>).
+ * <code>mandatory</code> is <code>false</code>).
* @throws IllegalArgumentException if object was not found in registry and
* <code>mandatory</code> is <code>true</code>.
*/
@@ -329,9 +333,9 @@ public final class EndpointHelper {
* Resolves a reference list parameter by making lookups in the registry.
* The parameter value must be one of the following:
* <ul>
- * <li>a comma-separated list of references to beans of type T</li>
- * <li>a single reference to a bean type T</li>
- * <li>a single reference to a bean of type java.util.List</li>
+ * <li>a comma-separated list of references to beans of type T</li>
+ * <li>a single reference to a bean type T</li>
+ * <li>a single reference to a bean of type java.util.List</li>
* </ul>
*
* @param context Camel context to use for lookup.
@@ -396,7 +400,7 @@ public final class EndpointHelper {
/**
* Gets the route id for the given endpoint in which there is a consumer listening.
*
- * @param endpoint the endpoint
+ * @param endpoint the endpoint
* @return the route id, or <tt>null</tt> if none found
*/
public static String getRouteIdFromEndpoint(Endpoint endpoint) {
@@ -425,7 +429,7 @@ public final class EndpointHelper {
/**
* Lookup the id the given endpoint has been enlisted with in the {@link org.apache.camel.spi.Registry}.
*
- * @param endpoint the endpoint
+ * @param endpoint the endpoint
* @return the endpoint id, or <tt>null</tt> if not found
*/
public static String lookupEndpointRegistryId(Endpoint endpoint) {
@@ -453,9 +457,9 @@ public final class EndpointHelper {
/**
* Browses the {@link BrowsableEndpoint} within the given range, and returns the messages as a XML payload.
*
- * @param endpoint the browsable endpoint
- * @param fromIndex from range
- * @param toIndex to range
+ * @param endpoint the browsable endpoint
+ * @param fromIndex from range
+ * @param toIndex to range
* @param includeBody whether to include the message body in the XML payload
* @return XML payload with the messages
* @throws IllegalArgumentException if the from and to range is invalid
@@ -509,4 +513,154 @@ public final class EndpointHelper {
return null;
}
+ /**
+ * Parses the endpoint uri and builds a map of documentation information for each option which is extracted
+ * from the component json documentation
+ *
+ * @param camelContext the Camel context
+ * @param uri the endpoint uri
+ * @return a map for each option in the uri with the corresponding information from the json
+ * @throws Exception is thrown in case of error
+ */
+ public static Map<String, Object> endpointProperties(CamelContext camelContext, String uri) throws Exception {
+ // NOTICE: This logic is similar to org.apache.camel.catalog.DefaultCamelCatalog#endpointProperties
+ // as the catalog also offers similar functionality (without having camel-core on classpath)
+
+ // parse the uri
+ URI u = new URI(uri);
+ String scheme = u.getScheme();
+
+ String json = camelContext.getComponentParameterJsonSchema(u.getScheme());
+ if (json == null) {
+ throw new IllegalArgumentException("Cannot find endpoint with scheme " + scheme);
+ }
+
+ // grab the syntax
+ String syntax = null;
+ List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("component", json, false);
+ for (Map<String, String> row : rows) {
+ if (row.containsKey("syntax")) {
+ syntax = row.get("syntax");
+ break;
+ }
+ }
+ if (syntax == null) {
+ throw new IllegalArgumentException("Endpoint with scheme " + scheme + " has no syntax defined in the json schema");
+ }
+
+ // parse the syntax and find the same group in the uri
+ Matcher matcher = SYNTAX_PATTERN.matcher(syntax);
+ List<String> word = new ArrayList<String>();
+ while (matcher.find()) {
+ String s = matcher.group(1);
+ if (!scheme.equals(s)) {
+ word.add(s);
+ }
+ }
+
+ String uriPath = stripQuery(uri);
+
+ // if there is only one, then use uriPath as is
+ List<String> word2 = new ArrayList<String>();
+
+ if (word.size() == 1) {
+ String s = uriPath;
+ s = URISupport.stripPrefix(s, scheme);
+ // strip any leading : or / after the scheme
+ while (s.startsWith(":") || s.startsWith("/")) {
+ s = s.substring(1);
+ }
+ word2.add(s);
+ } else {
+ Matcher matcher2 = SYNTAX_PATTERN.matcher(uriPath);
+ while (matcher2.find()) {
+ String s = matcher2.group(1);
+ if (!scheme.equals(s)) {
+ word2.add(s);
+ }
+ }
+ }
+
+ rows = JsonSchemaHelper.parseJsonSchema("properties", json, true);
+
+ boolean defaultValueAdded = false;
+
+ // now parse the uri to know which part isw what
+ Map<String, String> options = new LinkedHashMap<String, String>();
+
+ // word contains the syntax path elements
+ Iterator<String> it = word2.iterator();
+ for (int i = 0; i < word.size(); i++) {
+ String key = word.get(i);
+
+ boolean allOptions = word.size() == word2.size();
+ boolean required = JsonSchemaHelper.isPropertyRequired(rows, key);
+ String defaultValue = JsonSchemaHelper.getPropertyDefaultValue(rows, key);
+
+ // we have all options so no problem
+ if (allOptions) {
+ String value = it.next();
+ options.put(key, value);
+ } else {
+ // we have a little problem as we do not not have all options
+ if (!required) {
+ String value = defaultValue;
+ options.put(key, value);
+ defaultValueAdded = true;
+ } else {
+ String value = it.next();
+ options.put(key, value);
+ }
+ }
+ }
+
+ Map<String, Object> answer = new LinkedHashMap<String, Object>();
+
+ // remove all options which are using default values and are not required
+ for (Map.Entry<String, String> entry : options.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+
+ if (defaultValueAdded) {
+ boolean required = JsonSchemaHelper.isPropertyRequired(rows, key);
+ String defaultValue = JsonSchemaHelper.getPropertyDefaultValue(rows, key);
+
+ if (!required && defaultValue != null) {
+ if (defaultValue.equals(value)) {
+ continue;
+ }
+ }
+ }
+
+ // we should keep this in the answer
+ answer.put(key, value);
+ }
+
+ // now parse the uri parameters
+ Map<String, Object> parameters = URISupport.parseParameters(u);
+
+ // and covert the values to String so its JMX friendly
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue() != null ? entry.getValue().toString() : "";
+ answer.put(key, value);
+ }
+
+ return answer;
+ }
+
+ /**
+ * Strips the query parameters from the uri
+ *
+ * @param uri the uri
+ * @return the uri without the query parameter
+ */
+ private static String stripQuery(String uri) {
+ int idx = uri.indexOf('?');
+ if (idx > -1) {
+ uri = uri.substring(0, idx);
+ }
+ return uri;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/62b4310a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
index 336bf85..41dffe3 100644
--- a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
@@ -39,15 +39,15 @@ public final class JsonSchemaHelper {
/**
* Gets the JSon schema type.
*
- * @param type the java type
- * @return the json schema type, is never null, but returns <tt>object</tt> as the generic type
+ * @param type the java type
+ * @return the json schema type, is never null, but returns <tt>object</tt> as the generic type
*/
public static String getType(Class<?> type) {
if (type.isEnum()) {
return "enum";
} else if (type.isArray()) {
return "array";
- }
+ }
if (type.isAssignableFrom(URI.class) || type.isAssignableFrom(URL.class)) {
return "sting";
}
@@ -63,8 +63,8 @@ public final class JsonSchemaHelper {
/**
* Gets the JSon schema primitive type.
*
- * @param type the java type
- * @return the json schema primitive type, or <tt>null</tt> if not a primitive
+ * @param type the java type
+ * @return the json schema primitive type, or <tt>null</tt> if not a primitive
*/
public static String getPrimitiveType(Class<?> type) {
String name = type.getCanonicalName();
@@ -118,7 +118,7 @@ public final class JsonSchemaHelper {
* Parses the json schema to split it into a list or rows, where each row contains key value pairs with the metadata
*
* @param group the group to parse from such as <tt>component</tt>, <tt>componentProperties</tt>, or <tt>properties</tt>.
- * @param json the json
+ * @param json the json
* @return a list of all the rows, where each row is a set of key value pairs with metadata
*/
public static List<Map<String, String>> parseJsonSchema(String group, String json, boolean parseProperties) {
@@ -195,4 +195,52 @@ public final class JsonSchemaHelper {
return value;
}
+ /**
+ * Is the property required
+ *
+ * @param rows the rows of properties
+ * @param name name of the property
+ * @return <tt>true</tt> if required, or <tt>false</tt> if not
+ */
+ public static boolean isPropertyRequired(List<Map<String, String>> rows, String name) {
+ for (Map<String, String> row : rows) {
+ boolean required = false;
+ boolean found = false;
+ if (row.containsKey("name")) {
+ found = name.equals(row.get("name"));
+ }
+ if (row.containsKey("required")) {
+ required = "true".equals(row.get("required"));
+ }
+ if (found) {
+ return required;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Gets the default value of the property
+ *
+ * @param rows the rows of properties
+ * @param name name of the property
+ * @return the default value or <tt>null</tt> if no default value exists
+ */
+ public static String getPropertyDefaultValue(List<Map<String, String>> rows, String name) {
+ for (Map<String, String> row : rows) {
+ String defaultValue = null;
+ boolean found = false;
+ if (row.containsKey("name")) {
+ found = name.equals(row.get("name"));
+ }
+ if (row.containsKey("defaultValue")) {
+ defaultValue = row.get("defaultValue");
+ }
+ if (found) {
+ return defaultValue;
+ }
+ }
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/62b4310a/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 46237b7..3677611 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
@@ -268,8 +268,8 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
int pos2 = json.indexOf("groupDelay");
assertTrue("LoggerName should come before groupDelay", pos < pos2);
- assertEquals(8, StringHelper.countChar(json, '{'));
- assertEquals(8, StringHelper.countChar(json, '}'));
+ assertEquals(6, StringHelper.countChar(json, '{'));
+ assertEquals(6, StringHelper.countChar(json, '}'));
assertTrue(json.contains("\"scheme\": \"log\""));
assertTrue(json.contains("\"label\": \"core,monitoring\""));
@@ -303,8 +303,8 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
int pos2 = json.indexOf("groupDelay");
assertTrue("LoggerName should come before groupDelay", pos < pos2);
- assertEquals(14, StringHelper.countChar(json, '{'));
- assertEquals(14, StringHelper.countChar(json, '}'));
+ assertEquals(12, StringHelper.countChar(json, '{'));
+ assertEquals(12, StringHelper.countChar(json, '}'));
assertTrue(json.contains("\"scheme\": \"log\""));
assertTrue(json.contains("\"label\": \"core,monitoring\""));
http://git-wip-us.apache.org/repos/asf/camel/blob/62b4310a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
index 288c530..86459ed 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
@@ -40,4 +40,38 @@ public class JmsComponentConfigurationAndDocumentationTest extends CamelTestSupp
assertNotNull(json);
}
+ @Test
+ public void testExplainComponentJson() throws Exception {
+ String json = context.explainComponentJson("jms", false);
+ assertNotNull(json);
+
+ log.info(json);
+ assertTrue(json.contains("\"syntax\": \"jms:destinationType:destinationName\""));
+ }
+
+ @Test
+ public void testExplainEndpointJson() throws Exception {
+ String json = context.explainEndpointJson("jms:queue:foo?replyTo=bar", false);
+ assertNotNull(json);
+ log.info(json);
+ assertTrue(json.contains("\"syntax\": \"jms:destinationType:destinationName\""));
+ assertTrue(json.contains("\"destinationType\": { \"kind\": \"path\", \"type\": \"string\", \"javaType\": \"java.lang.String\""
+ + ", \"deprecated\": \"false\", \"value\": \"queue\", \"defaultValue\": \"queue\""));
+ assertTrue(json.contains("\"destinationName\": { \"kind\": \"path\", \"required\": \"true\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"foo\""));
+ assertTrue(json.contains("\"replyTo\": { \"kind\": \"parameter\", \"label\": \"consumer\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"bar\""));
+
+ json = context.explainEndpointJson("jms:foo?replyTo=bar", false);
+ assertNotNull(json);
+ log.info(json);
+ assertTrue(json.contains("\"syntax\": \"jms:destinationType:destinationName\""));
+ assertTrue(json.contains("\"destinationType\": { \"kind\": \"path\", \"type\": \"string\", \"javaType\": \"java.lang.String\""
+ + ", \"deprecated\": \"false\", \"defaultValue\": \"queue\""));
+ assertTrue(json.contains("\"destinationName\": { \"kind\": \"path\", \"required\": \"true\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"foo\""));
+ assertTrue(json.contains("\"replyTo\": { \"kind\": \"parameter\", \"label\": \"consumer\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"bar\""));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/62b4310a/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 88566b3..a510fc5 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
@@ -447,6 +447,9 @@ public class DefaultCamelCatalog implements CamelCatalog {
@Override
public Map<String, String> endpointProperties(String uri) throws URISyntaxException {
+ // NOTICE: This logic is similar to org.apache.camel.util.EndpointHelper#endpointProperties
+ // as the catalog also offers similar functionality (without having camel-core on classpath)
+
// parse the uri
URI u = new URI(uri);
String scheme = u.getScheme();
http://git-wip-us.apache.org/repos/asf/camel/blob/62b4310a/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 34fa5c7..e905e81 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
@@ -184,6 +184,12 @@ public class CamelCatalogTest extends TestCase {
assertEquals("queue", map.get("destinationType"));
assertEquals("foo", map.get("destinationName"));
+
+ map = catalog.endpointProperties("jms:foo");
+ assertNotNull(map);
+ assertEquals(1, map.size());
+
+ assertEquals("foo", map.get("destinationName"));
}
@Test
[2/4] camel git commit: CAMEL-9213: CamelContext - Fixed
explainEndpointJson to deal with uris such as from jms and reuse same logic
as in the catalog
Posted by da...@apache.org.
CAMEL-9213: CamelContext - Fixed explainEndpointJson to deal with uris such as from jms and reuse same logic as in the catalog
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5c034c84
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5c034c84
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5c034c84
Branch: refs/heads/master
Commit: 5c034c845f69fa98f570422a81f259a7b21085df
Parents: da2729a
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Oct 11 10:09:25 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Oct 11 10:51:30 2015 +0200
----------------------------------------------------------------------
.../apache/camel/impl/DefaultCamelContext.java | 11 +-
.../org/apache/camel/util/EndpointHelper.java | 202 ++++++++++++++++---
.../org/apache/camel/util/JsonSchemaHelper.java | 60 +++++-
.../management/ManagedCamelContextTest.java | 8 +-
...ponentConfigurationAndDocumentationTest.java | 34 ++++
.../camel/catalog/DefaultCamelCatalog.java | 3 +
.../apache/camel/catalog/CamelCatalogTest.java | 6 +
7 files changed, 283 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5c034c84/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 c03d9a4..50f7060 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
@@ -19,6 +19,7 @@ package org.apache.camel.impl;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -39,6 +40,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.naming.Context;
@@ -1968,7 +1971,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
Map<String, String[]> uriOptions = new LinkedHashMap<String, String[]>();
// insert values from uri
- Map<String, Object> options = URISupport.parseParameters(u);
+ Map<String, Object> options = EndpointHelper.endpointProperties(this, uri);
// extract consumer. prefix options
Map<String, Object> consumerOptions = IntrospectionSupport.extractProperties(options, "consumer.");
@@ -2024,12 +2027,6 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
value = URISupport.sanitizePath(value);
String description = row.get("description");
- if ("path".equals(kind)) {
- // if its the path option then we need to grab the actual value from the uri, which is the remainder path
- value = URISupport.extractRemainderPath(u, false);
- value = URISupport.sanitizePath(value);
- }
-
boolean isUriOption = uriOptions.containsKey(name);
// always include from uri or path options
http://git-wip-us.apache.org/repos/asf/camel/blob/5c034c84/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
index 524d8dc..93c2be2 100644
--- a/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/EndpointHelper.java
@@ -16,14 +16,18 @@
*/
package org.apache.camel.util;
+import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.apache.camel.CamelContext;
@@ -42,13 +46,13 @@ import org.slf4j.LoggerFactory;
/**
* Some helper methods for working with {@link Endpoint} instances
- *
- * @version
*/
public final class EndpointHelper {
private static final Logger LOG = LoggerFactory.getLogger(EndpointHelper.class);
private static final AtomicLong ENDPOINT_COUNTER = new AtomicLong(0);
+ private static final Pattern SYNTAX_PATTERN = Pattern.compile("(\\w+)");
+
private EndpointHelper() {
//Utility Class
@@ -98,10 +102,10 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>exact match, returns true</li>
- * <li>wildcard match (pattern ends with a * and the uri starts with the pattern), returns true</li>
- * <li>regular expression match, returns true</li>
- * <li>otherwise returns false</li>
+ * <li>exact match, returns true</li>
+ * <li>wildcard match (pattern ends with a * and the uri starts with the pattern), returns true</li>
+ * <li>regular expression match, returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param context the Camel context, if <tt>null</tt> then property placeholder resolution is skipped.
@@ -148,8 +152,8 @@ public final class EndpointHelper {
/**
* Matches the endpoint with the given pattern.
- * @see #matchEndpoint(org.apache.camel.CamelContext, String, String)
*
+ * @see #matchEndpoint(org.apache.camel.CamelContext, String, String)
* @deprecated use {@link #matchEndpoint(org.apache.camel.CamelContext, String, String)} instead.
*/
@Deprecated
@@ -162,10 +166,10 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>exact match, returns true</li>
- * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
- * <li>regular expression match, returns true</li>
- * <li>otherwise returns false</li>
+ * <li>exact match, returns true</li>
+ * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
+ * <li>regular expression match, returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param name the name
@@ -199,8 +203,8 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
- * <li>otherwise returns false</li>
+ * <li>wildcard match (pattern ends with a * and the name starts with the pattern), returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param name the name
@@ -220,8 +224,8 @@ public final class EndpointHelper {
* <p/>
* The match rules are applied in this order:
* <ul>
- * <li>regular expression match, returns true</li>
- * <li>otherwise returns false</li>
+ * <li>regular expression match, returns true</li>
+ * <li>otherwise returns false</li>
* </ul>
*
* @param name the name
@@ -312,7 +316,7 @@ public final class EndpointHelper {
* @param value reference parameter value.
* @param type type of object to lookup.
* @return lookup result (or <code>null</code> only if
- * <code>mandatory</code> is <code>false</code>).
+ * <code>mandatory</code> is <code>false</code>).
* @throws IllegalArgumentException if object was not found in registry and
* <code>mandatory</code> is <code>true</code>.
*/
@@ -329,9 +333,9 @@ public final class EndpointHelper {
* Resolves a reference list parameter by making lookups in the registry.
* The parameter value must be one of the following:
* <ul>
- * <li>a comma-separated list of references to beans of type T</li>
- * <li>a single reference to a bean type T</li>
- * <li>a single reference to a bean of type java.util.List</li>
+ * <li>a comma-separated list of references to beans of type T</li>
+ * <li>a single reference to a bean type T</li>
+ * <li>a single reference to a bean of type java.util.List</li>
* </ul>
*
* @param context Camel context to use for lookup.
@@ -396,7 +400,7 @@ public final class EndpointHelper {
/**
* Gets the route id for the given endpoint in which there is a consumer listening.
*
- * @param endpoint the endpoint
+ * @param endpoint the endpoint
* @return the route id, or <tt>null</tt> if none found
*/
public static String getRouteIdFromEndpoint(Endpoint endpoint) {
@@ -425,7 +429,7 @@ public final class EndpointHelper {
/**
* Lookup the id the given endpoint has been enlisted with in the {@link org.apache.camel.spi.Registry}.
*
- * @param endpoint the endpoint
+ * @param endpoint the endpoint
* @return the endpoint id, or <tt>null</tt> if not found
*/
public static String lookupEndpointRegistryId(Endpoint endpoint) {
@@ -453,9 +457,9 @@ public final class EndpointHelper {
/**
* Browses the {@link BrowsableEndpoint} within the given range, and returns the messages as a XML payload.
*
- * @param endpoint the browsable endpoint
- * @param fromIndex from range
- * @param toIndex to range
+ * @param endpoint the browsable endpoint
+ * @param fromIndex from range
+ * @param toIndex to range
* @param includeBody whether to include the message body in the XML payload
* @return XML payload with the messages
* @throws IllegalArgumentException if the from and to range is invalid
@@ -509,4 +513,154 @@ public final class EndpointHelper {
return null;
}
+ /**
+ * Parses the endpoint uri and builds a map of documentation information for each option which is extracted
+ * from the component json documentation
+ *
+ * @param camelContext the Camel context
+ * @param uri the endpoint uri
+ * @return a map for each option in the uri with the corresponding information from the json
+ * @throws Exception is thrown in case of error
+ */
+ public static Map<String, Object> endpointProperties(CamelContext camelContext, String uri) throws Exception {
+ // NOTICE: This logic is similar to org.apache.camel.catalog.DefaultCamelCatalog#endpointProperties
+ // as the catalog also offers similar functionality (without having camel-core on classpath)
+
+ // parse the uri
+ URI u = new URI(uri);
+ String scheme = u.getScheme();
+
+ String json = camelContext.getComponentParameterJsonSchema(u.getScheme());
+ if (json == null) {
+ throw new IllegalArgumentException("Cannot find endpoint with scheme " + scheme);
+ }
+
+ // grab the syntax
+ String syntax = null;
+ List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("component", json, false);
+ for (Map<String, String> row : rows) {
+ if (row.containsKey("syntax")) {
+ syntax = row.get("syntax");
+ break;
+ }
+ }
+ if (syntax == null) {
+ throw new IllegalArgumentException("Endpoint with scheme " + scheme + " has no syntax defined in the json schema");
+ }
+
+ // parse the syntax and find the same group in the uri
+ Matcher matcher = SYNTAX_PATTERN.matcher(syntax);
+ List<String> word = new ArrayList<String>();
+ while (matcher.find()) {
+ String s = matcher.group(1);
+ if (!scheme.equals(s)) {
+ word.add(s);
+ }
+ }
+
+ String uriPath = stripQuery(uri);
+
+ // if there is only one, then use uriPath as is
+ List<String> word2 = new ArrayList<String>();
+
+ if (word.size() == 1) {
+ String s = uriPath;
+ s = URISupport.stripPrefix(s, scheme);
+ // strip any leading : or / after the scheme
+ while (s.startsWith(":") || s.startsWith("/")) {
+ s = s.substring(1);
+ }
+ word2.add(s);
+ } else {
+ Matcher matcher2 = SYNTAX_PATTERN.matcher(uriPath);
+ while (matcher2.find()) {
+ String s = matcher2.group(1);
+ if (!scheme.equals(s)) {
+ word2.add(s);
+ }
+ }
+ }
+
+ rows = JsonSchemaHelper.parseJsonSchema("properties", json, true);
+
+ boolean defaultValueAdded = false;
+
+ // now parse the uri to know which part isw what
+ Map<String, String> options = new LinkedHashMap<String, String>();
+
+ // word contains the syntax path elements
+ Iterator<String> it = word2.iterator();
+ for (int i = 0; i < word.size(); i++) {
+ String key = word.get(i);
+
+ boolean allOptions = word.size() == word2.size();
+ boolean required = JsonSchemaHelper.isPropertyRequired(rows, key);
+ String defaultValue = JsonSchemaHelper.getPropertyDefaultValue(rows, key);
+
+ // we have all options so no problem
+ if (allOptions) {
+ String value = it.next();
+ options.put(key, value);
+ } else {
+ // we have a little problem as we do not not have all options
+ if (!required) {
+ String value = defaultValue;
+ options.put(key, value);
+ defaultValueAdded = true;
+ } else {
+ String value = it.next();
+ options.put(key, value);
+ }
+ }
+ }
+
+ Map<String, Object> answer = new LinkedHashMap<String, Object>();
+
+ // remove all options which are using default values and are not required
+ for (Map.Entry<String, String> entry : options.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+
+ if (defaultValueAdded) {
+ boolean required = JsonSchemaHelper.isPropertyRequired(rows, key);
+ String defaultValue = JsonSchemaHelper.getPropertyDefaultValue(rows, key);
+
+ if (!required && defaultValue != null) {
+ if (defaultValue.equals(value)) {
+ continue;
+ }
+ }
+ }
+
+ // we should keep this in the answer
+ answer.put(key, value);
+ }
+
+ // now parse the uri parameters
+ Map<String, Object> parameters = URISupport.parseParameters(u);
+
+ // and covert the values to String so its JMX friendly
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue() != null ? entry.getValue().toString() : "";
+ answer.put(key, value);
+ }
+
+ return answer;
+ }
+
+ /**
+ * Strips the query parameters from the uri
+ *
+ * @param uri the uri
+ * @return the uri without the query parameter
+ */
+ private static String stripQuery(String uri) {
+ int idx = uri.indexOf('?');
+ if (idx > -1) {
+ uri = uri.substring(0, idx);
+ }
+ return uri;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5c034c84/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
index 336bf85..41dffe3 100644
--- a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
@@ -39,15 +39,15 @@ public final class JsonSchemaHelper {
/**
* Gets the JSon schema type.
*
- * @param type the java type
- * @return the json schema type, is never null, but returns <tt>object</tt> as the generic type
+ * @param type the java type
+ * @return the json schema type, is never null, but returns <tt>object</tt> as the generic type
*/
public static String getType(Class<?> type) {
if (type.isEnum()) {
return "enum";
} else if (type.isArray()) {
return "array";
- }
+ }
if (type.isAssignableFrom(URI.class) || type.isAssignableFrom(URL.class)) {
return "sting";
}
@@ -63,8 +63,8 @@ public final class JsonSchemaHelper {
/**
* Gets the JSon schema primitive type.
*
- * @param type the java type
- * @return the json schema primitive type, or <tt>null</tt> if not a primitive
+ * @param type the java type
+ * @return the json schema primitive type, or <tt>null</tt> if not a primitive
*/
public static String getPrimitiveType(Class<?> type) {
String name = type.getCanonicalName();
@@ -118,7 +118,7 @@ public final class JsonSchemaHelper {
* Parses the json schema to split it into a list or rows, where each row contains key value pairs with the metadata
*
* @param group the group to parse from such as <tt>component</tt>, <tt>componentProperties</tt>, or <tt>properties</tt>.
- * @param json the json
+ * @param json the json
* @return a list of all the rows, where each row is a set of key value pairs with metadata
*/
public static List<Map<String, String>> parseJsonSchema(String group, String json, boolean parseProperties) {
@@ -195,4 +195,52 @@ public final class JsonSchemaHelper {
return value;
}
+ /**
+ * Is the property required
+ *
+ * @param rows the rows of properties
+ * @param name name of the property
+ * @return <tt>true</tt> if required, or <tt>false</tt> if not
+ */
+ public static boolean isPropertyRequired(List<Map<String, String>> rows, String name) {
+ for (Map<String, String> row : rows) {
+ boolean required = false;
+ boolean found = false;
+ if (row.containsKey("name")) {
+ found = name.equals(row.get("name"));
+ }
+ if (row.containsKey("required")) {
+ required = "true".equals(row.get("required"));
+ }
+ if (found) {
+ return required;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Gets the default value of the property
+ *
+ * @param rows the rows of properties
+ * @param name name of the property
+ * @return the default value or <tt>null</tt> if no default value exists
+ */
+ public static String getPropertyDefaultValue(List<Map<String, String>> rows, String name) {
+ for (Map<String, String> row : rows) {
+ String defaultValue = null;
+ boolean found = false;
+ if (row.containsKey("name")) {
+ found = name.equals(row.get("name"));
+ }
+ if (row.containsKey("defaultValue")) {
+ defaultValue = row.get("defaultValue");
+ }
+ if (found) {
+ return defaultValue;
+ }
+ }
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5c034c84/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 46237b7..3677611 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
@@ -268,8 +268,8 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
int pos2 = json.indexOf("groupDelay");
assertTrue("LoggerName should come before groupDelay", pos < pos2);
- assertEquals(8, StringHelper.countChar(json, '{'));
- assertEquals(8, StringHelper.countChar(json, '}'));
+ assertEquals(6, StringHelper.countChar(json, '{'));
+ assertEquals(6, StringHelper.countChar(json, '}'));
assertTrue(json.contains("\"scheme\": \"log\""));
assertTrue(json.contains("\"label\": \"core,monitoring\""));
@@ -303,8 +303,8 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
int pos2 = json.indexOf("groupDelay");
assertTrue("LoggerName should come before groupDelay", pos < pos2);
- assertEquals(14, StringHelper.countChar(json, '{'));
- assertEquals(14, StringHelper.countChar(json, '}'));
+ assertEquals(12, StringHelper.countChar(json, '{'));
+ assertEquals(12, StringHelper.countChar(json, '}'));
assertTrue(json.contains("\"scheme\": \"log\""));
assertTrue(json.contains("\"label\": \"core,monitoring\""));
http://git-wip-us.apache.org/repos/asf/camel/blob/5c034c84/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
index 288c530..86459ed 100644
--- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
+++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsComponentConfigurationAndDocumentationTest.java
@@ -40,4 +40,38 @@ public class JmsComponentConfigurationAndDocumentationTest extends CamelTestSupp
assertNotNull(json);
}
+ @Test
+ public void testExplainComponentJson() throws Exception {
+ String json = context.explainComponentJson("jms", false);
+ assertNotNull(json);
+
+ log.info(json);
+ assertTrue(json.contains("\"syntax\": \"jms:destinationType:destinationName\""));
+ }
+
+ @Test
+ public void testExplainEndpointJson() throws Exception {
+ String json = context.explainEndpointJson("jms:queue:foo?replyTo=bar", false);
+ assertNotNull(json);
+ log.info(json);
+ assertTrue(json.contains("\"syntax\": \"jms:destinationType:destinationName\""));
+ assertTrue(json.contains("\"destinationType\": { \"kind\": \"path\", \"type\": \"string\", \"javaType\": \"java.lang.String\""
+ + ", \"deprecated\": \"false\", \"value\": \"queue\", \"defaultValue\": \"queue\""));
+ assertTrue(json.contains("\"destinationName\": { \"kind\": \"path\", \"required\": \"true\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"foo\""));
+ assertTrue(json.contains("\"replyTo\": { \"kind\": \"parameter\", \"label\": \"consumer\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"bar\""));
+
+ json = context.explainEndpointJson("jms:foo?replyTo=bar", false);
+ assertNotNull(json);
+ log.info(json);
+ assertTrue(json.contains("\"syntax\": \"jms:destinationType:destinationName\""));
+ assertTrue(json.contains("\"destinationType\": { \"kind\": \"path\", \"type\": \"string\", \"javaType\": \"java.lang.String\""
+ + ", \"deprecated\": \"false\", \"defaultValue\": \"queue\""));
+ assertTrue(json.contains("\"destinationName\": { \"kind\": \"path\", \"required\": \"true\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"foo\""));
+ assertTrue(json.contains("\"replyTo\": { \"kind\": \"parameter\", \"label\": \"consumer\", \"type\": \"string\""
+ + ", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\", \"value\": \"bar\""));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5c034c84/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 88566b3..a510fc5 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
@@ -447,6 +447,9 @@ public class DefaultCamelCatalog implements CamelCatalog {
@Override
public Map<String, String> endpointProperties(String uri) throws URISyntaxException {
+ // NOTICE: This logic is similar to org.apache.camel.util.EndpointHelper#endpointProperties
+ // as the catalog also offers similar functionality (without having camel-core on classpath)
+
// parse the uri
URI u = new URI(uri);
String scheme = u.getScheme();
http://git-wip-us.apache.org/repos/asf/camel/blob/5c034c84/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 34fa5c7..e905e81 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
@@ -184,6 +184,12 @@ public class CamelCatalogTest extends TestCase {
assertEquals("queue", map.get("destinationType"));
assertEquals("foo", map.get("destinationName"));
+
+ map = catalog.endpointProperties("jms:foo");
+ assertNotNull(map);
+ assertEquals(1, map.size());
+
+ assertEquals("foo", map.get("destinationName"));
}
@Test