3636import static com .aliyun .oss .common .parser .RequestMarshallers .setBucketVersioningRequestMarshaller ;
3737import static com .aliyun .oss .common .parser .RequestMarshallers .setBucketEncryptionRequestMarshaller ;
3838import static com .aliyun .oss .common .parser .RequestMarshallers .setBucketPolicyRequestMarshaller ;
39+ import static com .aliyun .oss .common .parser .RequestMarshallers .setBucketRequestPaymentRequestMarshaller ;
3940import static com .aliyun .oss .common .utils .CodingUtils .assertParameterNotNull ;
4041import static com .aliyun .oss .internal .OSSUtils .OSS_RESOURCE_MANAGER ;
4142import static com .aliyun .oss .internal .OSSUtils .ensureBucketNameValid ;
6566import static com .aliyun .oss .internal .ResponseParsers .getBucketImageProcessConfResponseParser ;
6667import static com .aliyun .oss .internal .ResponseParsers .getBucketEncryptionResponseParser ;
6768import static com .aliyun .oss .internal .ResponseParsers .getBucketPolicyResponseParser ;
69+ import static com .aliyun .oss .internal .ResponseParsers .getBucketRequestPaymentResponseParser ;
6870
6971import java .io .ByteArrayInputStream ;
7072import java .util .ArrayList ;
106108import com .aliyun .oss .model .GenericRequest ;
107109import com .aliyun .oss .model .GetBucketImageResult ;
108110import com .aliyun .oss .model .GetBucketReplicationProgressRequest ;
111+ import com .aliyun .oss .model .GetBucketRequestPaymentResult ;
109112import com .aliyun .oss .model .ImageProcess ;
110113import com .aliyun .oss .model .ReplicationRule ;
111114import com .aliyun .oss .model .ServerSideEncryptionConfiguration ;
116119import com .aliyun .oss .model .ListObjectsRequest ;
117120import com .aliyun .oss .model .ListVersionsRequest ;
118121import com .aliyun .oss .model .ObjectListing ;
122+ import com .aliyun .oss .model .Payer ;
119123import com .aliyun .oss .model .PutBucketImageRequest ;
120124import com .aliyun .oss .model .PutImageStyleRequest ;
121125import com .aliyun .oss .model .SetBucketAclRequest ;
124128import com .aliyun .oss .model .SetBucketLoggingRequest ;
125129import com .aliyun .oss .model .SetBucketProcessRequest ;
126130import com .aliyun .oss .model .SetBucketRefererRequest ;
131+ import com .aliyun .oss .model .SetBucketRequestPaymentRequest ;
127132import com .aliyun .oss .model .AddBucketReplicationRequest ;
128133import com .aliyun .oss .model .SetBucketStorageCapacityRequest ;
129134import com .aliyun .oss .model .SetBucketTaggingRequest ;
@@ -408,8 +413,11 @@ public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws O
408413 Map <String , String > params = new LinkedHashMap <String , String >();
409414 populateListObjectsRequestParameters (listObjectsRequest , params );
410415
416+ Map <String , String > headers = new HashMap <String , String >();
417+ populateRequestPayerHeader (headers , listObjectsRequest .getRequestPayer ());
418+
411419 RequestMessage request = new OSSRequestMessageBuilder (getInnerClient ()).setEndpoint (getEndpoint ())
412- .setMethod (HttpMethod .GET ).setBucket (bucketName ).setParameters (params )
420+ .setMethod (HttpMethod .GET ).setBucket (bucketName ).setHeaders ( headers ). setParameters (params )
413421 .setOriginalRequest (listObjectsRequest ).build ();
414422
415423 return doOperation (request , listObjectsReponseParser , bucketName , null , true );
@@ -429,8 +437,11 @@ public VersionListing listVersions(ListVersionsRequest listVersionsRequest) thro
429437 Map <String , String > params = new LinkedHashMap <String , String >();
430438 populateListVersionsRequestParameters (listVersionsRequest , params );
431439
440+ Map <String , String > headers = new HashMap <String , String >();
441+ populateRequestPayerHeader (headers , listVersionsRequest .getRequestPayer ());
442+
432443 RequestMessage request = new OSSRequestMessageBuilder (getInnerClient ()).setEndpoint (getEndpoint ())
433- .setMethod (HttpMethod .GET ).setBucket (bucketName ).setParameters (params )
444+ .setMethod (HttpMethod .GET ).setBucket (bucketName ).setHeaders ( headers ). setParameters (params )
434445 .setOriginalRequest (listVersionsRequest ).build ();
435446
436447 return doOperation (request , listVersionsReponseParser , bucketName , null , true );
@@ -1320,6 +1331,50 @@ public void deleteBucketPolicy(GenericRequest genericRequest) throws OSSExceptio
13201331 doOperation (request , emptyResponseParser , bucketName , null );
13211332 }
13221333
1334+ public void setBucketRequestPayment (SetBucketRequestPaymentRequest setBucketRequestPaymentRequest )
1335+ throws OSSException , ClientException {
1336+
1337+ assertParameterNotNull (setBucketRequestPaymentRequest , "setBucketRequestPaymentRequest" );
1338+ assertParameterNotNull (setBucketRequestPaymentRequest .getPayer (), "setBucketRequestPaymentRequest.payer" );
1339+
1340+ String bucketName = setBucketRequestPaymentRequest .getBucketName ();
1341+ assertParameterNotNull (bucketName , "bucketName" );
1342+ ensureBucketNameValid (bucketName );
1343+
1344+ Map <String , String > params = new HashMap <String , String >();
1345+ params .put (RequestParameters .SUBRESOURCE_REQUEST_PAYMENT , null );
1346+
1347+ Payer payer = setBucketRequestPaymentRequest .getPayer ();
1348+ byte [] rawContent = setBucketRequestPaymentRequestMarshaller .marshall (payer .toString ());
1349+ Map <String , String > headers = new HashMap <String , String >();
1350+ addRequestRequiredHeaders (headers , rawContent );
1351+
1352+ RequestMessage request = new OSSRequestMessageBuilder (getInnerClient ()).setEndpoint (getEndpoint ())
1353+ .setMethod (HttpMethod .PUT ).setBucket (bucketName ).setParameters (params ).setHeaders (headers )
1354+ .setInputSize (rawContent .length ).setInputStream (new ByteArrayInputStream (rawContent ))
1355+ .setOriginalRequest (setBucketRequestPaymentRequest ).build ();
1356+
1357+ doOperation (request , emptyResponseParser , bucketName , null );
1358+ }
1359+
1360+ public GetBucketRequestPaymentResult getBucketRequestPayment (GenericRequest genericRequest ) throws OSSException , ClientException {
1361+
1362+ assertParameterNotNull (genericRequest , "genericRequest" );
1363+
1364+ String bucketName = genericRequest .getBucketName ();
1365+ assertParameterNotNull (bucketName , "bucketName" );
1366+ ensureBucketNameValid (bucketName );
1367+
1368+ Map <String , String > params = new HashMap <String , String >();
1369+ params .put (RequestParameters .SUBRESOURCE_REQUEST_PAYMENT , null );
1370+
1371+ RequestMessage request = new OSSRequestMessageBuilder (getInnerClient ()).setEndpoint (getEndpoint ())
1372+ .setMethod (HttpMethod .GET ).setBucket (bucketName ).setParameters (params )
1373+ .setOriginalRequest (genericRequest ).build ();
1374+
1375+ return doOperation (request , getBucketRequestPaymentResponseParser , bucketName , null , true );
1376+ }
1377+
13231378 private static void populateListObjectsRequestParameters (ListObjectsRequest listObjectsRequest ,
13241379 Map <String , String > params ) {
13251380
@@ -1379,4 +1434,10 @@ private static void addOptionalACLHeader(Map<String, String> headers, CannedAcce
13791434 headers .put (OSSHeaders .OSS_CANNED_ACL , cannedAcl .toString ());
13801435 }
13811436 }
1437+
1438+ private static void populateRequestPayerHeader (Map <String , String > headers , Payer payer ) {
1439+ if (payer != null && payer .equals (Payer .Requester )) {
1440+ headers .put (OSSHeaders .OSS_REQUEST_PAYER , payer .toString ().toLowerCase ());
1441+ }
1442+ }
13821443}
0 commit comments