Skip to content

Commit

Permalink
Switch from Async to Synchronous S3 client
Browse files Browse the repository at this point in the history
  • Loading branch information
inigo-cobian committed Jan 23, 2025
1 parent 2cd3141 commit 4d59d26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions adapters/klab.ogc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
</dependency>
<!--- AWS dependencies-->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
<version>${aws.version}</version>
<exclusions>
<artifactId>apache-client</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>${aws.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -162,16 +163,16 @@ private void sortByDate(List<HMStacItem> 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 {
credentials = AwsBasicCredentials.create(awsCredentials.getCredentials().get(0), awsCredentials.getCredentials().get(1));
} 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();
Expand Down Expand Up @@ -275,8 +276,7 @@ public void getEncodedData(IResource resource, Map<String, String> 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);
}

Expand Down

0 comments on commit 4d59d26

Please sign in to comment.