当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientConfig.Builder方法代码示例

本文整理汇总了Java中io.searchbox.client.config.HttpClientConfig.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientConfig.Builder方法的具体用法?Java HttpClientConfig.Builder怎么用?Java HttpClientConfig.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.searchbox.client.config.HttpClientConfig的用法示例。


在下文中一共展示了HttpClientConfig.Builder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createClient

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
@Override
public JestClient createClient() {
    if (client == null) {
        JestClientFactory factory = new JestClientFactory();

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

        factory.setHttpClientConfig(builder.build());

        client = factory.getObject();
    }
    return client;
}
 
开发者ID:rfoltyns,项目名称:log4j2-elasticsearch,代码行数:20,代码来源:JestHttpObjectFactory.java

示例2: createHttpClientConfig

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
protected HttpClientConfig createHttpClientConfig() {
	HttpClientConfig.Builder builder = new HttpClientConfig.Builder(
			this.properties.getUris());
	if (StringUtils.hasText(this.properties.getUsername())) {
		builder.defaultCredentials(this.properties.getUsername(),
				this.properties.getPassword());
	}
	String proxyHost = this.properties.getProxy().getHost();
	if (StringUtils.hasText(proxyHost)) {
		Integer proxyPort = this.properties.getProxy().getPort();
		Assert.notNull(proxyPort, "Proxy port must not be null");
		builder.proxy(new HttpHost(proxyHost, proxyPort));
	}
	Gson gson = this.gsonProvider.getIfUnique();
	if (gson != null) {
		builder.gson(gson);
	}
	return builder.connTimeout(this.properties.getConnectionTimeout())
			.readTimeout(this.properties.getReadTimeout()).build();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:JestAutoConfiguration.java

示例3: getClient

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
protected static JestClient getClient(ElasticsearchConfig config) {
  JestClientFactory jestFactory = new JestClientFactory();
  HttpClientConfig.Builder httpClientBuilder = new HttpClientConfig.Builder(config.getHTTPURL());
  //Although we have a single writer thread per system producer, we set multiThreaded as true so that Jest
  //will used a pooled connection manager which re-establishes connections after they go stale
  httpClientBuilder.multiThreaded(true);
  httpClientBuilder.connTimeout(config.getConnectTimeoutMs());
  httpClientBuilder.readTimeout(config.getReadTimeoutMs());
  if (config.getAuthType().equals(ElasticsearchConfig.AuthType.BASIC)) {
    String user = config.getBasicAuthUser();
    String password = config.getBasicAuthPassword();
    if (user == null || password == null) {
      throw new SamzaException("Please specify a user and password for HTTP basic auth");
    }
    httpClientBuilder.defaultCredentials(user, password);
  }
  jestFactory.setHttpClientConfig(httpClientBuilder.build());
  return jestFactory.getObject();
}
 
开发者ID:quantiply,项目名称:rico,代码行数:20,代码来源:ElasticsearchSystemFactory.java

示例4: createJestClient

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
/**
 * Create Jest client with URI
 * @param uri URI of Elasticsearch
 * @return JestClient
 */
private JestClient createJestClient(String uri) {

	HttpClientConfig.Builder builder = new HttpClientConfig.Builder(uri)
		.maxTotalConnection(properties.getMaxTotalConnection())
		.defaultMaxTotalConnectionPerRoute(properties.getDefaultMaxTotalConnectionPerRoute())
		.readTimeout(properties.getReadTimeout())
		.multiThreaded(properties.getMultiThreaded());

	if (StringUtils.hasText(this.properties.getUsername())) {
		builder.defaultCredentials(this.properties.getUsername(), this.properties.getPassword());
	}
	
	String proxyHost = this.properties.getProxy().getHost();
	if (StringUtils.hasText(proxyHost)) {
		Integer proxyPort = this.properties.getProxy().getPort();
		Assert.notNull(proxyPort, "Proxy port must not be null");
		builder.proxy(new HttpHost(proxyHost, proxyPort));
	}
	
	List<HttpClientConfigBuilderCustomizer> configBuilderCustomizers = builderCustomizers != null ? builderCustomizers.getIfAvailable() : new ArrayList<>();
	if (!CollectionUtils.isEmpty(configBuilderCustomizers)) {
		logger.info("Custom HttpClientConfigBuilderCustomizers detected. Applying these to the HttpClientConfig builder.");
		configBuilderCustomizers.stream().forEach(customizer -> customizer.customize(builder));
		logger.info("Custom HttpClientConfigBuilderCustomizers applied.");
	}

	JestClientFactory factory = jestClientFactory != null ? jestClientFactory : new JestClientFactory();
	factory.setHttpClientConfig(builder.build());
	return factory.getObject();
}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:36,代码来源:ElasticsearchJestAutoConfiguration.java

示例5: startUpClient

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
@Override
protected void startUpClient() {
    JestClientFactory factory = new JestClientFactory();
    HttpClientConfig.Builder config = new HttpClientConfig
            .Builder("http://" + extension.getHostname() + ":" + extension.getHttpPort())
            .multiThreaded(false);
    if (!Strings.isNullOrEmpty(extension.getEsBasicAuthUsername())) {
        config.defaultCredentials(extension.getEsBasicAuthUsername(), extension.getEsBasicAuthPassword());
    }
    factory.setHttpClientConfig(config.build());
    client = factory.getObject();
}
 
开发者ID:nebula-plugins,项目名称:gradle-metrics-plugin,代码行数:13,代码来源:HttpESMetricsDispatcher.java

示例6: getClientForRestProtocol

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
private JestClient getClientForRestProtocol() {
    final JestClientFactory factory = new JestClientFactory();
    HttpClientConfig.Builder builder =
            new HttpClientConfig.Builder("http://" + _hostname + ":" + _port).multiThreaded(true);
    if (!Strings.isNullOrEmpty(_username)) {
        builder = builder.defaultCredentials(_username, _password);
    }
    factory.setHttpClientConfig(builder.build());

    return factory.getObject();
}
 
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:12,代码来源:ElasticSearchDatastore.java

示例7: ScanAndScroll

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
public ScanAndScroll(String url,String username, String password,String outputFilePath,int outputType,String outputFile,int runTika,String htmlField) throws FileNotFoundException, UnsupportedEncodingException{
	
	SSLContext sslContext;
       try {
           sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
               public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                   return true;
               }
           }).build();
       } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
           throw new IllegalStateException(e);
       }

       // Skip hostname checks
       HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
       SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);

       HttpClientConfig.Builder httpClientBuilder = new HttpClientConfig.Builder(url.toString())
                                                   .sslSocketFactory(sslSocketFactory)
                                                   .readTimeout(30000) // Milliseconds
                                                   .multiThreaded(false);

	
	System.out.println(url);
	
	if(username.trim() != "" && password.trim() != ""){
		httpClientBuilder.defaultCredentials(username, password);
	}
	
	JestClientFactory jcf = new JestClientFactory();
	
	jcf.setHttpClientConfig(httpClientBuilder.build());
	
	this.client = jcf.getObject();
	
	
	this.outputType = outputType;
	this.outputFile = outputFile;
	this.runTika = runTika;
	this.htmlField = htmlField;
}
 
