Example usage for java.net URI getRawAuthority

List of usage examples for java.net URI getRawAuthority

Introduction

In this page you can find the example usage for java.net URI getRawAuthority.

Prototype

public String getRawAuthority() 

Source Link

Document

Returns the raw authority component of this URI.

Usage

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.java2s.com");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
}

From source file:Main.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://www.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:IRIDemo.java

public static void main(String[] args) throws NullPointerException, URISyntaxException {
    URI uri = new URI("http://r%C3%A9sum%C3%A9.example.org");
    System.out.println("URI      : " + uri);
    System.out.println("Raw Authority : " + uri.getRawAuthority());
    System.out.println("Raw Fragment : " + uri.getRawFragment());
    System.out.println("Fragment : " + uri.getFragment());
    System.out.println("Authority : " + uri.getAuthority());
    System.out.println("Authority : " + uri.getRawPath());
    System.out.println("RawQuery : " + uri.getRawQuery());
    System.out.println("RawSchemeSpecificPart : " + uri.getRawSchemeSpecificPart());
    System.out.println("RawUserInfo : " + uri.getRawUserInfo());

}

From source file:sf.net.experimaestro.scheduler.ResourceLocator.java

public static ResourceLocator parse(String idString) {
    try {//w ww .ja  va 2s.c  o  m
        final URI uri = new URI(idString);
        StringBuilder connectorId = new StringBuilder();
        StringBuilder path = new StringBuilder();

        connectorId.append(uri.getScheme());
        connectorId.append("://");
        if (uri.getRawAuthority() != null)
            connectorId.append(uri.getRawAuthority());

        path.append(uri.getRawPath());

        return new ResourceLocator(connectorId.toString(), path.toString());
    } catch (URISyntaxException e) {
        throw new XPMRuntimeException("Could not parse locator URI [%s]", idString);
    }
}

From source file:org.zaproxy.zap.spider.URLCanonicalizer.java

/**
 * Gets the canonical url, starting from a relative or absolute url found in a given context (baseURL).
 * /*from   w w w . j  ava 2 s  . c  o m*/
 * @param url the url string defining the reference
 * @param baseURL the context in which this url was found
 * @return the canonical url
 */
public static String getCanonicalURL(String url, String baseURL) {

    try {
        /* Build the absolute URL, from the url and the baseURL */
        String resolvedURL = URLResolver.resolveUrl(baseURL == null ? "" : baseURL, url);
        log.debug("Resolved URL: " + resolvedURL);
        URI canonicalURI;
        try {
            canonicalURI = new URI(resolvedURL);
        } catch (Exception e) {
            canonicalURI = new URI(URIUtil.encodeQuery(resolvedURL));
        }

        /* Some checking. */
        if (canonicalURI.getScheme() == null) {
            throw new MalformedURLException("Protocol could not be reliably evaluated from uri: " + canonicalURI
                    + " and base url: " + baseURL);
        }

        if (canonicalURI.getRawAuthority() == null) {
            log.debug("Ignoring URI with no authority (host[\":\"port]): " + canonicalURI);
            return null;
        }

        if (canonicalURI.getHost() == null) {
            throw new MalformedURLException("Host could not be reliably evaluated from: " + canonicalURI);
        }

        /*
         * Normalize: no empty segments (i.e., "//"), no segments equal to ".", and no segments equal to
         * ".." that are preceded by a segment not equal to "..".
         */
        String path = canonicalURI.normalize().getRawPath();

        /* Convert '//' -> '/' */
        int idx = path.indexOf("//");
        while (idx >= 0) {
            path = path.replace("//", "/");
            idx = path.indexOf("//");
        }

        /* Drop starting '/../' */
        while (path.startsWith("/../")) {
            path = path.substring(3);
        }

        /* Trim */
        path = path.trim();

        /* Process parameters and sort them. */
        final SortedMap<String, String> params = createParameterMap(canonicalURI.getRawQuery());
        final String queryString;
        String canonicalParams = canonicalize(params);
        queryString = (canonicalParams.isEmpty() ? "" : "?" + canonicalParams);

        /* Add starting slash if needed */
        if (path.length() == 0) {
            path = "/" + path;
        }

        /* Drop default port: example.com:80 -> example.com */
        int port = canonicalURI.getPort();
        if (port == 80) {
            port = -1;
        }

        /* Lowercasing protocol and host */
        String protocol = canonicalURI.getScheme().toLowerCase();
        String host = canonicalURI.getHost().toLowerCase();
        String pathAndQueryString = normalizePath(path) + queryString;

        URL result = new URL(protocol, host, port, pathAndQueryString);
        return result.toExternalForm();

    } catch (Exception ex) {
        log.warn("Error while Processing URL in the spidering process (on base " + baseURL + "): "
                + ex.getMessage());
        return null;
    }
}

