Search in sources :

Example 1 with GetBucketImageResult

use of com.aliyun.oss.model.GetBucketImageResult in project aliyun-oss-java-sdk by aliyun.

the class TestForImg method testPutGetBucketImage.

public void testPutGetBucketImage() {
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    clientImg.putBucketImage(request);
    sleepSecond(10);
    GetBucketImageResult result = clientImg.getBucketImage(bucketName);
    Assert.assertEquals(result.GetBucketName(), bucketName);
    Assert.assertEquals(result.GetDefault404Pic(), "");
    Assert.assertFalse(result.GetIsAutoSetContentType());
    Assert.assertFalse(result.GetIsForbidOrigPicAccess());
    Assert.assertFalse(result.GetIsUseSrcFormat());
    Assert.assertFalse(result.GetIsSetAttachName());
    Assert.assertEquals(result.GetStyleDelimiters(), "!");
    Assert.assertEquals(result.GetStatus(), "Enabled");
    request.SetIsForbidOrigPicAccess(true);
    request.SetIsUseStyleOnly(true);
    request.SetIsAutoSetContentType(true);
    request.SetIsUseSrcFormat(true);
    request.SetIsSetAttachName(true);
    String default404Pic = "index.png";
    request.SetDefault404Pic(default404Pic);
    String styleDelimiters = "_";
    request.SetStyleDelimiters(styleDelimiters);
    clientImg.putBucketImage(request);
    sleepSecond(20);
    result = clientImg.getBucketImage(bucketName);
    Assert.assertEquals(result.GetBucketName(), bucketName);
    Assert.assertEquals(result.GetDefault404Pic(), default404Pic);
    Assert.assertFalse(!result.GetIsAutoSetContentType());
    // TODO img's problem
    Assert.assertFalse(!result.GetIsForbidOrigPicAccess());
    Assert.assertFalse(!result.GetIsUseSrcFormat());
    Assert.assertFalse(!result.GetIsSetAttachName());
    Assert.assertEquals(result.GetStyleDelimiters(), styleDelimiters);
    Assert.assertEquals(result.GetStatus(), "Enabled");
}
Also used : PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest) GetBucketImageResult(com.aliyun.oss.model.GetBucketImageResult)

Example 2 with GetBucketImageResult

use of com.aliyun.oss.model.GetBucketImageResult 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)

Aggregations

GetBucketImageResult (com.aliyun.oss.model.GetBucketImageResult)2 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 PutBucketImageRequest (com.aliyun.oss.model.PutBucketImageRequest)1 ParseException (java.text.ParseException)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1