Example usage for java.net URI getHost

List of usage examples for java.net URI getHost

Introduction

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

Prototype

public String getHost() 

Source Link

Document

Returns the host component of this URI.

Usage

From source file:org.mulgara.scon.Connection.java

/**
 * Encodes a URI if it looks like it needs it.
 * @param u The URI to encode, if needed.
 * @return a minimally encoded URI./*  ww w.j  a  va2 s .  c  om*/
 */
private static final String enc(URI u) {
    try {
        // if there is no query, then just return the unencoded URI
        String query = u.getRawQuery();
        if (query == null)
            return u.toString();
        // encode the query, and add it to the end of the URI
        String encQuery = encode(query);
        String encU = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), encQuery,
                u.getFragment()).toString();
        // if the partial encoding works, then return it
        if (decode(encU).equals(u.toString()))
            return encU;
        // nothing else worked, so encode it fully
        return encode(u.toString());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Unable to encode a URI", e);
    }
}

From source file:com.orange.cloud.servicebroker.filter.securitygroups.domain.Destination.java

public Destination(String uriString) {
    try {//w w  w. j  a  v  a2s  .  c  o  m
        URI uri = new URI(uriString);
        setHost(uri.getHost());
        if (noPort(uri)) {
            setDefaultPort(uri.getScheme());
        } else {
            setPort(ImmutablePort.of(uri.getPort()));
        }
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Cannot create connection info. Invalid URI " + uriString, e);
    }
}

From source file:com.orange.spring.cloud.connector.s3.heroku.S3ServiceInfoCreator.java

public S3ServiceInfo createServiceInfo(S3DetectableService s3DetectableService) {
    Map<String, String> env = environment.getEnv();
    String accessKeyId = env.get(s3DetectableService.getAccessKeyIdEnvKey());
    String secretAccessKey = env.get(s3DetectableService.getSecretAccessKeyEnvKey());
    String bucketName = env.get(s3DetectableService.getBucketNameEnvKey());
    String finalUrl = this.getFinalUrl(s3DetectableService, bucketName);
    URI finalUri = URI.create(finalUrl);
    return new S3ServiceInfo(bucketName, finalUri.getScheme(), finalUri.getHost(), finalUri.getPort(),
            accessKeyId, secretAccessKey, finalUri.getPath());
}

From source file:com.github.frankfarrell.snowball.Application.java

@Bean
public RedissonClient redisson() throws URISyntaxException {
    /*//ww  w . j  a v a 2  s.  c o  m
    Three Possibilities here
    Redis Running on Local,etc
    Redis Running Embedded
    Redis Running Heroku
     */
    Config config = new Config();

    //Unfortunately this is the only way to get it to work
    if (redisHeroku) {

        URI redisURI = new URI(System.getenv("REDIS_URL"));
        config.useSingleServer().setAddress(redisURI.getHost() + ":" + redisURI.getPort())
                .setPassword(redisURI.getAuthority().split("[:@]")[1]); //Strip the username from password
    } else {
        config.useSingleServer().setAddress(redisAddress + ":" + redisPort);
    }

    return Redisson.create(config);
}

From source file:lumbermill.aws.kcl.internal.KinesisConsumerBootstrap.java

public KinesisConsumerBootstrap(KinesisClientLibConfiguration kinesisCfg, UnitOfWorkListener unitOfWorkListener,
        ExceptionStrategy exceptionStrategy, Metrics metricsCallback, boolean dry) {
    this.kinesisCfg = kinesisCfg;
    this.unitOfWorkListener = unitOfWorkListener;
    this.exceptionStrategy = exceptionStrategy;
    this.metricsCallback = metricsCallback;
    this.dry = dry;
    String httpsProxy = System.getenv("https_proxy");
    if (StringUtils.isNotEmpty(httpsProxy)) {
        URI proxy = URI.create(httpsProxy);
        kinesisCfg.getKinesisClientConfiguration().setProxyHost(proxy.getHost());
        kinesisCfg.getKinesisClientConfiguration().setProxyPort(proxy.getPort());
        kinesisCfg.getDynamoDBClientConfiguration().setProxyHost(proxy.getHost());
        kinesisCfg.getDynamoDBClientConfiguration().setProxyPort(proxy.getPort());
        kinesisCfg.getCloudWatchClientConfiguration().setProxyHost(proxy.getHost());
        kinesisCfg.getCloudWatchClientConfiguration().setProxyPort(proxy.getPort());
    }//from  w  ww  .  j ava 2  s  .  c o m
}

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  ww  w  .  ja v a  2 s  .com

    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());
    }
}

From source file:com.basho.riak.client.raw.http.HTTPClusterClient.java

/**
 * Make an {@link HttpRoute} for the given URL
 * //from   w w w.  j  av a  2 s .  c  o m
 * @param url
 * @return a {@link HttpRoute} for the given URL
 */
private HttpRoute makeRoute(String url) throws IOException {
    try {
        URI uri = new URI(url);
        HttpHost host = new HttpHost(uri.getHost(), uri.getPort());
        return new HttpRoute(host);
    } catch (URISyntaxException e) {
        throw new IOException(e.toString());
    }
}

From source file:be.agiv.security.client.ClientProxySelector.java

@Override
public List<Proxy> select(URI uri) {
    LOG.debug("select for: " + uri);
    String hostname = uri.getHost();
    Proxy proxy = this.proxies.get(hostname);
    if (null != proxy) {
        LOG.debug("using proxy: " + proxy);
        return Collections.singletonList(proxy);
    }//from  ww w  . ja va2s  .c  o m
    if (null != this.defaultProxySelector) {
        return this.defaultProxySelector.select(uri);
    }
    return Collections.singletonList(Proxy.NO_PROXY);
}

From source file:com.amazonaws.services.s3.internal.S3V4AuthErrorRetryStrategy.java

private AuthRetryParameters buildRetryParams(AWSS3V4Signer signer, URI endpoint) {
    log.warn("Attempting to re-send the request to " + endpoint.getHost() + " with AWS V4 authentication. "
            + "To avoid this warning in the future, " + V4_REGION_WARNING);
    return new AuthRetryParameters(signer, endpoint);
}

From source file:net.netheos.pcsapi.oauth.PasswordSessionManager.java

@Override
public CResponse execute(HttpUriRequest request) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("{}: {}", request.getMethod(), PcsUtils.shortenUrl(request.getURI()));
    }//from w w  w.j a v a 2s .  co  m

    try {
        URI uri = request.getURI();
        HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
        HttpContext context = getHttpContext(host);

        HttpResponse httpResponse = httpClient.execute(host, request, context);
        return new CResponse(request, httpResponse);

    } catch (IOException ex) {
        // a low level error should be retried :
        throw new CRetriableException(ex);
    }
}