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


Java RestClientBuilder.setHttpClientConfigCallback方法代码示例

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


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

示例1: createClient

import org.elasticsearch.client.RestClientBuilder; //导入方法依赖的package包/类
public static RestClient createClient(ElasticsearchDatastoreProperties datastore) throws MalformedURLException {
    String urlStr = datastore.nodes.getValue();
    String[] urls = urlStr.split(",");
    HttpHost[] hosts = new HttpHost[urls.length];
    int i = 0;
    for (String address : urls) {
        URL url = new URL("http://" + address);
        hosts[i] = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
        i++;
    }
    RestClientBuilder restClientBuilder = RestClient.builder(hosts);
    if (datastore.auth.useAuth.getValue()) {
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(datastore.auth.userId.getValue(), datastore.auth.password.getValue()));
        restClientBuilder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {

            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) {
                return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
            }
        });
    }
    return restClientBuilder.build();
}
 
开发者ID:Talend,项目名称:components,代码行数:25,代码来源:ElasticsearchConnection.java

示例2: ElasticSearchFilter

import org.elasticsearch.client.RestClientBuilder; //导入方法依赖的package包/类
@JsonCreator
public ElasticSearchFilter(@JsonProperty("hostname") String hostname, @JsonProperty("port") int port,
                           @JsonProperty("username") Optional<String> username,
                           @JsonProperty("password") Optional<String> password) {
  Header[] headers = {
    new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"),
    new BasicHeader("Role", "Read")};
  final RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(hostname, port))
    .setDefaultHeaders(headers);
  if (username.isPresent() && !username.get().isEmpty() && password.isPresent() && !password.get().isEmpty()) {
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

    credentialsProvider.setCredentials(
      AuthScope.ANY,
      new UsernamePasswordCredentials(username.get(), password.get())
    );

    restClientBuilder.setHttpClientConfigCallback(b -> b.setDefaultCredentialsProvider(credentialsProvider));
  }
  restClient = restClientBuilder.build();
  mapper = new ObjectMapper();
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:23,代码来源:ElasticSearchFilter.java

示例3: buildClient

import org.elasticsearch.client.RestClientBuilder; //导入方法依赖的package包/类
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
    RestClientBuilder builder = RestClient.builder(hosts);
    String keystorePath = settings.get(TRUSTSTORE_PATH);
    if (keystorePath != null) {
        final String keystorePass = settings.get(TRUSTSTORE_PASSWORD);
        if (keystorePass == null) {
            throw new IllegalStateException(TRUSTSTORE_PATH + " is provided but not " + TRUSTSTORE_PASSWORD);
        }
        Path path = PathUtils.get(keystorePath);
        if (!Files.exists(path)) {
            throw new IllegalStateException(TRUSTSTORE_PATH + " is set but points to a non-existing file");
        }
        try {
            KeyStore keyStore = KeyStore.getInstance("jks");
            try (InputStream is = Files.newInputStream(path)) {
                keyStore.load(is, keystorePass.toCharArray());
            }
            SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keyStore, null).build();
            SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(sslcontext);
            builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setSSLStrategy(sessionStrategy));
        } catch (KeyStoreException|NoSuchAlgorithmException|KeyManagementException|CertificateException e) {
            throw new RuntimeException("Error setting up ssl", e);
        }
    }

    try (ThreadContext threadContext = new ThreadContext(settings)) {
        Header[] defaultHeaders = new Header[threadContext.getHeaders().size()];
        int i = 0;
        for (Map.Entry<String, String> entry : threadContext.getHeaders().entrySet()) {
            defaultHeaders[i++] = new BasicHeader(entry.getKey(), entry.getValue());
        }
        builder.setDefaultHeaders(defaultHeaders);
    }
    return builder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:ESRestTestCase.java

示例4: createClient

