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:com.thinkbiganalytics.nifi.rest.config.SpringNifiRestConfiguration.java

/**
 * Gets the configuration for the NiFi REST client.
 *
 * <p>Looks for {@code thinkbig.nifi.rest} properties first then for {@code nifi.rest} properties.</p>
 *
 * @return the NiFi REST client configuration
 *///from w  ww . j  ava2  s . c o  m
@Bean(name = "nifiRestClientConfig")
@ConfigurationProperties(prefix = "nifi.rest")
public NifiRestClientConfig nifiRestClientConfig() {
    final NifiRestClientConfig config = new NifiRestClientConfig();
    config.setUsername(env.getProperty("thinkbig.nifi.rest.username"));
    config.setPassword(env.getProperty("thinkbig.nifi.rest.password"));
    config.setHttps(BooleanUtils.toBoolean(env.getProperty("thinkbig.nifi.rest.https")));
    config.setUseConnectionPooling(
            BooleanUtils.toBoolean(env.getProperty("thinkbig.nifi.rest.useConnectionPooling")));
    config.setTruststorePath(env.getProperty("thinkbig.nifi.rest.truststorePath"));
    config.setTruststorePassword(env.getProperty("thinkbig.nifi.rest.truststorePassword"));
    config.setKeystorePassword(env.getProperty("thinkbig.nifi.rest.keystorePassword"));
    config.setKeystorePath(env.getProperty("thinkbig.nifi.rest.keystorePath"));
    config.setTrustStoreType(env.getProperty("thinkbig.nifi.rest.truststoreType"));
    config.setKeystoreType(env.getProperty("thinkbig.nifi.rest.keystoreType"));
    final String host = env.getProperty("thinkbig.nifi.rest.host");
    if (host != null) {
        try {
            final URL url = new URL(host);
            config.setHost(url.getHost());
            config.setPort((url.getPort() > -1) ? url.getPort() : 8079);
        } catch (final MalformedURLException e) {
            throw new IllegalArgumentException("Invalid thinkbig.nifi.rest.host: " + host, e);
        }
    }

    return config;
}

From source file:com.ewcms.plugin.crawler.generate.robotstxt.RobotstxtServer.java

public boolean allows(WebURL webURL) {
    if (!config.isEnabled()) {
        return true;
    }/*from  ww w. j  a v a 2 s .c  o  m*/
    try {
        URL url = new URL(webURL.getURL());
        String host = url.getHost().toLowerCase();
        String path = url.getPath();

        HostDirectives directives = host2directivesCache.get(host);

        if (directives != null && directives.needsRefetch()) {
            synchronized (host2directivesCache) {
                host2directivesCache.remove(host);
                directives = null;
            }
        }

        if (directives == null) {
            directives = fetchDirectives(host);
        }
        return directives.allows(path);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return true;
}

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

private void addProxyCredentials(CredentialsProvider credsProvider) {
    if (proxySettings.getUrl() == null) {
        return;//ww w  .  ja va 2  s .  c o m
    }
    if (proxySettings.getAuthenticationType() == null) {
        throw new IllegalStateException("Both proxy url and proxy authentication type have to be specified.");
    }

    ProxyAuthenticationType authType = proxySettings.getAuthenticationType();

    URL proxyUrl = proxySettings.getUrl();
    HttpHost proxyHost = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol());

    Credentials credentials;
    switch (authType) {
    case NONE:
        break;

    case BASIC:
        credentials = new UsernamePasswordCredentials(proxySettings.getUsername(), proxySettings.getPassword());
        credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials);
        break;

    case NTLM:
        credentials = new NTCredentials(proxySettings.getUsername(), proxySettings.getPassword(),
                proxySettings.getWorkstation(), proxySettings.getDomain());
        credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials);
        break;

    default:
        throw new IllegalStateException("Unsupported authentication type: " + authType);
    }
}

From source file:com.ge.predix.sample.blobstore.config.LocalConfig.java

@Bean
public BlobstoreService objectStoreService() {
    log.info("objectStoreService(): " + objectStoreProperties.getAccessKey()
            + objectStoreProperties.getSecretKey() + ", " + objectStoreProperties.getBucket());

    AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(objectStoreProperties.getAccessKey(),
            objectStoreProperties.getSecretKey()));
    s3Client.setEndpoint(objectStoreProperties.getUrl());

    try {//w w  w .ja  va 2  s.  c  o m
        // Remove the Credentials from the Object Store URL
        URL url = new URL(objectStoreProperties.getUrl());
        String urlWithoutCredentials = url.getProtocol() + "://" + url.getHost();

        // Return BlobstoreService
        return new BlobstoreService(s3Client, objectStoreProperties.getBucket(), urlWithoutCredentials);
    } catch (MalformedURLException e) {
        log.error("create(): Couldnt parse the URL provided by VCAP_SERVICES. Exception = " + e.getMessage());
        throw new RuntimeException("Blobstore URL is Invalid", e);
    }
}

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

