Example usage for org.apache.commons.httpclient URI getRawHost

List of usage examples for org.apache.commons.httpclient URI getRawHost

Introduction

In this page you can find the example usage for org.apache.commons.httpclient URI getRawHost.

Prototype

public char[] getRawHost() 

Source Link

Document

Get the host.

Usage

From source file:org.zaproxy.zap.extension.spiderAjax.HttpPrefixUriValidator.java

/**
 * Constructs a {@code HttpPrefixFetchFilter} using the given {@code URI} as prefix.
 *
 * <p>The user info, query component and fragment of the given {@code URI} are discarded. The
 * scheme and domain comparisons are done in a case insensitive way while the path component
 * comparison is case sensitive.//  ww w.ja  v  a2s. c  om
 *
 * @param prefix the {@code URI} that will be used as prefix
 * @throws IllegalArgumentException if any of the following conditions is {@code true}:
 *     <ul>
 *       <li>The given {@code prefix} is {@code null};
 *       <li>The given {@code prefix} has {@code null} scheme;
 *       <li>The scheme of the given {@code prefix} is not HTTP or HTTPS;
 *       <li>The given {@code prefix} has {@code null} host;
 *       <li>The given {@code prefix} has malformed host.
 *     </ul>
 */
public HttpPrefixUriValidator(URI prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("Parameter prefix must not be null.");
    }

    char[] rawScheme = prefix.getRawScheme();
    if (rawScheme == null) {
        throw new IllegalArgumentException("Parameter prefix must have a scheme.");
    }
    String normalisedScheme = normalisedScheme(rawScheme);
    if (!isHttpOrHttps(normalisedScheme)) {
        throw new IllegalArgumentException("The prefix's scheme must be HTTP or HTTPS.");
    }
    scheme = normalisedScheme;

    if (prefix.getRawHost() == null) {
        throw new IllegalArgumentException("Parameter prefix must have a host.");
    }
    try {
        host = normalisedHost(prefix);
    } catch (URIException e) {
        throw new IllegalArgumentException("Failed to obtain the host from the prefix:", e);
    }

    port = normalisedPort(scheme, prefix.getPort());
    path = prefix.getRawPath();
}

From source file:org.zaproxy.zap.extension.spiderAjax.HttpPrefixUriValidator.java

/**
 * Returns the normalised form of the host of the given {@code uri}.
 *
 * <p>The normalisation process consists in converting the host to lowercase, if {@code null} it
 * is returned an empty {@code String}./*from www .j  ava 2 s.c  om*/
 *
 * @param uri the URI whose host will be extracted and normalised
 * @return a {@code String} with the host normalised, never {@code null}
 * @throws URIException if the host of the given {@code uri} is malformed
 */
private static String normalisedHost(URI uri) throws URIException {
    if (uri.getRawHost() == null) {
        return "";
    }
    return uri.getHost().toLowerCase(Locale.ROOT);
}

From source file:org.zaproxy.zap.extension.spiderAjax.HttpPrefixUriValidator.java

/**
 * Tells whether or not the given {@code uri} has the same host as required by this prefix.
 *
 * <p>For malformed hosts it returns always {@code false}.
 *
 * @param uri the {@code URI} whose host will be checked
 * @return {@code true} if the host is same, {@code false} otherwise
 *//*from   ww  w  .  j  ava2s .c  om*/
private boolean hasSameHost(URI uri) {
    try {
        return host.equals(normalisedHost(uri));
    } catch (URIException e) {
        LOGGER.warn("Failed to normalise host: " + Arrays.toString(uri.getRawHost()), e);
    }
    return false;
}

From source file:org.zaproxy.zap.spider.filters.HttpPrefixFetchFilter.java

/**
 * Constructs a {@code HttpPrefixFetchFilter} using the given {@code URI} as prefix.
 * <p>//w w w  . ja v  a2s  .  c  om
 * The user info, query component and fragment of the given {@code URI} are discarded. The scheme and domain comparisons are
 * done in a case insensitive way while the path component comparison is case sensitive.
 *
 * @param prefix the {@code URI} that will be used as prefix
 * @throws IllegalArgumentException if any of the following conditions is {@code true}:
 *             <ul>
 *             <li>The given {@code prefix} is {@code null};</li>
 *             <li>The given {@code prefix} has {@code null} scheme;</li>
 *             <li>The scheme of the given {@code prefix} is not HTTP or HTTPS;</li>
 *             <li>The given {@code prefix} has {@code null} host;</li>
 *             <li>The given {@code prefix} has malformed host.</li>
 *             </ul>
 */
public HttpPrefixFetchFilter(URI prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("Parameter prefix must not be null.");
    }

    char[] rawScheme = prefix.getRawScheme();
    if (rawScheme == null) {
        throw new IllegalArgumentException("Parameter prefix must have a scheme.");
    }
    String normalisedScheme = normalisedScheme(rawScheme);
    if (!isHttpOrHttps(normalisedScheme)) {
        throw new IllegalArgumentException("The prefix's scheme must be HTTP or HTTPS.");
    }
    scheme = normalisedScheme;

    if (prefix.getRawHost() == null) {
        throw new IllegalArgumentException("Parameter prefix must have a host.");
    }
    try {
        host = normalisedHost(prefix);
    } catch (URIException e) {
        throw new IllegalArgumentException("Failed to obtain the host from the prefix:", e);
    }

    port = normalisedPort(scheme, prefix.getPort());
    path = prefix.getRawPath();
}

From source file:pl.nask.hsn2.NewUrlObject.java

private String getHost(URI uri) {
    if (!uri.getProtocolCharset().equals("UTF-8")) {
        LOG.warn("Encoding should be set to UTF-8");
        return null;
    }//from  w w  w . j a v a  2 s  . c  om
    return new String(uri.getRawHost());
}

From source file:ru.org.linux.util.LorURL.java

public LorURL(URI mainURI, String url) throws URIException {
    parsed = new Impl(url);

    char[] _main_host = mainURI.getRawHost();
    int _main_port = mainURI.getPort();

    char[] _https_scheme = "https".toCharArray();
    char[] _http_scheme = "http".toCharArray();

    _true_lor_url = Arrays.equals(_main_host, parsed.getRawHost()) && _main_port == parsed.getPort()
            && (Arrays.equals(_http_scheme, parsed.getRawScheme())
                    || Arrays.equals(_https_scheme, parsed.getRawScheme()));

    findURLIds();//  w w  w.ja v  a2  s.  c  o  m
}