public static String getDecodeQuery(final String uri) {
        try {
            URI u = new URI(uri);
            String query = URISupport.prepareQuery(u);
            String uriWithoutQuery = URISupport.stripQuery(uri);
            if (query == null) {
                return uriWithoutQuery;
            } else {
                Map<String, Object> parameters = URISupport.parseQuery(query, false, false);
                if (parameters.size() == 1) {
                    // only 1 parameter need to create new query string
                    query = URISupport.createQueryString(parameters);
                } else {
                    // reorder parameters a..z
                    final Set<String> keySet = parameters.keySet();
                    final String[] parametersArray = keySet.toArray(new String[0]);
                    Arrays.sort(parametersArray);

                    // build uri object with sorted parameters
                    query = URISupport.createQueryString(parametersArray, parameters, true);
                }
                return makeUri(uriWithoutQuery, query);
            }
        } catch (URISyntaxException ex) {
            return null;
        }
    }
@Test
    public void testGetDecodeQuery() throws Exception {
        String out = URISupport.normalizeUri("smtp://localhost?username=davsclaus&password=secret");
        String enc = UnsafeUriCharactersEncoder.encode(out);
        String dec = URISupport.getDecodeQuery(enc);
        assertEquals(out, dec);

        out = URISupport.normalizeUri("smtp://localhost?password=secret&username=davsclaus");
        assertEquals(out, dec);

        out = URISupport.normalizeUri("http://localhost?username=davsclaus&password=RAW(#@a)");
        enc = UnsafeUriCharactersEncoder.encode(out);
        assertNotEquals(out, enc);

        dec = URISupport.getDecodeQuery(enc);
        assertEquals(out, dec);

        out = URISupport.normalizeUri("bean://MyBean?method=RAW(addString(%22#@a%23, test))");
        enc = UnsafeUriCharactersEncoder.encode(out);
        assertNotEquals(out, enc);

        dec = URISupport.getDecodeQuery(enc);
        assertEquals(out, dec);

    }