-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to specify different HTTP clients (#267)
* Ability to specify different HTTP clients * Ability to specify different HTTP clients * prevent setting both http builder and client * fixed license and style issues * added sample configuration
- Loading branch information
Showing
27 changed files
with
494 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...va/com/agorapulse/micronaut/amazon/awssdk/core/client/ApacheHttpClientBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2024 Agorapulse. | ||
* | ||
* 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 com.agorapulse.micronaut.amazon.awssdk.core.client; | ||
|
||
import io.micronaut.context.annotation.Bean; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
import software.amazon.awssdk.http.apache.ApacheHttpClient; | ||
|
||
@Factory | ||
@Requires(classes = ApacheHttpClient.class) | ||
public class ApacheHttpClientBuilderFactory { | ||
|
||
@Bean | ||
@Singleton | ||
@Named("apache") | ||
public ApacheHttpClient.Builder awsCrtHttpClientBuilder() { | ||
return ApacheHttpClient.builder(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...va/com/agorapulse/micronaut/amazon/awssdk/core/client/AwsCrtHttpClientBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2024 Agorapulse. | ||
* | ||
* 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 com.agorapulse.micronaut.amazon.awssdk.core.client; | ||
|
||
import io.micronaut.context.annotation.Bean; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient; | ||
import software.amazon.awssdk.http.crt.AwsCrtHttpClient; | ||
|
||
@Factory | ||
@Requires(classes = {AwsCrtHttpClient.class, AwsCrtAsyncHttpClient.class}) | ||
public class AwsCrtHttpClientBuilderFactory { | ||
|
||
@Bean | ||
@Singleton | ||
@Named("aws-crt") | ||
public AwsCrtAsyncHttpClient.Builder awsCrtHttpAsyncClientBuilder() { | ||
return AwsCrtAsyncHttpClient.builder(); | ||
} | ||
|
||
@Bean | ||
@Singleton | ||
@Named("aws-crt") | ||
public AwsCrtHttpClient.Builder awsCrtHttpClientBuilder() { | ||
return AwsCrtHttpClient.builder(); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...c/main/java/com/agorapulse/micronaut/amazon/awssdk/core/client/ClientBuilderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2024 Agorapulse. | ||
* | ||
* 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 com.agorapulse.micronaut.amazon.awssdk.core.client; | ||
|
||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ClientBuilderProvider { | ||
|
||
String APACHE = "apache"; | ||
String AWS_CRT = "aws-crt"; | ||
String URL_CONNECTION = "url-connection"; | ||
String NETTY = "netty"; | ||
|
||
<B extends SdkHttpClient.Builder<B>> Optional<SdkHttpClient.Builder<B>> findHttpClientBuilder(String implementation); | ||
|
||
<B extends SdkAsyncHttpClient.Builder<B>> Optional<SdkAsyncHttpClient.Builder<B>> findAsyncHttpClientBuilder(String implementation); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...java/com/agorapulse/micronaut/amazon/awssdk/core/client/DefaultClientBuilderProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2024 Agorapulse. | ||
* | ||
* 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 com.agorapulse.micronaut.amazon.awssdk.core.client; | ||
|
||
import io.micronaut.context.annotation.Bean; | ||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Bean | ||
public class DefaultClientBuilderProvider implements ClientBuilderProvider { | ||
|
||
private final Map<String, SdkHttpClient.Builder<?>> httpClientBuilders; | ||
private final Map<String, SdkAsyncHttpClient.Builder<?>> httpAsyncClientBuilders; | ||
|
||
public DefaultClientBuilderProvider(Map<String, SdkHttpClient.Builder<?>> httpClientBuilders, Map<String, SdkAsyncHttpClient.Builder<?>> httpAsyncClientBuilders) { | ||
this.httpClientBuilders = httpClientBuilders; | ||
this.httpAsyncClientBuilders = httpAsyncClientBuilders; | ||
} | ||
|
||
@Override | ||
public <B extends SdkHttpClient.Builder<B>> Optional<SdkHttpClient.Builder<B>> findHttpClientBuilder(String implementation) { | ||
return Optional.ofNullable((SdkHttpClient.Builder<B>) httpClientBuilders.get(implementation)); | ||
} | ||
|
||
@Override | ||
public <B extends SdkAsyncHttpClient.Builder<B>> Optional<SdkAsyncHttpClient.Builder<B>> findAsyncHttpClientBuilder(String implementation) { | ||
return Optional.ofNullable((SdkAsyncHttpClient.Builder<B>) httpAsyncClientBuilders.get(implementation)); | ||
} | ||
|
||
} |
Oops, something went wrong.