use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseBucketLogging.
/**
* Unmarshall get bucket logging response body to corresponding result.
*/
public static BucketLoggingResult parseBucketLogging(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
BucketLoggingResult result = new BucketLoggingResult();
if (root.getChild("LoggingEnabled") != null) {
result.setTargetBucket(root.getChild("LoggingEnabled").getChildText("TargetBucket"));
}
if (root.getChild("LoggingEnabled") != null) {
result.setTargetPrefix(root.getChild("LoggingEnabled").getChildText("TargetPrefix"));
}
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 parseGetBucketLifecycle.
/**
* Unmarshall get bucket lifecycle response body to lifecycle rules.
*/
@SuppressWarnings("unchecked")
public static List<LifecycleRule> parseGetBucketLifecycle(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
List<LifecycleRule> lifecycleRules = new ArrayList<LifecycleRule>();
List<Element> ruleElements = root.getChildren("Rule");
for (Element ruleElem : ruleElements) {
LifecycleRule rule = new LifecycleRule();
if (ruleElem.getChild("ID") != null) {
rule.setId(ruleElem.getChildText("ID"));
}
if (ruleElem.getChild("Prefix") != null) {
rule.setPrefix(ruleElem.getChildText("Prefix"));
}
if (ruleElem.getChild("Status") != null) {
rule.setStatus(RuleStatus.valueOf(ruleElem.getChildText("Status")));
}
if (ruleElem.getChild("Expiration") != null) {
if (ruleElem.getChild("Expiration").getChild("Date") != null) {
Date expirationDate = DateUtil.parseIso8601Date(ruleElem.getChild("Expiration").getChildText("Date"));
rule.setExpirationTime(expirationDate);
} else if (ruleElem.getChild("Expiration").getChild("Days") != null) {
rule.setExpirationDays(Integer.parseInt(ruleElem.getChild("Expiration").getChildText("Days")));
} else {
Date createdBeforeDate = DateUtil.parseIso8601Date(ruleElem.getChild("Expiration").getChildText("CreatedBeforeDate"));
rule.setCreatedBeforeDate(createdBeforeDate);
}
}
if (ruleElem.getChild("AbortMultipartUpload") != null) {
LifecycleRule.AbortMultipartUpload abortMultipartUpload = new LifecycleRule.AbortMultipartUpload();
if (ruleElem.getChild("AbortMultipartUpload").getChild("Days") != null) {
abortMultipartUpload.setExpirationDays(Integer.parseInt(ruleElem.getChild("AbortMultipartUpload").getChildText("Days")));
} else {
Date createdBeforeDate = DateUtil.parseIso8601Date(ruleElem.getChild("AbortMultipartUpload").getChildText("CreatedBeforeDate"));
abortMultipartUpload.setCreatedBeforeDate(createdBeforeDate);
}
rule.setAbortMultipartUpload(abortMultipartUpload);
}
List<Element> transitionElements = ruleElem.getChildren("Transition");
List<StorageTransition> storageTransitions = new ArrayList<StorageTransition>();
for (Element transitionElem : transitionElements) {
LifecycleRule.StorageTransition storageTransition = new LifecycleRule.StorageTransition();
if (transitionElem.getChild("Days") != null) {
storageTransition.setExpirationDays(Integer.parseInt(transitionElem.getChildText("Days")));
} else {
Date createdBeforeDate = DateUtil.parseIso8601Date(transitionElem.getChildText("CreatedBeforeDate"));
storageTransition.setCreatedBeforeDate(createdBeforeDate);
}
if (transitionElem.getChild("StorageClass") != null) {
storageTransition.setStorageClass(StorageClass.parse(transitionElem.getChildText("StorageClass")));
}
storageTransitions.add(storageTransition);
}
rule.setStorageTransition(storageTransitions);
lifecycleRules.add(rule);
}
return lifecycleRules;
} 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 parseListBucketCORS.
/**
* Unmarshall get bucket cors response body to cors rules.
*/
@SuppressWarnings("unchecked")
public static List<CORSRule> parseListBucketCORS(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
List<CORSRule> corsRules = new ArrayList<CORSRule>();
List<Element> corsRuleElems = root.getChildren("CORSRule");
for (Element corsRuleElem : corsRuleElems) {
CORSRule rule = new CORSRule();
List<Element> allowedOriginElems = corsRuleElem.getChildren("AllowedOrigin");
for (Element allowedOriginElement : allowedOriginElems) {
rule.getAllowedOrigins().add(allowedOriginElement.getValue());
}
List<Element> allowedMethodElems = corsRuleElem.getChildren("AllowedMethod");
for (Element allowedMethodElement : allowedMethodElems) {
rule.getAllowedMethods().add(allowedMethodElement.getValue());
}
List<Element> allowedHeaderElems = corsRuleElem.getChildren("AllowedHeader");
for (Element allowedHeaderElement : allowedHeaderElems) {
rule.getAllowedHeaders().add(allowedHeaderElement.getValue());
}
List<Element> exposeHeaderElems = corsRuleElem.getChildren("ExposeHeader");
for (Element exposeHeaderElement : exposeHeaderElems) {
rule.getExposeHeaders().add(exposeHeaderElement.getValue());
}
Element maxAgeSecondsElem = corsRuleElem.getChild("MaxAgeSeconds");
if (maxAgeSecondsElem != null) {
rule.setMaxAgeSeconds(Integer.parseInt(maxAgeSecondsElem.getValue()));
}
corsRules.add(rule);
}
return corsRules;
} 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 parseListImageStyle.
/**
* Unmarshall list image style response body to style list.
*/
@SuppressWarnings("unchecked")
public static List<Style> parseListImageStyle(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
List<Style> styleList = new ArrayList<Style>();
List<Element> styleElems = root.getChildren("Style");
for (Element e : styleElems) {
Style style = new Style();
style.SetStyleName(e.getChildText("Name"));
style.SetStyle(e.getChildText("Content"));
style.SetLastModifyTime(DateUtil.parseRfc822Date(e.getChildText("LastModifyTime")));
style.SetCreationDate(DateUtil.parseRfc822Date(e.getChildText("CreateTime")));
styleList.add(style);
}
return styleList;
} 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 parseCompleteMultipartUpload.
/**
* Unmarshall complete multipart upload response body to corresponding
* result.
*/
public static CompleteMultipartUploadResult parseCompleteMultipartUpload(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
CompleteMultipartUploadResult result = new CompleteMultipartUploadResult();
result.setBucketName(root.getChildText("Bucket"));
result.setETag(trimQuotes(root.getChildText("ETag")));
result.setKey(root.getChildText("Key"));
result.setLocation(root.getChildText("Location"));
return result;
} catch (JDOMParseException e) {
throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations