Search in sources :

Example 31 with ResponseParseException

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

the class ResponseParsers method parseGetBucketAcl.

/**
 * Unmarshall get bucket acl response body to ACL.
 */
public static AccessControlList parseGetBucketAcl(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        AccessControlList acl = new AccessControlList();
        String id = root.getChild("Owner").getChildText("ID");
        String displayName = root.getChild("Owner").getChildText("DisplayName");
        Owner owner = new Owner(id, displayName);
        acl.setOwner(owner);
        String aclString = root.getChild("AccessControlList").getChildText("Grant");
        CannedAccessControlList cacl = CannedAccessControlList.parse(aclString);
        acl.setCannedACL(cacl);
        switch(cacl) {
            case PublicRead:
                acl.grantPermission(GroupGrantee.AllUsers, Permission.Read);
                break;
            case PublicReadWrite:
                acl.grantPermission(GroupGrantee.AllUsers, Permission.FullControl);
                break;
            default:
                break;
        }
        return acl;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) AccessControlList(com.aliyun.oss.model.AccessControlList) JDOMParseException(org.jdom.input.JDOMParseException) Owner(com.aliyun.oss.model.Owner) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) CannedAccessControlList(com.aliyun.oss.model.CannedAccessControlList) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 32 with ResponseParseException

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

the class ResponseParsers method parseGetBucketTagging.

/**
 * Unmarshall get bucket tagging response body to cors rules.
 */
@SuppressWarnings("unchecked")
public static TagSet parseGetBucketTagging(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        TagSet tagSet = new TagSet();
        List<Element> tagElems = root.getChild("TagSet").getChildren("Tag");
        for (Element tagElem : tagElems) {
            String key = null;
            String value = null;
            if (tagElem.getChild("Key") != null) {
                key = tagElem.getChildText("Key");
            }
            if (tagElem.getChild("Value") != null) {
                value = tagElem.getChildText("Value");
            }
            tagSet.setTag(key, value);
        }
        return tagSet;
    } 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) TagSet(com.aliyun.oss.model.TagSet) 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 33 with ResponseParseException

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

the class ResponseParsers method parseGetLiveChannelHistory.

/**
 * Unmarshall get live channel history response body to corresponding
 * result.
 */
@SuppressWarnings("unchecked")
public static List<LiveRecord> parseGetLiveChannelHistory(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<LiveRecord> liveRecords = new ArrayList<LiveRecord>();
        List<Element> recordElements = root.getChildren("LiveRecord");
        for (Element recordElem : recordElements) {
            LiveRecord record = new LiveRecord();
            record.setStartDate(DateUtil.parseIso8601Date(recordElem.getChildText("StartTime")));
            record.setEndDate(DateUtil.parseIso8601Date(recordElem.getChildText("EndTime")));
            record.setRemoteAddress(recordElem.getChildText("RemoteAddr"));
            liveRecords.add(record);
        }
        return liveRecords;
    } 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) LiveRecord(com.aliyun.oss.model.LiveRecord) 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 34 with ResponseParseException

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

the class ResponseParsers method parseImageStyle.

/**
 * Unmarshall get image style response body to corresponding result.
 */
public static GetImageStyleResult parseImageStyle(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        GetImageStyleResult result = new GetImageStyleResult();
        result.SetStyleName(root.getChildText("Name"));
        result.SetStyle(root.getChildText("Content"));
        result.SetLastModifyTime(DateUtil.parseRfc822Date(root.getChildText("LastModifyTime")));
        result.SetCreationDate(DateUtil.parseRfc822Date(root.getChildText("CreateTime")));
        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) GetImageStyleResult(com.aliyun.oss.model.GetImageStyleResult) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 35 with ResponseParseException

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

the class ResponseParsers method parseGetLiveChannelStat.

/**
 * Unmarshall get live channel stat response body to corresponding result.
 */
public static LiveChannelStat parseGetLiveChannelStat(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        LiveChannelStat result = new LiveChannelStat();
        result.setPushflowStatus(PushflowStatus.parse(root.getChildText("Status")));
        if (root.getChild("ConnectedTime") != null) {
            result.setConnectedDate(DateUtil.parseIso8601Date(root.getChildText("ConnectedTime")));
        }
        if (root.getChild("RemoteAddr") != null) {
            result.setRemoteAddress(root.getChildText("RemoteAddr"));
        }
        Element videoElem = root.getChild("Video");
        if (videoElem != null) {
            VideoStat videoStat = new VideoStat();
            videoStat.setWidth(Integer.parseInt(videoElem.getChildText("Width")));
            videoStat.setHeight(Integer.parseInt(videoElem.getChildText("Height")));
            videoStat.setFrameRate(Integer.parseInt(videoElem.getChildText("FrameRate")));
            videoStat.setBandWidth(Integer.parseInt(videoElem.getChildText("Bandwidth")));
            videoStat.setCodec(videoElem.getChildText("Codec"));
            result.setVideoStat(videoStat);
        }
        Element audioElem = root.getChild("Audio");
        if (audioElem != null) {
            AudioStat audioStat = new AudioStat();
            audioStat.setBandWidth(Integer.parseInt(audioElem.getChildText("Bandwidth")));
            audioStat.setSampleRate(Integer.parseInt(audioElem.getChildText("SampleRate")));
            audioStat.setCodec(audioElem.getChildText("Codec"));
            result.setAudioStat(audioStat);
        }
        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) AudioStat(com.aliyun.oss.model.LiveChannelStat.AudioStat) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) VideoStat(com.aliyun.oss.model.LiveChannelStat.VideoStat) LiveChannelStat(com.aliyun.oss.model.LiveChannelStat) 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