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.wso2.carbon.http2.transport.util.Http2ConnectionFactory.java

/**
 * Generate hash-key for each clientHandler using uri
 *
 * @param uri/*from w  w w . ja  v a  2 s  . c  om*/
 * @return
 */
private String generateKey(URI uri) {
    String host = uri.getHost();
    int port = uri.getPort();
    String ssl;
    if (uri.getScheme().equalsIgnoreCase(Http2Constants.HTTPS2) || uri.getScheme().equalsIgnoreCase("https")) {
        ssl = "https://";
    } else
        ssl = "http://";
    return ssl + host + ":" + port;
}

From source file:io.wcm.caravan.commons.httpasyncclient.impl.HttpAsyncClientFactoryImpl.java

private HttpAsyncClientItem getFactoryItem(URI targetUrl, String wsAddressingToUri) {
    for (HttpAsyncClientItem item : factoryItems.values()) {
        if (item.matches(targetUrl.getHost(), wsAddressingToUri)) {
            return item;
        }/*w  w w . j  ava2  s  . co m*/
    }
    return defaultFactoryItem;
}

From source file:com.nesscomputing.cache.CacheTopologyProvider.java

@Inject
CacheTopologyProvider(final CacheConfiguration config, final ReadOnlyDiscoveryClient discoveryClient,
        @Named("cacheName") String cacheName) {
    this.discoveryClient = discoveryClient;
    this.cacheName = cacheName;

    List<URI> uris = config.getCacheUri();
    if (uris != null) {
        ImmutableList.Builder<InetSocketAddress> addrBuilder = ImmutableList.builder();
        for (URI uri : uris) {
            if ("memcache".equals(uri.getScheme())) {
                addrBuilder.add(new InetSocketAddress(uri.getHost(), uri.getPort()));
            } else {
                LOG.warn("Ignored uri %s due to wrong scheme", uri);
            }/*from  w  ww .j  a  v  a2 s .  c o  m*/
        }
        addrs = addrBuilder.build();
        LOG.info("Using configured caches: %s", addrs);
    } else {
        addrs = null;
        LOG.info("Using dynamically discovered caches.");
    }
}

From source file:bibibi.configs.ProductionProfile.java

@Bean
public BasicDataSource dataSource() throws URISyntaxException {
    URI dbUri = new URI(System.getenv("DATABASE_URL"));

    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);//www . j ava 2 s  . c  o  m
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);

    return basicDataSource;
}

From source file:com.adobe.acs.commons.replication.impl.AgentHostsImpl.java

@Override
public final List<String> getHosts(final AgentFilter agentFilter) {
    final List<String> hosts = new ArrayList<String>();
    final Map<String, Agent> agents = agentManager.getAgents();

    for (final Agent agent : agents.values()) {
        if (!agentFilter.isIncluded(agent)) {
            continue;
        }//from  w  w w. j a v  a  2 s .com

        try {
            final URI uri = new URI(agent.getConfiguration().getTransportURI());

            String tmp = StringUtils.defaultIfEmpty(uri.getScheme(), DEFAULT_SCHEME) + "://" + uri.getHost();
            if (uri.getPort() > 0) {
                tmp += ":" + uri.getPort();
            }

            hosts.add(tmp);
        } catch (URISyntaxException e) {
            log.error("Unable to extract a scheme/host/port from Agent transport URI [ {} ]",
                    agent.getConfiguration().getTransportURI());
        }
    }

    return hosts;
}

From source file:com.esri.geoportal.harvester.folder.FolderBroker.java

private File generateFileName(URI brokerUri, URI sourceUri, String id) {
    URI ssp = URI.create(brokerUri.getSchemeSpecificPart());
    String root = StringUtils.defaultIfEmpty(ssp.getHost(), ssp.getPath());
    File rootFolder = definition.getRootFolder().toPath().resolve(root).toFile();

    File fileName = rootFolder;/* w  w w  . j  av a2  s  . c om*/
    if (sourceUri.getPath() != null) {
        List<String> subFolder = splitPath(sourceUri.getPath().replaceAll("/[a-zA-Z]:/|/$", ""));
        if (!subFolder.isEmpty() && subFolder.get(0).equals(root)) {
            subFolder.remove(0);
        }
        for (String sf : subFolder) {
            fileName = new File(fileName, sf);
        }
        if (!fileName.getName().contains(".")) {
            fileName = fileName.getParentFile().toPath().resolve(fileName.getName() + ".xml").toFile();
        }
    } else {
        fileName = new File(fileName, id + ".xml");
    }

    return fileName;
}

