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:com.openshift.internal.client.ApplicationSSHSessionIntegrationTest.java

private Session createSSHSession(String sshUrl) throws JSchException, URISyntaxException {
    JSch.setConfig("StrictHostKeyChecking", "no");
    JSch jsch = new JSch();
    jsch.addIdentity(SSHKeyTestUtils.SSH_TEST_PRIVATEKEY, SSHKeyTestUtils.DEFAULT_PASSPHRASE);
    URI sshUri = new URI(sshUrl);
    Session session = jsch.getSession(sshUri.getUserInfo(), sshUri.getHost());
    session.connect();//from  w ww .j  ava 2s  . c  o  m
    return session;
}

From source file:com.orange.clara.cloud.servicedbdumper.helper.UrlForge.java

public String createDownloadLink(DatabaseDumpFile databaseDumpFile) {
    URI appInUri = URI.create(appUri);
    String port = this.getPortInString();
    return appInUri.getScheme() + "://" + databaseDumpFile.getUser() + ":" + databaseDumpFile.getPassword()
            + "@" + appInUri.getHost() + port + DOWNLOAD_ROUTE + "/" + databaseDumpFile.getId();
}

From source file:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java

private URI base(final URI uri) {
    try {//from   w w w .j  a va  2s  .  c  o  m
        URIBuilder uriBuilder = new URIBuilder();
        uriBuilder.setScheme(uri.getScheme());
        uriBuilder.setHost(uri.getHost());
        uriBuilder.setPort(uri.getPort());
        uriBuilder.setPath(uri.getPath());

        if (uri.getUserInfo() != null) {
            uriBuilder.setUserInfo(uri.getUserInfo());
        }
        return uriBuilder.build();
    } catch (final URISyntaxException ignored) {
        // This should never happen since we are using a valid URI to construct ours.
        return null;
    }
}

From source file:de.fhg.igd.mapviewer.cache.FileTileCache.java

/**
 * Get the local cache file name for the given URI
 * /*from w  w w  . j av  a  2s  .c o m*/
 * @param tile the tile info
 * 
 * @return the local file or <code>null</code>
 */
protected File getLocalFile(TileInfo tile) {
    URI uri = tile.getIdentifier();
    File dir = new File(cacheDir, uri.getHost());
    dir = new File(dir, "level-" + tile.getZoom()); //$NON-NLS-1$
    try {
        String mapKey = computeHash(uri.toString());
        return new File(dir, tile.getX() + "_" + tile.getY() + "_" + mapKey); //$NON-NLS-1$ //$NON-NLS-2$
    } catch (Throwable e) {
        log.error("Error determinating local file name for caching", e); //$NON-NLS-1$
        return null;
    }
}

From source file:org.doxu.g2.gwc.crawler.CrawlThread.java

private InetAddress getIPAddress(URI uri) {
    try {/* www.  j  a v  a 2 s  .  c  om*/
        InetAddress address = InetAddress.getByName(uri.getHost());
        return address;
    } catch (UnknownHostException ex) {
        return null;
    }
}

From source file:at.bitfire.davdroid.mirakel.syncadapter.LoginURLFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean ok = editUserName.getText().length() > 0 && editPassword.getText().length() > 0;

    if (ok)// w  w w.  j ava 2  s . com
        // check host name
        try {
            URI uri = new URI(URLUtils.sanitize(scheme + editBaseURI.getText().toString()));
            if (StringUtils.isBlank(uri.getHost()))
                ok = false;
        } catch (URISyntaxException e) {
            ok = false;
        }

    MenuItem item = menu.findItem(R.id.next);
    item.setEnabled(ok);
}

From source file:edu.infsci2560.DatabaseConfig.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()
            + "?sslmode=require";

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);/*from w  ww. j  ava 2 s .  c om*/
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);

    return basicDataSource;
}

From source file:com.okta.sdk.impl.http.httpclient.HttpClientRequestFactory.java

/**
 * Configures the headers in the specified Apache HTTP request.
 *//*from  w  w  w.ja  v a2 s. c om*/
private void applyHeaders(HttpRequestBase httpRequest, Request request) {
    /*
     * Apache HttpClient omits the port number in the Host header (even if
     * we explicitly specify it) if it's the default port for the protocol
     * in use. To ensure that we use the same Host header in the request and
     * in the calculated string to sign (even if Apache HttpClient changed
     * and started honoring our explicit host with endpoint), we follow this
     * same behavior here and in the RequestAuthenticator.
     */
    URI endpoint = request.getResourceUrl();
    String hostHeader = endpoint.getHost();
    if (!RequestUtils.isDefaultPort(endpoint)) {
        hostHeader += ":" + endpoint.getPort();
    }
    httpRequest.addHeader("Host", hostHeader);
    httpRequest.addHeader("Accept-Encoding", "gzip");

    // Copy over any other headers already in our request
    for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) {
        String key = entry.getKey();
        List<String> value = entry.getValue();
        /*
         * HttpClient4 fills in the Content-Length header and complains if
         * it's already present, so we skip it here. We also skip the Host
         * header to avoid sending it twice, which will interfere with some
         * signing schemes.
         */
        if (!"Content-Length".equalsIgnoreCase(key) && !"Host".equalsIgnoreCase(key)) {
            String delimited = Strings.collectionToCommaDelimitedString(value);
            httpRequest.addHeader(key, delimited);
        }
    }
}

From source file:com.vaushell.superpipes.transforms.bitly.T_ShortenExpandTest.java

/**
 * Test T_Shorten and T_Expand.//from  w ww.  j ava 2  s .  co m
 *
 * @throws java.lang.Exception
 */
@Test
public void testTransform() throws Exception {
    final A_Node n = dispatcher.addNode("dummy", N_Dummy.class, ConfigProperties.EMPTY_COMMONS);

    final ConfigProperties common = dispatcher.getCommon("bitly");

    final A_Transform tShorten = n.addTransformIN(T_Shorten.class, Arrays.asList(common));
    final A_Transform tExpand = n.addTransformIN(T_Expand.class, Arrays.asList(common));

    // Prepare node
    n.prepare();

    // Test : shorten
    final URI refURI = new URI("http://fabien.vauchelles.com/");
    final Message m = Message.create(Message.KeyIndex.URI, refURI);

    assertNotNull("Transform should return a message", tShorten.transform(m));

    final URI shortenURL = (URI) m.getProperty(Message.KeyIndex.URI);

    assertTrue("Shorten URL should contains bit.ly domain", shortenURL.getHost().contains("bit.ly"));

    // Test : expand
    assertNotNull("Transform should return a message", tExpand.transform(m));

    final URI expandURL = (URI) m.getProperty(Message.KeyIndex.URI);

    assertEquals("URI must be the same after a reduce/expand", refURI, expandURL);

    // Terminate node
    n.terminate();
}