Search in sources :

Example 1 with ResponseParseException

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

the class ResponseParsers method parseGetBucketInfo.

/**
 * Unmarshall get bucket info response body to bucket info.
 */
public static BucketInfo parseGetBucketInfo(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        Element bucketElem = root.getChild("Bucket");
        BucketInfo bucketInfo = new BucketInfo();
        // owner
        Bucket bucket = new Bucket();
        String id = bucketElem.getChild("Owner").getChildText("ID");
        String displayName = bucketElem.getChild("Owner").getChildText("DisplayName");
        Owner owner = new Owner(id, displayName);
        bucket.setOwner(owner);
        // bucket
        bucket.setName(bucketElem.getChildText("Name"));
        bucket.setLocation(bucketElem.getChildText("Location"));
        bucket.setExtranetEndpoint(bucketElem.getChildText("ExtranetEndpoint"));
        bucket.setIntranetEndpoint(bucketElem.getChildText("IntranetEndpoint"));
        bucket.setCreationDate(DateUtil.parseIso8601Date(bucketElem.getChildText("CreationDate")));
        if (bucketElem.getChild("StorageClass") != null) {
            bucket.setStorageClass(StorageClass.parse(bucketElem.getChildText("StorageClass")));
        }
        bucketInfo.setBucket(bucket);
        // acl
        String aclString = bucketElem.getChild("AccessControlList").getChildText("Grant");
        CannedAccessControlList acl = CannedAccessControlList.parse(aclString);
        bucketInfo.setCannedACL(acl);
        switch(acl) {
            case PublicRead:
                bucketInfo.grantPermission(GroupGrantee.AllUsers, Permission.Read);
                break;
            case PublicReadWrite:
                bucketInfo.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
                break;
            default:
                break;
        }
        return bucketInfo;
    } 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) BucketInfo(com.aliyun.oss.model.BucketInfo) CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 2 with ResponseParseException

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

the class ResponseParsers method parseSymbolicLink.

/**
 * Unmarshall symlink link from response headers.
 */
public static OSSSymlink parseSymbolicLink(ResponseMessage response) throws ResponseParseException {
    try {
        OSSSymlink smyLink = null;
        String targetObject = response.getHeaders().get(OSSHeaders.OSS_HEADER_SYMLINK_TARGET);
        if (targetObject != null) {
            targetObject = HttpUtil.urlDecode(targetObject, "UTF-8");
            smyLink = new OSSSymlink(null, targetObject);
        }
        smyLink.setMetadata(parseObjectMetadata(response.getHeaders()));
        return smyLink;
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) OSSSymlink(com.aliyun.oss.model.OSSSymlink)

Example 3 with ResponseParseException

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

the class ResponseParsers method parseListMultipartUploads.

/**
 * Unmarshall list multipart uploads response body to multipart upload
 * listing.
 */
@SuppressWarnings("unchecked")
public static MultipartUploadListing parseListMultipartUploads(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        MultipartUploadListing multipartUploadListing = new MultipartUploadListing();
        multipartUploadListing.setBucketName(root.getChildText("Bucket"));
        multipartUploadListing.setMaxUploads(Integer.valueOf(root.getChildText("MaxUploads")));
        multipartUploadListing.setTruncated(Boolean.valueOf(root.getChildText("IsTruncated")));
        if (root.getChild("Delimiter") != null) {
            String delimiter = root.getChildText("Delimiter");
            if (!isNullOrEmpty(delimiter)) {
                multipartUploadListing.setDelimiter(delimiter);
            }
        }
        if (root.getChild("Prefix") != null) {
            String prefix = root.getChildText("Prefix");
            if (!isNullOrEmpty(prefix)) {
                multipartUploadListing.setPrefix(prefix);
            }
        }
        if (root.getChild("KeyMarker") != null) {
            String keyMarker = root.getChildText("KeyMarker");
            if (!isNullOrEmpty(keyMarker)) {
                multipartUploadListing.setKeyMarker(keyMarker);
            }
        }
        if (root.getChild("UploadIdMarker") != null) {
            String uploadIdMarker = root.getChildText("UploadIdMarker");
            if (!isNullOrEmpty(uploadIdMarker)) {
                multipartUploadListing.setUploadIdMarker(uploadIdMarker);
            }
        }
        if (root.getChild("NextKeyMarker") != null) {
            String nextKeyMarker = root.getChildText("NextKeyMarker");
            if (!isNullOrEmpty(nextKeyMarker)) {
                multipartUploadListing.setNextKeyMarker(nextKeyMarker);
            }
        }
        if (root.getChild("NextUploadIdMarker") != null) {
            String nextUploadIdMarker = root.getChildText("NextUploadIdMarker");
            if (!isNullOrEmpty(nextUploadIdMarker)) {
                multipartUploadListing.setNextUploadIdMarker(nextUploadIdMarker);
            }
        }
        List<Element> uploadElems = root.getChildren("Upload");
        for (Element elem : uploadElems) {
            if (elem.getChild("Initiated") == null) {
                continue;
            }
            MultipartUpload mu = new MultipartUpload();
            mu.setKey(elem.getChildText("Key"));
            mu.setUploadId(elem.getChildText("UploadId"));
            mu.setStorageClass(elem.getChildText("StorageClass"));
            mu.setInitiated(DateUtil.parseIso8601Date(elem.getChildText("Initiated")));
            multipartUploadListing.addMultipartUpload(mu);
        }
        List<Element> commonPrefixesElems = root.getChildren("CommonPrefixes");
        for (Element elem : commonPrefixesElems) {
            String prefix = elem.getChildText("Prefix");
            if (!isNullOrEmpty(prefix)) {
                multipartUploadListing.addCommonPrefix(prefix);
            }
        }
        return multipartUploadListing;
    } 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) MultipartUploadListing(com.aliyun.oss.model.MultipartUploadListing) MultipartUpload(com.aliyun.oss.model.MultipartUpload) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 4 with ResponseParseException

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

the class ResponseParsers method parseCreateLiveChannel.

/**
 * Unmarshall create live channel response body to corresponding result.
 */
@SuppressWarnings("unchecked")
public static CreateLiveChannelResult parseCreateLiveChannel(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        CreateLiveChannelResult result = new CreateLiveChannelResult();
        List<String> publishUrls = new ArrayList<String>();
        List<Element> publishElems = root.getChild("PublishUrls").getChildren("Url");
        for (Element urlElem : publishElems) {
            publishUrls.add(urlElem.getText());
        }
        result.setPublishUrls(publishUrls);
        List<String> playUrls = new ArrayList<String>();
        List<Element> playElems = root.getChild("PlayUrls").getChildren("Url");
        for (Element urlElem : playElems) {
            playUrls.add(urlElem.getText());
        }
        result.setPlayUrls(playUrls);
        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) CreateLiveChannelResult(com.aliyun.oss.model.CreateLiveChannelResult) 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)

Example 5 with ResponseParseException

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

the class ResponseParsers method parseGetBucketStat.

/**
 * Unmarshall get bucket info response body to bucket stat.
 */
public static BucketStat parseGetBucketStat(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        Long storage = Long.parseLong(root.getChildText("Storage"));
        Long objectCount = Long.parseLong(root.getChildText("ObjectCount"));
        Long multipartUploadCount = Long.parseLong(root.getChildText("MultipartUploadCount"));
        BucketStat bucketStat = new BucketStat(storage, objectCount, multipartUploadCount);
        return bucketStat;
    } 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) BucketStat(com.aliyun.oss.model.BucketStat) 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)

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