From source file:io.druid.storage.oss.OssDataSegmentPuller.java

private String getBucket(URI uri) {
    return uri.getHost();
}

From source file:org.fishwife.jrugged.httpclient.PerHostServiceWrappedHttpClient.java

private HttpHost getCanonicalHost(HttpHost host) {
    URI uri;
    try {//from   ww w  . ja  v a  2  s .com
        uri = new URI(host.toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    String hostname = uri.getHost();
    int port = uri.getPort();
    String scheme = uri.getScheme();
    boolean isHttps = "HTTPS".equalsIgnoreCase(scheme);
    String schemePart = isHttps ? (scheme + "://") : "";
    if (port == -1) {
        port = isHttps ? 443 : 80;
    }
    return new HttpHost(schemePart + hostname + ":" + port);
}

From source file:com.collective.celos.ci.deploy.WorkflowFilesDeployer.java

URI getTargetJsFileUri(URI uri) throws URISyntaxException {
    String path = uri.getPath() + File.separator + config.getWorkflowName() + ".js";
    return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(),
            uri.getFragment());//from  w ww . jav  a  2  s. c  o  m
}

From source file:com.mirth.connect.connectors.file.FileConnectorServlet.java

protected ConnectionTestResponse testReadOrWrite(String channelId, String channelName, String host,
        String username, String password, SchemeProperties schemeProperties, FileScheme scheme,
        String timeoutString, boolean secure, boolean passive, boolean read) {
    try {//from w w w  . j a  v  a  2  s  .c o  m
        host = replacer.replaceValues(host, channelId, channelName);
        username = replacer.replaceValues(username, channelId, channelName);
        password = replacer.replaceValues(password, channelId, channelName);

        SftpSchemeProperties sftpProperties = null;
        if (schemeProperties instanceof SftpSchemeProperties) {
            sftpProperties = (SftpSchemeProperties) schemeProperties;

            sftpProperties
                    .setKeyFile(replacer.replaceValues(sftpProperties.getKeyFile(), channelId, channelName));
            sftpProperties.setPassPhrase(
                    replacer.replaceValues(sftpProperties.getPassPhrase(), channelId, channelName));
            sftpProperties.setKnownHostsFile(
                    replacer.replaceValues(sftpProperties.getKnownHostsFile(), channelId, channelName));
            sftpProperties.setConfigurationSettings(
                    replacer.replaceValues(sftpProperties.getConfigurationSettings(), channelId, channelName));
        }

        int timeout = Integer.parseInt(timeoutString);

        URI address = FileConnector.getEndpointURI(host, scheme, secure);
        String addressHost = address.getHost();
        int port = address.getPort();
        String dir = address.getPath();

        String hostDisplayName = "";
        if (!scheme.equals(FileScheme.FILE)) {
            hostDisplayName = scheme.getDisplayName() + "://" + address.getHost();
        }
        hostDisplayName += dir;

        FileSystemConnectionFactory factory = new FileSystemConnectionFactory(scheme,
                new FileSystemConnectionOptions(username, password, sftpProperties), addressHost, port, passive,
                secure, timeout);

        FileSystemConnection connection = null;

        try {
            connection = ((PooledObject<FileSystemConnection>) factory.makeObject()).getObject();

            if (read && connection.canRead(dir) || !read && connection.canWrite(dir)) {
                return new ConnectionTestResponse(ConnectionTestResponse.Type.SUCCESS,
                        "Successfully connected to: " + hostDisplayName);
            } else {
                return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE,
                        "Unable to connect to: " + hostDisplayName);
            }
        } catch (Exception e) {
            return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE,
                    "Unable to connect to: " + hostDisplayName + ", Reason: " + e.getMessage());
        } finally {
            if (connection != null) {
                connection.destroy();
            }
        }
    } catch (Exception e) {
        throw new MirthApiException(e);
    }
}