3333import software .amazon .awssdk .core .exception .SdkClientException ;
3434import software .amazon .awssdk .core .exception .SdkException ;
3535import software .amazon .awssdk .core .internal .async .FileAsyncRequestBody ;
36+ import software .amazon .awssdk .services .s3 .DelegatingS3AsyncClient ;
3637import software .amazon .awssdk .services .s3 .S3AsyncClient ;
3738import software .amazon .awssdk .services .s3 .internal .multipart .MultipartS3AsyncClient ;
3839import software .amazon .awssdk .services .s3 .internal .resource .S3AccessPointResource ;
@@ -110,11 +111,11 @@ class GenericS3TransferManager implements S3TransferManager {
110111 }
111112
112113 @ SdkTestInternalApi
113- GenericS3TransferManager (S3AsyncClient s3CrtAsyncClient ,
114+ GenericS3TransferManager (S3AsyncClient s3AsyncClient ,
114115 UploadDirectoryHelper uploadDirectoryHelper ,
115116 TransferManagerConfiguration configuration ,
116117 DownloadDirectoryHelper downloadDirectoryHelper ) {
117- this .s3AsyncClient = s3CrtAsyncClient ;
118+ this .s3AsyncClient = s3AsyncClient ;
118119 this .isDefaultS3AsyncClient = false ;
119120 this .transferConfiguration = configuration ;
120121 this .uploadDirectoryHelper = uploadDirectoryHelper ;
@@ -138,13 +139,13 @@ public Upload upload(UploadRequest uploadRequest) {
138139 try {
139140 assertNotUnsupportedArn (uploadRequest .putObjectRequest ().bucket (), "upload" );
140141
141- CompletableFuture <PutObjectResponse > crtFuture =
142+ CompletableFuture <PutObjectResponse > future =
142143 s3AsyncClient .putObject (uploadRequest .putObjectRequest (), requestBody );
143144
144- // Forward upload cancellation to CRT future
145- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
145+ // Forward upload cancellation to future
146+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
146147
147- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
148+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
148149 r -> CompletedUpload .builder ()
149150 .response (r )
150151 .build ());
@@ -298,13 +299,12 @@ public <ResultT> Download<ResultT> download(DownloadRequest<ResultT> downloadReq
298299 try {
299300 assertNotUnsupportedArn (downloadRequest .getObjectRequest ().bucket (), "download" );
300301
301- CompletableFuture <ResultT > crtFuture =
302- s3AsyncClient .getObject (downloadRequest .getObjectRequest (), responseTransformer );
302+ CompletableFuture <ResultT > future = doGetObject (downloadRequest .getObjectRequest (), responseTransformer );
303303
304- // Forward download cancellation to CRT future
305- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
304+ // Forward download cancellation to future
305+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
306306
307- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
307+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
308308 r -> CompletedDownload .builder ()
309309 .result (r )
310310 .build ());
@@ -341,14 +341,12 @@ private TransferProgressUpdater doDownloadFile(
341341
342342 assertNotUnsupportedArn (downloadRequest .getObjectRequest ().bucket (), "download" );
343343
344- CompletableFuture <GetObjectResponse > crtFuture =
345- s3AsyncClient .getObject (downloadRequest .getObjectRequest (),
346- responseTransformer );
344+ CompletableFuture <GetObjectResponse > future = doGetObject (downloadRequest .getObjectRequest (), responseTransformer );
347345
348- // Forward download cancellation to CRT future
349- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
346+ // Forward download cancellation to future
347+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
350348
351- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
349+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
352350 res -> CompletedFileDownload .builder ()
353351 .response (res )
354352 .build ());
@@ -450,13 +448,13 @@ public Copy copy(CopyRequest copyRequest) {
450448 assertNotUnsupportedArn (copyRequest .copyObjectRequest ().sourceBucket (), "copy sourceBucket" );
451449 assertNotUnsupportedArn (copyRequest .copyObjectRequest ().destinationBucket (), "copy destinationBucket" );
452450
453- CompletableFuture <CopyObjectResponse > crtFuture =
451+ CompletableFuture <CopyObjectResponse > future =
454452 s3AsyncClient .copyObject (copyRequest .copyObjectRequest ());
455453
456- // Forward transfer cancellation to CRT future
457- CompletableFutureUtils .forwardExceptionTo (returnFuture , crtFuture );
454+ // Forward transfer cancellation to future
455+ CompletableFutureUtils .forwardExceptionTo (returnFuture , future );
458456
459- CompletableFutureUtils .forwardTransformedResultTo (crtFuture , returnFuture ,
457+ CompletableFutureUtils .forwardTransformedResultTo (future , returnFuture ,
460458 r -> CompletedCopy .builder ()
461459 .response (r )
462460 .build ());
@@ -511,4 +509,14 @@ private static boolean isMrapArn(Arn arn) {
511509
512510 return !s3EndpointResource .region ().isPresent ();
513511 }
512+
513+ // TODO remove once MultipartS3AsyncClient is complete
514+ private <ResultT > CompletableFuture <ResultT > doGetObject (
515+ GetObjectRequest getObjectRequest , AsyncResponseTransformer <GetObjectResponse , ResultT > asyncResponseTransformer ) {
516+ S3AsyncClient clientToUse = s3AsyncClient ;
517+ if (s3AsyncClient instanceof MultipartS3AsyncClient ) {
518+ clientToUse = (S3AsyncClient ) ((DelegatingS3AsyncClient ) s3AsyncClient ).delegate ();
519+ }
520+ return clientToUse .getObject (getObjectRequest , asyncResponseTransformer );
521+ }
514522}
0 commit comments