Search in sources :

Example 6 with CORSRule

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

the class BucketOperationsSample method doBucketCORSOperations.

private static void doBucketCORSOperations() {
    SetBucketCORSRequest request = new SetBucketCORSRequest(bucketName);
    CORSRule r0 = new CORSRule();
    r0.addAllowdOrigin("http://www.a.com");
    r0.addAllowdOrigin("http://www.b.com");
    r0.addAllowedMethod("GET");
    r0.addAllowedHeader("Authorization");
    r0.addExposeHeader("x-oss-test");
    r0.addExposeHeader("x-oss-test1");
    r0.setMaxAgeSeconds(100);
    request.addCorsRule(r0);
    System.out.println("Setting bucket CORS\n");
    client.setBucketCORS(request);
    System.out.println("Getting bucket CORS:");
    List<CORSRule> rules = client.getBucketCORSRules(bucketName);
    r0 = rules.get(0);
    System.out.println("\tAllowedOrigins " + r0.getAllowedOrigins());
    System.out.println("\tAllowedMethods " + r0.getAllowedMethods());
    System.out.println("\tAllowedHeaders " + r0.getAllowedHeaders());
    System.out.println("\tExposeHeaders " + r0.getExposeHeaders());
    System.out.println("\tMaxAgeSeconds " + r0.getMaxAgeSeconds());
    System.out.println();
    System.out.println("Deleting bucket CORS\n");
    client.deleteBucketCORSRules(bucketName);
}
Also used : CORSRule(com.aliyun.oss.model.SetBucketCORSRequest.CORSRule) SetBucketCORSRequest(com.aliyun.oss.model.SetBucketCORSRequest)

Aggregations

CORSRule (com.aliyun.oss.model.SetBucketCORSRequest.CORSRule)6 SetBucketCORSRequest (com.aliyun.oss.model.SetBucketCORSRequest)4 OSSException (com.aliyun.oss.OSSException)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 OSSClient (com.aliyun.oss.OSSClient)1 ResponseParseException (com.aliyun.oss.common.parser.ResponseParseException)1 AccessControlList (com.aliyun.oss.model.AccessControlList)1 BucketLoggingResult (com.aliyun.oss.model.BucketLoggingResult)1 BucketReferer (com.aliyun.oss.model.BucketReferer)1 CannedAccessControlList (com.aliyun.oss.model.CannedAccessControlList)1 Grant (com.aliyun.oss.model.Grant)1 LifecycleRule (com.aliyun.oss.model.LifecycleRule)1 ObjectListing (com.aliyun.oss.model.ObjectListing)1 SetBucketLifecycleRequest (com.aliyun.oss.model.SetBucketLifecycleRequest)1 SetBucketLoggingRequest (com.aliyun.oss.model.SetBucketLoggingRequest)1 SetBucketWebsiteRequest (com.aliyun.oss.model.SetBucketWebsiteRequest)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 JSONException (org.codehaus.jettison.json.JSONException)1