Andrea Cosentino created CAMEL-26343:
----------------------------------------

             Summary: camel-aws - set the AWS SDK HTTP client explicitly 
instead of the classpath lookup
                 Key: CAMEL-26343
                 URL: https://issues.apache.org/jira/browse/CAMEL-26343
             Project: Camel
          Issue Type: Bug
          Components: camel-aws2
            Reporter: Andrea Cosentino
             Fix For: 4.24.0, 4.22.3


Since CAMEL-23866 (4.22.0) the camel-aws components use the AWS SDK 
{{apache5-client}} instead of {{apache-client}}. {{AwsClientBuilderUtil}} sets 
an HTTP client on the SDK client builder only when a proxy or 
{{trustAllCertificates}} is configured. Otherwise the AWS SDK picks one with 
{{ServiceLoader}}: {{ClasspathSdkHttpServiceProvider}} loads every registered 
{{SdkHttpService}} and then ranks them, so one registration that cannot be 
loaded fails the whole lookup, even though the {{Apache5SdkHttpService}} that 
Camel ships is there.

This happens under Kafka Connect plugin isolation. With Camel Kafka Connector 
4.22.0 on {{confluentinc/cp-kafka-connect:8.2.4}}, the worker classpath has its 
own AWS SDK 2.29.39 with the classic {{apache-client}}. The plugin class loader 
also returns the worker's {{META-INF/services}} files, and 
{{ApacheSdkHttpService}}, which the plugin no longer ships, is loaded from the 
worker's class loader:

{noformat}
java.util.ServiceConfigurationError: 
software.amazon.awssdk.http.SdkHttpService: 
software.amazon.awssdk.http.apache.ApacheSdkHttpService not a subtype
        at java.base/java.util.ServiceLoader.fail(Unknown Source)
        ...
        at 
software.amazon.awssdk.core.internal.http.loader.ClasspathSdkHttpServiceProvider.loadService(ClasspathSdkHttpServiceProvider.java:75)
        ...
        at 
software.amazon.awssdk.core.internal.http.loader.DefaultSdkHttpClientBuilder.buildWithDefaults(DefaultSdkHttpClientBuilder.java:42)
        ...
        at 
software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder.build(SdkDefaultClientBuilder.java:173)
        at 
org.apache.camel.component.aws.common.AwsClientBuilderUtil.buildClient(AwsClientBuilderUtil.java:131)
        at 
org.apache.camel.component.aws2.s3.client.AWS2S3ClientFactory.getS3Client(AWS2S3ClientFactory.java:38)
        at 
org.apache.camel.component.aws2.s3.AWS2S3Endpoint.doStart(AWS2S3Endpoint.java:139)
{noformat}

Every sync client built through {{AwsClientBuilderUtil}} without a proxy or 
{{trustAllCertificates}} is exposed; async clients go through the same lookup 
for {{SdkAsyncHttpService}}. Before 4.22.0 the components depended on 
{{apache-client}}, so the plugin had its own {{ApacheSdkHttpService}} and the 
worker's registration resolved to it, which hid the problem.

Proposed fix: when no HTTP client is configured, {{AwsClientBuilderUtil}} sets 
{{Apache5HttpClient.builder()}} on sync clients and 
{{NettyNioAsyncHttpClient.builder()}} on async clients. These are the 
implementations the lookup selects when it succeeds, so nothing changes for a 
working setup. When an implementation is chosen with the AWS SDK setting 
{{software.amazon.awssdk.http.service.impl}} (or 
{{software.amazon.awssdk.http.async.service.impl}}), Camel keeps leaving the 
choice to the SDK.

Reported in https://github.com/apache/camel-kafka-connector/issues/1849

_Claude Code on behalf of Andrea Cosentino_




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to