Search in sources :

Example 21 with ResponseParseException

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

Example 22 with ResponseParseException

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

Example 23 with ResponseParseException

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);
    }
}
Also used : CopyObjectResult(com.aliyun.oss.model.CopyObjectResult) 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 24 with ResponseParseException

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

Example 25 with ResponseParseException

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

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