Returns a {@link URI} of this endpoint as a string. The omitted values in the {@link URI} will be
replaced with the specified default values, such as {@code defaultScheme}, {@code defaultHostname}
and {@code defaultPort}.
9450
String toUriString(String defaultScheme, String defaultHostname, int defaultPort) {
        requireNonNull(defaultScheme, "defaultScheme");
        requireNonNull(defaultHostname, "defaultHostname");
        validatePort(defaultPort);

        final StringBuilder sb = new StringBuilder();
        sb.append(firstNonNull(uri.getScheme(), defaultScheme)).append("://")
          .append(firstNonNull(uri.getHost(), defaultHostname)).append(':')
          .append(uri.getPort() > 0 ? uri.getPort() : defaultPort)
          .append(uri.getPath());
        return sb.toString();
    }
929477
public static URI stringAsURI(String s) throws IOException {
    URI u = null;
    // try to make a URI
    try {
      u = new URI(s);
    } catch (URISyntaxException e){
      LOG.error("Syntax error in URI " + s
          + ". Please check hdfs configuration.", e);
    }

    // if URI is null or scheme is undefined, then assume it's file://
    if(u == null || u.getScheme() == null){
      LOG.warn("Path " + s + " should be specified as a URI "
          + "in configuration files. Please update hdfs configuration.");
      u = fileAsURI(new File(s));
    }
    return u;
  }
880788
public static String getString(HttpServletRequest request, String parameterName, String defaultValue) {
		String value = request.getParameter(parameterName);
		if (value == null || value.length() == 0) {
			return defaultValue;
		}
		else {
			return value;
		}
		// return StringUtils.isEmpty(value) ? defaultValue : value;
	}
1040762
public Optional<CmsSite> getSiteForDefaultUri() {

        String defaultUri = getDefaultUri();
        CmsSite candidate = m_siteRootSites.get(CmsFileUtil.removeTrailingSeparator(defaultUri));
        return Optional.fromNullable(candidate);
    }
670313
public String getEncodedRequestURI()
    {
        if (WCCustomProperties.CHECK_REQUEST_OBJECT_IN_USE){
            checkRequestObjectInUse();
        }
        // 321485
        String uri = null;
        if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.logp(Level.FINE, CLASS_NAME,"getEncodedRequestURI", "");
        }
        if (getDispatchContext() == null)
            uri = _request.getRequestURI();
        else
            uri = getDispatchContext().getRequestURI();
        if (TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.logp(Level.FINE, CLASS_NAME,"getEncodedRequestURI", " uri --> " + uri);
        }

        return uri;
    }
271082
public String getRequestURL()
    {
    	HttpServletRequest httpReq = getRequest();
    	if (httpReq==null)
    		return null;
    	else
    		return httpReq.getRequestURL().toString();
    }
1347828
def host_from_uri(uri):
    
    default_ports = {
        'HTTP': '80',
        'HTTPS': '443',
    }

    sch, netloc, path, par, query, fra = urlparse(uri)
    if ':' in netloc:
        netloc, port = netloc.split(':', 1)
    else:
        port = default_ports.get(sch.upper())

    return netloc, port
322264
public static URI getDefaultUri(Configuration conf) {
    return URI.create(fixName(conf.get(FS_DEFAULT_NAME_KEY, "file:///")));
  }
636329
public String namespaceURI() {
        if (namespacePrefix == null || namespacePrefix.isEmpty()) return "";
        String uri = namespaceTagHints.get(namespacePrefix);
        return uri == null ? "" : uri;
    }
1196397
public static String stripHost(final String uri)
        {
        if (!uri.startsWith("http")) 
            {
            // It's likely a URI path, not the full URI (i.e. the host is 
            // already stripped).
            return uri;
            }
        final String noHttpUri = StringUtils.substringAfter(uri, "://");
        final int slashIndex = noHttpUri.indexOf("/");
        if (slashIndex == -1)
            {
            return "/";
            }
        final String noHostUri = noHttpUri.substring(slashIndex);
        return noHostUri;
        }
