# Java Rest client builder method throwing error for using HttpClientConfigCallback() method

**URL:** <https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558>\
**Category:** Elasticsearch\
**Created:** [September 4, 2020, 2:28pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558 "2020-09-04T14:28:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [September 4, 2020, 2:28pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/1 "2020-09-04T14:28:12Z")

</div>

I am trying to set up an Elasticsearch high level rest client to connect with an already set up ES cluster via Http Host setup and regular credential authentication. I am setting this up to ingest data from my local system to the central cluster, periodically. My code snippet for that looks something like the following :

```auto
         final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
        RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, "https"))
            .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                @Override
                public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                    return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                }
            });

```

Howver, I seem to be facing the Error : "Class anonymous class derived from HttpClientConfigCallback() must be declared abstract or implement abstract method customizeHttpClient(HttpAsyncClientBuilder) in HttpClientConfigCallback" and also an error on the @Override method following it, stating "Method does not override method from it's superclass".

This is the same snippet provided in the Elastic official page for implementing Basic Authentication.  
Can anyone tell me how should I implement that abstract method or do I need to import anything else?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 4, 2020, 2:56pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/2 "2020-09-04T14:56:55Z")

</div>

Here is what I'm doing:

> <https://github.com/dadoonet/legacy-search/blob/a709936d294aa5df46d62f466e9f32454dbc94ab/src/main/java/fr/pilato/demo/legacysearch/dao/ElasticsearchDao.java#L65-L69>

---

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [September 4, 2020, 3:17pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/3 "2020-09-04T15:17:01Z")

</div>

I tried this snippet now.  
It shows "cannot resolve method HttpClientConfigCallback()" and also same for .setDefaultCredentialsProvider

Am I missing some JAR files or libraries?  
I am importing "org.apache.http.client.CredentialsProvider"

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 4, 2020, 4:00pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/4 "2020-09-04T16:00:48Z")

</div>

I guess a dependency issue. Checkout the project and branch I shared and try it.  
That could help you finding the problem.

---

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [September 4, 2020, 9:04pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/5 "2020-09-04T21:04:24Z")

</div>

Yes I tried out your version. It's working, but mine still has the issue. Will figure it out. Thanks

---

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [September 5, 2020, 8:02am UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/6 "2020-09-05T08:02:42Z")

</div>

Hi @dadoonet, just one last question. Can I initialize my client with Transport client and then execute the other functionalities similarly like the high level rest client? Because I found initializing Transport client doesn't need additional dependencies

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 5, 2020, 9:04am UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/7 "2020-09-05T09:04:15Z")

</div>

The TransportClient is deprecated and will be removed. Don't use it.

---

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [September 5, 2020, 11:10am UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/8 "2020-09-05T11:10:35Z")

</div>

Oh ok. So if I have further dependency issues, would you suggest me to use it as a Maven project rather than a Java project, or will it be the other way? Because currently I am using it inside a plain Java project

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 5, 2020, 12:13pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/9 "2020-09-05T12:13:42Z")

</div>

If you are not using maven or gradle or any dependency manager, then it will be hard IMO.

---

<div class="post-metadata">

**Author:** ![soumrock123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumrock123/32/41473_2.png) [@soumrock123](https://discuss.elastic.co/u/soumrock123)\
**Post date:** [September 5, 2020, 1:11pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/10 "2020-09-05T13:11:14Z")

</div>

Ok, thank you for the useful advice

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 3, 2020, 1:11pm UTC](https://discuss.elastic.co/t/java-rest-client-builder-method-throwing-error-for-using-httpclientconfigcallback-method/247558/11 "2020-10-03T13:11:22Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
