Search in sources :

Example 26 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) BucketLoggingResult(com.aliyun.oss.model.BucketLoggingResult) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 27 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ArrayList(java.util.ArrayList) StorageTransition(com.aliyun.oss.model.LifecycleRule.StorageTransition) StorageTransition(com.aliyun.oss.model.LifecycleRule.StorageTransition) LifecycleRule(com.aliyun.oss.model.LifecycleRule) Date(java.util.Date) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 28 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) CORSRule(com.aliyun.oss.model.SetBucketCORSRequest.CORSRule) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 29 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ArrayList(java.util.ArrayList) Style(com.aliyun.oss.model.Style) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 30 with ResponseParseException

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);
    }
}
Also used : JDOMParseException(org.jdom.input.JDOMParseException) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) CompleteMultipartUploadResult(com.aliyun.oss.model.CompleteMultipartUploadResult) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)41 ParseException (java.text.ParseException)39 JDOMParseException (org.jdom.input.JDOMParseException)39 Element (org.jdom.Element)37 ArrayList (java.util.ArrayList)15 Date (java.util.Date)6 Owner (com.aliyun.oss.model.Owner)5 BigInteger (java.math.BigInteger)3 Bucket (com.aliyun.oss.model.Bucket)2 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)2 CannedUdfAcl (com.aliyun.oss.model.CannedUdfAcl)2 InstanceFlavor (com.aliyun.oss.model.InstanceFlavor)2 UdfApplicationInfo (com.aliyun.oss.model.UdfApplicationInfo)2 OSSException (com.aliyun.oss.OSSException)1 RequestSigner (com.aliyun.oss.common.auth.RequestSigner)1 ExecutionContext (com.aliyun.oss.common.comm.ExecutionContext)1 RequestChecksumHanlder (com.aliyun.oss.common.comm.RequestChecksumHanlder)1 RequestHandler (com.aliyun.oss.common.comm.RequestHandler)1 RequestProgressHanlder (com.aliyun.oss.common.comm.RequestProgressHanlder)1 ResponseChecksumHandler (com.aliyun.oss.common.comm.ResponseChecksumHandler)1