use of com.aliyun.oss.model.CnameConfiguration in project aliyun-oss-java-sdk by aliyun.
the class BucketCnameTest method testNormalAddBucketCname.
@Test
@SuppressWarnings("deprecation")
public void testNormalAddBucketCname() {
final String bucketName = "normal-add-bucket-cname";
Date curDate;
try {
ossClient.createBucket(bucketName);
// set cname
ossClient.addBucketCname(new AddBucketCnameRequest(bucketName).withDomain(domains[0]));
curDate = new Date(System.currentTimeMillis());
waitForCacheExpiration(5);
List<CnameConfiguration> cnames = ossClient.getBucketCname(bucketName);
Assert.assertEquals(cnames.size(), 1);
Assert.assertEquals(cnames.get(0).getDomain(), domains[0]);
Assert.assertEquals(cnames.get(0).getStatus(), CnameConfiguration.CnameStatus.Enabled);
Assert.assertEquals(cnames.get(0).getLastMofiedTime().getYear(), curDate.getYear());
Assert.assertEquals(cnames.get(0).getLastMofiedTime().getMonth(), curDate.getMonth());
Assert.assertEquals(cnames.get(0).getLastMofiedTime().getDay(), curDate.getDay());
System.out.println(cnames.get(0));
ossClient.deleteBucketCname(bucketName, domains[0]);
cnames = ossClient.getBucketCname(bucketName);
Assert.assertEquals(cnames.size(), 0);
// set multi cname
for (String domain : domains) {
AddBucketCnameRequest request = new AddBucketCnameRequest(bucketName);
request.setDomain(domain);
ossClient.addBucketCname(request);
}
curDate = new Date(System.currentTimeMillis());
waitForCacheExpiration(5);
cnames = ossClient.getBucketCname(bucketName);
Assert.assertEquals(cnames.size(), domains.length);
for (int i = 0; i < cnames.size(); i++) {
System.out.println(cnames.get(i));
Assert.assertEquals(cnames.get(i).getDomain(), domains[i]);
Assert.assertEquals(cnames.get(0).getStatus(), CnameConfiguration.CnameStatus.Enabled);
Assert.assertEquals(cnames.get(0).getLastMofiedTime().getYear(), curDate.getYear());
Assert.assertEquals(cnames.get(0).getLastMofiedTime().getMonth(), curDate.getMonth());
Assert.assertEquals(cnames.get(0).getLastMofiedTime().getDay(), curDate.getDay());
}
for (String domain : domains) {
DeleteBucketCnameRequest req = new DeleteBucketCnameRequest(bucketName);
req.setDomain(domain);
ossClient.deleteBucketCname(req);
}
cnames = ossClient.getBucketCname(bucketName);
Assert.assertEquals(cnames.size(), 0);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
} finally {
ossClient.deleteBucket(bucketName);
}
}
use of com.aliyun.oss.model.CnameConfiguration in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetBucketCname.
/**
* Unmarshall get bucket cname response body to cname configuration.
*/
@SuppressWarnings("unchecked")
public static List<CnameConfiguration> parseGetBucketCname(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
List<CnameConfiguration> cnames = new ArrayList<CnameConfiguration>();
List<Element> cnameElements = root.getChildren("Cname");
for (Element cnameElem : cnameElements) {
CnameConfiguration cname = new CnameConfiguration();
cname.setDomain(cnameElem.getChildText("Domain"));
cname.setStatus(CnameConfiguration.CnameStatus.valueOf(cnameElem.getChildText("Status")));
cname.setLastMofiedTime(DateUtil.parseIso8601Date(cnameElem.getChildText("LastModified")));
if (cnameElem.getChildText("IsPurgeCdnCache") != null) {
boolean purgeCdnCache = Boolean.valueOf(cnameElem.getChildText("IsPurgeCdnCache"));
cname.setPurgeCdnCache(purgeCdnCache);
}
cnames.add(cname);
}
return cnames;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations