Skip to content

Commit 4f6470c

Browse files
committed
adds method to header and host
1 parent d2dee6f commit 4f6470c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ public ElasticsearchDocumentConfiguration() {
6565
.forEach(httpHosts::add);
6666
}
6767

68+
/**
69+
* Adds a host in the configuration
70+
*
71+
* @param host the host
72+
* @throws NullPointerException when host is null
73+
*/
74+
public void add(HttpHost host) {
75+
this.httpHosts.add(Objects.requireNonNull(host, "host is required"));
76+
}
77+
78+
/**
79+
* Adds a header in the configuration
80+
*
81+
* @param header the header
82+
* @throws NullPointerException when header is null
83+
*/
84+
public void add(Header header) {
85+
this.headers.add(Objects.requireNonNull(header, "header is required"));
86+
}
87+
6888

6989
@Override
7090
public ElasticsearchDocumentCollectionManagerFactory get() throws UnsupportedOperationException {
@@ -86,6 +106,7 @@ public ElasticsearchDocumentCollectionManagerFactory get(Settings settings) thro
86106
.forEach(httpHosts::add);
87107

88108
RestClientBuilder builder = RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()]));
109+
builder.setDefaultHeaders(headers.stream().toArray(Header[]::new));
89110
RestHighLevelClient client = new RestHighLevelClient(builder);
90111
return new ElasticsearchDocumentCollectionManagerFactory(client);
91112
}
@@ -129,5 +150,4 @@ public ElasticsearchDocumentCollectionManagerFactory get(RestHighLevelClient cli
129150
}
130151

131152

132-
133153
}

0 commit comments

Comments
 (0)