@Test public void testGetProtocolHostPort() { String url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, true), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, true), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "https: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "https: url = "https: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "https: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, true), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, true), "http: url = "ftp: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "ftp: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "test.de/blah"; Assert.assertNull(UrlHelper.getProtocolHostPort(url, false)); url = "/blah?query=true#id"; Assert.assertNull(UrlHelper.getProtocolHostPort(url, false)); url = "http:"; Assert.assertNull(UrlHelper.getProtocolHostPort(url, false)); url = "http: Assert.assertNull(UrlHelper.getProtocolHostPort(url, false)); url = "http: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: url = "HTTP: Assert.assertEquals(UrlHelper.getProtocolHostPort(url, false), "http: }
public static String getProtocolHostPort(String url, boolean stripUserInfo) { try { URL urlObj = new URL(url); if (urlObj.getHost() != null && urlObj.getHost().length() > 0) { StringBuilder result = new StringBuilder(urlObj.getProtocol()); result.append(": if (!stripUserInfo && urlObj.getUserInfo() != null) { result.append(urlObj.getUserInfo()); result.append("@"); } result.append(urlObj.getHost()); if (urlObj.getPort() != -1) { result.append(":"); result.append(urlObj.getPort()); } return result.toString(); } } catch (MalformedURLException e) { } return null; }
UrlHelper { public static String getProtocolHostPort(String url, boolean stripUserInfo) { try { URL urlObj = new URL(url); if (urlObj.getHost() != null && urlObj.getHost().length() > 0) { StringBuilder result = new StringBuilder(urlObj.getProtocol()); result.append(": if (!stripUserInfo && urlObj.getUserInfo() != null) { result.append(urlObj.getUserInfo()); result.append("@"); } result.append(urlObj.getHost()); if (urlObj.getPort() != -1) { result.append(":"); result.append(urlObj.getPort()); } return result.toString(); } } catch (MalformedURLException e) { } return null; } }
UrlHelper { public static String getProtocolHostPort(String url, boolean stripUserInfo) { try { URL urlObj = new URL(url); if (urlObj.getHost() != null && urlObj.getHost().length() > 0) { StringBuilder result = new StringBuilder(urlObj.getProtocol()); result.append(": if (!stripUserInfo && urlObj.getUserInfo() != null) { result.append(urlObj.getUserInfo()); result.append("@"); } result.append(urlObj.getHost()); if (urlObj.getPort() != -1) { result.append(":"); result.append(urlObj.getPort()); } return result.toString(); } } catch (MalformedURLException e) { } return null; } private  UrlHelper(); }
UrlHelper { public static String getProtocolHostPort(String url, boolean stripUserInfo) { try { URL urlObj = new URL(url); if (urlObj.getHost() != null && urlObj.getHost().length() > 0) { StringBuilder result = new StringBuilder(urlObj.getProtocol()); result.append(": if (!stripUserInfo && urlObj.getUserInfo() != null) { result.append(urlObj.getUserInfo()); result.append("@"); } result.append(urlObj.getHost()); if (urlObj.getPort() != -1) { result.append(":"); result.append(urlObj.getPort()); } return result.toString(); } } catch (MalformedURLException e) { } return null; } private  UrlHelper(); static void assertIsValidUrl(String url); static String convertAnchorsToString(String content); static String getProtocolHostPort(String url, boolean stripUserInfo); static String insertSessionIdInUrl(String url, String sessionId); static boolean isAbsoluteHttpUrl(String url); static boolean isAbsoluteUrl(String url); static String shortenUrl(String protocolHostPart, String pathPart, String queryPart,
            String fragmentIdentifier); static String urlEncodeUrlPath(String path); }
UrlHelper { public static String getProtocolHostPort(String url, boolean stripUserInfo) { try { URL urlObj = new URL(url); if (urlObj.getHost() != null && urlObj.getHost().length() > 0) { StringBuilder result = new StringBuilder(urlObj.getProtocol()); result.append(": if (!stripUserInfo && urlObj.getUserInfo() != null) { result.append(urlObj.getUserInfo()); result.append("@"); } result.append(urlObj.getHost()); if (urlObj.getPort() != -1) { result.append(":"); result.append(urlObj.getPort()); } return result.toString(); } } catch (MalformedURLException e) { } return null; } private  UrlHelper(); static void assertIsValidUrl(String url); static String convertAnchorsToString(String content); static String getProtocolHostPort(String url, boolean stripUserInfo); static String insertSessionIdInUrl(String url, String sessionId); static boolean isAbsoluteHttpUrl(String url); static boolean isAbsoluteUrl(String url); static String shortenUrl(String protocolHostPart, String pathPart, String queryPart,
            String fragmentIdentifier); static String urlEncodeUrlPath(String path); static final Pattern URL_PATTERN; }