use of software.amazon.awssdk.crt.s3.S3Client in project DataSpaceConnector by eclipse-dataspaceconnector.
the class S3BucketWriter method write.
@Override
public Result<Void> write(DataAddress destination, String name, InputStream data, String secretToken) {
var bucketName = destination.getProperty(S3BucketSchema.BUCKET_NAME);
var region = destination.getProperty(S3BucketSchema.REGION);
var awsSecretToken = typeManager.readValue(secretToken, AwsTemporarySecretToken.class);
try (S3Client s3 = S3Client.builder().credentialsProvider(buildCredentialsProvider(awsSecretToken)).region(Region.of(region)).build()) {
PutObjectRequest request = createRequest(bucketName, name);
PutObjectRequest completionMarker = createRequest(bucketName, name + ".complete");
monitor.debug("Data request: begin transfer...");
Failsafe.with(retryPolicy).get(() -> s3.putObject(request, RequestBody.fromBytes(data.readAllBytes())));
Failsafe.with(retryPolicy).get(() -> s3.putObject(completionMarker, RequestBody.empty()));
monitor.debug("Data request done.");
return Result.success();
} catch (S3Exception ex) {
monitor.severe("Data request: transfer failed!");
return Result.failure("Data transfer failed");
}
}
use of software.amazon.awssdk.crt.s3.S3Client in project spring-cloud-aws by awspring.
the class CrossRegionS3ClientGenerator method addOverriddenMethods.
private static void addOverriddenMethods(ClassOrInterfaceDeclaration crossRegionS3Client) {
TypeSolver typeSolver = new ClassLoaderTypeSolver(CrossRegionS3ClientGenerator.class.getClassLoader());
ResolvedReferenceTypeDeclaration resolvedReferenceTypeDeclaration = typeSolver.solveType(S3Client.class.getName());
resolvedReferenceTypeDeclaration.getAllMethods().stream().sorted(Comparator.comparing(MethodUsage::getSignature)).forEach(method -> {
if (isRegionSpecific(method) && isCanonical(method)) {
MethodDeclaration methodDeclaration = crossRegionS3Client.addMethod(method.getName(), Modifier.Keyword.PUBLIC);
// collect & create method parameters
List<String> parameterStrings = new ArrayList<>();
for (int i = 0; i < method.getParamTypes().size(); i++) {
methodDeclaration.addParameter(new Parameter(StaticJavaParser.parseClassOrInterfaceType(method.getParamTypes().get(i).describe()), "p" + i));
parameterStrings.add("p" + i);
}
// handle generic types
if (method.getDeclaration().getReturnType().isTypeVariable()) {
methodDeclaration.addTypeParameter(method.getDeclaration().getReturnType().describe());
}
methodDeclaration.setType(StaticJavaParser.parseClassOrInterfaceType(method.getDeclaration().getReturnType().describe()));
methodDeclaration.setBody(new BlockStmt().addStatement("return executeInBucketRegion(p0.bucket(), s3Client -> s3Client." + method.getName() + "(" + String.join(",", parameterStrings) + "));"));
methodDeclaration.addMarkerAnnotation(Override.class);
methodDeclaration.addThrownException(AwsServiceException.class);
methodDeclaration.addThrownException(SdkClientException.class);
}
});
}
use of software.amazon.awssdk.crt.s3.S3Client in project spring-cloud-aws by awspring.
the class DiskBufferingS3OutputStreamTests method setsMd5hash.
@Test
void setsMd5hash() throws IOException {
S3Client s3Client = mock(S3Client.class);
try (DiskBufferingS3OutputStream diskBufferingS3OutputStream = new DiskBufferingS3OutputStream(new Location("bucket", "key"), s3Client, null)) {
diskBufferingS3OutputStream.write("hello".getBytes(StandardCharsets.UTF_8));
}
ArgumentCaptor<PutObjectRequest> captor = ArgumentCaptor.forClass(PutObjectRequest.class);
verify(s3Client).putObject(captor.capture(), any(RequestBody.class));
assertThat(captor.getValue().contentMD5()).isNotNull();
}
use of software.amazon.awssdk.crt.s3.S3Client in project sis by apache.
the class ClientFileSystem method close.
/**
* Closes all channels and other closeable objects associated with the file system and releases resources.
* If the file system is already closed then invoking this method has no effect.
*/
@Override
public synchronized void close() throws IOException {
final S3Client c = client;
client = null;
if (c != null)
try {
provider.dispose(accessKey);
c.close();
} catch (SdkException e) {
throw new IOException(e);
}
}
use of software.amazon.awssdk.crt.s3.S3Client in project fluency by komamitsu.
the class AwsS3SenderTest method close.
@Test
void close() {
S3Client s3Client = mock(S3Client.class);
S3ClientBuilder s3ClientBuilder = mock(S3ClientBuilder.class);
doReturn(s3Client).when(s3ClientBuilder).build();
AwsS3Sender sender = new AwsS3Sender(s3ClientBuilder);
sender.close();
verify(s3Client, times(1)).close();
}
Aggregations