code: private static String makeBaseUri(URL url) {
  		String r = url.getProtocol().toLowerCase() + "://" +
  				url.getHost().toLowerCase();
  		if ((url.getProtocol().equalsIgnoreCase("http") &&
  				url.getPort() != -1 && url.getPort() != 80) ||
  			(url.getProtocol().equalsIgnoreCase("https") &&
  					url.getPort() != -1 && url.getPort() != 443)) {
  			r += ":" + url.getPort();
  		}
  		return r;
  	}
docs: Generates a base URI from a given URL. The base URI consists of the
  protocol, the host, and also the port if its not the default port
  for the given protocol.
  @param url the URL from which the URI should be generated
  @return the base URI