Skip to content

Commit 171ee09

Browse files
committed
support Put/GetBucketCnameToken api.
1 parent ba656f5 commit 171ee09

14 files changed

+682
-256
lines changed

src/main/java/com/aliyun/oss/OSS.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,39 @@ public List<String> getBucketReplicationLocation(GenericRequest genericRequest)
26702670
public VoidResult deleteBucketCname(DeleteBucketCnameRequest deleteBucketCnameRequest)
26712671
throws OSSException, ClientException;
26722672

2673+
/**
2674+
* Creates a cname token for the {@link Bucket} instance.
2675+
*
2676+
* @param createBucketCnameTokenRequest
2677+
* The request specifies the bucket name and the Cname
2678+
* information.
2679+
*
2680+
* @return A {@link CreateBucketCnameTokenResult} instance contains token
2681+
* and some basic response options, such as requestId.
2682+
*
2683+
* @throws OSSException
2684+
* OSS Server side exception.
2685+
* @throws ClientException
2686+
* OSS Client side exception.
2687+
*/
2688+
public CreateBucketCnameTokenResult createBucketCnameToken(CreateBucketCnameTokenRequest createBucketCnameTokenRequest) throws OSSException, ClientException;
2689+
2690+
/**
2691+
* Gets a cname token for the {@link Bucket} instance.
2692+
*
2693+
* @param getBucketCnameTokenRequest
2694+
* The request specifies the bucket name and the cname token.
2695+
*
2696+
* @return A {@link CreateBucketCnameTokenResult} instance contains token
2697+
* and some basic response options, such as requestId.
2698+
*
2699+
* @throws OSSException
2700+
* OSS Server side exception.
2701+
* @throws ClientException
2702+
* OSS Client side exception.
2703+
*/
2704+
public GetBucketCnameTokenResult getBucketCnameToken(GetBucketCnameTokenRequest getBucketCnameTokenRequest) throws OSSException, ClientException;
2705+
26732706
/**
26742707
* Gets the {@link Bucket}'s basic information as well as its ACL.
26752708
*

src/main/java/com/aliyun/oss/OSSClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,18 @@ public VoidResult deleteBucketCname(DeleteBucketCnameRequest deleteBucketCnameRe
12241224
return this.bucketOperation.deleteBucketCname(deleteBucketCnameRequest);
12251225
}
12261226

1227+
@Override
1228+
public CreateBucketCnameTokenResult createBucketCnameToken(CreateBucketCnameTokenRequest createBucketCnameTokenRequest)
1229+
throws OSSException, ClientException {
1230+
return this.bucketOperation.createBucketCnameToken(createBucketCnameTokenRequest);
1231+
}
1232+
1233+
@Override
1234+
public GetBucketCnameTokenResult getBucketCnameToken(GetBucketCnameTokenRequest getBucketCnameTokenRequest)
1235+
throws OSSException, ClientException {
1236+
return this.bucketOperation.getBucketCnameToken(getBucketCnameTokenRequest);
1237+
}
1238+
12271239
@Override
12281240
public BucketInfo getBucketInfo(String bucketName) throws OSSException, ClientException {
12291241
return this.getBucketInfo(new GenericRequest(bucketName));

src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public final class RequestMarshallers {
6767
public static final DeleteBucketReplicationRequestMarshaller deleteBucketReplicationRequestMarshaller = new DeleteBucketReplicationRequestMarshaller();
6868
public static final AddBucketCnameRequestMarshaller addBucketCnameRequestMarshaller = new AddBucketCnameRequestMarshaller();
6969
public static final DeleteBucketCnameRequestMarshaller deleteBucketCnameRequestMarshaller = new DeleteBucketCnameRequestMarshaller();
70+
public static final CreateBucketCnameTokenRequestMarshaller createBucketCnameTokenRequestMarshaller = new CreateBucketCnameTokenRequestMarshaller();
7071
public static final SetBucketQosRequestMarshaller setBucketQosRequestMarshaller = new SetBucketQosRequestMarshaller();
7172
public static final CompleteMultipartUploadRequestMarshaller completeMultipartUploadRequestMarshaller = new CompleteMultipartUploadRequestMarshaller();
7273
public static final CreateLiveChannelRequestMarshaller createLiveChannelRequestMarshaller = new CreateLiveChannelRequestMarshaller();
@@ -1005,6 +1006,11 @@ public byte[] marshall(AddBucketCnameRequest request) {
10051006
if (certConf.isForceOverwriteCert()) {
10061007
xmlBody.append("<Force>true</Force>");
10071008
}
1009+
1010+
if (certConf.getDeleteCertificate() != null) {
1011+
xmlBody.append("<DeleteCertificate>" + certConf.getDeleteCertificate().toString() + "</DeleteCertificate>");
1012+
}
1013+
10081014
xmlBody.append("</CertificateConfiguration>");
10091015
}
10101016

@@ -1045,6 +1051,28 @@ public byte[] marshall(DeleteBucketCnameRequest request) {
10451051

10461052
}
10471053

1054+
public static final class CreateBucketCnameTokenRequestMarshaller
1055+
implements RequestMarshaller2<CreateBucketCnameTokenRequest> {
1056+
1057+
@Override
1058+
public byte[] marshall(CreateBucketCnameTokenRequest request) {
1059+
StringBuffer xmlBody = new StringBuffer();
1060+
xmlBody.append("<BucketCnameConfiguration>");
1061+
xmlBody.append("<Cname>");
1062+
xmlBody.append("<Domain>" + request.getDomain() + "</Domain>");
1063+
xmlBody.append("</Cname>");
1064+
xmlBody.append("</BucketCnameConfiguration>");
1065+
1066+
byte[] rawData = null;
1067+
try {
1068+
rawData = xmlBody.toString().getBytes(DEFAULT_CHARSET_NAME);
1069+
} catch (UnsupportedEncodingException e) {
1070+
throw new ClientException("Unsupported encoding " + e.getMessage(), e);
1071+
}
1072+
return rawData;
1073+
}
1074+
}
1075+
10481076
public static final class SetBucketQosRequestMarshaller implements RequestMarshaller2<UserQos> {
10491077

10501078
@Override

src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java

Lines changed: 51 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -19,81 +19,14 @@
1919

2020
package com.aliyun.oss.internal;
2121

22-
import static com.aliyun.oss.common.parser.RequestMarshallers.bucketRefererMarshaller;
23-
import static com.aliyun.oss.common.parser.RequestMarshallers.createBucketRequestMarshaller;
24-
import static com.aliyun.oss.common.parser.RequestMarshallers.putBucketImageRequestMarshaller;
25-
import static com.aliyun.oss.common.parser.RequestMarshallers.putImageStyleRequestMarshaller;
26-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketLifecycleRequestMarshaller;
27-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketLoggingRequestMarshaller;
28-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketTaggingRequestMarshaller;
29-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketWebsiteRequestMarshaller;
30-
import static com.aliyun.oss.common.parser.RequestMarshallers.addBucketReplicationRequestMarshaller;
31-
import static com.aliyun.oss.common.parser.RequestMarshallers.deleteBucketReplicationRequestMarshaller;
32-
import static com.aliyun.oss.common.parser.RequestMarshallers.addBucketCnameRequestMarshaller;
33-
import static com.aliyun.oss.common.parser.RequestMarshallers.deleteBucketCnameRequestMarshaller;
34-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketQosRequestMarshaller;
35-
import static com.aliyun.oss.common.parser.RequestMarshallers.bucketImageProcessConfMarshaller;
36-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketVersioningRequestMarshaller;
37-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketEncryptionRequestMarshaller;
38-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketPolicyRequestMarshaller;
39-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketRequestPaymentRequestMarshaller;
40-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketQosInfoRequestMarshaller;
41-
import static com.aliyun.oss.common.parser.RequestMarshallers.setAsyncFetchTaskRequestMarshaller;
42-
import static com.aliyun.oss.common.parser.RequestMarshallers.createVpcipRequestMarshaller;
43-
import static com.aliyun.oss.common.parser.RequestMarshallers.deleteVpcipRequestMarshaller;
44-
import static com.aliyun.oss.common.parser.RequestMarshallers.createBucketVpcipRequestMarshaller;
45-
import static com.aliyun.oss.common.parser.RequestMarshallers.deleteBucketVpcipRequestMarshaller;
46-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketInventoryRequestMarshaller;
47-
import static com.aliyun.oss.common.parser.RequestMarshallers.extendBucketWormRequestMarshaller;
48-
import static com.aliyun.oss.common.parser.RequestMarshallers.initiateBucketWormRequestMarshaller;
49-
import static com.aliyun.oss.common.parser.RequestMarshallers.setBucketResourceGroupRequestMarshaller;
50-
import static com.aliyun.oss.common.parser.RequestMarshallers.putBucketTransferAccelerationRequestMarshaller;
22+
import static com.aliyun.oss.common.parser.RequestMarshallers.*;
5123
import static com.aliyun.oss.common.utils.CodingUtils.assertParameterNotNull;
5224
import static com.aliyun.oss.internal.OSSUtils.OSS_RESOURCE_MANAGER;
5325
import static com.aliyun.oss.internal.OSSUtils.ensureBucketNameValid;
5426
import static com.aliyun.oss.internal.OSSUtils.ensureBucketNameCreationValid;
5527
import static com.aliyun.oss.internal.OSSUtils.safeCloseResponse;
5628
import static com.aliyun.oss.internal.RequestParameters.*;
57-
import static com.aliyun.oss.internal.ResponseParsers.addBucketCnameResponseParser;
58-
import static com.aliyun.oss.internal.ResponseParsers.getBucketAclResponseParser;
59-
import static com.aliyun.oss.internal.ResponseParsers.getBucketLifecycleResponseParser;
60-
import static com.aliyun.oss.internal.ResponseParsers.getBucketLocationResponseParser;
61-
import static com.aliyun.oss.internal.ResponseParsers.getBucketLoggingResponseParser;
62-
import static com.aliyun.oss.internal.ResponseParsers.getBucketRefererResponseParser;
63-
import static com.aliyun.oss.internal.ResponseParsers.getTaggingResponseParser;
64-
import static com.aliyun.oss.internal.ResponseParsers.getBucketWebsiteResponseParser;
65-
import static com.aliyun.oss.internal.ResponseParsers.getBucketReplicationResponseParser;
66-
import static com.aliyun.oss.internal.ResponseParsers.getBucketReplicationProgressResponseParser;
67-
import static com.aliyun.oss.internal.ResponseParsers.getBucketReplicationLocationResponseParser;
68-
import static com.aliyun.oss.internal.ResponseParsers.getBucketCnameResponseParser;
69-
import static com.aliyun.oss.internal.ResponseParsers.getBucketInfoResponseParser;
70-
import static com.aliyun.oss.internal.ResponseParsers.getBucketStatResponseParser;
71-
import static com.aliyun.oss.internal.ResponseParsers.getBucketQosResponseParser;
72-
import static com.aliyun.oss.internal.ResponseParsers.getBucketVersioningResponseParser;
73-
import static com.aliyun.oss.internal.ResponseParsers.listBucketResponseParser;
74-
import static com.aliyun.oss.internal.ResponseParsers.listObjectsReponseParser;
75-
import static com.aliyun.oss.internal.ResponseParsers.listObjectsV2ResponseParser;
76-
import static com.aliyun.oss.internal.ResponseParsers.listVersionsReponseParser;
77-
import static com.aliyun.oss.internal.ResponseParsers.getBucketImageResponseParser;
78-
import static com.aliyun.oss.internal.ResponseParsers.getImageStyleResponseParser;
79-
import static com.aliyun.oss.internal.ResponseParsers.listImageStyleResponseParser;
80-
import static com.aliyun.oss.internal.ResponseParsers.getBucketImageProcessConfResponseParser;
81-
import static com.aliyun.oss.internal.ResponseParsers.getBucketEncryptionResponseParser;
82-
import static com.aliyun.oss.internal.ResponseParsers.getBucketPolicyResponseParser;
83-
import static com.aliyun.oss.internal.ResponseParsers.getBucketRequestPaymentResponseParser;
84-
import static com.aliyun.oss.internal.ResponseParsers.getUSerQosInfoResponseParser;
85-
import static com.aliyun.oss.internal.ResponseParsers.getBucketQosInfoResponseParser;
86-
import static com.aliyun.oss.internal.ResponseParsers.getAsyncFetchTaskResponseParser;
87-
import static com.aliyun.oss.internal.ResponseParsers.setAsyncFetchTaskResponseParser;
88-
import static com.aliyun.oss.internal.ResponseParsers.createVpcipResultResponseParser;
89-
import static com.aliyun.oss.internal.ResponseParsers.listVpcipResultResponseParser;
90-
import static com.aliyun.oss.internal.ResponseParsers.listVpcPolicyResultResponseParser;
91-
import static com.aliyun.oss.internal.ResponseParsers.getBucketInventoryConfigurationParser;
92-
import static com.aliyun.oss.internal.ResponseParsers.listBucketInventoryConfigurationsParser;
93-
import static com.aliyun.oss.internal.ResponseParsers.initiateBucketWormResponseParser;
94-
import static com.aliyun.oss.internal.ResponseParsers.getBucketWormResponseParser;
95-
import static com.aliyun.oss.internal.ResponseParsers.getBucketResourceGroupResponseParser;
96-
import static com.aliyun.oss.internal.ResponseParsers.getBucketTransferAccelerationResponseParser;
29+
import static com.aliyun.oss.internal.ResponseParsers.*;
9730

9831
import java.io.ByteArrayInputStream;
9932
import java.util.ArrayList;
@@ -115,93 +48,8 @@
11548
import com.aliyun.oss.common.utils.BinaryUtil;
11649
import com.aliyun.oss.common.utils.ExceptionFactory;
11750
import com.aliyun.oss.common.utils.HttpHeaders;
118-
import com.aliyun.oss.model.AccessControlList;
119-
import com.aliyun.oss.model.AddBucketCnameResult;
120-
import com.aliyun.oss.model.Bucket;
121-
import com.aliyun.oss.model.BucketInfo;
122-
import com.aliyun.oss.model.BucketList;
123-
import com.aliyun.oss.model.BucketLoggingResult;
124-
import com.aliyun.oss.model.BucketMetadata;
125-
import com.aliyun.oss.model.BucketProcess;
126-
import com.aliyun.oss.model.BucketQosInfo;
127-
import com.aliyun.oss.model.BucketReferer;
128-
import com.aliyun.oss.model.BucketReplicationProgress;
129-
import com.aliyun.oss.model.BucketStat;
130-
import com.aliyun.oss.model.BucketVersioningConfiguration;
131-
import com.aliyun.oss.model.BucketWebsiteResult;
132-
import com.aliyun.oss.model.CannedAccessControlList;
133-
import com.aliyun.oss.model.CnameConfiguration;
134-
import com.aliyun.oss.model.CreateBucketRequest;
135-
import com.aliyun.oss.model.DeleteBucketCnameRequest;
136-
import com.aliyun.oss.model.DeleteBucketReplicationRequest;
137-
import com.aliyun.oss.model.GenericRequest;
138-
import com.aliyun.oss.model.GetBucketImageResult;
139-
import com.aliyun.oss.model.GetBucketReplicationProgressRequest;
140-
import com.aliyun.oss.model.GetBucketRequestPaymentResult;
141-
import com.aliyun.oss.model.ImageProcess;
142-
import com.aliyun.oss.model.ListObjectsV2Request;
143-
import com.aliyun.oss.model.ListObjectsV2Result;
144-
import com.aliyun.oss.model.ReplicationRule;
145-
import com.aliyun.oss.model.ServerSideEncryptionConfiguration;
146-
import com.aliyun.oss.model.SetBucketEncryptionRequest;
147-
import com.aliyun.oss.model.GetImageStyleResult;
148-
import com.aliyun.oss.model.LifecycleRule;
149-
import com.aliyun.oss.model.ListBucketsRequest;
150-
import com.aliyun.oss.model.ListObjectsRequest;
151-
import com.aliyun.oss.model.ListVersionsRequest;
152-
import com.aliyun.oss.model.ObjectListing;
153-
import com.aliyun.oss.model.Payer;
154-
import com.aliyun.oss.model.PutBucketImageRequest;
155-
import com.aliyun.oss.model.PutImageStyleRequest;
156-
import com.aliyun.oss.model.SetBucketAclRequest;
157-
import com.aliyun.oss.model.AddBucketCnameRequest;
158-
import com.aliyun.oss.model.SetBucketLifecycleRequest;
159-
import com.aliyun.oss.model.SetBucketLoggingRequest;
160-
import com.aliyun.oss.model.SetBucketProcessRequest;
161-
import com.aliyun.oss.model.SetBucketQosInfoRequest;
162-
import com.aliyun.oss.model.SetBucketRefererRequest;
163-
import com.aliyun.oss.model.SetBucketRequestPaymentRequest;
164-
import com.aliyun.oss.model.AddBucketReplicationRequest;
165-
import com.aliyun.oss.model.SetBucketStorageCapacityRequest;
166-
import com.aliyun.oss.model.SetBucketTaggingRequest;
167-
import com.aliyun.oss.model.SetBucketVersioningRequest;
168-
import com.aliyun.oss.model.SetBucketWebsiteRequest;
169-
import com.aliyun.oss.model.SetBucketPolicyRequest;
170-
import com.aliyun.oss.model.GetBucketPolicyResult;
171-
import com.aliyun.oss.model.TagSet;
172-
import com.aliyun.oss.model.Style;
173-
import com.aliyun.oss.model.UserQos;
174-
import com.aliyun.oss.model.UserQosInfo;
175-
import com.aliyun.oss.model.VersionListing;
176-
import com.aliyun.oss.model.VoidResult;
51+
import com.aliyun.oss.model.*;
17752
import org.apache.http.HttpStatus;
178-
import com.aliyun.oss.model.SetAsyncFetchTaskRequest;
179-
import com.aliyun.oss.model.SetAsyncFetchTaskResult;
180-
import com.aliyun.oss.model.GetAsyncFetchTaskRequest;
181-
import com.aliyun.oss.model.GetAsyncFetchTaskResult;
182-
import com.aliyun.oss.model.AsyncFetchTaskConfiguration;
183-
import com.aliyun.oss.model.CreateBucketVpcipRequest;
184-
import com.aliyun.oss.model.CreateVpcipRequest;
185-
import com.aliyun.oss.model.CreateVpcipResult;
186-
import com.aliyun.oss.model.DeleteBucketVpcipRequest;
187-
import com.aliyun.oss.model.DeleteVpcipRequest;
188-
import com.aliyun.oss.model.VpcPolicy;
189-
import com.aliyun.oss.model.Vpcip;
190-
import com.aliyun.oss.model.SetBucketInventoryConfigurationRequest;
191-
import com.aliyun.oss.model.GetBucketInventoryConfigurationRequest;
192-
import com.aliyun.oss.model.GetBucketInventoryConfigurationResult;
193-
import com.aliyun.oss.model.ListBucketInventoryConfigurationsRequest;
194-
import com.aliyun.oss.model.ListBucketInventoryConfigurationsResult;
195-
import com.aliyun.oss.model.DeleteBucketInventoryConfigurationRequest;
196-
import com.aliyun.oss.model.ExtendBucketWormRequest;
197-
import com.aliyun.oss.model.GetBucketWormResult;
198-
import com.aliyun.oss.model.CompleteBucketWormRequest;
199-
import com.aliyun.oss.model.InitiateBucketWormRequest;
200-
import com.aliyun.oss.model.InitiateBucketWormResult;
201-
import com.aliyun.oss.model.SetBucketResourceGroupRequest;
202-
import com.aliyun.oss.model.GetBucketResourceGroupResult;
203-
import com.aliyun.oss.model.TransferAcceleration;
204-
import com.aliyun.oss.model.SetBucketTransferAccelerationRequest;
20553

20654
/**
20755
* Bucket operation.
@@ -1213,6 +1061,54 @@ public VoidResult deleteBucketCname(DeleteBucketCnameRequest deleteBucketCnameRe
12131061
return doOperation(request, requestIdResponseParser, bucketName, null);
12141062
}
12151063

1064+
public CreateBucketCnameTokenResult createBucketCnameToken(CreateBucketCnameTokenRequest createBucketCnameTokenRequest)
1065+
throws OSSException, ClientException {
1066+
1067+
assertParameterNotNull(createBucketCnameTokenRequest, "createBucketCnameTokenRequest");
1068+
assertParameterNotNull(createBucketCnameTokenRequest.getDomain(), "createBucketCnameTokenRequest.domain");
1069+
1070+
String bucketName = createBucketCnameTokenRequest.getBucketName();
1071+
assertParameterNotNull(bucketName, "bucketName");
1072+
ensureBucketNameValid(bucketName);
1073+
1074+
Map<String, String> params = new HashMap<String, String>();
1075+
params.put(RequestParameters.SUBRESOURCE_CNAME, null);
1076+
params.put(RequestParameters.SUBRESOURCE_COMP, RequestParameters.COMP_TOKEN);
1077+
1078+
byte[] rawContent = createBucketCnameTokenRequestMarshaller.marshall(createBucketCnameTokenRequest);
1079+
Map<String, String> headers = new HashMap<String, String>();
1080+
addRequestRequiredHeaders(headers, rawContent);
1081+
1082+
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint(createBucketCnameTokenRequest))
1083+
.setMethod(HttpMethod.POST).setBucket(bucketName).setParameters(params).setHeaders(headers)
1084+
.setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent))
1085+
.setOriginalRequest(createBucketCnameTokenRequest).build();
1086+
1087+
return doOperation(request, createBucketCnameTokenResponseParser, bucketName, null, true);
1088+
}
1089+
1090+
public GetBucketCnameTokenResult getBucketCnameToken(GetBucketCnameTokenRequest getBucketCnameTokenRequest)
1091+
throws OSSException, ClientException {
1092+
1093+
assertParameterNotNull(getBucketCnameTokenRequest, "getBucketCnameTokenRequest");
1094+
assertParameterNotNull(getBucketCnameTokenRequest.getDomain(), "getBucketCnameTokenRequest.domain");
1095+
1096+
String bucketName = getBucketCnameTokenRequest.getBucketName();
1097+
assertParameterNotNull(bucketName, "bucketName");
1098+
ensureBucketNameValid(bucketName);
1099+
assertParameterNotNull(getBucketCnameTokenRequest.getDomain(), "bucketName");
1100+
1101+
Map<String, String> params = new HashMap<String, String>();
1102+
params.put(RequestParameters.SUBRESOURCE_CNAME, getBucketCnameTokenRequest.getDomain());
1103+
params.put(RequestParameters.SUBRESOURCE_COMP, RequestParameters.COMP_TOKEN);
1104+
1105+
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint(getBucketCnameTokenRequest))
1106+
.setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params)
1107+
.setOriginalRequest(getBucketCnameTokenRequest).build();
1108+
1109+
return doOperation(request, getBucketCnameTokenResponseParser, bucketName, null, true);
1110+
}
1111+
12161112
public BucketInfo getBucketInfo(GenericRequest genericRequest) throws OSSException, ClientException {
12171113

12181114
assertParameterNotNull(genericRequest, "genericRequest");

0 commit comments

Comments
 (0)