Search in sources :

Example 11 with ResponseParseException

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

the class ResponseParsers method parseGetUdfApplicationInfo.

/**
 * Unmarshall get udf info response body to udf application info.
 */
public static UdfApplicationInfo parseGetUdfApplicationInfo(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        String id = root.getChildText("ID");
        String name = root.getChildText("Name");
        String status = root.getChildText("Status");
        String region = root.getChildText("Region");
        Integer imageVersion = Integer.valueOf(root.getChildText("ImageVersion"));
        Integer instanceNum = Integer.valueOf(root.getChildText("InstanceNum"));
        Date date = DateUtil.parseIso8601Date(root.getChildText("CreationDate"));
        String instanceType = root.getChild("Flavor").getChildText("InstanceType");
        InstanceFlavor flavor = new InstanceFlavor(instanceType);
        return new UdfApplicationInfo(name, id, region, status, imageVersion, instanceNum, date, flavor);
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : BigInteger(java.math.BigInteger) JDOMParseException(org.jdom.input.JDOMParseException) InstanceFlavor(com.aliyun.oss.model.InstanceFlavor) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) UdfApplicationInfo(com.aliyun.oss.model.UdfApplicationInfo) Date(java.util.Date) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 12 with ResponseParseException

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

the class ResponseParsers method parseGetUserQos.

/**
 * Unmarshall get user qos response body to user qos.
 */
public static UserQos parseGetUserQos(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        UserQos userQos = new UserQos();
        if (root.getChild("StorageCapacity") != null) {
            userQos.setStorageCapacity(Integer.parseInt(root.getChildText("StorageCapacity")));
        }
        return userQos;
    } 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) UserQos(com.aliyun.oss.model.UserQos) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 13 with ResponseParseException

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

the class ResponseParsers method parseDeleteObjectsResult.

/**
 * Unmarshall delete objects response body to corresponding result.
 */
@SuppressWarnings("unchecked")
public static DeleteObjectsResult parseDeleteObjectsResult(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        DeleteObjectsResult deleteObjectsResult = new DeleteObjectsResult();
        if (root.getChild("EncodingType") != null) {
            String encodingType = root.getChildText("EncodingType");
            deleteObjectsResult.setEncodingType(isNullOrEmpty(encodingType) ? null : encodingType);
        }
        List<String> deletedObjects = new ArrayList<String>();
        List<Element> deletedElements = root.getChildren("Deleted");
        for (Element elem : deletedElements) {
            deletedObjects.add(elem.getChildText("Key"));
        }
        deleteObjectsResult.setDeletedObjects(deletedObjects);
        return deleteObjectsResult;
    } 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) DeleteObjectsResult(com.aliyun.oss.model.DeleteObjectsResult) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 14 with ResponseParseException

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

the class ResponseParsers method parseListUdfApplicationInfo.

/**
 * Unmarshall get udf info response body to udf image info list.
 */
@SuppressWarnings("unchecked")
public static List<UdfApplicationInfo> parseListUdfApplicationInfo(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        List<UdfApplicationInfo> udfApps = new ArrayList<UdfApplicationInfo>();
        if (root.getChild("UDFApplicationInfo") != null) {
            List<Element> udfImageElems = root.getChildren("UDFApplicationInfo");
            for (Element elem : udfImageElems) {
                String id = elem.getChildText("ID");
                String name = elem.getChildText("Name");
                String status = elem.getChildText("Status");
                String region = elem.getChildText("Region");
                Integer imageVersion = Integer.valueOf(elem.getChildText("ImageVersion"));
                Integer instanceNum = Integer.valueOf(elem.getChildText("InstanceNum"));
                Date date = DateUtil.parseIso8601Date(elem.getChildText("CreationDate"));
                String instanceType = elem.getChild("Flavor").getChildText("InstanceType");
                InstanceFlavor flavor = new InstanceFlavor(instanceType);
                UdfApplicationInfo udfApp = new UdfApplicationInfo(name, id, region, status, imageVersion, instanceNum, date, flavor);
                udfApps.add(udfApp);
            }
        }
        return udfApps;
    } catch (JDOMParseException e) {
        throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e);
    } catch (Exception e) {
        throw new ResponseParseException(e.getMessage(), e);
    }
}
Also used : BigInteger(java.math.BigInteger) JDOMParseException(org.jdom.input.JDOMParseException) InstanceFlavor(com.aliyun.oss.model.InstanceFlavor) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) UdfApplicationInfo(com.aliyun.oss.model.UdfApplicationInfo) ArrayList(java.util.ArrayList) Date(java.util.Date) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Example 15 with ResponseParseException

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

the class ResponseParsers method parseGetUdfInfo.

/**
 * Unmarshall get udf info response body to udf info.
 */
public static UdfInfo parseGetUdfInfo(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        String name = root.getChildText("Name");
        String id = root.getChildText("ID");
        String owner = root.getChildText("Owner");
        String desc = root.getChildText("Description");
        Date date = DateUtil.parseIso8601Date(root.getChildText("CreationDate"));
        CannedUdfAcl acl = CannedUdfAcl.parse(root.getChildText("ACL"));
        return new UdfInfo(name, owner, id, desc, acl, date);
    } 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) 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)

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