Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DA72F102B2 for ; Mon, 2 Mar 2015 07:19:11 +0000 (UTC) Received: (qmail 83791 invoked by uid 500); 2 Mar 2015 07:18:53 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 83739 invoked by uid 500); 2 Mar 2015 07:18:53 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 83730 invoked by uid 99); 2 Mar 2015 07:18:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2015 07:18:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8B7A3E055B; Mon, 2 Mar 2015 07:18:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: CAMEL-8417: Fixed RAW on endpoints to support multiple querty parameters of the same key. Date: Mon, 2 Mar 2015 07:18:53 +0000 (UTC) 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 Authored: Sun Mar 1 15:21:36 2015 +0100 Committer: Claus Ibsen 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 parameters) { for (Map.Entry 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 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 getLines() { + return lines; + } + + public void setLines(List 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 lines = (List) 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 lines = (List) 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"); } }; }