use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseBucketWebsite.
/**
* Unmarshall get bucket website response body to corresponding result.
*/
@SuppressWarnings("unchecked")
public static BucketWebsiteResult parseBucketWebsite(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
BucketWebsiteResult result = new BucketWebsiteResult();
if (root.getChild("IndexDocument") != null) {
result.setIndexDocument(root.getChild("IndexDocument").getChildText("Suffix"));
}
if (root.getChild("ErrorDocument") != null) {
result.setErrorDocument(root.getChild("ErrorDocument").getChildText("Key"));
}
if (root.getChild("RoutingRules") != null) {
List<Element> ruleElements = root.getChild("RoutingRules").getChildren("RoutingRule");
for (Element ruleElem : ruleElements) {
RoutingRule rule = new RoutingRule();
rule.setNumber(Integer.parseInt(ruleElem.getChildText("RuleNumber")));
Element condElem = ruleElem.getChild("Condition");
if (condElem != null) {
rule.getCondition().setKeyPrefixEquals(condElem.getChildText("KeyPrefixEquals"));
if (condElem.getChild("HttpErrorCodeReturnedEquals") != null) {
rule.getCondition().setHttpErrorCodeReturnedEquals(Integer.parseInt(condElem.getChildText("HttpErrorCodeReturnedEquals")));
}
}
Element redirectElem = ruleElem.getChild("Redirect");
if (redirectElem.getChild("RedirectType") != null) {
rule.getRedirect().setRedirectType(RoutingRule.RedirectType.parse(redirectElem.getChildText("RedirectType")));
}
rule.getRedirect().setHostName(redirectElem.getChildText("HostName"));
if (redirectElem.getChild("Protocol") != null) {
rule.getRedirect().setProtocol(RoutingRule.Protocol.parse(redirectElem.getChildText("Protocol")));
}
rule.getRedirect().setReplaceKeyPrefixWith(redirectElem.getChildText("ReplaceKeyPrefixWith"));
rule.getRedirect().setReplaceKeyWith(redirectElem.getChildText("ReplaceKeyWith"));
if (redirectElem.getChild("HttpRedirectCode") != null) {
rule.getRedirect().setHttpRedirectCode(Integer.parseInt(redirectElem.getChildText("HttpRedirectCode")));
}
rule.getRedirect().setMirrorURL(redirectElem.getChildText("MirrorURL"));
rule.getRedirect().setMirrorSecondaryURL(redirectElem.getChildText("MirrorURLSlave"));
rule.getRedirect().setMirrorProbeURL(redirectElem.getChildText("MirrorURLProbe"));
if (redirectElem.getChildText("MirrorPassQueryString") != null) {
rule.getRedirect().setPassQueryString(Boolean.valueOf(redirectElem.getChildText("MirrorPassQueryString")));
}
if (redirectElem.getChildText("MirrorPassOriginalSlashes") != null) {
rule.getRedirect().setPassOriginalSlashes(Boolean.valueOf(redirectElem.getChildText("MirrorPassOriginalSlashes")));
}
result.AddRoutingRule(rule);
}
}
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 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.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.
the class ResponseParsers method parseGetUdfImageInfo.
/**
* Unmarshall get udf info response body to udf image info list.
*/
@SuppressWarnings("unchecked")
public static List<UdfImageInfo> parseGetUdfImageInfo(InputStream responseBody) throws ResponseParseException {
try {
Element root = getXmlRootElement(responseBody);
List<UdfImageInfo> udfImages = new ArrayList<UdfImageInfo>();
if (root.getChild("Item") != null) {
List<Element> udfImageElems = root.getChildren("Item");
for (Element elem : udfImageElems) {
Integer version = Integer.valueOf(elem.getChildText("Version"));
String status = elem.getChildText("Status");
String region = elem.getChildText("CanonicalRegion");
String desc = elem.getChildText("Description");
Date date = DateUtil.parseIso8601Date(elem.getChildText("CreationDate"));
udfImages.add(new UdfImageInfo(version, status, desc, region, date));
}
}
return udfImages;
} 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 parseGetBucketReplicationProgress.
/**
* Unmarshall get bucket replication response body to replication progress.
*/
public static BucketReplicationProgress parseGetBucketReplicationProgress(InputStream responseBody) throws ResponseParseException {
try {
BucketReplicationProgress progress = new BucketReplicationProgress();
Element root = getXmlRootElement(responseBody);
Element ruleElem = root.getChild("Rule");
progress.setReplicationRuleID(ruleElem.getChildText("ID"));
Element destination = ruleElem.getChild("Destination");
progress.setTargetBucketName(destination.getChildText("Bucket"));
progress.setTargetBucketLocation(destination.getChildText("Location"));
progress.setReplicationStatus(ReplicationStatus.parse(ruleElem.getChildText("Status")));
if (ruleElem.getChildText("HistoricalObjectReplication").equals("enabled")) {
progress.setEnableHistoricalObjectReplication(true);
} else {
progress.setEnableHistoricalObjectReplication(false);
}
Element progressElem = ruleElem.getChild("Progress");
if (progressElem != null) {
if (progressElem.getChild("HistoricalObject") != null) {
progress.setHistoricalObjectProgress(Float.parseFloat(progressElem.getChildText("HistoricalObject")));
}
progress.setNewObjectProgress(DateUtil.parseIso8601Date(progressElem.getChildText("NewObject")));
}
return progress;
} 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 parseObjectMetadata.
/**
* Unmarshall object metadata from response headers.
*/
public static ObjectMetadata parseObjectMetadata(Map<String, String> headers) throws ResponseParseException {
try {
ObjectMetadata objectMetadata = new ObjectMetadata();
for (Iterator<String> it = headers.keySet().iterator(); it.hasNext(); ) {
String key = it.next();
if (key.indexOf(OSSHeaders.OSS_USER_METADATA_PREFIX) >= 0) {
key = key.substring(OSSHeaders.OSS_USER_METADATA_PREFIX.length());
objectMetadata.addUserMetadata(key, headers.get(OSSHeaders.OSS_USER_METADATA_PREFIX + key));
} else if (key.equals(OSSHeaders.LAST_MODIFIED) || key.equals(OSSHeaders.DATE)) {
try {
objectMetadata.setHeader(key, DateUtil.parseRfc822Date(headers.get(key)));
} catch (ParseException pe) {
throw new ResponseParseException(pe.getMessage(), pe);
}
} else if (key.equals(OSSHeaders.CONTENT_LENGTH)) {
Long value = Long.valueOf(headers.get(key));
objectMetadata.setHeader(key, value);
} else if (key.equals(OSSHeaders.ETAG)) {
objectMetadata.setHeader(key, trimQuotes(headers.get(key)));
} else {
objectMetadata.setHeader(key, headers.get(key));
}
}
return objectMetadata;
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
Aggregations