5
5
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
6
6
import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
7
7
import software .amazon .awssdk .awscore .AwsRequestOverrideConfiguration ;
8
- import software .amazon .awssdk .awscore .client .builder .AwsClientBuilder ;
9
8
import software .amazon .awssdk .awscore .exception .AwsServiceException ;
10
9
import software .amazon .awssdk .core .ResponseInputStream ;
11
10
import software .amazon .awssdk .core .async .AsyncRequestBody ;
12
11
import software .amazon .awssdk .core .async .AsyncResponseTransformer ;
12
+ import software .amazon .awssdk .core .client .builder .SdkSyncClientBuilder ;
13
13
import software .amazon .awssdk .core .client .config .ClientOverrideConfiguration ;
14
14
import software .amazon .awssdk .core .exception .SdkClientException ;
15
15
import software .amazon .awssdk .core .interceptor .ExecutionAttribute ;
16
16
import software .amazon .awssdk .core .sync .RequestBody ;
17
17
import software .amazon .awssdk .core .sync .ResponseTransformer ;
18
18
import software .amazon .awssdk .endpoints .EndpointProvider ;
19
19
import software .amazon .awssdk .http .AbortableInputStream ;
20
+ import software .amazon .awssdk .http .SdkHttpClient ;
21
+ import software .amazon .awssdk .http .async .SdkAsyncHttpClient ;
20
22
import software .amazon .awssdk .regions .Region ;
21
23
import software .amazon .awssdk .services .kms .KmsClient ;
22
24
import software .amazon .awssdk .services .s3 .DelegatingS3Client ;
23
25
import software .amazon .awssdk .services .s3 .S3AsyncClient ;
26
+ import software .amazon .awssdk .services .s3 .S3BaseClientBuilder ;
24
27
import software .amazon .awssdk .services .s3 .S3Client ;
28
+ import software .amazon .awssdk .services .s3 .S3Configuration ;
25
29
import software .amazon .awssdk .services .s3 .model .AbortMultipartUploadRequest ;
26
30
import software .amazon .awssdk .services .s3 .model .AbortMultipartUploadResponse ;
27
31
import software .amazon .awssdk .services .s3 .model .CompleteMultipartUploadRequest ;
65
69
import java .util .ArrayList ;
66
70
import java .util .List ;
67
71
import java .util .Map ;
72
+ import java .util .Optional ;
68
73
import java .util .concurrent .CompletableFuture ;
69
74
import java .util .concurrent .CompletionException ;
70
75
import java .util .concurrent .ExecutionException ;
@@ -507,9 +512,9 @@ public void close() {
507
512
_wrappedAsyncClient .close ();
508
513
}
509
514
510
- // This is very similar to the S3EncryptionClient builder
515
+ // This is very similar to the S3AsyncEncryptionClient builder
511
516
// Make sure to keep both clients in mind when adding new builder options
512
- public static class Builder implements AwsClientBuilder {
517
+ public static class Builder implements S3BaseClientBuilder < Builder , S3EncryptionClient >, SdkSyncClientBuilder < Builder , S3EncryptionClient > {
513
518
// The non-encrypted APIs will use a default client.
514
519
private S3Client _wrappedClient ;
515
520
private S3AsyncClient _wrappedAsyncClient ;
@@ -536,6 +541,15 @@ public static class Builder implements AwsClientBuilder {
536
541
private ClientOverrideConfiguration _overrideConfiguration = null ;
537
542
// this should only be applied to S3 clients
538
543
private URI _endpointOverride = null ;
544
+ private S3Configuration _serviceConfiguration = null ;
545
+ private Boolean _accelerate = null ;
546
+ private Boolean _disableMultiRegionAccessPoints = null ;
547
+ private Boolean _forcePathStyle = null ;
548
+ private Boolean _useArnRegion = null ;
549
+ private SdkHttpClient _httpClient = null ;
550
+ private SdkHttpClient .Builder _httpClientBuilder = null ;
551
+ private SdkAsyncHttpClient _asyncHttpClient = null ;
552
+ private SdkAsyncHttpClient .Builder _asyncHttpClientBuilder = null ;
539
553
540
554
private Builder () {
541
555
}
@@ -811,7 +825,7 @@ public Builder region(Region region) {
811
825
*/
812
826
@ Override
813
827
public Builder dualstackEnabled (Boolean isDualStackEnabled ) {
814
- _dualStackEnabled = isDualStackEnabled ;
828
+ _dualStackEnabled = Optional . ofNullable ( isDualStackEnabled ). orElse ( Boolean . FALSE ) ;
815
829
return this ;
816
830
}
817
831
@@ -833,7 +847,7 @@ public Builder dualstackEnabled(Boolean isDualStackEnabled) {
833
847
*/
834
848
@ Override
835
849
public Builder fipsEnabled (Boolean isFipsEnabled ) {
836
- _fipsEnabled = isFipsEnabled ;
850
+ _fipsEnabled = Optional . ofNullable ( isFipsEnabled ). orElse ( Boolean . FALSE ) ;
837
851
return this ;
838
852
}
839
853
@@ -876,6 +890,135 @@ public Builder endpointOverride(URI endpointOverride) {
876
890
return this ;
877
891
}
878
892
893
+ @ Override
894
+ public Builder serviceConfiguration (S3Configuration serviceConfiguration ) {
895
+ _serviceConfiguration = serviceConfiguration ;
896
+ return this ;
897
+ }
898
+
899
+ /**
900
+ * Enables this client to use S3 Transfer Acceleration endpoints.
901
+ *
902
+ * @param accelerate
903
+ */
904
+ @ Override
905
+ public Builder accelerate (Boolean accelerate ) {
906
+ _accelerate = accelerate ;
907
+ return this ;
908
+ }
909
+
910
+ /**
911
+ * Disables this client's usage of Multi-Region Access Points.
912
+ *
913
+ * @param disableMultiRegionAccessPoints
914
+ */
915
+ @ Override
916
+ public Builder disableMultiRegionAccessPoints (Boolean disableMultiRegionAccessPoints ) {
917
+ _disableMultiRegionAccessPoints = disableMultiRegionAccessPoints ;
918
+ return this ;
919
+ }
920
+
921
+ /**
922
+ * Forces this client to use path-style addressing for buckets.
923
+ *
924
+ * @param forcePathStyle
925
+ */
926
+ @ Override
927
+ public Builder forcePathStyle (Boolean forcePathStyle ) {
928
+ _forcePathStyle = forcePathStyle ;
929
+ return this ;
930
+ }
931
+
932
+ /**
933
+ * Enables this client to use an ARN's region when constructing an endpoint instead of the client's configured
934
+ * region.
935
+ *
936
+ * @param useArnRegion
937
+ */
938
+ @ Override
939
+ public Builder useArnRegion (Boolean useArnRegion ) {
940
+ _useArnRegion = useArnRegion ;
941
+ return this ;
942
+ }
943
+
944
+ /**
945
+ * Sets the {@link SdkHttpClient} that the SDK service client will use to make HTTP calls. This HTTP client may be
946
+ * shared between multiple SDK service clients to share a common connection pool. To create a client you must use an
947
+ * implementation-specific builder. Note that this method is only recommended when you wish to share an HTTP client across
948
+ * multiple SDK service clients. If you do not wish to share HTTP clients, it is recommended to use
949
+ * {@link #httpClientBuilder(SdkHttpClient.Builder)} so that service-specific default configuration may be applied.
950
+ *
951
+ * <p>
952
+ * <b>This client must be closed by the user when it is ready to be disposed. The SDK will not close the HTTP client
953
+ * when the service client is closed.</b>
954
+ * </p>
955
+ *
956
+ * @param httpClient
957
+ */
958
+ @ Override
959
+ public Builder httpClient (SdkHttpClient httpClient ) {
960
+ _httpClient = httpClient ;
961
+ return this ;
962
+ }
963
+
964
+ /**
965
+ * Sets a {@link SdkHttpClient.Builder} that will be used to obtain a configured instance of {@link SdkHttpClient}. Any
966
+ * service-specific HTTP configuration will be merged with the builder's configuration prior to creating the client. When
967
+ * there is no desire to share HTTP clients across multiple service clients, the client builder is the preferred way to
968
+ * customize the HTTP client as it benefits from service-specific default configuration.
969
+ *
970
+ * <p>
971
+ * <b>Clients created by the builder are managed by the SDK and will be closed when the service client is closed.</b>
972
+ * </p>
973
+ *
974
+ * @param httpClientBuilder
975
+ */
976
+ @ Override
977
+ public Builder httpClientBuilder (SdkHttpClient .Builder httpClientBuilder ) {
978
+ _httpClientBuilder = httpClientBuilder ;
979
+ return this ;
980
+ }
981
+
982
+ /**
983
+ * Sets the {@link SdkAsyncHttpClient} that the SDK service client will use to make HTTP calls. This HTTP client may be
984
+ * shared between multiple SDK service clients to share a common connection pool. To create a client you must use an
985
+ * implementation specific builder. Note that this method is only recommended when you wish to share an HTTP client across
986
+ * multiple SDK service clients. If you do not wish to share HTTP clients, it is recommended to use
987
+ * {@link #asyncHttpClientBuilder(SdkAsyncHttpClient.Builder)} so that service specific default configuration may be applied.
988
+ * In the S3 Encryption Client, this configuration is applied to the inner async client.
989
+ *
990
+ * <p>
991
+ * <b>This client must be closed by the caller when it is ready to be disposed. The SDK will not close the HTTP client
992
+ * when the service client is closed.</b>
993
+ * </p>
994
+ *
995
+ * @param asyncHttpClient
996
+ * @return This builder for method chaining.
997
+ */
998
+ public Builder asyncHttpClient (SdkAsyncHttpClient asyncHttpClient ) {
999
+ _asyncHttpClient = asyncHttpClient ;
1000
+ return this ;
1001
+ }
1002
+
1003
+ /**
1004
+ * Sets a custom HTTP client builder that will be used to obtain a configured instance of {@link SdkAsyncHttpClient}. Any
1005
+ * service specific HTTP configuration will be merged with the builder's configuration prior to creating the client. When
1006
+ * there is no desire to share HTTP clients across multiple service clients, the client builder is the preferred way to
1007
+ * customize the HTTP client as it benefits from service specific defaults.
1008
+ * In the S3 Encryption Client, this configuration is applied to the inner async client.
1009
+ *
1010
+ * <p>
1011
+ * <b>Clients created by the builder are managed by the SDK and will be closed when the service client is closed.</b>
1012
+ * </p>
1013
+ *
1014
+ * @param asyncHttpClientBuilder
1015
+ * @return This builder for method chaining.
1016
+ */
1017
+ public Builder asyncHttpClientBuilder (SdkAsyncHttpClient .Builder asyncHttpClientBuilder ) {
1018
+ _asyncHttpClientBuilder = asyncHttpClientBuilder ;
1019
+ return this ;
1020
+ }
1021
+
879
1022
/**
880
1023
* Validates and builds the S3EncryptionClient according
881
1024
* to the configuration options passed to the Builder object.
@@ -902,6 +1045,13 @@ public S3EncryptionClient build() {
902
1045
.fipsEnabled (_fipsEnabled )
903
1046
.overrideConfiguration (_overrideConfiguration )
904
1047
.endpointOverride (_endpointOverride )
1048
+ .serviceConfiguration (_serviceConfiguration )
1049
+ .accelerate (_accelerate )
1050
+ .disableMultiRegionAccessPoints (_disableMultiRegionAccessPoints )
1051
+ .forcePathStyle (_forcePathStyle )
1052
+ .useArnRegion (_useArnRegion )
1053
+ .httpClient (_httpClient )
1054
+ .httpClientBuilder (_httpClientBuilder )
905
1055
.build ();
906
1056
}
907
1057
@@ -913,6 +1063,13 @@ public S3EncryptionClient build() {
913
1063
.fipsEnabled (_fipsEnabled )
914
1064
.overrideConfiguration (_overrideConfiguration )
915
1065
.endpointOverride (_endpointOverride )
1066
+ .serviceConfiguration (_serviceConfiguration )
1067
+ .accelerate (_accelerate )
1068
+ .disableMultiRegionAccessPoints (_disableMultiRegionAccessPoints )
1069
+ .forcePathStyle (_forcePathStyle )
1070
+ .useArnRegion (_useArnRegion )
1071
+ .httpClient (_asyncHttpClient )
1072
+ .httpClientBuilder (_asyncHttpClientBuilder )
916
1073
.build ();
917
1074
}
918
1075
0 commit comments