Example usage for java.net URI getPort

List of usage examples for java.net URI getPort

Introduction

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

Prototype

public int getPort() 

Source Link

Document

Returns the port number of this URI.

Usage

From source file:com.microsoft.azure.keyvault.authentication.KeyVaultCredentials.java

private static String getAuthority(URI uri) {
    String scheme = uri.getScheme();
    String host = uri.getHost();/*from   w ww  . j  av  a  2s.c  om*/
    int port = uri.getPort();
    StringBuilder builder = new StringBuilder();
    if (scheme != null) {
        builder.append(scheme).append("://");
    }
    builder.append(host);
    if (port >= 0) {
        builder.append(':').append(port);
    }
    return builder.toString();
}

From source file:oracle.custom.ui.utils.ServerUtils.java

public static PublicKey getServerPublicKey(String domainName) throws Exception {
    HttpClient client = getClient(domainName);
    PublicKey key = null;/* w w w  . j av  a2  s . c o m*/
    String url = getIDCSBaseURL(domainName) + "/admin/v1/SigningCert/jwk";
    URI uri = new URI(url);
    HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    HttpGet httpGet = new HttpGet(uri);
    httpGet.addHeader("Authorization", "Bearer " + AccessTokenUtils.getAccessToken(domainName));
    HttpResponse response = client.execute(host, httpGet);
    try {
        HttpEntity entity2 = response.getEntity();
        String res = EntityUtils.toString(entity2);
        EntityUtils.consume(entity2);
        ObjectMapper mapper = new ObjectMapper();
        System.out.println("result is " + res);
        SigningKeys signingKey = mapper.readValue(res, SigningKeys.class);

        String base64Cert = signingKey.getKeys().get(0).getX5c().get(0);
        byte encodedCert[] = Base64.getDecoder().decode(base64Cert);
        ByteArrayInputStream inputStream = new ByteArrayInputStream(encodedCert);

        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) certFactory.generateCertificate(inputStream);
        key = cert.getPublicKey();
    } finally {
        if (response instanceof CloseableHttpResponse) {
            ((CloseableHttpResponse) response).close();
        }
    }
    return key;
}

From source file:com.ibm.watson.retrieveandrank.app.rest.UtilityFunctions.java

public static HttpClientBuilder createHTTPBuilder(URI uri, String username, String password) {
    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
            new UsernamePasswordCredentials(username, password));

    final HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnTotal(128).setMaxConnPerRoute(32)
            .setDefaultRequestConfig(//from w  w w.ja v a2 s  .  c  o m
                    RequestConfig.copy(RequestConfig.DEFAULT).setRedirectsEnabled(true).build());
    builder.setDefaultCredentialsProvider(credentialsProvider);
    builder.addInterceptorFirst(new PreemptiveAuthInterceptor());
    return builder;
}

From source file:nl.esciencecenter.octopus.webservice.mac.MacScheme.java

/**
 *
 * @param uri//from   w w w  .  j a v  a 2 s . c o  m
 * @return Port of `uri` based on explicit port or derived from scheme
 */
public static int getPort(URI uri) {
    int port = uri.getPort();
    if (port == -1) {
        String scheme = uri.getScheme();
        if (scheme.equals("http")) {
            port = 80;
        } else if (scheme.equals("https")) {
            port = 443;
        }
    }
    return port;
}

From source file:URIUtil.java

/**
 * Get the parent URI of the supplied URI
 * @param uri The input URI for which the parent URI is being requrested.
 * @return The parent URI.  Returns a URI instance equivalent to "../" if
 * the supplied URI path has no parent.//from   w w  w . j a v a2  s .co  m
 * @throws URISyntaxException Failed to reconstruct the parent URI.
 */
public static URI getParent(URI uri) throws URISyntaxException {

    String parentPath = new File(uri.getPath()).getParent();

    if (parentPath == null) {
        return new URI("../");
    }

    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
            parentPath.replace('\\', '/'), uri.getQuery(), uri.getFragment());
}

From source file:nl.esciencecenter.osmium.mac.MacScheme.java

