Skip to content

Commit

Permalink
Use HttpHost.create instead of HttpHost::new.
Browse files Browse the repository at this point in the history
The latter one expects a hostname instead of a URL.
  • Loading branch information
smarsching committed Mar 28, 2024
1 parent f49786b commit b10db0c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/main/java/org/phoebus/channelfinder/ElasticConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class ElasticConfig implements ServletContextListener {
@Value("${elasticsearch.network.host:localhost}")
private String host;
@Value("${elasticsearch.host_urls:http://localhost:9200}")
private HttpHost[] httpHosts;
private String[] httpHostUrls;
@Value("${elasticsearch.http.port:9200}")
private int port;
@Value("${elasticsearch.authorization.header:}")
Expand Down Expand Up @@ -145,24 +146,21 @@ private static ElasticsearchClient createClient(ElasticsearchClient currentClien
}

private HttpHost[] getHttpHosts() {
HttpHost[] localHttpHosts = this.httpHosts;
boolean hostIsDefault = host.equals("localhost");
boolean hostUrlsIsDefault = localHttpHosts.length == 1 && localHttpHosts[0].equals(new HttpHost("http://localhost:9200"));
boolean hostUrlsIsDefault = httpHostUrls.length == 1 && httpHostUrls[0].equals("http://localhost:9200");
boolean portIsDefault = (port == 9200);
if (hostUrlsIsDefault) {
if (!hostIsDefault || !portIsDefault) {
logger.warning("Specifying elasticsearch.network.host and elasticsearch.http.port is deprecated, please consider using elasticsearch.host_urls instead.");
localHttpHosts = new HttpHost[] {new HttpHost("http://" + host + ":" + port)};
}
if (hostUrlsIsDefault && (!hostIsDefault || !portIsDefault)) {
logger.warning("Specifying elasticsearch.network.host and elasticsearch.http.port is deprecated, please consider using elasticsearch.host_urls instead.");
return new HttpHost[] {new HttpHost(host, port)};
} else {
if (!hostIsDefault) {
logger.warning("Only one of elasticsearch.host_urls and elasticsearch.network.host can be set, ignoring elasticsearch.network.host.");
}
if (!portIsDefault) {
logger.warning("Only one of elasticsearch.host_urls and elasticsearch.http.port can be set, ignoring elasticsearch.http.port.");
}
return Arrays.stream(httpHostUrls).map(HttpHost::create).toArray(HttpHost[]::new);
}
return localHttpHosts;
}

@Bean({ "searchClient" })
Expand Down

0 comments on commit b10db0c

Please sign in to comment.