XUrl { public static int port(String url) { Preconditions.checkNotNull(url); Matcher matcher = URL_PROTOCOL_REGEX.matcher(url); url = addProtocol(url); try { URI uri = new URI(url); if (uri.getPort() == -1) { if (!matcher.find()) { return 80; } else { return 443; } } else { return uri.getPort(); } } catch (URISyntaxException e) { log.info("Malformed url: {}", url); return -1; } }  static String host(String url); static int port(String url); static String domainChecked(String url); static String path(String url); static String stripUrlParameters(String url); static String stripUrlParameters(URL url); static String rawQueryParameters(String url); static String addProtocol(String url); static Map<String, List<String>> decodeQueryString(String url); static InetSocketAddress inetSocket(String url);  }
@Test void getPort() { assertEquals(443, XUrl.port(url1)); assertEquals(8080, XUrl.port(url2)); assertEquals(8080, XUrl.port("https: }