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/05/28 15:27:53 UTC

[2/2] camel git commit: Camel catalog should provide xml variation of creating endpoint uris

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/b604e167
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b604e167
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b604e167

Branch: refs/heads/camel-2.15.x
Commit: b604e1675db6758e82fe33c442a07310ddb97c64
Parents: 6d05e43
Author: Claus Ibsen <da...@apache.org>
Authored: Thu May 28 15:31:48 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu May 28 15:32:35 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/b604e167/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 f71fb8e..3a370d2 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
@@ -168,7 +168,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
@@ -176,4 +186,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/b604e167/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 2ea2d56..df45b19 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
@@ -572,6 +572,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, "&amp;");
+    }
+
+    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>();
@@ -604,11 +613,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, "&amp;");
+    }
+
+    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);
@@ -686,7 +704,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/b604e167/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 &amp; 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/b604e167/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 0f1b4d0..a8d4dba 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&amp;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&amp;deliveryPersistent=false", uri2);
     }
 
     @Test