From 7a2b1f1e5a9005d706cb475b288c48bd4119695e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Cobi=C3=A1n?= Date: Thu, 23 Jan 2025 14:01:42 +0100 Subject: [PATCH] Switch from Async to Synchronous S3 client --- adapters/klab.ogc/pom.xml | 8 ++++---- .../integratedmodelling/klab/stac/STACEncoder.java | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/adapters/klab.ogc/pom.xml b/adapters/klab.ogc/pom.xml index 17e7a65f6..510b3f1d5 100644 --- a/adapters/klab.ogc/pom.xml +++ b/adapters/klab.ogc/pom.xml @@ -64,10 +64,10 @@ - software.amazon.awssdk - netty-nio-client - ${aws.version} - + apache-client + software.amazon.awssdk + ${aws.version} + commons-logging commons-logging diff --git a/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/stac/STACEncoder.java b/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/stac/STACEncoder.java index 6e1e1af10..091175737 100644 --- a/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/stac/STACEncoder.java +++ b/adapters/klab.ogc/src/main/java/org/integratedmodelling/klab/stac/STACEncoder.java @@ -56,13 +56,14 @@ import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; +import kong.unirest.apache.ApacheClient; import kong.unirest.json.JSONObject; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.AwsCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; -import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; +import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.s3.S3AsyncClient; +import software.amazon.awssdk.services.s3.S3Client; public class STACEncoder implements IResourceEncoder { @@ -162,7 +163,7 @@ private void sortByDate(List items, IMonitor monitor) { "Ordered STAC items. First: [" + items.get(0).getTimestamp() + "]; Last [" + items.get(items.size() - 1).getTimestamp() + "]"); } - private S3AsyncClient buildS3Client(String bucketRegion) throws IOException { + private S3Client buildS3Client(String bucketRegion) throws IOException { ExternalAuthenticationCredentials awsCredentials = Authentication.INSTANCE.getCredentials(S3URLUtils.AWS_ENDPOINT); AwsCredentials credentials = null; try { @@ -170,8 +171,8 @@ private S3AsyncClient buildS3Client(String bucketRegion) throws IOException { } catch (Exception e) { throw new KlabIOException("Error defining AWS credenetials. " + e.getMessage()); } - return S3AsyncClient.builder() - .httpClient(NettyNioAsyncHttpClient.builder().build()) + return S3Client.builder() + .httpClientBuilder(ApacheHttpClient.builder()) .region(Region.of(bucketRegion)) .credentialsProvider(StaticCredentialsProvider.create(credentials)) .build(); @@ -275,8 +276,7 @@ public void getEncodedData(IResource resource, Map urnParameters if (resource.getParameters().contains("s3BucketRegion")) { String bucketRegion = resource.getParameters().get("s3BucketRegion", String.class); - S3AsyncClient s3Client = buildS3Client(bucketRegion); - // TODO waiting until the library version is updated + S3Client s3Client = buildS3Client(bucketRegion); collection.setS3Client(s3Client); }