io.searchbox.client.config.HttpClientConfig Java Examples

The following examples show how to use io.searchbox.client.config.HttpClientConfig. 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: XPackAuthTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void appliesCertInfoIfConfigured() {

    // given
    CertInfo<HttpClientConfig.Builder> certInfo = Mockito.mock(CertInfo.class);

    HttpClientConfig.Builder settingsBuilder = createDefaultClientConfigBuilder();

    XPackAuth xPackAuth = createTestBuilder()
            .withCertInfo(certInfo)
            .build();

    // when
    xPackAuth.configure(settingsBuilder);

    // then
    verify(certInfo).applyTo(builderArgumentCaptor.capture());
    Assert.assertEquals(settingsBuilder, builderArgumentCaptor.getValue());

}
 
Example #2
Source File: Jest.java    From easy-sync with Apache License 2.0 6 votes vote down vote up
private JestClient createJestClient(Es es) {
    JestClientFactory factory = new JestClientFactory();
    List<String> addresses = Arrays.asList(es.getAddresses().split(";"));
    factory.setHttpClientConfig(new HttpClientConfig
            .Builder(addresses)// "http://localhost:9200")
            .multiThreaded(true)
            .connTimeout(10 * 000)
            .readTimeout(10 * 000)
            //Per default this implementation will create no more than 2 concurrent connections per given route
            // .defaultMaxTotalConnectionPerRoute(<YOUR_DESIRED_LEVEL_OF_CONCURRENCY_PER_ROUTE>)
            // and no more 20 connections in total
            // .maxTotalConnection(<YOUR_DESIRED_LEVEL_OF_CONCURRENCY_TOTAL>)
            .build());
    JestClient jestClient = factory.getObject();
    return jestClient;
}
 
Example #3
Source File: TestCdiFactory.java    From apiman with Apache License 2.0 6 votes vote down vote up
@Produces @ApplicationScoped @Named("metrics")
public static JestClient provideMetricsJestClient() {
    boolean enableESMetrics = "true".equals(System.getProperty("apiman-test.es-metrics", "false"));
    if (enableESMetrics) {
        String host = System.getProperty("apiman-test.es-metrics.host", "localhost");
        String port = System.getProperty("apiman-test.es-metrics.port", "9200");

        String connectionUrl = "http://" + host + ":" + port + "";
        JestClientFactory factory = new JestClientFactory();
        factory.setHttpClientConfig(new HttpClientConfig.Builder(connectionUrl).multiThreaded(true).
                connTimeout(JEST_TIMEOUT).readTimeout(JEST_TIMEOUT).build());
        return factory.getObject();
    } else {
        return null;
    }
}
 
Example #4
Source File: JestHttpObjectFactory.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public JestClient createClient() {
    if (client == null) {

        HttpClientConfig.Builder builder = new HttpClientConfig.Builder(serverUris)
                .maxTotalConnection(maxTotalConnections)
                .defaultMaxTotalConnectionPerRoute(defaultMaxTotalConnectionsPerRoute)
                .connTimeout(connTimeout)
                .readTimeout(readTimeout)
                .discoveryEnabled(discoveryEnabled)
                .multiThreaded(true);

        if (this.auth != null) {
            auth.configure(builder);
        }

        WrappedHttpClientConfig.Builder wrappedHttpClientConfigBuilder =
                new WrappedHttpClientConfig.Builder(builder.build())
                        .ioThreadCount(ioThreadCount);

        client = getClientProvider(wrappedHttpClientConfigBuilder).createClient();
    }
    return client;
}
 
