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:us.askplatyp.kb.lucene.wikimedia.rest.WikimediaREST.java

private URL getURLForPageAction(String action, String pageIRI) throws MalformedURLException {
    URL pageURL = new URL(pageIRI);
    return UriBuilder.fromUri("https://host/api/rest_v1/page/").host(pageURL.getHost())
            .segment(action, pageURL.getPath().replaceFirst("/wiki/", "")).queryParam("redirect", "false")
            .build().toURL();/*from   w  w w  .  j a  v  a 2  s  . c o m*/
}

From source file:com.netflix.prana.http.api.HealthCheckHandler.java

private Observable<HttpClientResponse<ByteBuf>> getResponse(String externalHealthCheckURL) {
    String host = "localhost";
    int port = DEFAULT_APPLICATION_PORT;
    String path = "/healthcheck";
    try {/*from  ww w.  j  a  v a  2  s.c  o  m*/
        URL url = new URL(externalHealthCheckURL);
        host = url.getHost();
        port = url.getPort();
        path = url.getPath();
    } catch (MalformedURLException e) {
        //continue
    }
    Integer timeout = DynamicProperty.getInstance("prana.host.healthcheck.timeout")
            .getInteger(DEFAULT_CONNECTION_TIMEOUT);
    HttpClient<ByteBuf, ByteBuf> httpClient = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(host, port)
            .pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
            .channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout).build();
    return httpClient.submit(HttpClientRequest.createGet(path));

}

From source file:com.dtolabs.client.utils.BasicAuthenticator.java

public boolean authenticate(URL reqUrl, HttpClient client) throws HttpClientException {
    AuthScope scope = new AuthScope(reqUrl.getHost(), reqUrl.getPort(), REALM_NAME);
    Credentials creds = new UsernamePasswordCredentials(getUsername(), getPassword());
    client.getParams().setAuthenticationPreemptive(true);
    if (client.getState().getCredentials(scope) == null) {
        client.getState().setCredentials(scope, creds);
    }/*from  w w w  .  j  av a2s .  c o  m*/
    return true;
}

From source file:com.esri.gpt.control.webharvest.validator.WAFValidator.java

@Override
public boolean checkConnection(IMessageCollector mb) {
    if (url.toLowerCase().startsWith("ftp://")) {
        FTPClient client = null;/*from w ww  .j a va 2s.  c  om*/
        try {
            URL u = new URL(url);
            String host = u.getHost();
            int port = u.getPort() >= 0 ? u.getPort() : 21;
            client = new FTPClient();
            client.connect(host, port);
            CredentialProvider cp = getCredentialProvider();
            if (cp == null) {
                client.login("anonymous", "anonymous");
            } else {
                client.login(cp.getUsername(), cp.getPassword());
            }
            return true;
        } catch (MalformedURLException ex) {
            mb.addErrorMessage("catalog.harvest.manage.test.err.HarvestInvalidUrl");
            return false;
        } catch (IOException ex) {
            mb.addErrorMessage("catalog.harvest.manage.test.err.HarvestConnectionException");
            return false;
        } finally {
            if (client != null) {
                try {
                    client.disconnect();
                } catch (IOException ex) {
                }
            }
        }
    } else {
        return super.checkConnection(mb);
    }
}

From source file:org.jcodec.player.filters.http.HttpMedia.java

public HttpMedia(URL url, File cacheWhere) throws IOException {
    cacheWhere = new File(cacheWhere, url.getHost() + "_" + url.getPath().replace("/", "_"));

    String data = requestInfo(url, getHttpClient(url.toExternalForm()));

    MediaInfo[] mediaInfos = MediaInfoParser.parseMediaInfos(data);
    for (int i = 0; i < mediaInfos.length; i++) {
        if (mediaInfos[i] == null)
            continue;
        try {//  www.j a va  2s .  com
            HttpPacketSource ps = new HttpPacketSource(url.toExternalForm() + "/" + i,
                    new File(cacheWhere + "_" + i), mediaInfos[i]);
            tracks.add(ps);
            if (mediaInfos[i] instanceof VideoInfo)
                videoTrack = ps;
            else
                audioTracks.add(ps);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.esri.gpt.framework.http.crawl.HttpCrawlRequest.java

private String getProtocolHostPort() throws MalformedURLException {
    URL u = new URL(getUrl());
    return String.format("%s://%s%s", u.getProtocol(), u.getHost(), u.getPort() >= 0 ? ":" + u.getPort() : "");
}

From source file:de.fraunhofer.iosb.ilt.stc.auth.AuthBasic.java

@Override
public void setAuth(SensorThingsService service) {
    try {//from w  ww .j  a v a2s .  c  o  m
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        URL url = service.getEndpoint().toURL();
        credsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()),
                new UsernamePasswordCredentials(editorUsername.getValue(), editorPassword.getValue()));
        CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
                .build();
        service.setClient(httpclient);
    } catch (MalformedURLException ex) {
        LOGGER.error("Failed to initialise basic auth.", ex);
    }
}

From source file:org.xwiki.contrib.jira.macro.internal.source.HTTPJIRAFetcher.java

private HttpHost createHttpHost(JIRAServer server) throws MalformedURLException {
    URL jiraURL = new URL(server.getURL());
    return new HttpHost(jiraURL.getHost(), jiraURL.getPort(), jiraURL.getProtocol());
}

From source file:com.contentful.vaultintegration.BaseTest.java

protected String getServerUrl() {
    URL url = server.getUrl("/");
    return "http://" + url.getHost() + ":" + url.getPort();
}

From source file:io.fabric8.maven.core.handler.ProbeHandler.java

private HTTPGetAction getHTTPGetAction(String getUrl) {
    if (getUrl == null || !getUrl.subSequence(0, 4).toString().equalsIgnoreCase("http")) {
        return null;
    }/*from  w  w  w .  j a va 2 s  . c o m*/
    try {
        URL url = new URL(getUrl);
        return new HTTPGetAction(url.getHost(), null /* headers */, url.getPath(),
                new IntOrString(url.getPort()), url.getProtocol());
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Invalid URL " + getUrl + " given for HTTP GET readiness check");
    }
}