use of com.aliyun.oss.model.Owner in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetBucketInfo.
/**
* Unmarshall get bucket info response body to bucket info.
*/
public static BucketInfo parseGetBucketInfo(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
Element bucketElem = root.getChild("Bucket");
BucketInfo bucketInfo = new BucketInfo();
// owner
Bucket bucket = new Bucket();
String id = bucketElem.getChild("Owner").getChildText("ID");
String displayName = bucketElem.getChild("Owner").getChildText("DisplayName");
Owner owner = new Owner(id, displayName);
bucket.setOwner(owner);
// bucket
bucket.setName(bucketElem.getChildText("Name"));
bucket.setLocation(bucketElem.getChildText("Location"));
bucket.setExtranetEndpoint(bucketElem.getChildText("ExtranetEndpoint"));
bucket.setIntranetEndpoint(bucketElem.getChildText("IntranetEndpoint"));
bucket.setCreationDate(DateUtil.parseIso8601Date(bucketElem.getChildText("CreationDate")));
if (bucketElem.getChild("StorageClass") != null) {
bucket.setStorageClass(StorageClass.parse(bucketElem.getChildText("StorageClass")));
}
bucketInfo.setBucket(bucket);
// acl
String aclString = bucketElem.getChild("AccessControlList").getChildText("Grant");
CannedAccessControlList acl = CannedAccessControlList.parse(aclString);
bucketInfo.setCannedACL(acl);
switch(acl) {
case PublicRead:
bucketInfo.grantPermission(GroupGrantee.AllUsers, Permission.Read);
break;
case PublicReadWrite:
bucketInfo.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
break;
default:
break;
}
return bucketInfo;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.model.Owner in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseListObjects.
/**
* Unmarshall list objects response body to object listing.
*/
@SuppressWarnings("unchecked")
public static ObjectListing parseListObjects(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
ObjectListing objectListing = new ObjectListing();
objectListing.setBucketName(root.getChildText("Name"));
objectListing.setMaxKeys(Integer.valueOf(root.getChildText("MaxKeys")));
objectListing.setTruncated(Boolean.valueOf(root.getChildText("IsTruncated")));
if (root.getChild("Prefix") != null) {
String prefix = root.getChildText("Prefix");
objectListing.setPrefix(isNullOrEmpty(prefix) ? null : prefix);
}
if (root.getChild("Marker") != null) {
String marker = root.getChildText("Marker");
objectListing.setMarker(isNullOrEmpty(marker) ? null : marker);
}
if (root.getChild("Delimiter") != null) {
String delimiter = root.getChildText("Delimiter");
objectListing.setDelimiter(isNullOrEmpty(delimiter) ? null : delimiter);
}
if (root.getChild("NextMarker") != null) {
String nextMarker = root.getChildText("NextMarker");
objectListing.setNextMarker(isNullOrEmpty(nextMarker) ? null : nextMarker);
}
if (root.getChild("EncodingType") != null) {
String encodingType = root.getChildText("EncodingType");
objectListing.setEncodingType(isNullOrEmpty(encodingType) ? null : encodingType);
}
List<Element> objectSummaryElems = root.getChildren("Contents");
for (Element elem : objectSummaryElems) {
OSSObjectSummary ossObjectSummary = new OSSObjectSummary();
ossObjectSummary.setKey(elem.getChildText("Key"));
ossObjectSummary.setETag(trimQuotes(elem.getChildText("ETag")));
ossObjectSummary.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
ossObjectSummary.setSize(Long.valueOf(elem.getChildText("Size")));
ossObjectSummary.setStorageClass(elem.getChildText("StorageClass"));
ossObjectSummary.setBucketName(objectListing.getBucketName());
String id = elem.getChild("Owner").getChildText("ID");
String displayName = elem.getChild("Owner").getChildText("DisplayName");
ossObjectSummary.setOwner(new Owner(id, displayName));
objectListing.addObjectSummary(ossObjectSummary);
}
List<Element> commonPrefixesElems = root.getChildren("CommonPrefixes");
for (Element elem : commonPrefixesElems) {
String prefix = elem.getChildText("Prefix");
if (!isNullOrEmpty(prefix)) {
objectListing.addCommonPrefix(prefix);
}
}
return objectListing;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.model.Owner in project druid by druid-io.
the class OssTaskLogsTest method testPushInternal.
private List<Grant> testPushInternal(boolean disableAcl, String ownerId, String ownerDisplayName) throws Exception {
EasyMock.expect(ossClient.putObject(EasyMock.anyObject())).andReturn(new PutObjectResult()).once();
AccessControlList aclExpected = new AccessControlList();
aclExpected.setOwner(new Owner(ownerId, ownerDisplayName));
EasyMock.expect(ossClient.getBucketAcl(TEST_BUCKET)).andReturn(aclExpected).once();
EasyMock.expect(ossClient.putObject(EasyMock.anyObject(PutObjectRequest.class))).andReturn(new PutObjectResult()).once();
EasyMock.replay(ossClient);
OssTaskLogsConfig config = new OssTaskLogsConfig();
config.setDisableAcl(disableAcl);
config.setBucket(TEST_BUCKET);
CurrentTimeMillisSupplier timeSupplier = new CurrentTimeMillisSupplier();
OssInputDataConfig inputDataConfig = new OssInputDataConfig();
OssTaskLogs taskLogs = new OssTaskLogs(ossClient, config, inputDataConfig, timeSupplier);
String taskId = "index_test-datasource_2019-06-18T13:30:28.887Z";
File logFile = tempFolder.newFile("test_log_file");
taskLogs.pushTaskLog(taskId, logFile);
return new ArrayList<>(aclExpected.getGrants());
}
use of com.aliyun.oss.model.Owner in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetObjectAcl.
/**
* Unmarshall object acl response body to object ACL.
*/
public static ObjectAcl parseGetObjectAcl(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
ObjectAcl acl = new ObjectAcl();
String id = root.getChild("Owner").getChildText("ID");
String displayName = root.getChild("Owner").getChildText("DisplayName");
Owner owner = new Owner(id, displayName);
acl.setOwner(owner);
String grantString = root.getChild("AccessControlList").getChildText("Grant");
acl.setPermission(ObjectPermission.parsePermission(grantString));
return acl;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.model.Owner in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseListBucket.
/**
* Unmarshall list bucket response body to bucket list.
*/
@SuppressWarnings("unchecked")
public static BucketList parseListBucket(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
BucketList bucketList = new BucketList();
if (root.getChild("Prefix") != null) {
bucketList.setPrefix(root.getChildText("Prefix"));
}
if (root.getChild("Marker") != null) {
bucketList.setMarker(root.getChildText("Marker"));
}
if (root.getChild("MaxKeys") != null) {
String value = root.getChildText("MaxKeys");
bucketList.setMaxKeys(isNullOrEmpty(value) ? null : Integer.valueOf(value));
}
if (root.getChild("IsTruncated") != null) {
String value = root.getChildText("IsTruncated");
bucketList.setTruncated(isNullOrEmpty(value) ? false : Boolean.valueOf(value));
}
if (root.getChild("NextMarker") != null) {
bucketList.setNextMarker(root.getChildText("NextMarker"));
}
Element ownerElem = root.getChild("Owner");
String id = ownerElem.getChildText("ID");
String displayName = ownerElem.getChildText("DisplayName");
Owner owner = new Owner(id, displayName);
List<Bucket> buckets = new ArrayList<Bucket>();
if (root.getChild("Buckets") != null) {
List<Element> bucketElems = root.getChild("Buckets").getChildren("Bucket");
for (Element e : bucketElems) {
Bucket bucket = new Bucket();
bucket.setOwner(owner);
bucket.setName(e.getChildText("Name"));
bucket.setLocation(e.getChildText("Location"));
bucket.setCreationDate(DateUtil.parseIso8601Date(e.getChildText("CreationDate")));
if (e.getChild("StorageClass") != null) {
bucket.setStorageClass(StorageClass.parse(e.getChildText("StorageClass")));
}
bucket.setExtranetEndpoint(e.getChildText("ExtranetEndpoint"));
bucket.setIntranetEndpoint(e.getChildText("IntranetEndpoint"));
buckets.add(bucket);
}
}
bucketList.setBucketList(buckets);
return bucketList;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations