use of com.aliyun.oss.common.parser.ResponseParseException 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.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseSymbolicLink.
/**
* Unmarshall symlink link from response headers.
*/
public static OSSSymlink parseSymbolicLink(ResponseMessage response) throws ResponseParseException {
try {
OSSSymlink smyLink = null;
String targetObject = response.getHeaders().get(OSSHeaders.OSS_HEADER_SYMLINK_TARGET);
if (targetObject != null) {
targetObject = HttpUtil.urlDecode(targetObject, "UTF-8");
smyLink = new OSSSymlink(null, targetObject);
}
smyLink.setMetadata(parseObjectMetadata(response.getHeaders()));
return smyLink;
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseListMultipartUploads.
/**
* Unmarshall list multipart uploads response body to multipart upload
* listing.
*/
@SuppressWarnings("unchecked")
public static MultipartUploadListing parseListMultipartUploads(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
MultipartUploadListing multipartUploadListing = new MultipartUploadListing();
multipartUploadListing.setBucketName(root.getChildText("Bucket"));
multipartUploadListing.setMaxUploads(Integer.valueOf(root.getChildText("MaxUploads")));
multipartUploadListing.setTruncated(Boolean.valueOf(root.getChildText("IsTruncated")));
if (root.getChild("Delimiter") != null) {
String delimiter = root.getChildText("Delimiter");
if (!isNullOrEmpty(delimiter)) {
multipartUploadListing.setDelimiter(delimiter);
}
}
if (root.getChild("Prefix") != null) {
String prefix = root.getChildText("Prefix");
if (!isNullOrEmpty(prefix)) {
multipartUploadListing.setPrefix(prefix);
}
}
if (root.getChild("KeyMarker") != null) {
String keyMarker = root.getChildText("KeyMarker");
if (!isNullOrEmpty(keyMarker)) {
multipartUploadListing.setKeyMarker(keyMarker);
}
}
if (root.getChild("UploadIdMarker") != null) {
String uploadIdMarker = root.getChildText("UploadIdMarker");
if (!isNullOrEmpty(uploadIdMarker)) {
multipartUploadListing.setUploadIdMarker(uploadIdMarker);
}
}
if (root.getChild("NextKeyMarker") != null) {
String nextKeyMarker = root.getChildText("NextKeyMarker");
if (!isNullOrEmpty(nextKeyMarker)) {
multipartUploadListing.setNextKeyMarker(nextKeyMarker);
}
}
if (root.getChild("NextUploadIdMarker") != null) {
String nextUploadIdMarker = root.getChildText("NextUploadIdMarker");
if (!isNullOrEmpty(nextUploadIdMarker)) {
multipartUploadListing.setNextUploadIdMarker(nextUploadIdMarker);
}
}
List<Element> uploadElems = root.getChildren("Upload");
for (Element elem : uploadElems) {
if (elem.getChild("Initiated") == null) {
continue;
}
MultipartUpload mu = new MultipartUpload();
mu.setKey(elem.getChildText("Key"));
mu.setUploadId(elem.getChildText("UploadId"));
mu.setStorageClass(elem.getChildText("StorageClass"));
mu.setInitiated(DateUtil.parseIso8601Date(elem.getChildText("Initiated")));
multipartUploadListing.addMultipartUpload(mu);
}
List<Element> commonPrefixesElems = root.getChildren("CommonPrefixes");
for (Element elem : commonPrefixesElems) {
String prefix = elem.getChildText("Prefix");
if (!isNullOrEmpty(prefix)) {
multipartUploadListing.addCommonPrefix(prefix);
}
}
return multipartUploadListing;
} 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.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseCreateLiveChannel.
/**
* Unmarshall create live channel response body to corresponding result.
*/
@SuppressWarnings("unchecked")
public static CreateLiveChannelResult parseCreateLiveChannel(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
CreateLiveChannelResult result = new CreateLiveChannelResult();
List<String> publishUrls = new ArrayList<String>();
List<Element> publishElems = root.getChild("PublishUrls").getChildren("Url");
for (Element urlElem : publishElems) {
publishUrls.add(urlElem.getText());
}
result.setPublishUrls(publishUrls);
List<String> playUrls = new ArrayList<String>();
List<Element> playElems = root.getChild("PlayUrls").getChildren("Url");
for (Element urlElem : playElems) {
playUrls.add(urlElem.getText());
}
result.setPlayUrls(playUrls);
return result;
} 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.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetBucketStat.
/**
* Unmarshall get bucket info response body to bucket stat.
*/
public static BucketStat parseGetBucketStat(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
Long storage = Long.parseLong(root.getChildText("Storage"));
Long objectCount = Long.parseLong(root.getChildText("ObjectCount"));
Long multipartUploadCount = Long.parseLong(root.getChildText("MultipartUploadCount"));
BucketStat bucketStat = new BucketStat(storage, objectCount, multipartUploadCount);
return bucketStat;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations