From 4f9784dafc56c4b59fa7899b4bcddc2d1fabddf2 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 9 Mar 2011 15:17:59 +0000 Subject: [PATCH] apply patch for: https://issues.apache.org/jira/browse/AMQ-3209 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1079831 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/activemq/util/URISupport.java | 6 ++++- .../apache/activemq/util/URISupportTest.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java b/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java index 96359915c1..06a7c5000e 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/URISupport.java @@ -174,12 +174,16 @@ public class URISupport { String schemeSpecificPart = uri.getRawSchemeSpecificPart(); // strip existing query if any int questionMark = schemeSpecificPart.lastIndexOf("?"); + // make sure question mark is not within parentheses + if (questionMark < schemeSpecificPart.lastIndexOf(")")) { + questionMark = -1; + } if (questionMark > 0) { schemeSpecificPart = schemeSpecificPart.substring(0, questionMark); } if (query != null && query.length() > 0) { schemeSpecificPart += "?" + query; - } + } return new URI(uri.getScheme(), schemeSpecificPart, uri.getFragment()); } diff --git a/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java b/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java index f341fa6cc3..a7ac7b5b5c 100644 --- a/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/util/URISupportTest.java @@ -113,6 +113,28 @@ public class URISupportTest extends TestCase { parameters = URISupport.parseParameters(uri); } + public void testCompositeCreateURIWithQuery() throws Exception { + String queryString = "query=value"; + URI originalURI = new URI("outerscheme:(innerscheme:innerssp)"); + URI querylessURI = originalURI; + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null)); + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, "")); + assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI, queryString)); + originalURI = new URI("outerscheme:(innerscheme:innerssp)?outerquery=0"); + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null)); + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, "")); + assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI, queryString)); + originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)"); + querylessURI = originalURI; + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null)); + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, "")); + assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI, queryString)); + originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)?outerquery=0"); + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, null)); + assertEquals(querylessURI, URISupport.createURIWithQuery(originalURI, "")); + assertEquals(new URI(querylessURI + "?" + queryString), URISupport.createURIWithQuery(originalURI, queryString)); + } + private void verifyParams(Map parameters) { assertEquals(parameters.get("proxyHost"), "localhost"); assertEquals(parameters.get("proxyPort"), "80");