本文整理了Java中org.elasticsearch.client.RestClientBuilder.setDefaultHeaders
方法的一些代码示例,展示了RestClientBuilder.setDefaultHeaders
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestClientBuilder.setDefaultHeaders
方法的具体详情如下:
包路径:org.elasticsearch.client.RestClientBuilder
类名称:RestClientBuilder
方法名:setDefaultHeaders
[英]Sets the default request headers, which will be sent along with each request.
Request-time headers will always overwrite any default headers.
[中]设置默认的请求头,它将与每个请求一起发送。
请求时间标头将始终覆盖任何默认标头。
代码示例来源:origin: spring-projects/spring-data-elasticsearch
builder.setDefaultHeaders(httpHeaders);
代码示例来源:origin: apache/storm
/**
* Creates a new {@link RestClient} using given {@link EsConfig}.
*
* @return {@link RestClient} for Elasticsearch connection
*/
public RestClient construct() {
RestClientBuilder builder = RestClient.builder(esConfig.getHttpHosts());
if (esConfig.getMaxRetryTimeoutMillis() != null) {
builder.setMaxRetryTimeoutMillis(esConfig.getMaxRetryTimeoutMillis());
}
if (esConfig.getDefaultHeaders() != null) {
builder.setDefaultHeaders(esConfig.getDefaultHeaders());
}
if (esConfig.getFailureListener() != null) {
builder.setFailureListener(esConfig.getFailureListener());
}
if (esConfig.getHttpClientConfigCallback() != null) {
builder.setHttpClientConfigCallback(esConfig.getHttpClientConfigCallback());
}
if (esConfig.getRequestConfigCallback() != null) {
builder.setRequestConfigCallback(esConfig.getRequestConfigCallback());
}
if (esConfig.getPathPrefix() != null) {
builder.setPathPrefix(esConfig.getPathPrefix());
}
return builder.build();
}
}
代码示例来源:origin: HuygensING/timbuctoo
@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();
}
代码示例来源:origin: apache/incubator-griffin
public MetricStoreImpl(@Value("${elasticsearch.host}") String host,
@Value("${elasticsearch.port}") int port,
@Value("${elasticsearch.scheme:http}") String scheme,
@Value("${elasticsearch.user:}") String user,
@Value("${elasticsearch.password:}") String password) {
HttpHost httpHost = new HttpHost(host, port, scheme);
RestClientBuilder builder = RestClient.builder(httpHost);
if (!user.isEmpty() && !password.isEmpty()) {
String encodedAuth = buildBasicAuthString(user, password);
Header[] requestHeaders = new Header[]{
new BasicHeader(org.apache.http.HttpHeaders.AUTHORIZATION,
encodedAuth)};
builder.setDefaultHeaders(requestHeaders);
}
this.client = builder.build();
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
this.responseHeaders = responseHeaders;
String urlBase = String.format("/%s/%s", INDEX, TYPE);
this.urlGet = urlBase.concat("/_search?filter_path=hits.hits._source");
this.urlPost = urlBase.concat("/_bulk");
this.urlDelete = urlBase.concat("/_delete_by_query");
this.indexMetaData = String.format(
"{ \"index\" : { \"_index\" : " +
"\"%s\",\"_type\" : \"%s\" } }%n",
INDEX,
TYPE);
this.mapper = new ObjectMapper();
}
代码示例来源:origin: gauravrmazra/gauravbytes
public static RestClient createClientWithDefaultHeaders() {
RestClientBuilder clientBuilder = RestClient.builder(new HttpHost("localhost", 9200, "http"));
Header[] defaultHeaders = new Header[2];
defaultHeaders[0] = new BasicHeader("COMPANY", "GAURAVBYTES");
defaultHeaders[1] = new BasicHeader("OWNER", "Gaurav Rai Mazra");
clientBuilder.setDefaultHeaders(defaultHeaders);
clientBuilder.setFailureListener(failureListener());
return clientBuilder.build();
}
代码示例来源:origin: uk.gov.dstl.baleen/baleen-resources
@Override
protected boolean doInitialize(ResourceSpecifier specifier, Map<String, Object> additionalParams)
throws ResourceInitializationException {
URL parsedUrl = null;
try {
parsedUrl = new URL(url);
} catch (MalformedURLException e) {
throw new ResourceInitializationException(e);
}
RestClientBuilder rcb =
RestClient.builder(
new HttpHost(parsedUrl.getHost(), parsedUrl.getPort(), parsedUrl.getProtocol()));
if (!Strings.isNullOrEmpty(user) && !Strings.isNullOrEmpty(pass)) {
Header[] headers = {new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")};
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
AuthScope.ANY, new UsernamePasswordCredentials(user, pass));
rcb.setDefaultHeaders(headers);
rcb.setHttpClientConfigCallback(
builder -> builder.setDefaultCredentialsProvider(credentialsProvider));
}
client = rcb.build();
return true;
}
代码示例来源:origin: dstl/baleen
@Override
protected boolean doInitialize(ResourceSpecifier specifier, Map<String, Object> additionalParams)
throws ResourceInitializationException {
URL parsedUrl = null;
try {
parsedUrl = new URL(url);
} catch (MalformedURLException e) {
throw new ResourceInitializationException(e);
}
RestClientBuilder rcb =
RestClient.builder(
new HttpHost(parsedUrl.getHost(), parsedUrl.getPort(), parsedUrl.getProtocol()));
if (!Strings.isNullOrEmpty(user) && !Strings.isNullOrEmpty(pass)) {
Header[] headers = {new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")};
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
AuthScope.ANY, new UsernamePasswordCredentials(user, pass));
rcb.setDefaultHeaders(headers);
rcb.setHttpClientConfigCallback(
builder -> builder.setDefaultCredentialsProvider(credentialsProvider));
}
client = rcb.build();
return true;
}
代码示例来源:origin: com.strapdata.elasticsearch.test/framework
defaultHeaders[i++] = new BasicHeader(entry.getKey(), entry.getValue());
builder.setDefaultHeaders(defaultHeaders);
代码示例来源:origin: org.elasticsearch.plugin/reindex-client
.setDefaultHeaders(clientHeaders)
.setRequestConfigCallback(c -> {
c.setConnectTimeout(Math.toIntExact(remoteInfo.getConnectTimeout().millis()));
内容来源于网络,如有侵权,请联系作者删除!