Skip to content

Commit 58cc87d

Browse files
josegar74jodygarnett
authored andcommitted
Update the Elasticsearch client to use the server proxy if configured
1 parent 9486544 commit 58cc87d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

index/src/main/java/org/fao/geonet/index/es/EsRestClient.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2001-2023 Food and Agriculture Organization of the
2+
* Copyright (C) 2001-2025 Food and Agriculture Organization of the
33
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
44
* and United Nations Environment Programme (UNEP)
55
*
@@ -31,7 +31,6 @@
3131
import co.elastic.clients.elasticsearch._types.query_dsl.WrapperQuery;
3232
import co.elastic.clients.elasticsearch.cluster.HealthResponse;
3333
import co.elastic.clients.elasticsearch.core.*;
34-
import co.elastic.clients.elasticsearch.core.search.Hit;
3534
import co.elastic.clients.elasticsearch.indices.AnalyzeRequest;
3635
import co.elastic.clients.elasticsearch.indices.AnalyzeResponse;
3736
import co.elastic.clients.elasticsearch.indices.analyze.AnalyzeToken;
@@ -148,17 +147,19 @@ public boolean isTrusted(X509Certificate[] arg0, String arg1) throws Certificate
148147
credentialsProvider.setCredentials(AuthScope.ANY,
149148
new UsernamePasswordCredentials(username, password));
150149

151-
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setSSLContext(sslContext).setDefaultCredentialsProvider(credentialsProvider));
150+
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.useSystemProperties().setSSLContext(sslContext).setDefaultCredentialsProvider(credentialsProvider));
152151
} else {
153-
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setSSLContext(sslContext));
152+
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.useSystemProperties().setSSLContext(sslContext));
154153
}
155154
} else {
156155
if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
157156
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
158157
credentialsProvider.setCredentials(AuthScope.ANY,
159158
new UsernamePasswordCredentials(username, password));
160159

161-
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
160+
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.useSystemProperties().setDefaultCredentialsProvider(credentialsProvider));
161+
} else {
162+
builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.useSystemProperties());
162163
}
163164
}
164165

@@ -381,7 +382,7 @@ public String deleteByQuery(String index, String query) throws Exception {
381382
deleteByQueryResponse.failures().forEach(f -> stringBuilder.append(f.toString()));
382383

383384
throw new IOException(String.format(
384-
"Error during removal. Errors are '%s'.", stringBuilder.toString()
385+
"Error during removal. Errors are '%s'.", stringBuilder
385386
));
386387
}
387388
}

0 commit comments

Comments
 (0)