use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetBucketImageProcessConf.
/**
* Unmarshall get bucket process response body to bucket process.
*/
public static BucketProcess parseGetBucketImageProcessConf(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
String compliedHost = root.getChildText("CompliedHost");
boolean sourceFileProtect = false;
if (root.getChildText("SourceFileProtect").equals("Enabled")) {
sourceFileProtect = true;
}
String sourceFileProtectSuffix = root.getChildText("SourceFileProtectSuffix");
String styleDelimiters = root.getChildText("StyleDelimiters");
ImageProcess imageProcess = new ImageProcess(compliedHost, sourceFileProtect, sourceFileProtectSuffix, styleDelimiters);
if (root.getChildText("Version") != null) {
imageProcess.setVersion(Integer.parseInt(root.getChildText("Version")));
}
return new BucketProcess(imageProcess);
} 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 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);
}
}
use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseCopyObjectResult.
/**
* Unmarshall copy object response body to corresponding result.
*/
public static CopyObjectResult parseCopyObjectResult(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
CopyObjectResult result = new CopyObjectResult();
result.setLastModified(DateUtil.parseIso8601Date(root.getChildText("LastModified")));
result.setEtag(trimQuotes(root.getChildText("ETag")));
return result;
} 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 parseGetBucketReferer.
/**
* Unmarshall get bucket referer response body to bucket referer list.
*/
@SuppressWarnings("unchecked")
public static BucketReferer parseGetBucketReferer(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
boolean allowEmptyReferer = Boolean.valueOf(root.getChildText("AllowEmptyReferer"));
List<String> refererList = new ArrayList<String>();
if (root.getChild("RefererList") != null) {
Element refererListElem = root.getChild("RefererList");
List<Element> refererElems = refererListElem.getChildren("Referer");
if (refererElems != null && !refererElems.isEmpty()) {
for (Element e : refererElems) {
refererList.add(e.getText());
}
}
}
return new BucketReferer(allowEmptyReferer, refererList);
} 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 parseGetBucketReplication.
/**
* Unmarshall get bucket replication response body to replication result.
*/
@SuppressWarnings("unchecked")
public static List<ReplicationRule> parseGetBucketReplication(InputStream responseBody) throws ResponseParseException {
try {
List<ReplicationRule> repRules = new ArrayList<ReplicationRule>();
Element root = getXmlRootElement(responseBody);
List<Element> ruleElems = root.getChildren("Rule");
for (Element ruleElem : ruleElems) {
ReplicationRule repRule = new ReplicationRule();
repRule.setReplicationRuleID(ruleElem.getChildText("ID"));
Element destination = ruleElem.getChild("Destination");
repRule.setTargetBucketName(destination.getChildText("Bucket"));
repRule.setTargetBucketLocation(destination.getChildText("Location"));
repRule.setReplicationStatus(ReplicationStatus.parse(ruleElem.getChildText("Status")));
if (ruleElem.getChildText("HistoricalObjectReplication").equals("enabled")) {
repRule.setEnableHistoricalObjectReplication(true);
} else {
repRule.setEnableHistoricalObjectReplication(false);
}
if (ruleElem.getChild("PrefixSet") != null) {
List<String> objectPrefixes = new ArrayList<String>();
List<Element> prefixElems = ruleElem.getChild("PrefixSet").getChildren("Prefix");
for (Element prefixElem : prefixElems) {
objectPrefixes.add(prefixElem.getText());
}
repRule.setObjectPrefixList(objectPrefixes);
}
if (ruleElem.getChild("Action") != null) {
String[] actionStrs = ruleElem.getChildText("Action").split(",");
List<ReplicationAction> repActions = new ArrayList<ReplicationAction>();
for (String actionStr : actionStrs) {
repActions.add(ReplicationAction.parse(actionStr));
}
repRule.setReplicationActionList(repActions);
}
repRules.add(repRule);
}
return repRules;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations