@Test public void testSetPath() throws Exception { URI initialUri = new URI("http: assertEquals("http: URIUtils.setPath(initialUri, "/np1/np2").toString()); assertEquals("http: URIUtils.setPath(initialUri, "np1/np2").toString()); URI forceHostURI = new URI("http", "un:ps", "server.com", 9876, "/p1/p2", "z=3,y=4", "fragment"); assertEquals("http: URIUtils.setPath(forceHostURI, "np1/np2").toString()); URI forceAuthorityURI = new URI("http", "un:ps@server.com:9876", "/p1/p2", "z=3,y=4", "fragment"); assertEquals("http: URIUtils.setPath(forceAuthorityURI, "np1/np2").toString()); assertEquals("z=3,y=4", URIUtils.setPath(initialUri, "/p?y=2").getQuery()); assertTrue(URIUtils.setPath(initialUri, "/p?y=2").getPath().contains("p")); assertTrue(URIUtils.setPath(initialUri, "/p?y=2").getPath().contains("y=2")); assertEquals("fragment", URIUtils.setPath(initialUri, "/p#badFragment").getFragment()); assertTrue(URIUtils.setPath(initialUri, "/p#badFragment").getPath().contains("badFragment")); assertTrue(URIUtils.setPath(initialUri, "/p#badFragment").getPath().contains("p")); }
public static URI setPath(final URI initialUri, final String path) { String finalPath = path; if (!finalPath.startsWith("/")) { finalPath = '/' + path; } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } }
URIUtils { public static URI setPath(final URI initialUri, final String path) { String finalPath = path; if (!finalPath.startsWith("/")) { finalPath = '/' + path; } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } } }
URIUtils { public static URI setPath(final URI initialUri, final String path) { String finalPath = path; if (!finalPath.startsWith("/")) { finalPath = '/' + path; } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } } catch (URISyntaxException e) { throw ExceptionUtils.getRuntimeException(e); } } private  URIUtils(); }
URIUtils { public static URI setPath(final URI initialUri, final String path) { String finalPath = path; if (!finalPath.startsWith("/")) { finalPath = '/' + path; } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), finalPath, initialUri.getQuery(), 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 setPath(final URI initialUri, final String path) { String finalPath = path; if (!finalPath.startsWith("/")) { finalPath = '/' + path; } try { if (initialUri.getHost() == null && initialUri.getAuthority() != null) { return new URI(initialUri.getScheme(), initialUri.getAuthority(), finalPath, initialUri.getQuery(), initialUri.getFragment()); } else { return new URI(initialUri.getScheme(), initialUri.getUserInfo(), initialUri.getHost(), initialUri.getPort(), finalPath, initialUri.getQuery(), 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);  }