Search in sources :

Example 36 with ResponseParseException

use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseGetBucketCname.

/**
 * Unmarshall get bucket cname response body to cname configuration.
 */
@SuppressWarnings("unchecked")
public static List<CnameConfiguration> parseGetBucketCname(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<CnameConfiguration> cnames = new ArrayList<CnameConfiguration>();
        List<Element> cnameElements = root.getChildren("Cname");
        for (Element cnameElem : cnameElements) {
            CnameConfiguration cname = new CnameConfiguration();
            cname.setDomain(cnameElem.getChildText("Domain"));
            cname.setStatus(CnameConfiguration.CnameStatus.valueOf(cnameElem.getChildText("Status")));
            cname.setLastMofiedTime(DateUtil.parseIso8601Date(cnameElem.getChildText("LastModified")));
            if (cnameElem.getChildText("IsPurgeCdnCache") != null) {
                boolean purgeCdnCache = Boolean.valueOf(cnameElem.getChildText("IsPurgeCdnCache"));
                cname.setPurgeCdnCache(purgeCdnCache);
            }
            cnames.add(cname);
        }
        return cnames;
    } 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) CnameConfiguration(com.aliyun.oss.model.CnameConfiguration) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 37 with ResponseParseException

use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseListParts.

/**
 * Unmarshall list parts response body to part listing.
 */
@SuppressWarnings("unchecked")
public static PartListing parseListParts(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        PartListing partListing = new PartListing();
        partListing.setBucketName(root.getChildText("Bucket"));
        partListing.setKey(root.getChildText("Key"));
        partListing.setUploadId(root.getChildText("UploadId"));
        partListing.setStorageClass(root.getChildText("StorageClass"));
        partListing.setMaxParts(Integer.valueOf(root.getChildText("MaxParts")));
        partListing.setTruncated(Boolean.valueOf(root.getChildText("IsTruncated")));
        if (root.getChild("PartNumberMarker") != null) {
            String partNumberMarker = root.getChildText("PartNumberMarker");
            if (!isNullOrEmpty(partNumberMarker)) {
                partListing.setPartNumberMarker(Integer.valueOf(partNumberMarker));
            }
        }
        if (root.getChild("NextPartNumberMarker") != null) {
            String nextPartNumberMarker = root.getChildText("NextPartNumberMarker");
            if (!isNullOrEmpty(nextPartNumberMarker)) {
                partListing.setNextPartNumberMarker(Integer.valueOf(nextPartNumberMarker));
            }
        }
        List<Element> partElems = root.getChildren("Part");
        for (Element elem : partElems) {
            PartSummary ps = new PartSummary();
            ps.setPartNumber(Integer.valueOf(elem.getChildText("PartNumber")));
            ps.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
            ps.setETag(trimQuotes(elem.getChildText("ETag")));
            ps.setSize(Integer.valueOf(elem.getChildText("Size")));
            partListing.addPart(ps);
        }
        return partListing;
    } 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) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) PartListing(com.aliyun.oss.model.PartListing) PartSummary(com.aliyun.oss.model.PartSummary)

Example 38 with ResponseParseException

use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseBucketImage.

/**
 * Unmarshall get bucket image response body to corresponding result.
 */
public static GetBucketImageResult parseBucketImage(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        GetBucketImageResult result = new GetBucketImageResult();
        result.SetBucketName(root.getChildText("Name"));
        result.SetDefault404Pic(root.getChildText("Default404Pic"));
        result.SetStyleDelimiters(root.getChildText("StyleDelimiters"));
        result.SetStatus(root.getChildText("Status"));
        result.SetIsAutoSetContentType(root.getChildText("AutoSetContentType").equals("True"));
        result.SetIsForbidOrigPicAccess(root.getChildText("OrigPicForbidden").equals("True"));
        result.SetIsSetAttachName(root.getChildText("SetAttachName").equals("True"));
        result.SetIsUseStyleOnly(root.getChildText("UseStyleOnly").equals("True"));
        result.SetIsUseSrcFormat(root.getChildText("UseSrcFormat").equals("True"));
        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) GetBucketImageResult(com.aliyun.oss.model.GetBucketImageResult) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 39 with ResponseParseException

use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseListUdf.

/**
 * Unmarshall list udf response body to udf info list.
 */
@SuppressWarnings("unchecked")
public static List<UdfInfo> parseListUdf(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<UdfInfo> udfs = new ArrayList<UdfInfo>();
        if (root.getChild("UDFInfo") != null) {
            List<Element> udfElems = root.getChildren("UDFInfo");
            for (Element elem : udfElems) {
                String name = elem.getChildText("Name");
                String id = elem.getChildText("ID");
                String owner = elem.getChildText("Owner");
                String desc = elem.getChildText("Description");
                Date date = DateUtil.parseIso8601Date(elem.getChildText("CreationDate"));
                CannedUdfAcl acl = CannedUdfAcl.parse(elem.getChildText("ACL"));
                udfs.add(new UdfInfo(name, owner, id, desc, acl, date));
            }
        }
        return udfs;
    } 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) UdfInfo(com.aliyun.oss.model.UdfInfo) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ArrayList(java.util.ArrayList) Date(java.util.Date) CannedUdfAcl(com.aliyun.oss.model.CannedUdfAcl) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 40 with ResponseParseException

use of com.aliyun.oss.common.parser.ResponseParseException in project aliyun-oss-java-sdk by aliyun.

the class ResponseParsers method parseGetBucketReplicationLocation.

/**
 * Unmarshall get bucket replication response body to replication location.
 */
@SuppressWarnings("unchecked")
public static List<String> parseGetBucketReplicationLocation(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<String> locationList = new ArrayList<String>();
        List<Element> locElements = root.getChildren("Location");
        for (Element locElem : locElements) {
            locationList.add(locElem.getText());
        }
        return locationList;
    } 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) 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