Search in sources :

Example 1 with GenericRequest

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

the class OSSClientRequestTest method testBucketLocationRequest.

@Test
public void testBucketLocationRequest() {
    TestAction test = new TestAction() {

        @Override
        public void run() throws Exception {
            bucketOp.getBucketLocation(new GenericRequest(bucketName));
        }
    };
    executeTest(test, HttpMethod.GET, bucketName + "." + endpoint.getHost(), "?location", null);
}
Also used : GenericRequest(com.aliyun.oss.model.GenericRequest) Test(org.junit.Test)

Example 2 with GenericRequest

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

the class TestForImg method testGenernicRequest.

// 已抓包看了所有请求头
public void testGenernicRequest() {
    PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
    GenericRequest req = new GenericRequest();
    request.addHeader("oss-request-ip", "31.71.68.91");
    request.addHeader("oss-request-agent", "oss-java-sdk");
    request.addHeader("oss-operation", "PutBucketImage");
    try {
        clientImg.putBucketImage(request);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "GetBucketImage");
    try {
        clientImg.getBucketImage(bucketName, req);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "DeleteBucketImage");
    try {
        clientImg.deleteBucketImage(bucketName, req);
    } catch (Exception e) {
    }
    PutImageStyleRequest requestStyle = new PutImageStyleRequest();
    requestStyle.SetBucketName(bucketName);
    String styleName = "style";
    String styleContent = "200w";
    requestStyle.SetStyle(styleName);
    requestStyle.SetStyleName(styleContent);
    requestStyle.addHeader("oss-operation", "PutImageStyle");
    try {
        clientImg.putImageStyle(requestStyle);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "DeleteImageStyle");
    try {
        clientImg.deleteImageStyle(bucketName, styleName, req);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "GetImageStyle");
    try {
        clientImg.getImageStyle(bucketName, styleName, req);
    } catch (Exception e) {
    }
    req.addHeader("oss-operation", "ListImageStyle");
    try {
        clientImg.listImageStyle(bucketName, req);
    } catch (Exception e) {
    }
}
Also used : PutBucketImageRequest(com.aliyun.oss.model.PutBucketImageRequest) PutImageStyleRequest(com.aliyun.oss.model.PutImageStyleRequest) GenericRequest(com.aliyun.oss.model.GenericRequest)

Example 3 with GenericRequest

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

the class BucketTaggingTest method testSetBucketTagging.

@Test
public void testSetBucketTagging() {
    try {
        SetBucketTaggingRequest request = new SetBucketTaggingRequest(bucketName);
        request.setTag("tk1", "tv1");
        request.setTag("tk2", "tv2");
        ossClient.setBucketTagging(request);
        TagSet tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
        Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
        Map<String, String> tags = tagSet.getAllTags();
        Assert.assertEquals(2, tags.size());
        Assert.assertTrue(tags.containsKey("tk1"));
        Assert.assertTrue(tags.containsKey("tk2"));
        ossClient.deleteBucketTagging(new GenericRequest(bucketName));
        waitForCacheExpiration(5);
        tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
        Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
        tags = tagSet.getAllTags();
        Assert.assertTrue(tags.isEmpty());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : SetBucketTaggingRequest(com.aliyun.oss.model.SetBucketTaggingRequest) TagSet(com.aliyun.oss.model.TagSet) GenericRequest(com.aliyun.oss.model.GenericRequest) Test(org.junit.Test)

Example 4 with GenericRequest

use of com.aliyun.oss.model.GenericRequest 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 5 with GenericRequest

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

the class OSSBucketOperation method doesBucketExists.

/**
 * Determine whether a bucket exists or not.
 */
public boolean doesBucketExists(GenericRequest genericRequest) throws OSSException, ClientException {
    assertParameterNotNull(genericRequest, "genericRequest");
    String bucketName = genericRequest.getBucketName();
    assertParameterNotNull(bucketName, "bucketName");
    ensureBucketNameValid(bucketName);
    try {
        getBucketAcl(new GenericRequest(bucketName));
    } catch (OSSException oe) {
        if (oe.getErrorCode().equals(OSSErrorCode.NO_SUCH_BUCKET)) {
            return false;
        }
    }
    return true;
}
Also used : OSSException(com.aliyun.oss.OSSException) GenericRequest(com.aliyun.oss.model.GenericRequest)

Aggregations

GenericRequest (com.aliyun.oss.model.GenericRequest)6 Test (org.junit.Test)4 OSSException (com.aliyun.oss.OSSException)2 BucketProcess (com.aliyun.oss.model.BucketProcess)1 ImageProcess (com.aliyun.oss.model.ImageProcess)1 PutBucketImageRequest (com.aliyun.oss.model.PutBucketImageRequest)1 PutImageStyleRequest (com.aliyun.oss.model.PutImageStyleRequest)1 SetBucketAclRequest (com.aliyun.oss.model.SetBucketAclRequest)1 SetBucketProcessRequest (com.aliyun.oss.model.SetBucketProcessRequest)1 SetBucketTaggingRequest (com.aliyun.oss.model.SetBucketTaggingRequest)1 TagSet (com.aliyun.oss.model.TagSet)1