开发者ID:usc-isi-i2,项目名称:dig-elasticsearch,代码行数:42,代码来源:ScanAndScroll.java

示例8: createJestClient

import io.searchbox.client.config.HttpClientConfig; //导入方法依赖的package包/类
/**
 * Creates a transport client from a configuration map.
 * @param config the configuration
 * @param indexName the name of the index
 * @param defaultIndexName the default index name
 * @return the ES client
 */
protected JestClient createJestClient(Map<String, String> config, String indexName, String defaultIndexName) {
    String host = config.get("client.host"); //$NON-NLS-1$
    String port = config.get("client.port"); //$NON-NLS-1$
    String protocol = config.get("client.protocol"); //$NON-NLS-1$
    String initialize = config.get("client.initialize"); //$NON-NLS-1$

    if (initialize == null) {
        initialize = "true"; //$NON-NLS-1$
    }

    if (StringUtils.isBlank(host)) {
        throw new RuntimeException("Missing client.host configuration for ESRegistry."); //$NON-NLS-1$
    }
    if (StringUtils.isBlank(port)) {
        throw new RuntimeException("Missing client.port configuration for ESRegistry."); //$NON-NLS-1$
    }
    if (StringUtils.isBlank(protocol)) {
        protocol = "http"; //$NON-NLS-1$
    }
    
    String clientKey = "jest:" + host + ':' + port + '/' + indexName; //$NON-NLS-1$
    synchronized (clients) {
        if (clients.containsKey(clientKey)) {
            return clients.get(clientKey);
        } else {
            StringBuilder builder = new StringBuilder();
            builder.append(protocol);
            builder.append("://"); //$NON-NLS-1$
            builder.append(host);
            builder.append(":"); //$NON-NLS-1$
            builder.append(String.valueOf(port));
            String connectionUrl = builder.toString();

            JestClientFactory factory = new JestClientFactory();
            Builder httpClientConfig = new HttpClientConfig.Builder(connectionUrl);
            updateHttpConfig(httpClientConfig, config);
            factory.setHttpClientConfig(httpClientConfig.build());
            updateJestClientFactory(factory, config);
            
            JestClient client = factory.getObject();
            clients.put(clientKey, client);
            if ("true".equals(initialize)) { //$NON-NLS-1$
                initializeClient(client, indexName, defaultIndexName);
            }
            return client;
        }
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:56,代码来源:DefaultESClientFactory.java


注:本文中的io.searchbox.client.config.HttpClientConfig.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。