import org.elasticsearch.client.RestClientBuilder; //导入方法依赖的package包/类
@VisibleForTesting
RestClient createClient() throws IOException {
  HttpHost[] hosts = new HttpHost[getAddresses().size()];
  int i = 0;
  for (String address : getAddresses()) {
    URL url = new URL(address);
    hosts[i] = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
    i++;
  }
  RestClientBuilder restClientBuilder = RestClient.builder(hosts);
  if (getUsername() != null) {
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(
        AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword()));
    restClientBuilder.setHttpClientConfigCallback(
        new RestClientBuilder.HttpClientConfigCallback() {
          public HttpAsyncClientBuilder customizeHttpClient(
              HttpAsyncClientBuilder httpAsyncClientBuilder) {
            return httpAsyncClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
          }
        });
  }
  if (getKeystorePath() != null && !getKeystorePath().isEmpty()) {
    try {
      KeyStore keyStore = KeyStore.getInstance("jks");
      try (InputStream is = new FileInputStream(new File(getKeystorePath()))) {
        String keystorePassword = getKeystorePassword();
        keyStore.load(is, (keystorePassword == null) ? null : keystorePassword.toCharArray());
      }
      final SSLContext sslContext = SSLContexts.custom()
          .loadTrustMaterial(keyStore, new TrustSelfSignedStrategy()).build();
      final SSLIOSessionStrategy sessionStrategy = new SSLIOSessionStrategy(sslContext);
      restClientBuilder.setHttpClientConfigCallback(
          new RestClientBuilder.HttpClientConfigCallback() {
        @Override
        public HttpAsyncClientBuilder customizeHttpClient(
            HttpAsyncClientBuilder httpClientBuilder) {
          return httpClientBuilder.setSSLContext(sslContext).setSSLStrategy(sessionStrategy);
        }
      });
    } catch (Exception e) {
      throw new IOException("Can't load the client certificate from the keystore", e);
    }
  }
  return restClientBuilder.build();
}
 
开发者ID:apache,项目名称:beam,代码行数:47,代码来源:ElasticsearchIO.java

示例5: createClient

import org.elasticsearch.client.RestClientBuilder; //导入方法依赖的package包/类
private ElasticSearchRestClient createClient(final DataContextProperties properties) throws MalformedURLException {
    final URL url = new URL(properties.getUrl());
    final RestClientBuilder builder = RestClient.builder(new HttpHost(url.getHost(), url.getPort()));
    
    if (properties.getUsername() != null) {
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(properties.getUsername(),
                properties.getPassword()));

        builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(
                credentialsProvider));
    }

    return new ElasticSearchRestClient(builder.build());
}
 
开发者ID:apache,项目名称:metamodel,代码行数:16,代码来源:ElasticSearchRestDataContextFactory.java

示例6: createDataStore

import org.elasticsearch.client.RestClientBuilder; //导入方法依赖的package包/类
@Override
public DataStore createDataStore(Map<String, Serializable> params) throws IOException {
    final String searchHost = (String) getValue(HOSTNAME, params);
    final Integer hostPort = (Integer) getValue(HOSTPORT, params);
    final String indexName = (String) INDEX_NAME.lookUp(params);
    final String arrayEncoding = (String) getValue(ARRAY_ENCODING, params);
    final Boolean sslEnabled = (Boolean) getValue(SSL_ENABLED, params);
    final Boolean sslRejectUnauthorized = (Boolean) getValue(SSL_REJECT_UNAUTHORIZED, params);

    final String scheme = sslEnabled ? "https" : "http";
    final RestClientBuilder builder = RestClient.builder(new HttpHost(searchHost, hostPort, scheme));

    if (sslEnabled) {
        builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
            @Override
            public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                httpClientBuilder.useSystemProperties();
                if (!sslRejectUnauthorized) {
                    httpClientBuilder.setSSLHostnameVerifier((host,session) -> true);
                    try {
                        httpClientBuilder.setSSLContext(SSLContextBuilder.create().loadTrustMaterial((chain,authType) -> true).build());
                    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
                        throw new UncheckedIOException(new IOException("Unable to create SSLContext", e));
                    }
                }
                return httpClientBuilder;
            }
        });
    }

    final ElasticDataStore dataStore = new ElasticDataStore(builder.build(), indexName);
    dataStore.setDefaultMaxFeatures((Integer) getValue(DEFAULT_MAX_FEATURES, params));
    dataStore.setSourceFilteringEnabled((Boolean) getValue(SOURCE_FILTERING_ENABLED, params));
    dataStore.setScrollEnabled((Boolean)getValue(SCROLL_ENABLED, params));
    dataStore.setScrollSize(((Number)getValue(SCROLL_SIZE, params)).longValue());
    dataStore.setScrollTime((Integer)getValue(SCROLL_TIME_SECONDS, params));
    dataStore.setArrayEncoding(ArrayEncoding.valueOf(arrayEncoding.toUpperCase()));
    dataStore.setGridSize((Long) GRID_SIZE.lookUp(params));
    dataStore.setGridThreshold((Double) GRID_THRESHOLD.lookUp(params));
    return dataStore;
}
 
开发者ID:ngageoint,项目名称:elasticgeo,代码行数:42,代码来源:ElasticDataStoreFactory.java


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