Example usage for java.net URL getHost

List of usage examples for java.net URL getHost

Introduction

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

Prototype

public String getHost() 

Source Link

Document

Gets the host name of this URL , if applicable.

Usage

From source file:jhc.redsniff.webdriver.download.FileDownloader.java

private HttpClient createHttpClient(URL downloadURL) {
    HttpClient client = new HttpClient();
    client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
    client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort()));
    client.setState(mimicCookieState(driver.manage().getCookies()));
    return client;
}

From source file:v7cr.V7CR.java

Link getFile(BSONBackedObject file) {
    String fn = file.getStringField("filename");
    String sha = file.getStringField("sha");
    if (fn == null || sha == null)
        return null;

    URL url = getURL();
    return new Link(fn, new ExternalResource(
            url.getProtocol() + "://" + url.getHost() + ":8088/upload/v7cr?filename=" + fn + "&sha=" + sha));
}

From source file:com.predic8.membrane.core.interceptor.rewrite.ReverseProxyingInterceptor.java

private boolean isSameSchemeHostAndPort(String location2, String location) throws MalformedURLException {
    try {/*  w  w w.  j  av a2 s. c om*/
        if (location.startsWith("/") || location2.startsWith("/"))
            return false; // no host info available
        URL loc2 = new URL(location2);
        URL loc1 = new URL(location);
        if (loc2.getProtocol() != null && !loc2.getProtocol().equals(loc1.getProtocol()))
            return false;
        if (loc2.getHost() != null && !loc2.getHost().equals(loc1.getHost()))
            return false;
        int loc2Port = loc2.getPort() == -1 ? loc2.getDefaultPort() : loc2.getPort();
        int loc1Port = loc1.getPort() == -1 ? loc1.getDefaultPort() : loc1.getPort();
        if (loc2Port != loc1Port)
            return false;
        return true;
    } catch (MalformedURLException e) {
        log.warn("", e); // TODO: fix these cases
        return false;
    }
}

From source file:com.trunghoang.teammedical.utils.FileDownloader.java

public File urlDownloader(String downloadLocation) throws Exception {
    URL downloadURL = new URL(downloadLocation);
    HttpClient client = new HttpClient();
    client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
    client.setHostConfiguration(mimicHostConfiguration(downloadURL.getHost(), downloadURL.getPort()));
    client.getParams().makeLenient();//from   w  w w  .ja v  a2 s.  c o m
    client.setState(mimicCookieState(driver.manage().getCookies()));
    HttpMethod getRequest = new GetMethod(downloadLocation);
    getRequest.setFollowRedirects(true);
    FileHandler downloadedFile = new FileHandler(
            downloadPath + downloadURL.getFile().replaceFirst("/|\\\\", ""), true);
    try {
        int status = client.executeMethod(getRequest);
        log.info("HTTP Status {} when getting '{}'", status, downloadURL.toExternalForm());
        downloadedFile.getWritableFileOutputStream().write(getRequest.getResponseBody());
        downloadedFile.close();
        log.info("File downloaded to '{}'", downloadedFile.getAbsoluteFile());
    } catch (Exception Ex) {
        log.error("Download failed: {}", Ex);
        throw new Exception("Download failed!");
    } finally {
        getRequest.releaseConnection();
    }
    return downloadedFile.getFile();
}

From source file:org.dataconservancy.access.connector.MultiThreadedConnectorTest.java

@Override
protected DcsConnectorConfig getConnectorConfig() {
    final DcsConnectorConfig config = new DcsConnectorConfig();
    try {/*from   w  ww  .j a v  a 2  s . c o  m*/
        URL u = new URL(
                String.format(accessServiceUrl, testServer.getServiceHostName(), testServer.getServicePort()));
        config.setScheme(u.getProtocol());
        config.setHost(u.getHost());
        config.setPort(u.getPort());
        config.setContextPath(u.getPath());
    } catch (MalformedURLException e) {
        fail("Malformed DCS access http url: " + e.getMessage());
    }
    config.setMaxOpenConn(2);
    return config;
}

From source file:com.seajas.search.profiler.authentication.strategy.codex.CodexAuthenticationStrategy.java

/**
 * Determine the provider from the URL and mappings.
 * /*from w  w  w .j  a v a2 s.co  m*/
 * @param url
 * @return String
 */
private String urlToProviderId(final URL url) {
    // Prefer matching against the hostname

    for (Entry<String, String> urlToProviderMapping : urlToProviderMappings.entrySet())
        if (url.getHost().matches(urlToProviderMapping.getValue().replace(".", "\\.").replace("*", ".*")))
            return urlToProviderMapping.getKey();

    // Then the whole URL

    for (Entry<String, String> urlToProviderMapping : urlToProviderMappings.entrySet())
        if (url.toString().matches(urlToProviderMapping.getValue().replace(".", "\\.").replace("*", ".*")))
            return urlToProviderMapping.getKey();

    return null;
}

From source file:com.grendelscan.commons.http.CookieJar.java

public List<Cookie> getMatchingCookies(final URL url) {
    int port = url.getPort();
    if (port < 0) {
        port = url.getDefaultPort();/*www . j a  va2  s  . c o  m*/
    }
    CookieOrigin origin = new CookieOrigin(url.getHost(), port, url.getPath(),
            url.getProtocol().equalsIgnoreCase("https"));
    return getMatchingCookies(origin);
}

From source file:com.oakesville.mythling.util.MediaStreamProxy.java

private HttpResponse download() throws IOException {

    httpClient = AndroidHttpClient.newInstance("Android");
    // httpClient.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost("127.0.0.1"));

    URL netUrl = proxyInfo.netUrl;
    HttpHost host = new HttpHost(netUrl.getHost(), netUrl.getPort(), netUrl.getProtocol());

    HttpRequestBase request = new HttpGet(netUrl.toString());
    HttpResponse response = null;//w  ww .  j  a  v  a2  s. c o m
    Log.d(TAG, "Proxy starting download");
    if (authType == AuthType.Digest) {
        HttpContext context = HttpHelper.getDigestAuthContext(netUrl.getHost(), netUrl.getPort(),
                proxyInfo.user, proxyInfo.password);
        response = httpClient.execute(host, request, context);
    } else if (authType == AuthType.Basic) {
        String credentials = Base64.encodeToString((proxyInfo.user + ":" + proxyInfo.password).getBytes(),
                Base64.DEFAULT);
        request.setHeader("Authorization", "Basic " + credentials);
        response = httpClient.execute(host, request);
    } else {
        response = httpClient.execute(host, request);
    }
    Log.d(TAG, "Proxy response downloaded");
    return response;
}

From source file:com.hp.application.automation.tools.octane.client.JenkinsMqmRestClientFactoryImpl.java

private MqmRestClient create(String location, String sharedSpace, String username, Secret password) {
    MqmConnectionConfig clientConfig = new MqmConnectionConfig(location, sharedSpace, username,
            password.getPlainText(), CLIENT_TYPE);
    URL locationUrl;
    try {//from   w ww . j  a v  a 2  s  .  c  om
        locationUrl = new URL(clientConfig.getLocation());
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
    if (isProxyNeeded(locationUrl.getHost())) {
        clientConfig.setProxyHost(getProxyHost());
        clientConfig.setProxyPort(getProxyPort());
        final String proxyUsername = getUsername();
        if (!StringUtils.isEmpty(proxyUsername)) {
            clientConfig.setProxyCredentials(new UsernamePasswordProxyCredentials(username, getPassword()));
        }
    }
    return new MqmRestClientImpl(clientConfig);
}