Skip to content

Commit 4557395

Browse files
authored
Merge pull request #177 from amoscatelli/master
support for https protocol + authentication fix
2 parents e24ce2e + 961f3da commit 4557395

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

elasticsearch-driver/src/main/java/org/eclipse/jnosql/communication/elasticsearch/document/ElasticsearchAddress.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 Otávio Santana and others
2+
* Copyright (c) 2022 Otávio Santana and others
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* and Apache License v2.0 which accompanies this distribution.
@@ -11,33 +11,45 @@
1111
* Contributors:
1212
*
1313
* Otavio Santana
14+
* Alessandro Moscatelli
1415
*/
1516
package org.eclipse.jnosql.communication.elasticsearch.document;
1617

18+
import java.net.MalformedURLException;
19+
import java.net.URL;
20+
import java.util.Objects;
1721
import org.apache.http.HttpHost;
1822

1923
final class ElasticsearchAddress {
2024

21-
private final String host;
22-
23-
private final int port;
25+
private HttpHost host;
2426

2527
private ElasticsearchAddress(String address, int defaultPort) {
26-
String[] values = address.split(":");
27-
28-
this.host = values[0];
29-
this.port = values.length == 2 ? Integer.valueOf(values[1]) : defaultPort;
28+
try {
29+
URL tmp = new URL(address);
30+
this.host = new HttpHost(
31+
tmp.getHost(),
32+
Objects.equals(tmp.getPort(), -1) ? defaultPort : tmp.getPort(),
33+
tmp.getProtocol()
34+
);
35+
} catch (MalformedURLException ex) {
36+
String[] values = address.split(":");
37+
this.host = new HttpHost(
38+
values[0],
39+
values.length == 2 ? Integer.valueOf(values[1]) : defaultPort
40+
);
41+
}
3042
}
3143

3244
public HttpHost toHttpHost() {
33-
return new HttpHost(host, port);
45+
return this.host;
3446
}
3547

3648
@Override
3749
public String toString() {
3850
final StringBuilder sb = new StringBuilder("ElasticsearchAddress{");
39-
sb.append("host='").append(host).append('\'');
40-
sb.append(", port=").append(port);
51+
sb.append("host='").append(host.getHostName()).append('\'');
52+
sb.append(", port=").append(host.getPort());
4153
sb.append('}');
4254
return sb.toString();
4355
}

elasticsearch-driver/src/main/java/org/eclipse/jnosql/communication/elasticsearch/document/ElasticsearchDocumentConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Contributors:
1212
*
1313
* Otavio Santana
14+
* Alessandro Moscatelli
1415
*/
1516
package org.eclipse.jnosql.communication.elasticsearch.document;
1617

@@ -117,7 +118,7 @@ public ElasticsearchDocumentCollectionManagerFactory get(Settings settings) {
117118

118119
final Optional<String> username = settings
119120
.get(asList(Configurations.USER.get(),
120-
ElasticsearchConfigurations.HOST.get()))
121+
ElasticsearchConfigurations.USER.get()))
121122
.map(Object::toString);
122123
final Optional<String> password = settings
123124
.get(asList(Configurations.PASSWORD.get(),

0 commit comments

Comments
 (0)