Search in sources :

Example 1 with ImageProcess

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

the class BucketProcesTest method testBucketImageProcessConf.

@Test
public void testBucketImageProcessConf() {
    try {
        // get default
        BucketProcess bucketProcess = ossClient.getBucketProcess(bucketName);
        Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Both");
        Assert.assertFalse(bucketProcess.getImageProcess().isSourceFileProtect());
        Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "");
        Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "");
        Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
        Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
        Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
        // put 1
        ImageProcess imageProcess = new ImageProcess("Img", true, "jpg,png", "/,-");
        SetBucketProcessRequest request = new SetBucketProcessRequest(bucketName, imageProcess);
        ossClient.setBucketProcess(request);
        // get 1
        bucketProcess = ossClient.getBucketProcess(new GenericRequest(bucketName));
        Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Img");
        Assert.assertTrue(bucketProcess.getImageProcess().isSourceFileProtect());
        Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "jpg,png");
        Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "-,/");
        Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
        Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
        Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
        // put 2
        imageProcess = new ImageProcess("Both", false, "gif", "-");
        request = new SetBucketProcessRequest(bucketName, imageProcess);
        ossClient.setBucketProcess(request);
        // get 2
        bucketProcess = ossClient.getBucketProcess(new GenericRequest(bucketName));
        Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Both");
        Assert.assertFalse(bucketProcess.getImageProcess().isSourceFileProtect());
        Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "");
        Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "-");
        Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
        Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
        Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
        // put 3
        imageProcess = new ImageProcess("Img", true, "*", "/", true);
        request = new SetBucketProcessRequest(bucketName, imageProcess);
        ossClient.setBucketProcess(request);
        // get 3
        bucketProcess = ossClient.getBucketProcess(new GenericRequest(bucketName));
        Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Img");
        Assert.assertTrue(bucketProcess.getImageProcess().isSourceFileProtect());
        Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "*");
        Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "/");
        Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
        Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
        Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ImageProcess(com.aliyun.oss.model.ImageProcess) SetBucketProcessRequest(com.aliyun.oss.model.SetBucketProcessRequest) BucketProcess(com.aliyun.oss.model.BucketProcess) GenericRequest(com.aliyun.oss.model.GenericRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 2 with ImageProcess

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

the class BucketProcesTest method testBucketImageProcessConfNegative.

@Test
public void testBucketImageProcessConfNegative() {
    // bucket not exist
    try {
        ossClient.getBucketProcess("bucket-not-exist");
        Assert.fail("GetBucketImageProcessConf should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(OSSErrorCode.NO_SUCH_BUCKET, e.getErrorCode());
    }
    try {
        ImageProcess conf = new ImageProcess("img", false, "*", "/,-");
        SetBucketProcessRequest request = new SetBucketProcessRequest("bucket-not-exist", conf);
        ossClient.setBucketProcess(request);
        Assert.fail("PutBucketImageProcessConf should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(OSSErrorCode.NO_SUCH_BUCKET, e.getErrorCode());
    }
    // parameter invalid
    try {
        ImageProcess conf = null;
        SetBucketProcessRequest request = new SetBucketProcessRequest(bucketName, conf);
        ossClient.setBucketProcess(request);
        Assert.fail("PutBucketImageProcessConf should not be successful.");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof NullPointerException);
    }
    try {
        ImageProcess conf = new ImageProcess(null, false, "*", "/,-");
        SetBucketProcessRequest request = new SetBucketProcessRequest(bucketName, conf);
        ossClient.setBucketProcess(request);
        Assert.fail("PutBucketImageProcessConf should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(OSSErrorCode.INVALID_ARGUMENT, e.getErrorCode());
    }
    try {
        ImageProcess conf = new ImageProcess("xxx", false, "*", "/,-");
        SetBucketProcessRequest request = new SetBucketProcessRequest(bucketName, conf);
        ossClient.setBucketProcess(request);
        Assert.fail("PutBucketImageProcessConf should not be successful.");
    } catch (OSSException e) {
        Assert.assertEquals(OSSErrorCode.INVALID_ARGUMENT, e.getErrorCode());
    }
}
Also used : ImageProcess(com.aliyun.oss.model.ImageProcess) OSSException(com.aliyun.oss.OSSException) SetBucketProcessRequest(com.aliyun.oss.model.SetBucketProcessRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 3 with ImageProcess

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

the class OSSBucketOperation method setBucketProcess.

public void setBucketProcess(SetBucketProcessRequest setBucketProcessRequest) throws OSSException, ClientException {
    assertParameterNotNull(setBucketProcessRequest, "setBucketProcessRequest");
    ImageProcess imageProcessConf = setBucketProcessRequest.getImageProcess();
    assertParameterNotNull(imageProcessConf, "imageProcessConf");
    String bucketName = setBucketProcessRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    Map<String, String> params = new HashMap<String, String>();
    params.put(SUBRESOURCE_PROCESS_CONF, null);
    RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setParameters(params).setInputStreamWithLength(bucketImageProcessConfMarshaller.marshall(imageProcessConf)).setOriginalRequest(setBucketProcessRequest).build();
    doOperation(request, emptyResponseParser, bucketName, null);
}
Also used : ImageProcess(com.aliyun.oss.model.ImageProcess) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) RequestMessage(com.aliyun.oss.common.comm.RequestMessage)

Example 4 with ImageProcess

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

the class ResponseParsers method parseGetBucketImageProcessConf.

/**
 * Unmarshall get bucket process response body to bucket process.
 */
public static BucketProcess parseGetBucketImageProcessConf(InputStream responseBody) throws ResponseParseException {
    try {
        Element root = getXmlRootElement(responseBody);
        String compliedHost = root.getChildText("CompliedHost");
        boolean sourceFileProtect = false;
        if (root.getChildText("SourceFileProtect").equals("Enabled")) {
            sourceFileProtect = true;
        }
        String sourceFileProtectSuffix = root.getChildText("SourceFileProtectSuffix");
        String styleDelimiters = root.getChildText("StyleDelimiters");
        ImageProcess imageProcess = new ImageProcess(compliedHost, sourceFileProtect, sourceFileProtectSuffix, styleDelimiters);
        if (root.getChildText("Version") != null) {
            imageProcess.setVersion(Integer.parseInt(root.getChildText("Version")));
        }
        return new BucketProcess(imageProcess);
    } 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) ImageProcess(com.aliyun.oss.model.ImageProcess) Element(org.jdom.Element) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException) BucketProcess(com.aliyun.oss.model.BucketProcess) ParseException(java.text.ParseException) JDOMParseException(org.jdom.input.JDOMParseException) ResponseParseException(com.aliyun.oss.common.parser.ResponseParseException)

Aggregations

ImageProcess (com.aliyun.oss.model.ImageProcess)4 OSSException (com.aliyun.oss.OSSException)2 BucketProcess (com.aliyun.oss.model.BucketProcess)2 SetBucketProcessRequest (com.aliyun.oss.model.SetBucketProcessRequest)2 Test (org.junit.Test)2 RequestMessage (com.aliyun.oss.common.comm.RequestMessage)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 GenericRequest (com.aliyun.oss.model.GenericRequest)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Element (org.jdom.Element)1 JDOMParseException (org.jdom.input.JDOMParseException)1