Java Code Examples for org.elasticsearch.common.transport.InetSocketTransportAddress#getPort()

The following examples show how to use org.elasticsearch.common.transport.InetSocketTransportAddress#getPort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlPluginTest.java    From elasticsearch-xml with Apache License 2.0 6 votes vote down vote up
@Test
public void testHealthResponse() throws Exception {
    InetSocketTransportAddress httpAddress = findHttpAddress(client("1"));
    if (httpAddress == null) {
        throw new IllegalArgumentException("no HTTP address found");
    }
    URL base = new URL("http://" + httpAddress.getHost() + ":" + httpAddress.getPort());
    URL url = new URL(base, "/_cluster/health?xml");
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;
    if ((line = reader.readLine()) != null) {
        assertTrue(line.startsWith("<root xmlns=\"http://elasticsearch.org/ns/1.0/\">"));
        assertTrue(line.endsWith("</root>"));
    }
    reader.close();
}
 
Example 2
Source File: XmlPluginTest.java    From elasticsearch-xml with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrettyHealthResponse() throws Exception {
    InetSocketTransportAddress httpAddress = findHttpAddress(client("1"));
    if (httpAddress == null) {
        throw new IllegalArgumentException("no HTTP address found");
    }
    URL base = new URL("http://" + httpAddress.getHost() + ":" + httpAddress.getPort());
    URL url = new URL(base, "/_cluster/health?xml&pretty");
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    String line;
    // check only first line
    if ((line = reader.readLine()) != null) {
        assertTrue(line.startsWith("<root xmlns=\"http://elasticsearch.org/ns/1.0/\">"));
    }
    reader.close();
}
 
Example 3
Source File: XmlPluginTest.java    From elasticsearch-xml with Apache License 2.0 6 votes vote down vote up
@Test
public void testBigAndFatResponse() throws Exception {
    Client client = client("1");
    for (int i = 0; i < 10000; i++) {
        client.index(new IndexRequest("test", "test", Integer.toString(i))
                .source("{\"random\":\""+randomString(32)+ " " + randomString(32) + "\"}")).actionGet();
    }
    client.admin().indices().refresh(new RefreshRequest("test")).actionGet();
    InetSocketTransportAddress httpAddress = findHttpAddress(client);
    if (httpAddress == null) {
        throw new IllegalArgumentException("no HTTP address found");
    }
    URL base = new URL("http://" + httpAddress.getHost() + ":" + httpAddress.getPort());
    URL url = new URL(base, "/test/test/_search?xml&pretty&size=10000");
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    int count = 0;
    String line;
    while ((line = reader.readLine()) != null) {
        count += line.length();
    }
    assertTrue(count >= 2309156);
    reader.close();
    client.admin().indices().delete(new DeleteIndexRequest("test"));
}
 
Example 4
Source File: ElasticsearchRestWriter.java    From incubator-gobblin with Apache License 2.0 4 votes vote down vote up
private static RestClient buildRestClient(List<InetSocketTransportAddress> hosts, int threadCount, boolean sslEnabled,
    String keyStoreType, String keyStoreFilePassword, String identityFilepath, String trustStoreType,
    String trustStoreFilePassword, String cacertsFilepath) throws Exception {


  HttpHost[] httpHosts = new HttpHost[hosts.size()];
  String scheme = sslEnabled?"https":"http";
  for (int h = 0; h < httpHosts.length; h++) {
    InetSocketTransportAddress host = hosts.get(h);
    httpHosts[h] = new HttpHost(host.getAddress(), host.getPort(), scheme);
  }

  RestClientBuilder builder = RestClient.builder(httpHosts);

  if (sslEnabled) {
    log.info("ssl configuration: trustStoreType = {}, cacertsFilePath = {}", trustStoreType, cacertsFilepath);
    KeyStore truststore = KeyStore.getInstance(trustStoreType);
    FileInputStream trustInputStream = new FileInputStream(cacertsFilepath);
    try {
      truststore.load(trustInputStream, trustStoreFilePassword.toCharArray());
    }
    finally {
      trustInputStream.close();
    }
    SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(truststore, null);

    log.info("ssl key configuration: keyStoreType = {}, keyFilePath = {}", keyStoreType, identityFilepath);

    KeyStore keystore = KeyStore.getInstance(keyStoreType);
    FileInputStream keyInputStream = new FileInputStream(identityFilepath);
    try {
      keystore.load(keyInputStream, keyStoreFilePassword.toCharArray());
    }
    finally {
      keyInputStream.close();
    }
    sslBuilder.loadKeyMaterial(keystore, keyStoreFilePassword.toCharArray());

    final SSLContext sslContext = sslBuilder.build();
    builder = builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder
        // Set ssl context
        .setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier())
        // Configure number of threads for clients
        .setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(threadCount).build()));
  } else {
    builder = builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder
        // Configure number of threads for clients
        .setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(threadCount).build()));
  }

  // Configure timeouts
  builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder
      .setConnectionRequestTimeout(0)); // Important, otherwise the client has spurious timeouts

  return builder.build();
}