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 12:25:24 UTC
[1/2] camel git commit: camel-catalog - Make it possible to grab the
lenient properties from an url.
Repository: camel
Updated Branches:
refs/heads/camel-2.18.x bb2264d8f -> 96aa5be3e
refs/heads/master da0645994 -> de914aaea
camel-catalog - Make it possible to grab the lenient properties from an url.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/de914aae
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/de914aae
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/de914aae
Branch: refs/heads/master
Commit: de914aaeaddcebf138d6b7b67089821b17b644d1
Parents: da06459
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jan 16 13:24:27 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 16 13:24:27 2017 +0100
----------------------------------------------------------------------
.../org/apache/camel/catalog/CamelCatalog.java | 10 +++++
.../camel/catalog/DefaultCamelCatalog.java | 45 ++++++++++++++++++++
.../apache/camel/catalog/CamelCatalogTest.java | 25 +++++++++++
3 files changed, 80 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/de914aae/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index a83b886..6c23016 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -307,6 +307,16 @@ public interface CamelCatalog {
Map<String, String> endpointProperties(String uri) throws URISyntaxException;
/**
+ * Parses the endpoint uri and constructs a key/value properties of only the lenient properties (eg custom options)
+ * <p/>
+ * For example using the HTTP components to provide query parameters in the endpoint uri.
+ *
+ * @param uri the endpoint uri
+ * @return properties as key value pairs of each lenient properties
+ */
+ Map<String, String> endpointLenientProperties(String uri) throws URISyntaxException;
+
+ /**
* Validates the pattern whether its a valid time pattern.
*
* @param pattern the pattern such as 5000, 5s, 5sec, 4min, 4m30s, 1h, etc.
http://git-wip-us.apache.org/repos/asf/camel/blob/de914aae/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 7efa230..8e763db 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
@@ -39,6 +39,7 @@ import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import javax.print.attribute.URISyntax;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
@@ -1609,6 +1610,50 @@ public class DefaultCamelCatalog implements CamelCatalog {
}
@Override
+ public Map<String, String> endpointLenientProperties(String uri) throws URISyntaxException {
+ // need to normalize uri first
+
+ // parse the uri
+ URI u = normalizeUri(uri);
+ String scheme = u.getScheme();
+
+ String json = componentJSonSchema(scheme);
+ if (json == null) {
+ throw new IllegalArgumentException("Cannot find endpoint with scheme " + scheme);
+ }
+
+ List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
+
+ // now parse the uri parameters
+ Map<String, Object> parameters = URISupport.parseParameters(u);
+
+ // all the known options
+ Set<String> names = getNames(rows);
+
+ Map<String, String> answer = new LinkedHashMap<>();
+
+ // and covert the values to String so its JMX friendly
+ parameters.forEach((k, v) -> {
+ String key = k;
+ String value = v != null ? v.toString() : "";
+
+ // is the key a prefix property
+ int dot = key.indexOf('.');
+ if (dot != -1) {
+ String prefix = key.substring(0, dot + 1); // include dot in prefix
+ String option = getPropertyNameFromNameWithPrefix(rows, prefix);
+ if (option == null || !isPropertyMultiValue(rows, option)) {
+ answer.put(key, value);
+ }
+ } else if (!names.contains(key)) {
+ answer.put(key, value);
+ }
+ });
+
+ return answer;
+ }
+
+ @Override
public String endpointComponentName(String uri) {
if (uri != null) {
int idx = uri.indexOf(":");
http://git-wip-us.apache.org/repos/asf/camel/blob/de914aae/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 97cb5a3..c5242d3 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
@@ -286,6 +286,31 @@ public class CamelCatalogTest {
}
@Test
+ public void testEndpointLenientProperties() throws Exception {
+ Map<String, String> map = catalog.endpointLenientProperties("http:myserver?throwExceptionOnFailure=false&foo=123&bar=456");
+ assertNotNull(map);
+ assertEquals(2, map.size());
+
+ assertEquals("123", map.get("foo"));
+ assertEquals("456", map.get("bar"));
+
+ map = catalog.endpointLenientProperties("http:myserver?throwExceptionOnFailure=false&foo=123&bar=456&httpClient.timeout=5000&httpClient.soTimeout=10000");
+ assertNotNull(map);
+ assertEquals(2, map.size());
+
+ assertEquals("123", map.get("foo"));
+ assertEquals("456", map.get("bar"));
+
+ map = catalog.endpointLenientProperties("http:myserver?throwExceptionOnFailure=false&foo=123&bar=456&httpClient.timeout=5000&httpClient.soTimeout=10000&myPrefix.baz=beer");
+ assertNotNull(map);
+ assertEquals(3, map.size());
+
+ assertEquals("123", map.get("foo"));
+ assertEquals("456", map.get("bar"));
+ assertEquals("beer", map.get("myPrefix.baz"));
+ }
+
+ @Test
public void testEndpointPropertiesPlaceholders() throws Exception {
Map<String, String> map = catalog.endpointProperties("timer:foo?period={{howoften}}&repeatCount=5");
assertNotNull(map);
[2/2] camel git commit: camel-catalog - Make it possible to grab the
lenient properties from an url.
Posted by da...@apache.org.
camel-catalog - Make it possible to grab the lenient properties from an url.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/96aa5be3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/96aa5be3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/96aa5be3
Branch: refs/heads/camel-2.18.x
Commit: 96aa5be3e014178236f3ab573c69464c22e280d0
Parents: bb2264d
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jan 16 13:24:27 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jan 16 13:25:14 2017 +0100
----------------------------------------------------------------------
.../org/apache/camel/catalog/CamelCatalog.java | 10 +++++
.../camel/catalog/DefaultCamelCatalog.java | 45 ++++++++++++++++++++
.../apache/camel/catalog/CamelCatalogTest.java | 25 +++++++++++
3 files changed, 80 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/96aa5be3/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index 4c2b9b9..bc77e41 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -283,6 +283,16 @@ public interface CamelCatalog {
Map<String, String> endpointProperties(String uri) throws URISyntaxException;
/**
+ * Parses the endpoint uri and constructs a key/value properties of only the lenient properties (eg custom options)
+ * <p/>
+ * For example using the HTTP components to provide query parameters in the endpoint uri.
+ *
+ * @param uri the endpoint uri
+ * @return properties as key value pairs of each lenient properties
+ */
+ Map<String, String> endpointLenientProperties(String uri) throws URISyntaxException;
+
+ /**
* Validates the pattern whether its a valid time pattern.
*
* @param pattern the pattern such as 5000, 5s, 5sec, 4min, 4m30s, 1h, etc.
http://git-wip-us.apache.org/repos/asf/camel/blob/96aa5be3/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 766a2a1..27d818b 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
@@ -39,6 +39,7 @@ import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import javax.print.attribute.URISyntax;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
@@ -1465,6 +1466,50 @@ public class DefaultCamelCatalog implements CamelCatalog {
}
@Override
+ public Map<String, String> endpointLenientProperties(String uri) throws URISyntaxException {
+ // need to normalize uri first
+
+ // parse the uri
+ URI u = normalizeUri(uri);
+ String scheme = u.getScheme();
+
+ String json = componentJSonSchema(scheme);
+ if (json == null) {
+ throw new IllegalArgumentException("Cannot find endpoint with scheme " + scheme);
+ }
+
+ List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
+
+ // now parse the uri parameters
+ Map<String, Object> parameters = URISupport.parseParameters(u);
+
+ // all the known options
+ Set<String> names = getNames(rows);
+
+ Map<String, String> answer = new LinkedHashMap<>();
+
+ // and covert the values to String so its JMX friendly
+ parameters.forEach((k, v) -> {
+ String key = k;
+ String value = v != null ? v.toString() : "";
+
+ // is the key a prefix property
+ int dot = key.indexOf('.');
+ if (dot != -1) {
+ String prefix = key.substring(0, dot + 1); // include dot in prefix
+ String option = getPropertyNameFromNameWithPrefix(rows, prefix);
+ if (option == null || !isPropertyMultiValue(rows, option)) {
+ answer.put(key, value);
+ }
+ } else if (!names.contains(key)) {
+ answer.put(key, value);
+ }
+ });
+
+ return answer;
+ }
+
+ @Override
public String endpointComponentName(String uri) {
if (uri != null) {
int idx = uri.indexOf(":");
http://git-wip-us.apache.org/repos/asf/camel/blob/96aa5be3/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 c8d890c..aef9f93 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
@@ -286,6 +286,31 @@ public class CamelCatalogTest {
}
@Test
+ public void testEndpointLenientProperties() throws Exception {
+ Map<String, String> map = catalog.endpointLenientProperties("http:myserver?throwExceptionOnFailure=false&foo=123&bar=456");
+ assertNotNull(map);
+ assertEquals(2, map.size());
+
+ assertEquals("123", map.get("foo"));
+ assertEquals("456", map.get("bar"));
+
+ map = catalog.endpointLenientProperties("http:myserver?throwExceptionOnFailure=false&foo=123&bar=456&httpClient.timeout=5000&httpClient.soTimeout=10000");
+ assertNotNull(map);
+ assertEquals(2, map.size());
+
+ assertEquals("123", map.get("foo"));
+ assertEquals("456", map.get("bar"));
+
+ map = catalog.endpointLenientProperties("http:myserver?throwExceptionOnFailure=false&foo=123&bar=456&httpClient.timeout=5000&httpClient.soTimeout=10000&myPrefix.baz=beer");
+ assertNotNull(map);
+ assertEquals(3, map.size());
+
+ assertEquals("123", map.get("foo"));
+ assertEquals("456", map.get("bar"));
+ assertEquals("beer", map.get("myPrefix.baz"));
+ }
+
+ @Test
public void testEndpointPropertiesPlaceholders() throws Exception {
Map<String, String> map = catalog.endpointProperties("timer:foo?period={{howoften}}&repeatCount=5");
assertNotNull(map);