From source file:org.openanzo.servlet.EncryptedTokenAuthenticator.java

/**
 * Adds the give parameters to a URI string in the URI's query portion. It will add the '?' if needed, and will simply add the arguments if the URI already
 * has a query portion. It will also allow URIs with fragment portions (ex. '#foo') and place the query fragment and parameters in the appropriate place. It
 * will also escape any special URI characters in the parameter names or values.
 * /*ww w .j a v  a 2  s. com*/
 * This method assumes that the query string is in x-www-form-urlencoded format.
 * 
 * @param uri
 *            the URI string to modify
 * @param parameters
 *            the map with the key/value parameters to add to the query portion of the URI
 * @return a String URI with the parameters added to the given URI.
 * @throws URISyntaxException
 */
public static String addQueryParametersToURI(String uri, MultiMap<String> parameters)
        throws URISyntaxException {
    URI inUri = new URI(uri);

    String paramStr = UrlEncoded.encode(parameters, null, false);
    String newQuery = inUri.getQuery() == null ? paramStr : inUri.getQuery() + "&" + paramStr;
    StringBuilder outUri = new StringBuilder();
    if (inUri.getScheme() != null) {
        outUri.append(inUri.getScheme());
        outUri.append(':');
    }
    if (inUri.getRawAuthority() != null) {
        outUri.append("//");
        outUri.append(inUri.getRawAuthority());
    }
    if (inUri.getRawPath() != null) {
        outUri.append(inUri.getRawPath());
    }
    if (StringUtils.isNotEmpty(newQuery)) {
        outUri.append('?');
        outUri.append(newQuery);
    }
    if (inUri.getRawFragment() != null) {
        outUri.append("#");
        outUri.append(inUri.getRawFragment());
    }
    return outUri.toString();
}

From source file:cn.isif.util_plus.http.client.util.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery());
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}

From source file:org.orbeon.oxf.xforms.XFormsUtils.java

private static String uriToStringNoFragment(XFormsContainingDocument containingDocument, URI resolvedURI) {
    if (containingDocument.isPortletContainer() && resolvedURI.getFragment() != null) {
        // XForms page was loaded from a portlet and there is a fragment, remove it
        try {//from w ww. ja  v  a  2s . com
            return new URI(resolvedURI.getScheme(), resolvedURI.getRawAuthority(), resolvedURI.getRawPath(),
                    resolvedURI.getRawQuery(), null).toString();
        } catch (URISyntaxException e) {
            throw new OXFException(e);
        }
    } else {
        return resolvedURI.toString();
    }
}

From source file:com.gistlabs.mechanize.util.apache.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8);
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}

From source file:com.android.idtt.http.client.util.URIBuilder.java

private void digestURI(final URI uri) {
    this.scheme = uri.getScheme();
    this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart();
    this.encodedAuthority = uri.getRawAuthority();
    this.host = uri.getHost();
    this.port = uri.getPort();
    this.encodedUserInfo = uri.getRawUserInfo();
    this.userInfo = uri.getUserInfo();
    this.encodedPath = uri.getRawPath();
    this.path = uri.getPath();
    this.encodedQuery = uri.getRawQuery();
    this.queryParams = parseQuery(uri.getRawQuery(), Charset.forName(HTTP.UTF_8));
    this.encodedFragment = uri.getRawFragment();
    this.fragment = uri.getFragment();
}