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:Main.java

public String downloadWWWPage(URL pageURL) throws Exception {
    String host, file;/* ww w.j  av a  2 s .c  o m*/
    host = pageURL.getHost();
    file = pageURL.getFile();

    InputStream pageStream = getWWWPageStream(host, file);
    if (pageStream == null) {
        return "";
    }

    DataInputStream in = new DataInputStream(pageStream);
    StringBuffer pageBuffer = new StringBuffer();
    String line;

    while ((line = in.readUTF()) != null) {
        pageBuffer.append(line);
    }
    in.close();
    return pageBuffer.toString();
}

From source file:com.constellio.app.modules.es.connectors.http.fetcher.config.BasicUrlNormalizer.java

@Override
public String normalize(String url) throws MalformedURLException, URISyntaxException {
    String trimmedUrl = StringUtils.trim(url);
    String noFragmentUrl = StringUtils.substringBefore(trimmedUrl, "#");
    if (StringUtils.isEmpty(new URL(noFragmentUrl).getFile())) {
        noFragmentUrl = noFragmentUrl + "/";
    }/*from   ww w  .j a v a  2 s . c o m*/
    URL normalizedUrl = new URL(noFragmentUrl);
    String lowerCaseHost = StringUtils.lowerCase(normalizedUrl.getHost());
    normalizedUrl = new URL(normalizedUrl.getProtocol(), lowerCaseHost, normalizedUrl.getPort(),
            normalizedUrl.getFile());
    return normalizedUrl.toURI().normalize().toString();
}

From source file:com.textuality.keybase.lib.prover.HackerNews.java

@Override
public String getPresenceLabel() throws KeybaseException {
    String answer = mProof.getServiceUrl();
    try {//from   w  w  w . jav a2s .c  om
        URL u = new URL(answer);
        answer = u.getHost() + u.getPath() + '?' + u.getQuery();
    } catch (MalformedURLException e) {
        answer = super.getPresenceLabel();
    }
    return answer;
}

From source file:com.nanocrawler.robotstxt.RobotstxtServer.java

private String getHost(URL url) {
    return url.getHost().toLowerCase();
}

From source file:com.cisco.cta.taxii.adapter.httpclient.BasicAuthHttpRequestFactory.java

public BasicAuthHttpRequestFactory(HttpClient httpClient, TaxiiServiceSettings settings,
        ProxySettings proxySettings, CredentialsProvider credsProvider) {
    super(httpClient);
    this.credsProvider = credsProvider;

    URL url = settings.getPollEndpoint();
    HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());

    // Create auth cache with BASIC scheme
    authCache = new BasicAuthCache();
    authCache.put(targetHost, new BasicScheme());
}

From source file:com.zextras.zimbradrive.statustest.ConnectionTestUtils.java

public boolean pingHost(URL url, int connectionTimeout) throws MalformedURLException {
    String host = url.getHost();
    int port = url.getPort();
    if (port == -1) {
        if (url.getProtocol().equals("https")) {
            port = 443;/*from  ww w .  ja v  a2  s. com*/
        } else {
            port = 80;
        }
    }
    try (Socket socket = new Socket()) {
        InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port);
        socket.connect(inetSocketAddress, connectionTimeout);
        return true;
    } catch (IOException e) {
        return false; // Either timeout or unreachable or failed DNS lookup.
    }
}

From source file:com.googlesource.gerrit.plugins.github.oauth.PooledHttpClientProvider.java

@Override
public HttpClient get() {
    HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnPerRoute(maxConnectionPerRoute)
            .setMaxConnTotal(maxTotalConnection);

    if (proxy.getProxyUrl() != null) {
        URL url = proxy.getProxyUrl();
        builder.setProxy(new HttpHost(url.getHost(), url.getPort()));
        if (!Strings.isNullOrEmpty(proxy.getUsername()) && !Strings.isNullOrEmpty(proxy.getPassword())) {
            UsernamePasswordCredentials creds = new UsernamePasswordCredentials(proxy.getUsername(),
                    proxy.getPassword());
            CredentialsProvider credsProvider = new BasicCredentialsProvider();
            credsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()), creds);
            builder.setDefaultCredentialsProvider(credsProvider);
            builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
        }//  w w  w. j av  a 2s .c o  m
    }

    return builder.build();
}

From source file:com.cisco.cta.taxii.adapter.httpclient.CredentialsProviderFactory.java

private void addTaxiiCredentials(CredentialsProvider credsProvider) {
    URL url = settings.getPollEndpoint();
    HttpHost targetHost = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
    credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
            new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword()));
}

From source file:org.opendatakit.briefcase.reused.http.CommonsHttp.java

@Override
public <T> Response<T> execute(Request<T> request) {
    // Always instantiate a new Executor to avoid side-effects between executions
    Executor executor = Executor.newInstance(HttpClientBuilder.create()
            .setDefaultRequestConfig(custom().setCookieSpec(STANDARD).build()).build());
    // Apply auth settings if credentials are received
    request.ifCredentials((URL url, Credentials credentials) -> executor.auth(HttpHost.create(url.getHost()),
            credentials.getUsername(), credentials.getPassword()));
    // get the response body and let the Request map it
    return uncheckedExecute(request, executor).map(request::map);
}

From source file:com.brightcove.com.zartan.verifier.video.ThumbnailVerifier.java

@ZartanCheck(value = "Thumbnail is on the http cdn")
public ResultEnum assertVideoStillCDNCorrect(UploadData upData) throws Throwable {
    URL u = getThumbnailUrl(upData);
    assertEquals("Still should be on the PD", u.getHost(), upData.getmAccount().getPdCdn().getHostName());
    return ResultEnum.PASS;
}