-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
410c662
commit 913f2a0
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import com.aliyun.oss.ClientException; | ||
import com.aliyun.oss.OSS; | ||
import com.aliyun.oss.OSSClientBuilder; | ||
import com.aliyun.oss.OSSException; | ||
import com.aliyun.oss.model.*; | ||
import java.util.List; | ||
|
||
public class BucketCnameSample { | ||
|
||
private static String endpoint = "*** Provide OSS endpoint ***"; | ||
private static String accessKeyId = "*** Provide your AccessKeyId ***"; | ||
private static String accessKeySecret = "*** Provide your AccessKeySecret ***"; | ||
private static String bucketName = "*** Provide bucket name ***"; | ||
|
||
public static void main(String[] args) { | ||
// Create an OSSClient instance. | ||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); | ||
|
||
try { | ||
// Create cnametoken required for domain name ownership verification | ||
CreateBucketCnameTokenRequest request = new CreateBucketCnameTokenRequest(bucketName); | ||
request.setDomain("www.example.com"); | ||
ossClient.createBucketCnameToken(request); | ||
|
||
// Get the created cnametoken | ||
GetBucketCnameTokenRequest grequest = new GetBucketCnameTokenRequest(bucketName); | ||
grequest.setDomain("www.example.com"); | ||
GetBucketCnameTokenResult gresult = ossClient.getBucketCnameToken(grequest); | ||
System.out.println(gresult.getCname()); | ||
System.out.println(gresult.getToken()); | ||
|
||
// Bind a custom domain name to a bucket | ||
ossClient.addBucketCname(new AddBucketCnameRequest(bucketName).withDomain("www.example.com")); | ||
|
||
// Query the list of all cnames bound under a storage space (bucket) | ||
List<CnameConfiguration> list = ossClient.getBucketCname(bucketName); | ||
System.out.println(list.get(0).getDomain()); | ||
|
||
// Delete the bound CNAME of a storage space (bucket) | ||
ossClient.deleteBucketCname(bucketName, "www.example.com"); | ||
|
||
} catch (OSSException oe) { | ||
System.out.println("Error Message: " + oe.getErrorMessage()); | ||
System.out.println("Error Code: " + oe.getErrorCode()); | ||
System.out.println("Request ID: " + oe.getRequestId()); | ||
System.out.println("Host ID: " + oe.getHostId()); | ||
} catch (ClientException ce) { | ||
System.out.println("Error Message: " + ce.getMessage()); | ||
} finally { | ||
/* | ||
* Do not forget to shut down the client finally to release all allocated resources. | ||
*/ | ||
ossClient.shutdown(); | ||
} | ||
} | ||
} |