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

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 :

         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?

Here is what I'm doing:

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"

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

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

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

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

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

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

Ok, thank you for the useful advice

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