@Test public void testSetQueryParams() throws Exception { URI initialUri = new URI("http: Multimap<String, String> params = LinkedListMultimap.create(); params.put("a", "1"); params.put("b", "2"); params.put("b", "3"); assertEquals("http: URIUtils.setQueryParams(initialUri, params).toString()); initialUri = new URI("http", "un:ps", "server.com", 9876, "/p1/p2", "z=3&y=4", "fragment"); assertEquals("http: URIUtils.setQueryParams(initialUri, params).toString()); initialUri = new URI("http: assertEquals("http: URIUtils.setQueryParams(initialUri, params).toString()); initialUri = new URI("http: assertEquals("http: URIUtils.setQueryParams(initialUri, params).toString()); initialUri = new URI("http", "center_wmts_fixedscale.com:1234", "/wmts", "a=3", "fragment"); assertEquals("http: URIUtils.setQueryParams(initialUri, params).toString()); initialUri = new URI("http", "center_wmts_fixedscale.com:1234", "/wmts", null, null); assertEquals("http: URIUtils.setQueryParams(initialUri, params).toString()); params = LinkedListMultimap.create(); final String trickyKey = "a # param"; final String trickyValue = "a value &time=1#trickFrag"; params.put(trickyKey, trickyValue); initialUri = new URI("http: final URI updatedUri = URIUtils.setQueryParams(initialUri, params); assertFalse(updatedUri.toString().contains("a #")); assertFalse(updatedUri.toString().contains("1#t")); assertFalse(updatedUri.toString().contains(" &time")); assertFalse(updatedUri.toString().contains("#trick")); assertEquals("http", updatedUri.getScheme()); assertEquals("fragment", updatedUri.getFragment()); assertEquals("server.com", updatedUri.getHost()); assertEquals("/p1/p2", updatedUri.getPath()); assertEquals(9876, updatedUri.getPort()); }
public static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams) { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String> entry: queryParams.entries()) { if (queryString.length() > 0) { queryString.append("&"); } queryString.append(entry.getKey()).append("=").append(entry.getValue()); } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } }
URIUtils { public static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams) { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String> entry: queryParams.entries()) { if (queryString.length() > 0) { queryString.append("&"); } queryString.append(entry.getKey()).append("=").append(entry.getValue()); } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } } }
URIUtils { public static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams) { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String> entry: queryParams.entries()) { if (queryString.length() > 0) { queryString.append("&"); } queryString.append(entry.getKey()).append("=").append(entry.getValue()); } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } } private  URIUtils(); }
URIUtils { public static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams) { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String> entry: queryParams.entries()) { if (queryString.length() > 0) { queryString.append("&"); } queryString.append(entry.getKey()).append("=").append(entry.getValue()); } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } } private  URIUtils(); static Multimap<String, String> getParameters(final URI uri); static Multimap<String, String> getParameters(final String rawQuery); static String addParams(
            final String url, final Multimap<String, String> params, final Set<String> overrideParams); static URI addParams(
            final URI uri, final Multimap<String, String> params, final Set<String> overrideParams); static void addParamOverride(
            final Multimap<String, String> params, final String key, final String value); static void setParamDefault(
            final Multimap<String, String> params, final String key, final String value); static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams); static String toString(final MfClientHttpRequestFactory requestFactory, final URI uri); static String toString(final MfClientHttpRequestFactory requestFactory, final URL url); static URI setPath(final URI initialUri, final String path); }
URIUtils { public static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams) { StringBuilder queryString = new StringBuilder(); for (Map.Entry<String, String> entry: queryParams.entries()) { if (queryString.length() > 0) { queryString.append("&"); } queryString.append(entry.getKey()).append("=").append(entry.getValue()); } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), initialUri.getPath(), queryString.toString(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } } private  URIUtils(); static Multimap<String, String> getParameters(final URI uri); static Multimap<String, String> getParameters(final String rawQuery); static String addParams(
            final String url, final Multimap<String, String> params, final Set<String> overrideParams); static URI addParams(
            final URI uri, final Multimap<String, String> params, final Set<String> overrideParams); static void addParamOverride(
            final Multimap<String, String> params, final String key, final String value); static void setParamDefault(
            final Multimap<String, String> params, final String key, final String value); static URI setQueryParams(final URI initialUri, final Multimap<String, String> queryParams); static String toString(final MfClientHttpRequestFactory requestFactory, final URI uri); static String toString(final MfClientHttpRequestFactory requestFactory, final URL url); static URI setPath(final URI initialUri, final String path);  }