Example usage for java.net URL getAuthority

List of usage examples for java.net URL getAuthority

Introduction

In this page you can find the example usage for java.net URL getAuthority.

Prototype

public String getAuthority() 

Source Link

Document

Gets the authority part of this URL .

Usage

From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java

/**
 * Creates and returns a new URL identical to the specified URL, except using the specified query string.
 * @param u the URL on which to base the returned URL
 * @param newQuery the new query string to use in the returned URL
 * @return a new URL identical to the specified URL, except using the specified query string
 * @throws MalformedURLException if there is a problem creating the new URL
 *///from  ww w .  j  a va  2s .c om
public static URL getUrlWithNewQuery(final URL u, final String newQuery) throws MalformedURLException {
    return createNewUrl(u.getProtocol(), u.getAuthority(), u.getPath(), u.getRef(), newQuery);
}

From source file:com.erudika.para.utils.Utils.java

/**
 * The basic URL without any parameters: >scheme<:>authority<
 * @param url a full URL//from   w  w w.  ja  v  a  2s.  com
 * @return the basic URL
 */
public static String getBaseURL(String url) {
    URL u = toURL(url);
    String base = null;
    if (u != null) {
        try {
            base = u.toURI().getScheme().concat("://").concat(u.getAuthority());
        } catch (URISyntaxException ex) {
            base = null;
        }
    }
    return base;
}

From source file:com.mashape.unirest.request.HttpRequest.java

private URL parseUrl(String s) throws Exception {
    URL u = new URL(s);
    return new URI(u.getProtocol(), u.getAuthority(), u.getPath(), u.getQuery(), u.getRef()).toURL();
}

From source file:org.orbeon.oxf.util.NetUtils.java

/**
 * Check if an URL is relative to another URL.
 *//* w w w .  ja v  a 2 s .  co  m*/
public static boolean relativeURL(URL url1, URL url2) {
    return ((url1.getProtocol() == null && url2.getProtocol() == null)
            || url1.getProtocol().equals(url2.getProtocol()))
            && ((url1.getAuthority() == null && url2.getAuthority() == null)
                    || url1.getAuthority().equals(url2.getAuthority()))
            && ((url1.getPath() == null && url2.getPath() == null)
                    || url2.getPath().startsWith(url1.getPath()));
}

From source file:org.jasig.cas.adaptors.x509.authentication.handler.support.CRLDistributionPointRevocationChecker.java

private void addURL(final List<URL> list, final String uriString) {
    try {//from  w  ww . ja  v a 2s .c  o m
        // Build URI by components to facilitate proper encoding of querystring
        // e.g. http://example.com:8085/ca?action=crl&issuer=CN=CAS Test User CA
        final URL url = new URL(uriString);
        final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null);
        list.add(uri.toURL());
    } catch (final Exception e) {
        log.warn(uriString + " is not a valid distribution point URI.");
    }
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheInvalidator.java

protected void flushUriIfSameHost(URL requestURL, URL targetURL) throws IOException {
    URL canonicalTarget = new URL(uriExtractor.canonicalizeUri(targetURL.toString()));
    if (canonicalTarget.getAuthority().equalsIgnoreCase(requestURL.getAuthority())) {
        storage.removeEntry(canonicalTarget.toString());
    }// w ww  . j  a  v  a 2  s .  com
}

From source file:com.ehsy.solr.util.SimplePostTool.java

/**
 * Appends to the path of the URL// w w  w .  j  a v a  2  s  . com
 * @param url the URL
 * @param append the path to append
 * @return the final URL version 
 */
protected static URL appendUrlPath(URL url, String append) throws MalformedURLException {
    return new URL(url.getProtocol() + "://" + url.getAuthority() + url.getPath() + append
            + (url.getQuery() != null ? "?" + url.getQuery() : ""));
}

From source file:ua.pp.msk.cliqr.GetProcessorImpl.java

public GetProcessorImpl(URL url) throws BadCredentialsException, ClientSslException {

    if (url.getAuthority() != null) {
        logger.debug("Analyzing URL authority " + url.getAuthority());
        String[] credsAndHost = url.getAuthority().split("@");
        if (credsAndHost.length != 2) {
            throw new BadCredentialsException("Cannot get credentials from string " + url.getAuthority());
        }/*  w  w w . jav  a 2 s . co  m*/
        String[] creds = credsAndHost[0].split(":");
        if (creds.length != 2) {
            throw new BadCredentialsException(
                    "Cannot get username and password from string " + credsAndHost[0]);
        }
        logger.debug("Got username: " + creds[0]);

        URL cliqrUrl = responseHelper.normalizeUrl(url);
        init(cliqrUrl, creds[0], creds[1]);
    } else {
        throw new BadCredentialsException(
                "You must provide credentials in your URL to be able to tuse this constructor");
    }
}

From source file:ua.pp.msk.cliqr.PostProcessorImpl.java

public PostProcessorImpl(URL url) throws BadCredentialsException, ClientSslException {
    if (url.getAuthority() != null) {
        logger.debug("Analyzing URL authority " + url.getAuthority());
        String[] credsAndHost = url.getAuthority().split("@");
        if (credsAndHost.length != 2) {
            throw new BadCredentialsException("Cannot get credentials from string " + url.getAuthority());
        }//from w  ww . j a  v  a  2 s. co  m
        String[] creds = credsAndHost[0].split(":");
        if (creds.length != 2) {
            throw new BadCredentialsException(
                    "Cannot get username and password from string " + credsAndHost[0]);
        }
        logger.debug("Got username: " + creds[0]);

        URL cliqrUrl = responseHelper.normalizeUrl(url);
        init(cliqrUrl, creds[0], creds[1]);
    } else {
        throw new BadCredentialsException(
                "You must provide credentials in your URL to be able to tuse this constructor");
    }
}

From source file:com.hp.autonomy.searchcomponents.hod.view.HodViewServerService.java

@Override
public void viewDocument(final String reference, final ResourceIdentifier index,
        final OutputStream outputStream) throws IOException, HodErrorException {
    final GetContentRequestBuilder getContentParams = new GetContentRequestBuilder().setPrint(Print.all);
    final Documents<Document> documents = getContentService.getContent(Collections.singletonList(reference),
            index, getContentParams);/*from   w w  w  . j  a v  a  2s  . com*/

    // This document will always exist because the GetContentService.getContent throws a HodErrorException if the
    // reference doesn't exist in the index
    final Document document = documents.getDocuments().get(0);

    final Map<String, Serializable> fields = document.getFields();
    final Object urlField = fields.get(URL_FIELD);

    final String documentUrl = urlField instanceof List ? ((List<?>) urlField).get(0).toString()
            : document.getReference();

    final UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_2_SLASHES);
    InputStream inputStream = null;

    try {
        try {
            final URL url = new URL(documentUrl);
            final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), null);
            final String encodedUrl = uri.toASCIIString();

            if (urlValidator.isValid(encodedUrl)) {
                inputStream = viewDocumentService.viewUrl(encodedUrl, new ViewDocumentRequestBuilder());
            } else {
                throw new URISyntaxException(encodedUrl, "Invalid URL");
            }
        } catch (URISyntaxException | MalformedURLException e) {
            // URL was not valid, fall back to using the document content
            inputStream = formatRawContent(document);
        } catch (final HodErrorException e) {
            if (e.getErrorCode() == HodErrorCode.BACKEND_REQUEST_FAILED) {
                // HOD failed to read the url, fall back to using the document content
                inputStream = formatRawContent(document);
            } else {
                throw e;
            }
        }

        IOUtils.copy(inputStream, outputStream);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}