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/03/02 08:18:53 UTC

camel git commit: CAMEL-8417: Fixed RAW on endpoints to support multiple querty parameters of the same key.

Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x 8db720c62 -> 39947ceaa


CAMEL-8417: Fixed RAW on endpoints to support multiple querty parameters of the same key.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/39947cea
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/39947cea
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/39947cea

Branch: refs/heads/camel-2.14.x
Commit: 39947ceaac360bf2901c500145207f5772cb1f9e
Parents: 8db720c
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Mar 1 15:21:36 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Mar 2 08:19:19 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/util/URISupport.java  | 27 ++++++++++--
 .../issues/EndpointWithRawUriParameterTest.java | 44 ++++++++++++++++++++
 2 files changed, 67 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/39947cea/camel-core/src/main/java/org/apache/camel/util/URISupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/URISupport.java b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
index 607f859..1742432 100644
--- a/camel-core/src/main/java/org/apache/camel/util/URISupport.java
+++ b/camel-core/src/main/java/org/apache/camel/util/URISupport.java
@@ -22,6 +22,7 @@ import java.net.URISyntaxException;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -295,13 +296,31 @@ public final class URISupport {
      * @see #RAW_TOKEN_START
      * @see #RAW_TOKEN_END
      */
+    @SuppressWarnings("unchecked")
     public static void resolveRawParameterValues(Map<String, Object> parameters) {
         for (Map.Entry<String, Object> entry : parameters.entrySet()) {
             if (entry.getValue() != null) {
-                String value = entry.getValue().toString();
-                if (value.startsWith(RAW_TOKEN_START) && value.endsWith(RAW_TOKEN_END)) {
-                    value = value.substring(4, value.length() - 1);
-                    entry.setValue(value);
+                // if the value is a list then we need to iterate
+                Object value = entry.getValue();
+                if (value instanceof List) {
+                    List list = (List) value;
+                    for (int i = 0; i < list.size(); i++) {
+                        Object obj = list.get(i);
+                        if (obj != null) {
+                            String str = obj.toString();
+                            if (str.startsWith(RAW_TOKEN_START) && str.endsWith(RAW_TOKEN_END)) {
+                                str = str.substring(4, str.length() - 1);
+                                // update the string in the list
+                                list.set(i, str);
+                            }
+                        }
+                    }
+                } else {
+                    String str = entry.getValue().toString();
+                    if (str.startsWith(RAW_TOKEN_START) && str.endsWith(RAW_TOKEN_END)) {
+                        str = str.substring(4, str.length() - 1);
+                        entry.setValue(str);
+                    }
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/39947cea/camel-core/src/test/java/org/apache/camel/issues/EndpointWithRawUriParameterTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/EndpointWithRawUriParameterTest.java b/camel-core/src/test/java/org/apache/camel/issues/EndpointWithRawUriParameterTest.java
index b4bfcf5..19e5a63 100644
--- a/camel-core/src/test/java/org/apache/camel/issues/EndpointWithRawUriParameterTest.java
+++ b/camel-core/src/test/java/org/apache/camel/issues/EndpointWithRawUriParameterTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.issues;
 
+import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.Component;
@@ -46,6 +47,7 @@ public class EndpointWithRawUriParameterTest extends ContextTestSupport {
 
         private String username;
         private String password;
+        private List<String> lines;
 
         public MyEndpoint(String endpointUri, Component component) {
             super(endpointUri, component);
@@ -58,6 +60,7 @@ public class EndpointWithRawUriParameterTest extends ContextTestSupport {
                 public void process(Exchange exchange) throws Exception {
                     exchange.getIn().setHeader("username", getUsername());
                     exchange.getIn().setHeader("password", getPassword());
+                    exchange.getIn().setHeader("lines", getLines());
                 }
             };
         }
@@ -87,6 +90,14 @@ public class EndpointWithRawUriParameterTest extends ContextTestSupport {
         public void setPassword(String password) {
             this.password = password;
         }
+
+        public List<String> getLines() {
+            return lines;
+        }
+
+        public void setLines(List<String> lines) {
+            this.lines = lines;
+        }
     }
 
     public void testRawUriParameter() throws Exception {
@@ -97,7 +108,32 @@ public class EndpointWithRawUriParameterTest extends ContextTestSupport {
         template.sendBody("direct:start", "Hello World");
 
         assertMockEndpointsSatisfied();
+    }
 
+    public void testUriParameterLines() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:lines", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        List<String> lines = (List<String>) getMockEndpoint("mock:result").getReceivedExchanges().get(0).getIn().getHeader("lines");
+        assertEquals(2, lines.size());
+        assertEquals("abc", lines.get(0));
+        assertEquals("def", lines.get(1));
+    }
+
+    public void testRawUriParameterLines() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:rawlines", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        List<String> lines = (List<String>) getMockEndpoint("mock:result").getReceivedExchanges().get(0).getIn().getHeader("lines");
+        assertEquals(2, lines.size());
+        assertEquals("++abc++", lines.get(0));
+        assertEquals("++def++", lines.get(1));
     }
 
     @Override
@@ -110,6 +146,14 @@ public class EndpointWithRawUriParameterTest extends ContextTestSupport {
                 from("direct:start")
                     .to("mycomponent:foo?username=scott&password=RAW(++%%w?rd))")
                     .to("mock:result");
+
+                from("direct:lines")
+                    .to("mycomponent:foo?lines=abc&lines=def")
+                    .to("mock:result");
+
+                from("direct:rawlines")
+                    .to("mycomponent:foo?lines=RAW(++abc++)&lines=RAW(++def++)")
+                    .to("mock:result");
             }
         };
     }