diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java index 7cbfeaa0a7..d03f2f0934 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/URISupport.java @@ -463,7 +463,7 @@ public class URISupport { /** * Given a key / value mapping, create and return a URI formatted query string that is valid and - * can be appended to a URI. + * can be appended to a URI. Query parameters in the string are sorted by key. * * @param options The Mapping that will create the new Query string. * @return a URI formatted query string. @@ -472,9 +472,12 @@ public class URISupport { public static String createQueryString(Map options) throws URISyntaxException { try { if (options.size() > 0) { - StringBuffer rc = new StringBuffer(); + StringBuilder rc = new StringBuilder(); boolean first = true; - for (String key : options.keySet()) { + List keys = new ArrayList(); + keys.addAll(options.keySet()); + Collections.sort(keys); + for (String key : keys) { if (first) { first = false; } diff --git a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/URIParserTest.java b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/URIParserTest.java index 71a783344b..d4e9950811 100644 --- a/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/URIParserTest.java +++ b/artemis-commons/src/test/java/org/apache/activemq/artemis/utils/URIParserTest.java @@ -114,12 +114,12 @@ public class URIParserTest { System.out.println("queryString2: " + queryString); Assert.assertEquals("key1=value1", queryString); - query.put("key2", "value2"); + query.put("key3", "value3"); queryString = URISupport.createQueryString(query); System.out.println("queryString3: " + queryString); - Assert.assertEquals("key1=value1&key2=value2", queryString); + Assert.assertEquals("key1=value1&key3=value3", queryString); - query.put("key3", "value3"); + query.put("key2", "value2"); queryString = URISupport.createQueryString(query); System.out.println("queryString4: " + queryString); Assert.assertEquals("key1=value1&key2=value2&key3=value3", queryString);