Search in sources :

Example 41 with ResponseParseException

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

the class ResponseParsers method parseListLiveChannels.

/**
 * Unmarshall list live channels response body to live channel listing.
 */
@SuppressWarnings("unchecked")
public static LiveChannelListing parseListLiveChannels(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        LiveChannelListing liveChannelListing = new LiveChannelListing();
        liveChannelListing.setTruncated(Boolean.valueOf(root.getChildText("IsTruncated")));
        if (root.getChild("Prefix") != null) {
            String prefix = root.getChildText("Prefix");
            liveChannelListing.setPrefix(isNullOrEmpty(prefix) ? null : prefix);
        }
        if (root.getChild("Marker") != null) {
            String marker = root.getChildText("Marker");
            liveChannelListing.setMarker(isNullOrEmpty(marker) ? null : marker);
        }
        if (root.getChild("MaxKeys") != null) {
            String maxKeys = root.getChildText("MaxKeys");
            liveChannelListing.setMaxKeys(Integer.valueOf(maxKeys));
        }
        if (root.getChild("NextMarker") != null) {
            String nextMarker = root.getChildText("NextMarker");
            liveChannelListing.setNextMarker(isNullOrEmpty(nextMarker) ? null : nextMarker);
        }
        List<Element> liveChannelElems = root.getChildren("LiveChannel");
        for (Element elem : liveChannelElems) {
            LiveChannel liveChannel = new LiveChannel();
            liveChannel.setName(elem.getChildText("Name"));
            liveChannel.setDescription(elem.getChildText("Description"));
            liveChannel.setStatus(LiveChannelStatus.parse(elem.getChildText("Status")));
            liveChannel.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
            List<String> publishUrls = new ArrayList<String>();
            List<Element> publishElems = elem.getChild("PublishUrls").getChildren("Url");
            for (Element urlElem : publishElems) {
                publishUrls.add(urlElem.getText());
            }
            liveChannel.setPublishUrls(publishUrls);
            List<String> playUrls = new ArrayList<String>();
            List<Element> playElems = elem.getChild("PlayUrls").getChildren("Url");
            for (Element urlElem : playElems) {
                playUrls.add(urlElem.getText());
            }
            liveChannel.setPlayUrls(playUrls);
            liveChannelListing.addLiveChannel(liveChannel);
        }
        return liveChannelListing;
    } 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) LiveChannelListing(com.aliyun.oss.model.LiveChannelListing) LiveChannel(com.aliyun.oss.model.LiveChannel) 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