Example #5
Source File: JestHttpObjectFactory.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * This constructor is deprecated and will be removed in 1.5.
 * Use {@link #JestHttpObjectFactory(Collection, int, int, int, int, int, boolean, Auth, String, BackoffPolicy)} instead.
 *
 * @param serverUris List of semicolon-separated `http[s]://host:[port]` addresses of Elasticsearch nodes to connect with. Unless `discoveryEnabled=true`, this will be the final list of available nodes
 * @param connTimeout Number of milliseconds before ConnectException is thrown while attempting to connect
 * @param readTimeout Number of milliseconds before SocketTimeoutException is thrown while waiting for response bytes
 * @param maxTotalConnections Number of connections available
 * @param defaultMaxTotalConnectionPerRoute Number of connections available per Apache CPool
 * @param discoveryEnabled If `true`, `io.searchbox.client.config.discovery.NodeChecker` will use `serverUris` to auto-discover Elasticsearch nodes. Otherwise, `serverUris` will be the final list of available nodes
 * @param auth Security configuration
 * @deprecated As of 1.5, this constructor wil be removed. Use {@link #JestHttpObjectFactory(Builder)} instead.
 *
 */
@Deprecated
protected JestHttpObjectFactory(Collection<String> serverUris,
                                int connTimeout,
                                int readTimeout,
                                int maxTotalConnections,
                                int defaultMaxTotalConnectionPerRoute,
                                boolean discoveryEnabled,
                                Auth<io.searchbox.client.config.HttpClientConfig.Builder> auth) {
    this(serverUris,
            connTimeout,
            readTimeout,
            maxTotalConnections,
            defaultMaxTotalConnectionPerRoute,
            Runtime.getRuntime().availableProcessors(),
            discoveryEnabled,
            auth,
            DEFAULT_MAPPING_TYPE,
            new NoopBackoffPolicy<>());
}
 
Example #6
Source File: JestConfig.java    From light-reading-cloud with MIT License 6 votes vote down vote up
@Bean
public JestClient jestClient() {
    JestClientFactory factory = new JestClientFactory();
    String[] sers = es_servers.split(",");
    HttpClientConfig httpClientConfig =
            new HttpClientConfig.Builder(Arrays.asList(sers))
                    .multiThreaded(true)
                    .connTimeout(5000)
                    .readTimeout(3000)
                    .maxTotalConnection(10)
                    .defaultMaxTotalConnectionPerRoute(10)
                    .build();
    factory.setHttpClientConfig(httpClientConfig);
    LOGGER.info("es_servers:{}", es_servers);
    return factory.getObject();
}
 
Example #7
Source File: JestHttpObjectFactory.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * @param serverUris List of semicolon-separated `http[s]://host:[port]` addresses of Elasticsearch nodes to connect with. Unless `discoveryEnabled=true`, this will be the final list of available nodes
 * @param connTimeout Number of milliseconds before ConnectException is thrown while attempting to connect
 * @param readTimeout Number of milliseconds before SocketTimeoutException is thrown while waiting for response bytes
 * @param maxTotalConnections Number of connections available
 * @param defaultMaxTotalConnectionPerRoute Number of connections available per Apache CPool
 * @param discoveryEnabled If `true`, `io.searchbox.client.config.discovery.NodeChecker` will use `serverUris` to auto-discover Elasticsearch nodes. Otherwise, `serverUris` will be the final list of available nodes
 * @param ioThreadCount number of 'I/O Dispatcher' threads started by Apache HC `IOReactor`
 * @param auth Security configuration
 * @param mappingType Elasticsearch mapping type name. MAY be set to '_doc' for Elasticsearch 7.x compatibility
 * @deprecated As of 1.5, this constructor will be removed. Use {@link #JestHttpObjectFactory(Builder)} instead
 */
@Deprecated
protected JestHttpObjectFactory(Collection<String> serverUris,
                                int connTimeout,
                                int readTimeout,
                                int maxTotalConnections,
                                int defaultMaxTotalConnectionPerRoute,
                                int ioThreadCount,
                                boolean discoveryEnabled,
                                Auth<io.searchbox.client.config.HttpClientConfig.Builder> auth,
                                String mappingType,
                                BackoffPolicy backoffPolicy) {
    this.serverUris = serverUris;
    this.connTimeout = connTimeout;
    this.readTimeout = readTimeout;
    this.maxTotalConnections = maxTotalConnections;
    this.defaultMaxTotalConnectionsPerRoute = defaultMaxTotalConnectionPerRoute;
    this.ioThreadCount = ioThreadCount;
    this.discoveryEnabled = discoveryEnabled;
    this.auth = auth;
    this.mappingType = mappingType;
    this.backoffPolicy = backoffPolicy;
}
 
Example #8
Source File: ExtendedJestClientFactory.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected NHttpClientConnectionManager getAsyncConnectionManager() {

    PoolingNHttpClientConnectionManager connectionManager = createUnconfiguredPoolingNHttpClientConnectionManager();

    HttpClientConfig httpClientConfig = this.wrappedHttpClientConfig.getHttpClientConfig();

    final Integer maxTotal = httpClientConfig.getMaxTotalConnection();
    if (maxTotal != null) {
        connectionManager.setMaxTotal(maxTotal);
    }
    final Integer defaultMaxPerRoute = httpClientConfig.getDefaultMaxTotalConnectionPerRoute();
    if (defaultMaxPerRoute != null) {
        connectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
    }
    final Map<HttpRoute, Integer> maxPerRoute = httpClientConfig.getMaxTotalConnectionPerRoute();
    for (Map.Entry<HttpRoute, Integer> entry : maxPerRoute.entrySet()) {
        connectionManager.setMaxPerRoute(entry.getKey(), entry.getValue());
    }

    return connectionManager;
}
 
Example #9
Source File: BasicCredentialsTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void objectIsConfiguredWhenAllParamsAreSet() {

    // given
    BasicCredentials BasicCredentials = createTestBuilder()
            .withUsername(TEST_USER)
            .withPassword(TEST_PASSWORD)
            .build();

    HttpClientConfig.Builder settings = spy(createDefaultClientConfigBuilder());

    // when
    BasicCredentials.applyTo(settings);

    // then
    verify(settings).credentialsProvider((CredentialsProvider) notNull());

}
 
Example #10
Source File: SmokeTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
private static Auth<HttpClientConfig.Builder> getAuth() {
        CertInfo certInfo = PEMCertInfo.newBuilder()
                .withKeyPath(System.getProperty("pemCertInfo.keyPath"))
                .withKeyPassphrase(System.getProperty("pemCertInfo.keyPassphrase"))
                .withClientCertPath(System.getProperty("pemCertInfo.clientCertPath"))
                .withCaPath(System.getProperty("pemCertInfo.caPath"))
                .build();

//        CertInfo certInfo = JKSCertInfo.newBuilder()
//                .withKeystorePath(System.getProperty("jksCertInfo.keystorePath"))
//                .withKeystorePassword(System.getProperty("jksCertInfo.keystorePassword"))
//                .withTruststorePath(System.getProperty("jksCertInfo.truststorePath"))
//                .withTruststorePassword(System.getProperty("jksCertInfo.truststorePassword"))
//                .build();

        Credentials credentials = BasicCredentials.newBuilder()
                .withUsername("admin")
                .withPassword("changeme")
                .build();

        return XPackAuth.newBuilder()
                .withCertInfo(certInfo)
                .withCredentials(credentials)
                .build();
    }
 
Example #11
Source File: JKSCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void paramsArePassedToConfiguredObject() {

    // given
    JKSCertInfo certInfo = createTestCertInfoBuilder()
            .withKeystorePath(TEST_KEYSTORE_PATH)
            .withKeystorePassword(TEST_KEYSTORE_PASSWORD)
            .withTruststorePath(TEST_TRUSTSTORE_PATH)
            .withTruststorePassword(TEST_TRUSTSTORE_PASSWORD)
            .build();

    HttpClientConfig.Builder clientConfigBuilder = spy(createDefaultClientConfigBuilder());

    // when
    certInfo.applyTo(clientConfigBuilder);

    // then
    verify(clientConfigBuilder).httpsIOSessionStrategy((SchemeIOSessionStrategy) notNull());
    Assert.assertNotNull(clientConfigBuilder.build().getHttpsIOSessionStrategy());
}
 
Example #12
Source File: BeihuMutilElasticsearchJestAutoConfiguration.java    From beihu-boot with Apache License 2.0 6 votes vote down vote up
protected HttpClientConfig createHttpClientConfig(BeihuMutilElasticsearchJestProperties.Instances instance) {
    HttpClientConfig.Builder builder = new HttpClientConfig.Builder(
            instance.getUris());
    PropertyMapper map = PropertyMapper.get();
    map.from(instance::getUsername).whenHasText().to((username) -> builder
            .defaultCredentials(username, instance.getPassword()));

    map.from(this.gsonProvider::getIfUnique).whenNonNull().to(builder::gson);
    map.from(instance::isMultiThreaded).to(builder::multiThreaded);
    map.from(instance::getConnectionTimeout).whenNonNull()
            .asInt(Duration::toMillis).to(builder::connTimeout);
    map.from(instance::getReadTimeout).whenNonNull().asInt(Duration::toMillis)
            .to(builder::readTimeout);
    customize(builder);
    return builder.build();
}
 
Example #13
Source File: HooverResource.java    From newsleak with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
		throws ResourceInitializationException {
	if (!super.initialize(aSpecifier, aAdditionalParams)) {
		return false;
	}
	this.logger = this.getLogger();

	// Construct a new Jest client according to configuration via factory
	JestClientFactory factory = new JestClientFactory();
	factory.setHttpClientConfig(new HttpClientConfig.Builder(mHost + ":" + mPort).multiThreaded(false).build());
	client = factory.getObject();

	indexPath = mIndex + "/";

	return true;
}
 
Example #14
Source File: XPackAuthTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void appliesCredentialsIfConfigured() {

    // given
    Credentials<HttpClientConfig.Builder> credentials = Mockito.mock(Credentials.class);

    HttpClientConfig.Builder settingsBuilder = createDefaultClientConfigBuilder();

    XPackAuth xPackAuth = createTestBuilder()
            .withCredentials(credentials)
            .build();

    // when
    xPackAuth.configure(settingsBuilder);

    // then
    verify(credentials).applyTo(builderArgumentCaptor.capture());
    Assert.assertEquals(settingsBuilder, builderArgumentCaptor.getValue());

}
 
Example #15
Source File: XPackAuthTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void doesntApplyCertInfoIfNotConfigured() {

    // given
    XPackAuth auth = createTestBuilder()
            .withCertInfo(null)
            .build();

    HttpClientConfig.Builder settingsBuilder = spy(createDefaultClientConfigBuilder());

    // when
    auth.configure(settingsBuilder);

    // then
    verify(settingsBuilder, never()).sslSocketFactory(any());
    verify(settingsBuilder, never()).httpsIOSessionStrategy(any());
}
 
Example #16
Source File: WrappedHttpClientConfigTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void builderBuildsWithGivenIoThreadCount() {

    // given
    HttpClientConfig givenConfig = new HttpClientConfig.Builder("http://localhost:9200").build();
    WrappedHttpClientConfig.Builder builder = new WrappedHttpClientConfig.Builder(givenConfig);

    int ioThreadCount = new Random().nextInt(1000) + 10;
    builder.ioThreadCount(ioThreadCount);

    // when
    WrappedHttpClientConfig config = builder.build();

    // then
    assertEquals(ioThreadCount, config.getIoThreadCount());

}
 
Example #17
Source File: PEMCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void builderThrowsIfCantReadKey() {

    // given
    PEMCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeyPath(TEST_KEY_PATH_WITH_PASSPHRASE)
            .withKeyPassphrase("")
            .build();

    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    // when
    testCertInfo.applyTo(mock(HttpClientConfig.Builder.class));

}
 
Example #18
Source File: PEMCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void paramsArePassedToConfiguredObject() {

    // given
    PEMCertInfo certInfo = createTestCertInfoBuilder()
            .withKeyPath(TEST_KEY_PATH)
            .withKeyPassphrase(TEST_KEY_PASSPHRASE)
            .withClientCertPath(TEST_CLIENT_CERT_PATH)
            .withCaPath(TEST_CA_PATH)
            .build();

    HttpClientConfig.Builder clientConfigBuilder = spy(createDefaultClientConfigBuilder());

    // when
    certInfo.applyTo(clientConfigBuilder);

    // then
    verify(clientConfigBuilder).httpsIOSessionStrategy((SchemeIOSessionStrategy) notNull());
    Assert.assertNotNull(clientConfigBuilder.build().getHttpsIOSessionStrategy());
}
 
Example #19
Source File: ExtendedJestClientFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void getAsyncConnectionManagerConfiguresMaxTotalPerRouteIfConfigured() {

    // given
    HttpClientConfig.Builder config = createDefaultTestHttpClientConfigBuilder();

    HttpRoute expectedHttpRoute = new HttpRoute(new HttpHost("localhost"));
    int expectedMaxTotalConnection = random.nextInt(100) + 10;
    config.maxTotalConnectionPerRoute(expectedHttpRoute, expectedMaxTotalConnection);

    WrappedHttpClientConfig.Builder builder = createDefaultTestWrappedHttpClientConfigBuilder(config.build());
    ExtendedJestClientFactory factory = spy(new ExtendedJestClientFactory(builder.build()));

    PoolingNHttpClientConnectionManager mockedNHttpConnectionManager = mock(PoolingNHttpClientConnectionManager.class);
    when(factory.createUnconfiguredPoolingNHttpClientConnectionManager())
            .thenReturn(mockedNHttpConnectionManager);

    // when
    factory.getAsyncConnectionManager();

    // then
    verify(mockedNHttpConnectionManager).setMaxPerRoute(eq(expectedHttpRoute), eq(expectedMaxTotalConnection));

}
 
Example #20
Source File: ExtendedJestClientFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void getAsyncConnectionManagerConfiguresDefaultMaxTotalPerRouteIfConfigured() {

    // given
    HttpClientConfig.Builder config = createDefaultTestHttpClientConfigBuilder();

    int expectedMaxTotalConnection = random.nextInt(100) + 10;
    config.defaultMaxTotalConnectionPerRoute(expectedMaxTotalConnection);

    WrappedHttpClientConfig.Builder builder = createDefaultTestWrappedHttpClientConfigBuilder(config.build());
    ExtendedJestClientFactory factory = spy(new ExtendedJestClientFactory(builder.build()));

    PoolingNHttpClientConnectionManager mockedNHttpConnectionManager = mock(PoolingNHttpClientConnectionManager.class);
    when(factory.createUnconfiguredPoolingNHttpClientConnectionManager())
            .thenReturn(mockedNHttpConnectionManager);

    // when
    factory.getAsyncConnectionManager();

    // then
    verify(mockedNHttpConnectionManager).setDefaultMaxPerRoute(eq(expectedMaxTotalConnection));

}
 
Example #21
Source File: ExtendedJestClientFactoryTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void getAsyncConnectionManagerConfiguresMaxTotalIfConfigured() {

    // given
    HttpClientConfig.Builder config = createDefaultTestHttpClientConfigBuilder();

    int expectedMaxTotalConnection = random.nextInt(100) + 10;
    config.maxTotalConnection(expectedMaxTotalConnection);

    WrappedHttpClientConfig.Builder builder = createDefaultTestWrappedHttpClientConfigBuilder(config.build());
    ExtendedJestClientFactory factory = spy(new ExtendedJestClientFactory(builder.build()));

    PoolingNHttpClientConnectionManager mockedNHttpConnectionManager = mock(PoolingNHttpClientConnectionManager.class);
    when(factory.createUnconfiguredPoolingNHttpClientConnectionManager())
            .thenReturn(mockedNHttpConnectionManager);

    // when
    factory.getAsyncConnectionManager();

    // then
    verify(mockedNHttpConnectionManager).setMaxTotal(eq(expectedMaxTotalConnection));

}
 
Example #22
Source File: JKSCertInfoTest.java    From log4j2-elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void builderThrowsIfKeyIsInvalid() throws IOException {

    // given
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage(PEMCertInfo.configExceptionMessage);

    File invalidKey = createInvalidKey();

    JKSCertInfo testCertInfo = createTestCertInfoBuilder()
            .withKeystorePath(invalidKey.getAbsolutePath())
            .build();

    // when
    testCertInfo.applyTo(mock(HttpClientConfig.Builder.class));

}
 
Example #23
Source File: ArticleServiceImpl.java    From elasticsearch-jest-example with MIT License 5 votes vote down vote up
private static JestClient getJestClient() {
    JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(new HttpClientConfig
            .Builder("http://127.0.0.1:9200")
            .gson(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create())
            .multiThreaded(true)
            .readTimeout(10000)
            .build());
    JestClient client = factory.getObject();
    return client;
}
 
Example #24
Source File: BuildListener.java    From elasticsearch-jenkins with MIT License 5 votes vote down vote up
public BuildListener() {
    LOG.info("Initializing");

/*    final JestClientFactory factory = new JestClientFactory();
    ClientConfig clientConfig = new ClientConfig.Builder(new ArrayList<String>()).multiThreaded(true).build();
    factory.setClientConfig(clientConfig);
    jestClient = factory.getObject();
}*/
        final JestClientFactory factory = new JestClientFactory();
    HttpClientConfig clientConfig = new HttpClientConfig.Builder(new ArrayList<String>()).multiThreaded(true).build();
    factory.setHttpClientConfig(clientConfig);
    jestClient = factory.getObject();
}
 
Example #25
Source File: ElasticsearchConfig.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdownClient")
public JestClient jestClient() {
    // Construct a new Jest client according to configuration via factory
    JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(new HttpClientConfig
            .Builder(environment.getProperty("jest.url"))
            .connTimeout(15000)
            .readTimeout(30000)
            .multiThreaded(true)
            .build());

    return factory.getObject();
}
 
Example #26
Source File: JestClientDemo.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    // Construct a new Jest client according to configuration via factory
    JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(new HttpClientConfig
        .Builder("http://172.22.6.9:9200")
        .multiThreaded(true)
        //Per default this implementation will create no more than 2 concurrent connections per given route
        .defaultMaxTotalConnectionPerRoute(2)
        // and no more 20 connections in total
        .maxTotalConnection(100)
        .build());
    JestClient client = factory.getObject();
    JestResult result = client.execute(new CreateIndex.Builder("user").build());
    System.out.println("result = " + result.getJsonString());
}
 
Example #27
Source File: WrappedHttpClientConfigTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void builderBuildsWithGivenHttpClientConfig() {

    // given
    HttpClientConfig givenConfig = new HttpClientConfig.Builder("http://localhost:9200").build();
    WrappedHttpClientConfig.Builder builder = new WrappedHttpClientConfig.Builder(givenConfig);

    // when
    WrappedHttpClientConfig config = builder.build();

    // then
    assertTrue(config.getHttpClientConfig() == givenConfig);

}
 
Example #28
Source File: JestExample.java    From elasticsearch-jest-example with MIT License 5 votes vote down vote up
private static JestClient getJestClient() {
	JestClientFactory factory = new JestClientFactory();
	 factory.setHttpClientConfig(new HttpClientConfig
	                        .Builder("http://127.0.0.1:9200")
	                        .gson(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create())
	                        .multiThreaded(true)
	                        .readTimeout(10000)
	                        .build());
	 JestClient client = factory.getObject();
	 return client;
}
 
Example #29
Source File: JestDemoApplication.java    From tutorials with MIT License 5 votes vote down vote up
private static JestClient jestClient()
{
    JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(
       new HttpClientConfig.Builder("http://localhost:9200")
          .multiThreaded(true)
          .defaultMaxTotalConnectionPerRoute(2)
          .maxTotalConnection(20)
          .build());
    return factory.getObject();
}
 
Example #30
Source File: ElasticSearchClientBuilder.java    From vind with Apache License 2.0 5 votes vote down vote up
public static JestClient build(String host, String port) {
    final String conn = String.format("http://%s:%s", host, port);
    log.info("Creating ElasticSearch REST Client over {}..,", conn);
    final JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(new HttpClientConfig.Builder(conn)
            .maxTotalConnection(10)
            .readTimeout(30000)
            .maxConnectionIdleTime(20, TimeUnit.SECONDS)
            .build());

    return factory.getObject();
}