Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws-sdk-v2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
compileOnly(libs.awssdk.url.connection.client)
compileOnly(libs.awssdk.netty.nio.client)
compileOnly(libs.awssdk.apache.client)
compileOnly(libs.awssdk.aws.crt.client)

// Services
compileOnly(libs.awssdk.apigatewaymanagementapi)
Expand All @@ -34,6 +35,7 @@ dependencies {
testImplementation(libs.awssdk.url.connection.client)
testImplementation(libs.awssdk.netty.nio.client)
testImplementation(libs.awssdk.apache.client)
testImplementation(libs.awssdk.aws.crt.client)
testImplementation(libs.awssdk.s3)
testImplementation(libs.awssdk.dynamodb)
testImplementation(libs.awssdk.ses)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.aws.sdk.v2.client.crt;

import io.micronaut.aws.AWSConfiguration;
import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.ConfigurationBuilder;
import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.core.annotation.NonNull;
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
import software.amazon.awssdk.http.crt.AwsCrtHttpClient;
import software.amazon.awssdk.http.crt.ProxyConfiguration;

/**
* Configuration properties for the CRT HTTP client.
*
* @author Luis Duarte
* @since 4.12.x
*/
@ConfigurationProperties(AwsCrtClientConfiguration.PREFIX)
@BootstrapContextCompatible
public class AwsCrtClientConfiguration extends AWSConfiguration {

public static final String PREFIX = "crt-client";

@ConfigurationBuilder(prefixes = {""}, excludes = {"proxyConfiguration", "buildWithDefaults", "applyMutation"})
private AwsCrtHttpClient.Builder sync = AwsCrtHttpClient.builder();

@ConfigurationBuilder(prefixes = {""}, excludes = {"proxyConfiguration", "buildWithDefaults", "applyMutation"})
private AwsCrtAsyncHttpClient.Builder async = AwsCrtAsyncHttpClient.builder();

@ConfigurationBuilder(configurationPrefix = "proxy", prefixes = {""}, excludes = {"applyMutation", "copy"})
private ProxyConfiguration.Builder proxy = ProxyConfiguration.builder();

/**
*
* @return AWS CRT HTTP Client builder
*/
@NonNull
public AwsCrtHttpClient.Builder getSync() {
return sync;
}

/**
*
* @return AWS CRT Async HTTP Client builder
*/
@NonNull
public AwsCrtAsyncHttpClient.Builder getAsync() {
return async;
}

/**
* @return The builder for {@link ProxyConfiguration}
*/
public ProxyConfiguration.Builder getProxy() {
return proxy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2017-2025 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.aws.sdk.v2.client.crt;

import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Prototype;
import io.micronaut.context.annotation.Requires;
import io.micronaut.core.annotation.Internal;
import jakarta.inject.Singleton;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
import software.amazon.awssdk.http.crt.AwsCrtHttpClient;
import software.amazon.awssdk.http.crt.ProxyConfiguration;

import static io.micronaut.aws.sdk.v2.client.netty.NettyClientFactory.ASYNC_SERVICE_IMPL;
import static io.micronaut.aws.sdk.v2.client.urlConnection.UrlConnectionClientFactory.HTTP_SERVICE_IMPL;

/**
* @since 4.12.0
*/
@Factory
@BootstrapContextCompatible
@Internal
class AwsCrtClientFactory {
public static final String AWS_CRT_SDK_HTTP_SERVICE = "software.amazon.awssdk.http.crt.AwsCrtSdkHttpService";

@Prototype
ProxyConfiguration.Builder createProxyBuilder(AwsCrtClientConfiguration configuration) {
return ProxyConfiguration.builder();
}

@Prototype
ProxyConfiguration createProxyConfiguration(ProxyConfiguration.Builder builder) {
return builder.build();
}

/**
*
* @param proxyConfiguration Proxy Configuration
* @param awsCrtClientConfiguration AWS CRT Client Configuration
* @return AWS CRT HTTP Client Builder
*/
@Prototype
AwsCrtHttpClient.Builder createAwsCrtHttpClientBuilder(ProxyConfiguration proxyConfiguration,
AwsCrtClientConfiguration awsCrtClientConfiguration) {
AwsCrtHttpClient.Builder builder = awsCrtClientConfiguration.getSync();
if (isProxyConfigured(proxyConfiguration)) {
builder.proxyConfiguration(proxyConfiguration);
}
return builder;
}

/**
* @param awsCrtHttpClientBuilder AWS CRT HTTP Client Builder
* @return an instance of {@link SdkAsyncHttpClient}
*/
@Bean(preDestroy = "close")
@Singleton
@Requires(property = HTTP_SERVICE_IMPL, value = AWS_CRT_SDK_HTTP_SERVICE)
public SdkHttpClient systemPropertySdkHttpClient(AwsCrtHttpClient.Builder awsCrtHttpClientBuilder) {
return awsCrtHttpClientBuilder.build();
}

/**
*
* @param proxyConfiguration Proxy Configuration
* @param awsCrtClientConfiguration AWS CRT Client Configuration
* @return AWS CRT Async HTTP Client Builder
*/
@Prototype
AwsCrtAsyncHttpClient.Builder createAwsCrtAsyncHttpClientBuilder(ProxyConfiguration proxyConfiguration,
AwsCrtClientConfiguration awsCrtClientConfiguration) {
AwsCrtAsyncHttpClient.Builder builder = awsCrtClientConfiguration.getAsync();
if (isProxyConfigured(proxyConfiguration)) {
builder.proxyConfiguration(proxyConfiguration);
}
return builder;
}

/**
* @param awsCrtAsyncHttpClientBuilder AWS CRT Async HTTP Client Builder
* @return an instance of {@link SdkAsyncHttpClient}
*/
@Bean(preDestroy = "close")
@Singleton
@Requires(property = ASYNC_SERVICE_IMPL, value = AWS_CRT_SDK_HTTP_SERVICE)
public SdkAsyncHttpClient systemPropertySdkAsyncHttpClient(AwsCrtAsyncHttpClient.Builder awsCrtAsyncHttpClientBuilder) {
return awsCrtAsyncHttpClientBuilder.build();
}

private static boolean isProxyConfigured(ProxyConfiguration proxyConfiguration) {
return proxyConfiguration.host() != null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* AWS CRT client configuration and factory.
*
* @author Luis Duarte
* @since 4.12.x
*/
@Requires(classes = { AwsCrtHttpClient.class })
@Configuration
package io.micronaut.aws.sdk.v2.client.crt;

import io.micronaut.context.annotation.Configuration;
import io.micronaut.context.annotation.Requires;
import software.amazon.awssdk.http.crt.AwsCrtHttpClient;
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ProxyConfiguration.Builder getProxy() {
return proxy;
}

boolean isProxyConfigured() {
final boolean isProxyConfigured() {
ProxyConfiguration proxyConfig = proxy.build();
return proxyConfig.host() != null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.micronaut.aws.sdk.v2.client.crt

import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.BootstrapContextCompatible
import spock.lang.Specification

class AwsCrtClientConfigurationSpec extends Specification {

void 'AwsCrtClientConfiguration is annotated with BootstrapContextCompatible'() {
given:
ApplicationContext context = ApplicationContext.run()

expect:
context.getBeanDefinition(AwsCrtClientConfiguration).getAnnotationNameByStereotype(BootstrapContextCompatible).isPresent()

cleanup:
context.close()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.micronaut.aws.sdk.v2.client.crt

import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.BootstrapContextCompatible
import spock.lang.Specification

class AwsCrtClientFactorySpec extends Specification {

void 'AwsCrtClientFactory is annotated with BootstrapContextCompatible'() {
given:
ApplicationContext context = ApplicationContext.run()

expect:
context.getBeanDefinition(AwsCrtClientFactory).getAnnotationNameByStereotype(BootstrapContextCompatible).isPresent()

cleanup:
context.close()
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ awssdk-sqs = { module = 'software.amazon.awssdk:sqs' }
awssdk-ssm = { module = 'software.amazon.awssdk:ssm' }
awssdk-iam = { module = 'software.amazon.awssdk:iam' }
awssdk-url-connection-client = { module = 'software.amazon.awssdk:url-connection-client' }
awssdk-aws-crt-client = { module = 'software.amazon.awssdk:aws-crt-client' }

kotlin-stdlib-jdk8 = { module = 'org.jetbrains.kotlin:kotlin-stdlib-jdk8', version.ref = 'kotlin' }

Expand Down
5 changes: 5 additions & 0 deletions src/main/docs/guide/sdkv2/sdkHttpClient/awsCrtClient.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/http-configuration-crt.html[AWS CRT Client] can be configured with the following options:

include::{includedir}configurationProperties/software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient$Builder.adoc[]

include::{includedir}configurationProperties/software.amazon.awssdk.http.crt.ProxyConfiguration$Builder.adoc[]
3 changes: 3 additions & 0 deletions src/main/docs/guide/sdkv2/sdkHttpClient/urlConnection.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ following JVM system properties:
* `software.amazon.awssdk.http.service.impl`. Possible values:
** `software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService` for the `URLConnection` based client.
** `software.amazon.awssdk.http.apache.ApacheSdkHttpService` for the Apache HTTP client (if in the classpath).
** `software.amazon.awssdk.http.crt.AwsCrtSdkHttpService` for the <<awsCrtClient, AWS CRT client>>.

* `software.amazon.awssdk.http.async.service.impl`. Possible values:
** `software.amazon.awssdk.http.nio.netty.NettySdkAsyncHttpService` for the Netty client (if in the classpath).
** `software.amazon.awssdk.http.crt.AwsCrtSdkHttpService` for the <<awsCrtClient, AWS Async CRT client>>.
1 change: 1 addition & 0 deletions src/main/docs/guide/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sdkv2:
urlConnection: URLConnection client
apacheHttpClient: Apache HTTP client
nettyClient: Netty client
awsCrtClient: AWS CRT client
awsCredentials: Supplying AWS credentials
awsRegionSelection: AWS region selection
endpointoverride: Endpoint override
Expand Down
Loading