Repository: camel Updated Branches: refs/heads/camel-2.15.x 6d05e4390 -> b604e1675 refs/heads/master f08a36d21 -> a412cd90b
Camel catalog should provide xml variation of creating endpoint uris Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a412cd90 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a412cd90 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a412cd90 Branch: refs/heads/master Commit: a412cd90b841e14dd3a40aeec9b340bba7e00198 Parents: f08a36d Author: Claus Ibsen <davscl...@apache.org> Authored: Thu May 28 15:31:48 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu May 28 15:31:48 2015 +0200 ---------------------------------------------------------------------- .../org/apache/camel/catalog/CamelCatalog.java | 22 +++++++++++++++++++- .../camel/catalog/DefaultCamelCatalog.java | 22 ++++++++++++++++++-- .../org/apache/camel/catalog/URISupport.java | 5 +++-- .../apache/camel/catalog/CamelCatalogTest.java | 10 +++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a412cd90/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 f95b8d9..a32b0b1 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 @@ -176,7 +176,17 @@ public interface CamelCatalog { String asEndpointUri(String scheme, String json) throws URISyntaxException; /** - * Creates an endpoint uri from the information from the properties + * Creates an endpoint uri from the information in the json schema + * + * @param scheme the endpoint schema + * @param json the json schema with the endpoint properties + * @return the constructed endpoint uri + * @throws java.net.URISyntaxException is thrown if there is encoding error + */ + String asEndpointUriXml(String scheme, String json) throws URISyntaxException; + + /** + * Creates an endpoint uri in XML style from the information from the properties * * @param scheme the endpoint schema * @param properties the properties as key value pairs @@ -184,4 +194,14 @@ public interface CamelCatalog { * @throws java.net.URISyntaxException is thrown if there is encoding error */ String asEndpointUri(String scheme, Map<String, String> properties) throws URISyntaxException; + + /** + * Creates an endpoint uri in XML style from the information from the properties + * + * @param scheme the endpoint schema + * @param properties the properties as key value pairs + * @return the constructed endpoint uri + * @throws java.net.URISyntaxException is thrown if there is encoding error + */ + String asEndpointUriXml(String scheme, Map<String, String> properties) throws URISyntaxException; } http://git-wip-us.apache.org/repos/asf/camel/blob/a412cd90/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 f4732b1..88566b3 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 @@ -583,6 +583,15 @@ public class DefaultCamelCatalog implements CamelCatalog { @Override public String asEndpointUri(String scheme, String json) throws URISyntaxException { + return doAsEndpointUri(scheme, json, "&"); + } + + @Override + public String asEndpointUriXml(String scheme, String json) throws URISyntaxException { + return doAsEndpointUri(scheme, json, "&"); + } + + private String doAsEndpointUri(String scheme, String json, String ampersand) throws URISyntaxException { List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("properties", json, true); Map<String, String> copy = new HashMap<String, String>(); @@ -615,11 +624,20 @@ public class DefaultCamelCatalog implements CamelCatalog { } } - return asEndpointUri(scheme, copy); + return doAsEndpointUri(scheme, copy, ampersand); } @Override public String asEndpointUri(String scheme, Map<String, String> properties) throws URISyntaxException { + return doAsEndpointUri(scheme, properties, "&"); + } + + @Override + public String asEndpointUriXml(String scheme, Map<String, String> properties) throws URISyntaxException { + return doAsEndpointUri(scheme, properties, "&"); + } + + private String doAsEndpointUri(String scheme, Map<String, String> properties, String ampersand) throws URISyntaxException { String json = componentJSonSchema(scheme); if (json == null) { throw new IllegalArgumentException("Cannot find endpoint with scheme " + scheme); @@ -697,7 +715,7 @@ public class DefaultCamelCatalog implements CamelCatalog { if (!copy.isEmpty()) { sb.append('?'); - String query = createQueryString(copy); + String query = createQueryString(copy, ampersand); sb.append(query); } http://git-wip-us.apache.org/repos/asf/camel/blob/a412cd90/platforms/catalog/src/main/java/org/apache/camel/catalog/URISupport.java ---------------------------------------------------------------------- diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/URISupport.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/URISupport.java index ea62581..3c09d41 100644 --- a/platforms/catalog/src/main/java/org/apache/camel/catalog/URISupport.java +++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/URISupport.java @@ -267,11 +267,12 @@ public final class URISupport { * Assembles a query from the given map. * * @param options the map with the options (eg key/value pairs) + * @param ampersand to use & for Java code, and & for XML * @return a query string with <tt>key1=value&key2=value2&...</tt>, or an empty string if there is no options. * @throws URISyntaxException is thrown if uri has invalid syntax. */ @SuppressWarnings("unchecked") - public static String createQueryString(Map<String, String> options) throws URISyntaxException { + public static String createQueryString(Map<String, String> options, String ampersand) throws URISyntaxException { try { if (options.size() > 0) { StringBuilder rc = new StringBuilder(); @@ -280,7 +281,7 @@ public final class URISupport { if (first) { first = false; } else { - rc.append("&"); + rc.append(ampersand); } String key = (String) o; http://git-wip-us.apache.org/repos/asf/camel/blob/a412cd90/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 bed519f..ea5f78d 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 @@ -100,6 +100,9 @@ public class CamelCatalogTest extends TestCase { String uri = catalog.asEndpointUri("file", map); assertEquals("file:src/data/inbox?delay=5000&noop=true", uri); + + String uri2 = catalog.asEndpointUriXml("file", map); + assertEquals("file:src/data/inbox?delay=5000&noop=true", uri2); } @Test @@ -112,6 +115,9 @@ public class CamelCatalogTest extends TestCase { String uri = catalog.asEndpointUri("ftp", map); assertEquals("ftp:someserver:21/foo?connectTimeout=5000", uri); + + String uri2 = catalog.asEndpointUriXml("ftp", map); + assertEquals("ftp:someserver:21/foo?connectTimeout=5000", uri2); } @Test @@ -133,8 +139,12 @@ public class CamelCatalogTest extends TestCase { map.put("deliveryPersistent", "false"); map.put("allowNullBody", "true"); + uri = catalog.asEndpointUri("jms", map); assertEquals("jms:foo?allowNullBody=true&deliveryPersistent=false", uri); + + String uri2 = catalog.asEndpointUriXml("jms", map); + assertEquals("jms:foo?allowNullBody=true&deliveryPersistent=false", uri2); } @Test