|
30 | 30 | import org.hibernate.search.backend.elasticsearch.client.jdk.ElasticsearchHttpClientConfigurer; |
31 | 31 | import org.hibernate.search.backend.elasticsearch.client.jdk.cfg.ClientJdkElasticsearchBackendClientSettings; |
32 | 32 | import org.hibernate.search.backend.elasticsearch.client.jdk.cfg.spi.ClientJdkElasticsearchBackendClientSpiSettings; |
33 | | -import org.hibernate.search.backend.elasticsearch.client.jdk.cfg.spi.NodeProvider; |
34 | | -import org.hibernate.search.backend.elasticsearch.client.jdk.cfg.spi.RestJdkClient; |
35 | 33 | import org.hibernate.search.backend.elasticsearch.logging.spi.ConfigurationLog; |
36 | 34 | import org.hibernate.search.engine.cfg.ConfigurationPropertySource; |
37 | 35 | import org.hibernate.search.engine.cfg.spi.ConfigurationProperty; |
|
46 | 44 |
|
47 | 45 | public class ClientJdkElasticsearchClientFactory implements ElasticsearchClientFactory { |
48 | 46 |
|
49 | | - private static final OptionalConfigurationProperty<BeanReference<? extends RestJdkClient>> CLIENT_INSTANCE = |
| 47 | + private static final OptionalConfigurationProperty<BeanReference<? extends HttpClient>> CLIENT_INSTANCE = |
50 | 48 | ConfigurationProperty.forKey( ClientJdkElasticsearchBackendClientSpiSettings.CLIENT_INSTANCE ) |
51 | | - .asBeanReference( RestJdkClient.class ) |
| 49 | + .asBeanReference( HttpClient.class ) |
52 | 50 | .build(); |
53 | 51 |
|
54 | 52 | private static final OptionalConfigurationProperty<List<String>> HOSTS = |
@@ -106,18 +104,10 @@ public ElasticsearchClientImplementor create(BeanResolver beanResolver, Configur |
106 | 104 | GsonProvider gsonProvider) { |
107 | 105 | Optional<Integer> requestTimeoutMs = REQUEST_TIMEOUT.get( propertySource ); |
108 | 106 |
|
109 | | - Optional<BeanHolder<? extends RestJdkClient>> providedRestClientHolder = CLIENT_INSTANCE.getAndMap( |
110 | | - propertySource, beanResolver::resolve ); |
111 | | - |
112 | | - BeanHolder<? extends RestJdkClient> restClientHolder; |
113 | | - if ( providedRestClientHolder.isPresent() ) { |
114 | | - restClientHolder = providedRestClientHolder.get(); |
115 | | - } |
116 | | - else { |
117 | | - NodeProvider nodeProvider = NodeProvider.fromOptionalStrings( PROTOCOL.get( propertySource ), |
118 | | - HOSTS.get( propertySource ), URIS.get( propertySource ), PATH_PREFIX.get( propertySource ) ); |
119 | | - restClientHolder = createClient( beanResolver, propertySource, threadProvider, threadNamePrefix, nodeProvider ); |
120 | | - } |
| 107 | + NodeProvider nodeProvider = NodeProvider.fromOptionalStrings( PROTOCOL.get( propertySource ), |
| 108 | + HOSTS.get( propertySource ), URIS.get( propertySource ), PATH_PREFIX.get( propertySource ) ); |
| 109 | + BeanHolder<? extends RestJdkClient> restClientHolder = |
| 110 | + createClient( beanResolver, propertySource, threadProvider, threadNamePrefix, nodeProvider ); |
121 | 111 |
|
122 | 112 | return new ClientJdkElasticsearchClient( |
123 | 113 | restClientHolder, timeoutExecutorService, requestTimeoutMs, |
@@ -149,6 +139,12 @@ private static List<HttpRequestInterceptor> createRequestInterceptors(BeanResolv |
149 | 139 | private BeanHolder<? extends RestJdkClient> createClient(BeanResolver beanResolver, |
150 | 140 | ConfigurationPropertySource propertySource, |
151 | 141 | ThreadProvider threadProvider, String threadNamePrefix, NodeProvider nodeProvider) { |
| 142 | + Optional<BeanHolder<? extends HttpClient>> providedHttpClientHolder = CLIENT_INSTANCE.getAndMap( |
| 143 | + propertySource, beanResolver::resolve ); |
| 144 | + if ( providedHttpClientHolder.isPresent() ) { |
| 145 | + return BeanHolder.ofCloseable( new RestJdkClient( nodeProvider, providedHttpClientHolder.get().get() ) ); |
| 146 | + } |
| 147 | + |
152 | 148 | HttpClient.Builder builder = HttpClient.newBuilder() |
153 | 149 | // NOTE: ES does not work ok with HTTP 2 if we don't send the content length and that can happen so let's stick to 1.1 for now ? |
154 | 150 | // (we end up with Caused by: java.io.IOException: Received RST_STREAM: Stream cancelled) |
|
0 commit comments