29855
protected String calculateCurrentUri(HttpServletRequest request)
			throws UnsupportedEncodingException {
		ServletUriComponentsBuilder builder = ServletUriComponentsBuilder
				.fromRequest(request);
		// Now work around SPR-10172...
		String queryString = request.getQueryString();
		boolean legalSpaces = queryString != null && queryString.contains("+");
		if (legalSpaces) {
			builder.replaceQuery(queryString.replace("+", "%20"));
		}
		UriComponents uri = null;
		try {
			uri = builder.replaceQueryParam("code").build(true);
		} catch (IllegalArgumentException ex) {
			// ignore failures to parse the url (including query string). does't
			// make sense for redirection purposes anyway.
			return null;
		}
		String query = uri.getQuery();
		if (legalSpaces) {
			query = query.replace("%20", "+");
		}
		return ServletUriComponentsBuilder.fromUri(uri.toUri())
				.replaceQuery(query).build().toString();
	}
875983
public Map<String, String> getUrlParams(URI uri) throws URIException {
		Map<String, String> map = new HashMap<>();
		for (NameValuePair parameter : getUrlParamParser(uri.toString()).parseParameters(uri.getEscapedQuery())) {
			String value = parameter.getValue();
			if (value == null) {
				value = "";
			}
			map.put(parameter.getName(), value);
		}
		return map;
	}
1303529
protected static String getResource(Uri uri) {
        if (!isAPIUri(uri)) {
            return null;
        }

        String scheme = uri.getScheme();
        String apiScheme = getBaseUri().getScheme();

        // Strip out the protocol and store the result in the "remainder" variable
        String remainder = uri.toString().substring(scheme.length());

        // Strip out the protocol from the base URI
        String apiRemainder = getBaseUri().toString().substring(apiScheme.length());

        // Check that the remainder starts with the apiRemainder
        if (!remainder.startsWith(apiRemainder)) {
            return null;
        }

        // Return the path, stripped out of the base uri's path
        return uri.getPath().substring(getBaseUri().getPath().length());
    }
887118
private static String massageURI(String uri) {
    uri = uri.trim();
    int protocolEnd = uri.indexOf(':');
    if (protocolEnd < 0 || isColonFollowedByPortNumber(uri, protocolEnd)) {
      // No protocol, or found a colon, but it looks like it is after the host, so the protocol is still missing,
      // so assume http
      uri = "http://" + uri;
    }
    return uri;
  }
1062309
@Override
	public URI toUri() {
		try {
			if (this.encoded) {
				return new URI(toString());
			}
			else {
				String path = getPath();
				if (StringUtils.hasLength(path) && path.charAt(0) != PATH_DELIMITER) {
					// Only prefix the path delimiter if something exists before it
					if (getScheme() != null || getUserInfo() != null || getHost() != null || getPort() != -1) {
						path = PATH_DELIMITER + path;
					}
				}
				return new URI(getScheme(), getUserInfo(), getHost(), getPort(), path, getQuery(),
						getFragment());
			}
		}
		catch (URISyntaxException ex) {
			throw new IllegalStateException("Could not create URI object: " + ex.getMessage(), ex);
		}
	}
638611
private String convertURItoURL(String uri) {
        int indexScheme = uri.indexOf("://");
        if (-1 != indexScheme) {
            int indexQuery = uri.indexOf('?');
            if (-1 == indexQuery || indexScheme < indexQuery) {
                // already a full url
                return uri;
            }
        }
        StringBuilder sb = new StringBuilder();
        String scheme = this.request.getScheme();
        sb.append(scheme).append("://");
        sb.append(this.request.getServerName());
        int port = this.request.getServerPort();
        if ("http".equalsIgnoreCase(scheme) && 80 != port) {
            sb.append(':').append(port);
        } else if ("https".equalsIgnoreCase(scheme) && 443 != port) {
            sb.append(':').append(port);
        }
        String data = this.request.getContextPath();
        if (!"".equals(data)) {
            sb.append(data);
        }
        if (0 == uri.length()) {
            sb.append('/');
        } else if (uri.charAt(0) == '/') {
            // relative to servlet container root...
            sb.append(uri);
        } else {
            // relative to current URI,
            data = this.request.getServletPath();
            if (!"".equals(data)) {
                sb.append(data);
            }
            data = this.request.getPathInfo();
            if (null != data) {
                sb.append(data);
            }
            sb.append('/');
            sb.append(uri);
            // TODO: webcontainer converted "/./" and "/../" info too
        }

        return sb.toString();
    }
888872
public static String getCurrentUri() {
    HttpServletRequest request =
        ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();

    StringBuilder uri = new StringBuilder();
    uri.append(request.getAttribute("javax.servlet.forward.request_uri"));

    if (StringUtils.isNotBlank(request.getQueryString())) {
      uri.append("?").append(request.getQueryString());
    }

    return uri.toString();
  }