private TCPSocketAction getTCPSocketAction(String getUrl, String port) {
    if (port != null) {
        IntOrString portObj = new IntOrString(port);
        try {//from w  w w. j a va  2  s . c  om
            Integer portInt = Integer.parseInt(port);
            portObj.setIntVal(portInt);
        } catch (NumberFormatException e) {
            portObj.setStrVal(port);
        }
        if (getUrl == null)
            return new TCPSocketAction(getUrl, portObj);
        String validurl = getUrl.replaceFirst("(([a-zA-Z])+)://", "http://");
        try {
            URL url = new URL(validurl);
            return new TCPSocketAction(url.getHost(), portObj);
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Invalid URL " + getUrl + " given for TCP readiness check");
        }
    }
    return null;
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SamlConfig.java

public SamlConfig(Security security) {
    if (!security.getAuthn().getSaml().isEnabled()) {
        return;/* w  w w  . jav a 2s .c  om*/
    }

    Saml saml = security.getAuthn().getSaml();

    this.enabled = saml.isEnabled();
    this.issuerId = saml.getIssuerId();
    this.metadataUrl = "file:" + saml.getMetadataLocal();
    if (StringUtils.isNotEmpty(saml.getMetadataRemote())) {
        this.metadataUrl = saml.getMetadataRemote();
    }

    this.keyStore = "file:" + saml.getKeyStore();
    this.keyStoreAliasName = saml.getKeyStoreAliasName();
    this.keyStorePassword = saml.getKeyStorePassword();

    URL u = saml.getServiceAddress();
    this.redirectProtocol = u.getProtocol();
    this.redirectHostname = u.getHost();
    if (u.getPort() != -1) {
        this.redirectHostname += ":" + u.getPort();
    }
    if (StringUtils.isNotEmpty(u.getPath())) {
        this.redirectBasePath = u.getPath();
    }
}

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

@Inject
PooledHttpClientProvider(@GerritServerConfig Config config, ProxyProperties proxyProperties) {
    this.proxy = proxyProperties;
    URL proxyUrl = proxyProperties.getProxyUrl();
    if (proxyUrl != null) {
        setProxyProperty("proxyHost", proxyUrl.getHost());
        setProxyProperty("proxyPort", "" + proxyUrl.getPort());
        setProxyProperty("proxyUser", proxyProperties.getUsername());
        setProxyProperty("proxyPassword", proxyProperties.getPassword());
    }//w w  w  .j av  a 2  s.c om

    maxConnectionPerRoute = config.getInt("http", null, "pooledMaxConnectionsPerRoute", 16);
    maxTotalConnection = config.getInt("http", null, "pooledMaxTotalConnections", 32);
}

From source file:ai.baby.util.Parameter.java

public String toURL() {
    try {//w w w  .  j a  va  2 s .  c  o  m
        final URL url = new URL(parameterString.getObjectAsValid());
        final URI returnVal = new URI(url.getProtocol(), null, url.getHost(), 80, url.getPath(), url.getQuery(),
                null);
        return returnVal.toString();
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

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

@Override
public boolean fetchProofData() {

    try {/*w  ww.java2 s . c  o  m*/
        JSONObject sigJSON = readSig(mProof.getSigId());

        String proofUrl = mProof.getProofUrl();

        // fetch the post
        Fetch fetch = new Fetch(proofUrl);
        String problem = fetch.problem();
        if (problem != null) {
            mLog.add(problem);
            return false;
        }

        // Paranoid Interlude:
        // Lets make sure the URL is of the form https://coinbase.com/<nametag>/public-key
        //  and the actual host after redirects is coinbase
        //
        URL url = new URL(proofUrl);
        if (!(url.getProtocol().equals("https") && url.getHost().equals("coinbase.com")
                && url.getPath().equals("/" + mProof.getHandle() + "/public-key"))) {
            mLog.add("Bogus Coinbase proof URL: " + proofUrl);
            return false;
        }
        url = new URL(fetch.getActualUrl());
        if (!url.getHost().equals("coinbase.com")) {
            mLog.add("Coinbase proof doesnt come from coinbase.com: " + fetch.getActualUrl());
            return false;
        }

        // verify that message appears in body, which coinbase messes up with \rs
        String body = fetch.getBody().replace("\r", "");
        if (!body.contains(mPgpMessage)) {
            mLog.add("Coinbase proof doesnt contain signed PGP message");
            return false;
        }

        return true;

    } catch (KeybaseException e) {
        mLog.add("Keybase API problem: " + e.getLocalizedMessage());
    } catch (JSONException e) {
        mLog.add("Broken JSON message: " + e.getLocalizedMessage());
    } catch (MalformedURLException e) {
        mLog.add("Malformed Coinbase proof URL");
    }
    return false;
}

From source file:io.kamax.mxisd.dns.ClientDnsOverwrite.java

public URIBuilder transform(URI initial) {
    URIBuilder builder = new URIBuilder(initial);
    Entry mapping = mappings.get(initial.getHost());
    if (mapping == null) {
        throw new InternalServerError("No DNS client override for " + initial.getHost());
    }/*from w  ww  .j  a  va2  s.c  o m*/

    try {
        URL target = new URL(mapping.getValue());
        builder.setScheme(target.getProtocol());
        builder.setHost(target.getHost());
        if (target.getPort() != -1) {
            builder.setPort(target.getPort());
        }

        return builder;
    } catch (MalformedURLException e) {
        log.warn("Skipping DNS overwrite entry {} due to invalid value [{}]: {}", mapping.getName(),
                mapping.getValue(), e.getMessage());
        throw new ConfigurationException(
                "Invalid DNS overwrite entry in homeserver client: " + mapping.getName(), e.getMessage());
    }
}