16
16
package org .springframework .data .elasticsearch .client .elc ;
17
17
18
18
import co .elastic .clients .elasticsearch .ElasticsearchClient ;
19
+ import co .elastic .clients .json .JsonpMapper ;
19
20
import co .elastic .clients .json .jackson .JacksonJsonpMapper ;
20
21
import co .elastic .clients .transport .ElasticsearchTransport ;
21
22
import co .elastic .clients .transport .TransportOptions ;
24
25
import co .elastic .clients .transport .rest_client .RestClientOptions ;
25
26
import co .elastic .clients .transport .rest_client .RestClientTransport ;
26
27
27
- import java .io .ByteArrayOutputStream ;
28
- import java .io .IOException ;
29
28
import java .net .InetSocketAddress ;
30
29
import java .time .Duration ;
31
30
import java .util .Arrays ;
@@ -60,11 +59,12 @@ public final class ElasticsearchClients {
60
59
/**
61
60
* Name of whose value can be used to correlate log messages for this request.
62
61
*/
63
- private static final String LOG_ID_ATTRIBUTE = ElasticsearchClients .class .getName () + ".LOG_ID" ;
64
62
private static final String X_SPRING_DATA_ELASTICSEARCH_CLIENT = "X-SpringDataElasticsearch-Client" ;
65
63
private static final String IMPERATIVE_CLIENT = "imperative" ;
66
64
private static final String REACTIVE_CLIENT = "reactive" ;
67
65
66
+ private static final JsonpMapper DEFAULT_JSONP_MAPPER = new JacksonJsonpMapper ();
67
+
68
68
/**
69
69
* Creates a new {@link ReactiveElasticsearchClient}
70
70
*
@@ -75,7 +75,7 @@ public static ReactiveElasticsearchClient createReactive(ClientConfiguration cli
75
75
76
76
Assert .notNull (clientConfiguration , "clientConfiguration must not be null" );
77
77
78
- return createReactive (getRestClient (clientConfiguration ), null );
78
+ return createReactive (getRestClient (clientConfiguration ), null , DEFAULT_JSONP_MAPPER );
79
79
}
80
80
81
81
/**
@@ -90,7 +90,24 @@ public static ReactiveElasticsearchClient createReactive(ClientConfiguration cli
90
90
91
91
Assert .notNull (clientConfiguration , "ClientConfiguration must not be null!" );
92
92
93
- return createReactive (getRestClient (clientConfiguration ), transportOptions );
93
+ return createReactive (getRestClient (clientConfiguration ), transportOptions , DEFAULT_JSONP_MAPPER );
94
+ }
95
+
96
+ /**
97
+ * Creates a new {@link ReactiveElasticsearchClient}
98
+ *
99
+ * @param clientConfiguration configuration options, must not be {@literal null}.
100
+ * @param transportOptions options to be added to each request.
101
+ * @param jsonpMapper the JsonpMapper to use
102
+ * @return the {@link ReactiveElasticsearchClient}
103
+ */
104
+ public static ReactiveElasticsearchClient createReactive (ClientConfiguration clientConfiguration ,
105
+ @ Nullable TransportOptions transportOptions , JsonpMapper jsonpMapper ) {
106
+
107
+ Assert .notNull (clientConfiguration , "ClientConfiguration must not be null!" );
108
+ Assert .notNull (jsonpMapper , "jsonpMapper must not be null" );
109
+
110
+ return createReactive (getRestClient (clientConfiguration ), transportOptions , jsonpMapper );
94
111
}
95
112
96
113
/**
@@ -100,7 +117,7 @@ public static ReactiveElasticsearchClient createReactive(ClientConfiguration cli
100
117
* @return the {@link ReactiveElasticsearchClient}
101
118
*/
102
119
public static ReactiveElasticsearchClient createReactive (RestClient restClient ) {
103
- return createReactive (restClient , null );
120
+ return createReactive (restClient , null , DEFAULT_JSONP_MAPPER );
104
121
}
105
122
106
123
/**
@@ -111,8 +128,9 @@ public static ReactiveElasticsearchClient createReactive(RestClient restClient)
111
128
* @return the {@link ReactiveElasticsearchClient}
112
129
*/
113
130
public static ReactiveElasticsearchClient createReactive (RestClient restClient ,
114
- @ Nullable TransportOptions transportOptions ) {
115
- return new ReactiveElasticsearchClient (getElasticsearchTransport (restClient , REACTIVE_CLIENT , transportOptions ));
131
+ @ Nullable TransportOptions transportOptions , JsonpMapper jsonpMapper ) {
132
+ return new ReactiveElasticsearchClient (
133
+ getElasticsearchTransport (restClient , REACTIVE_CLIENT , transportOptions , jsonpMapper ));
116
134
}
117
135
118
136
/**
@@ -122,7 +140,7 @@ public static ReactiveElasticsearchClient createReactive(RestClient restClient,
122
140
* @return the {@link ElasticsearchClient}
123
141
*/
124
142
public static ElasticsearchClient createImperative (ClientConfiguration clientConfiguration ) {
125
- return createImperative (getRestClient (clientConfiguration ), null );
143
+ return createImperative (getRestClient (clientConfiguration ), null , DEFAULT_JSONP_MAPPER );
126
144
}
127
145
128
146
/**
@@ -134,7 +152,7 @@ public static ElasticsearchClient createImperative(ClientConfiguration clientCon
134
152
*/
135
153
public static ElasticsearchClient createImperative (ClientConfiguration clientConfiguration ,
136
154
TransportOptions transportOptions ) {
137
- return createImperative (getRestClient (clientConfiguration ), transportOptions );
155
+ return createImperative (getRestClient (clientConfiguration ), transportOptions , DEFAULT_JSONP_MAPPER );
138
156
}
139
157
140
158
/**
@@ -144,22 +162,24 @@ public static ElasticsearchClient createImperative(ClientConfiguration clientCon
144
162
* @return the {@link ElasticsearchClient}
145
163
*/
146
164
public static ElasticsearchClient createImperative (RestClient restClient ) {
147
- return createImperative (restClient , null );
165
+ return createImperative (restClient , null , DEFAULT_JSONP_MAPPER );
148
166
}
149
167
150
168
/**
151
169
* Creates a new imperative {@link ElasticsearchClient}
152
170
*
153
171
* @param restClient the RestClient to use
154
172
* @param transportOptions options to be added to each request.
173
+ * @param jsonpMapper the mapper for the transport to use
155
174
* @return the {@link ElasticsearchClient}
156
175
*/
157
- public static ElasticsearchClient createImperative (RestClient restClient ,
158
- @ Nullable TransportOptions transportOptions ) {
176
+ public static ElasticsearchClient createImperative (RestClient restClient , @ Nullable TransportOptions transportOptions ,
177
+ JsonpMapper jsonpMapper ) {
159
178
160
179
Assert .notNull (restClient , "restClient must not be null" );
161
180
162
- ElasticsearchTransport transport = getElasticsearchTransport (restClient , IMPERATIVE_CLIENT , transportOptions );
181
+ ElasticsearchTransport transport = getElasticsearchTransport (restClient , IMPERATIVE_CLIENT , transportOptions ,
182
+ jsonpMapper );
163
183
164
184
return new AutoCloseableElasticsearchClient (transport );
165
185
}
@@ -236,7 +256,7 @@ private static RestClientBuilder getRestClientBuilder(ClientConfiguration client
236
256
}
237
257
238
258
private static ElasticsearchTransport getElasticsearchTransport (RestClient restClient , String clientType ,
239
- @ Nullable TransportOptions transportOptions ) {
259
+ @ Nullable TransportOptions transportOptions , JsonpMapper jsonpMapper ) {
240
260
241
261
TransportOptions .Builder transportOptionsBuilder = transportOptions != null ? transportOptions .toBuilder ()
242
262
: new RestClientOptions (RequestOptions .DEFAULT ).toBuilder ();
@@ -260,7 +280,7 @@ private static ElasticsearchTransport getElasticsearchTransport(RestClient restC
260
280
TransportOptions transportOptionsWithHeader = transportOptionsBuilder
261
281
.addHeader (X_SPRING_DATA_ELASTICSEARCH_CLIENT , clientType ).build ();
262
282
263
- return new RestClientTransport (restClient , new JacksonJsonpMapper () , transportOptionsWithHeader );
283
+ return new RestClientTransport (restClient , jsonpMapper , transportOptionsWithHeader );
264
284
}
265
285
266
286
private static List <String > formattedHosts (List <InetSocketAddress > hosts , boolean useSsl ) {
0 commit comments