Skip to content

Allow lib user to change ssl factory #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

strokyl
Copy link
Contributor

@strokyl strokyl commented Feb 16, 2024

We wanted to inject a factory from sslcontext-kickstart.
I couldn't find any other solution to fork the repo and make HttpsContextBuilder so I could extend it to override:

  • getHostnameVerifier
  • getSslContext
  • getKeyManagers
  • getTrustManagers

@Crim
Copy link
Collaborator

Crim commented Feb 16, 2024

Hey hey!

Just trying to better understand what you're trying to do. Is this a possible solution for you?

// Instead of using
client = new KafkaConnectClient(yourConfig);

// Try using
client = new KafkaConnectClient(yourConfig, new HttpClientRestClient(new MyHttpClientConfigHooks());

// where MyHttpClientConfigHooks implements the HttpClientConfigHooks interface?

@Crim
Copy link
Collaborator

Crim commented Feb 16, 2024

I guess basically, does the HttpClientConfigHooks interface support what you're trying to do?

@strokyl
Copy link
Contributor Author

strokyl commented Feb 16, 2024

Hey hey!

Just trying to better understand what you're trying to do. Is this a possible solution for you?

// Instead of using
client = new KafkaConnectClient(yourConfig);

// Try using
client = new KafkaConnectClient(yourConfig, new HttpClientRestClient(new MyHttpClientConfigHooks());

// where MyHttpClientConfigHooks implements the HttpClientConfigHooks interface?

This is what I did but the SSL parts of:

    default HttpClientBuilder createHttpClientBuilder(final Configuration configuration) {
        return HttpClientBuilder.create();
    }

aren't used in the code.
What is used by the rest client is this part of HttpClientConfigHooks:

    /**
     * Create HttpsContextBuilder instance.
     * @param configuration KafkaConnectClient configuration.
     * @return HttpsContextBuilder instance.
     */
    default HttpsContextBuilder createHttpsContextBuilder(final Configuration configuration) {
        return new HttpsContextBuilder(configuration);
    }

but since HttpsContextBuilder is package private, I can't override this method. Thefore my PR.

@Crim
Copy link
Collaborator

Crim commented Feb 16, 2024

Ah gotcha, I'm following now! Makes sense, will merge it in

@strokyl
Copy link
Contributor Author

strokyl commented Feb 16, 2024

Ah gotcha, I'm following now! Makes sense, will merge it in

If I can give some architectural recommendations I would remove SSL stuff from the HttpClientBuilder since they are never used. At least it seems to me there are never used.

@Crim
Copy link
Collaborator

Crim commented Feb 16, 2024

@Crim Crim merged commit 415bb2b into SourceLabOrg:master Feb 16, 2024
@strokyl
Copy link
Contributor Author

strokyl commented Feb 16, 2024

This bit here?

https://github.com/SourceLabOrg/kafka-connect-client/blob/master/src/main/java/org/sourcelab/kafka/connect/apiclient/rest/HttpClientRestClient.java#L140-L141

Yes it come from:

        // Create https context builder utility.
        final HttpsContextBuilder httpsContextBuilder = configHooks.createHttpsContextBuilder(configuration);

and not from:

    /**
     * Create HttpClientBuilder instance.
     * @param configuration KafkaConnectClient configuration.
     * @return HttpClientBuilder instance.
     */
    default HttpClientBuilder createHttpClientBuilder(final Configuration configuration) {
        return HttpClientBuilder.create();
    }

But i just saw that HttpClientBuilder is from an other apache library so you can't modify it.
Therefore what I would do is to entirely remove HttpsContextBuilder and use entirely HttpClientBuilder but that might not be trivial

@Crim
Copy link
Collaborator

Crim commented Feb 16, 2024

I'll try to get an updated release published here shortly.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants