@Test public void shouldJoinUrlWithQueryParams() { String masterUrl = "https: final String fullUrl = URLUtils.join(masterUrl, "api"); assertThat(fullUrl, is("https: }
public static String join(String... parts) { StringBuilder sb = new StringBuilder(); String urlQueryParams = ""; if (parts.length > 0) { String urlWithoutQuery = parts[0]; try { URI uri = new URI(parts[0]); if (containsQueryParam(uri)) { urlQueryParams = uri.getQuery(); urlWithoutQuery = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()) .toString(); } } catch (URISyntaxException e) { } sb.append(urlWithoutQuery).append("/"); } StringBuilder queryParams = new StringBuilder(); for (int i = 1; i < parts.length; i++) { try { URI partUri = new URI(parts[i]); if (containsQueryParam(partUri)) { queryParams = getQueryParams(partUri, parts, i+1); break; } sb.append(parts[i]); } catch (URISyntaxException e) { sb.append(parts[i]); } if (i < parts.length - 1) { sb.append("/"); } } appendQueryParametersFromOriginalUrl(sb, urlQueryParams, queryParams); String joined = sb.toString(); return joined .replaceAll("/+", "/") .replaceAll("/\\?", "?") .replaceAll("/#", "#") .replaceAll(":/", ": }
URLUtils { public static String join(String... parts) { StringBuilder sb = new StringBuilder(); String urlQueryParams = ""; if (parts.length > 0) { String urlWithoutQuery = parts[0]; try { URI uri = new URI(parts[0]); if (containsQueryParam(uri)) { urlQueryParams = uri.getQuery(); urlWithoutQuery = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()) .toString(); } } catch (URISyntaxException e) { } sb.append(urlWithoutQuery).append("/"); } StringBuilder queryParams = new StringBuilder(); for (int i = 1; i < parts.length; i++) { try { URI partUri = new URI(parts[i]); if (containsQueryParam(partUri)) { queryParams = getQueryParams(partUri, parts, i+1); break; } sb.append(parts[i]); } catch (URISyntaxException e) { sb.append(parts[i]); } if (i < parts.length - 1) { sb.append("/"); } } appendQueryParametersFromOriginalUrl(sb, urlQueryParams, queryParams); String joined = sb.toString(); return joined .replaceAll("/+", "/") .replaceAll("/\\?", "?") .replaceAll("/#", "#") .replaceAll(":/", ": } }
URLUtils { public static String join(String... parts) { StringBuilder sb = new StringBuilder(); String urlQueryParams = ""; if (parts.length > 0) { String urlWithoutQuery = parts[0]; try { URI uri = new URI(parts[0]); if (containsQueryParam(uri)) { urlQueryParams = uri.getQuery(); urlWithoutQuery = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()) .toString(); } } catch (URISyntaxException e) { } sb.append(urlWithoutQuery).append("/"); } StringBuilder queryParams = new StringBuilder(); for (int i = 1; i < parts.length; i++) { try { URI partUri = new URI(parts[i]); if (containsQueryParam(partUri)) { queryParams = getQueryParams(partUri, parts, i+1); break; } sb.append(parts[i]); } catch (URISyntaxException e) { sb.append(parts[i]); } if (i < parts.length - 1) { sb.append("/"); } } appendQueryParametersFromOriginalUrl(sb, urlQueryParams, queryParams); String joined = sb.toString(); return joined .replaceAll("/+", "/") .replaceAll("/\\?", "?") .replaceAll("/#", "#") .replaceAll(":/", ": }  }
URLUtils { public static String join(String... parts) { StringBuilder sb = new StringBuilder(); String urlQueryParams = ""; if (parts.length > 0) { String urlWithoutQuery = parts[0]; try { URI uri = new URI(parts[0]); if (containsQueryParam(uri)) { urlQueryParams = uri.getQuery(); urlWithoutQuery = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()) .toString(); } } catch (URISyntaxException e) { } sb.append(urlWithoutQuery).append("/"); } StringBuilder queryParams = new StringBuilder(); for (int i = 1; i < parts.length; i++) { try { URI partUri = new URI(parts[i]); if (containsQueryParam(partUri)) { queryParams = getQueryParams(partUri, parts, i+1); break; } sb.append(parts[i]); } catch (URISyntaxException e) { sb.append(parts[i]); } if (i < parts.length - 1) { sb.append("/"); } } appendQueryParametersFromOriginalUrl(sb, urlQueryParams, queryParams); String joined = sb.toString(); return joined .replaceAll("/+", "/") .replaceAll("/\\?", "?") .replaceAll("/#", "#") .replaceAll(":/", ": }  static String join(String... parts); static String pathJoin(String... strings); static boolean isValidURL(String url); static String encodeToUTF(String url); }
URLUtils { public static String join(String... parts) { StringBuilder sb = new StringBuilder(); String urlQueryParams = ""; if (parts.length > 0) { String urlWithoutQuery = parts[0]; try { URI uri = new URI(parts[0]); if (containsQueryParam(uri)) { urlQueryParams = uri.getQuery(); urlWithoutQuery = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, uri.getFragment()) .toString(); } } catch (URISyntaxException e) { } sb.append(urlWithoutQuery).append("/"); } StringBuilder queryParams = new StringBuilder(); for (int i = 1; i < parts.length; i++) { try { URI partUri = new URI(parts[i]); if (containsQueryParam(partUri)) { queryParams = getQueryParams(partUri, parts, i+1); break; } sb.append(parts[i]); } catch (URISyntaxException e) { sb.append(parts[i]); } if (i < parts.length - 1) { sb.append("/"); } } appendQueryParametersFromOriginalUrl(sb, urlQueryParams, queryParams); String joined = sb.toString(); return joined .replaceAll("/+", "/") .replaceAll("/\\?", "?") .replaceAll("/#", "#") .replaceAll(":/", ": }  static String join(String... parts); static String pathJoin(String... strings); static boolean isValidURL(String url); static String encodeToUTF(String url);  }