/**
 * @param uri Uri from which to extract port
 * @return Port of `uri` based on explicit port or derived from scheme
 *//*from  w  w  w  .j a  v  a  2 s  .  c om*/
public static int getPort(URI uri) {
    int port = uri.getPort();
    if (port == -1) {
        String scheme = uri.getScheme();
        if (scheme.equals("http")) {
            port = HTTP_PORT;
        } else if (scheme.equals("https")) {
            port = HTTPS_PORT;
        }
    }
    return port;
}

From source file:com.qwazr.cluster.manager.ClusterNode.java

private static URI toUri(String address) throws URISyntaxException {
    if (!address.contains("//"))
        address = "//" + address;
    URI u = new URI(address);
    return new URI(StringUtils.isEmpty(u.getScheme()) ? "http" : u.getScheme(), null, u.getHost(), u.getPort(),
            null, null, null);//from   ww  w.ja  v a  2  s  .  c  o  m
}

From source file:org.projecthdata.social.api.connect.HDataServiceProvider.java

private static StringBuilder getBaseUrl(String ehrUrl) {
    URI uri = URIBuilder.fromUri(ehrUrl).build();
    StringBuilder builder = new StringBuilder();
    builder.append(uri.getScheme()).append("://");
    builder.append(uri.getHost());/*from  w  w w .j  av a 2 s  . c o  m*/
    if (uri.getPort() >= 0) {
        builder.append(":").append(uri.getPort());
    }
    if (uri.getPath() != null) {
        StringTokenizer tokenizer = new StringTokenizer(uri.getPath(), "/");
        // if there is more than one path element, then the first one should
        // be the webapp name
        if (tokenizer.countTokens() > 1) {
            builder.append("/").append(tokenizer.nextToken());
        }
    }
    return builder;
}

From source file:de.shadowhunt.subversion.internal.URIUtils.java

private static URI createURI0(final URI repository, final Resource... resources) throws URISyntaxException {
    final URIBuilder builder = new URIBuilder();
    builder.setScheme(repository.getScheme());
    builder.setHost(repository.getHost());
    builder.setPort(repository.getPort());
    final StringBuilder completePath = new StringBuilder(repository.getPath());
    for (final Resource resource : resources) {
        completePath.append(resource.getValue());
    }//w w  w.  j  a v  a 2s . c o  m
    builder.setPath(completePath.toString());
    return builder.build();
}

From source file:com.netflix.spinnaker.orca.config.RedisConfiguration.java

@Deprecated // rz - Kept for backwards compat with old connection configs
public static JedisPool createPool(GenericObjectPoolConfig redisPoolConfig, String connection, int timeout,
        Registry registry, String poolName) {
    URI redisConnection = URI.create(connection);

    String host = redisConnection.getHost();
    int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort();

    String redisConnectionPath = isNotEmpty(redisConnection.getPath()) ? redisConnection.getPath()
            : "/" + DEFAULT_DATABASE;
    int database = Integer.parseInt(redisConnectionPath.split("/", 2)[1]);

    String password = redisConnection.getUserInfo() != null ? redisConnection.getUserInfo().split(":", 2)[1]
            : null;/*from w  w  w  .j a  v  a 2s. c  o m*/

    JedisPool jedisPool = new JedisPool(
            redisPoolConfig != null ? redisPoolConfig : new GenericObjectPoolConfig(), host, port, timeout,
            password, database, null);
    final Field poolAccess;
    try {
        poolAccess = Pool.class.getDeclaredField("internalPool");
        poolAccess.setAccessible(true);
        GenericObjectPool<Jedis> pool = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool);
        registry.gauge(registry.createId("redis.connectionPool.maxIdle", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.minIdle", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMinIdle()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.numActive", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getNumActive()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.numIdle", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue());
        registry.gauge(registry.createId("redis.connectionPool.numWaiters", "poolName", poolName), pool,
                (GenericObjectPool<Jedis> p) -> Integer.valueOf(p.getMaxIdle()).doubleValue());
        return jedisPool;
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new BeanCreationException("Error creating Redis pool", e);
    }
}