use of com.aliyun.oss.model.TagSet in project aliyun-oss-java-sdk by aliyun.
the class BucketTaggingTest method testSetBucketTagging.
@Test
public void testSetBucketTagging() {
try {
SetBucketTaggingRequest request = new SetBucketTaggingRequest(bucketName);
request.setTag("tk1", "tv1");
request.setTag("tk2", "tv2");
ossClient.setBucketTagging(request);
TagSet tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
Map<String, String> tags = tagSet.getAllTags();
Assert.assertEquals(2, tags.size());
Assert.assertTrue(tags.containsKey("tk1"));
Assert.assertTrue(tags.containsKey("tk2"));
ossClient.deleteBucketTagging(new GenericRequest(bucketName));
waitForCacheExpiration(5);
tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
tags = tagSet.getAllTags();
Assert.assertTrue(tags.isEmpty());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.TagSet in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetBucketTagging.
/**
* Unmarshall get bucket tagging response body to cors rules.
*/
@SuppressWarnings("unchecked")
public static TagSet parseGetBucketTagging(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
TagSet tagSet = new TagSet();
List<Element> tagElems = root.getChild("TagSet").getChildren("Tag");
for (Element tagElem : tagElems) {
String key = null;
String value = null;
if (tagElem.getChild("Key") != null) {
key = tagElem.getChildText("Key");
}
if (tagElem.getChild("Value") != null) {
value = tagElem.getChildText("Value");
}
tagSet.setTag(key, value);
}
return tagSet;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations