Package org.jets3t.service.model

Examples of org.jets3t.service.model.S3Bucket


    public void testBucketLogging() throws Exception {
        S3Service s3Service = getS3Service(awsCredentials);

        String bucketName = awsCredentials.getAccessKey() + ".jets3t_TestCases";

        S3Bucket bucket = s3Service.createBucket(bucketName);
       
        // Check logging status is false
        S3BucketLoggingStatus loggingStatus = s3Service.getBucketLoggingStatus(bucket.getName());
        assertFalse("Expected logging to be disabled for bucket " + bucketName,
            loggingStatus.isLoggingEnabled());
       
        // Enable logging (non-existent target bucket)
        try {
            S3BucketLoggingStatus newLoggingStatus = new S3BucketLoggingStatus(
                awsCredentials.getAccessKey() + ".NonExistentBucketName", "access-log-");
            s3Service.setBucketLoggingStatus(bucket.getName(), newLoggingStatus, true);
            fail("Using non-existent target bucket should have caused an exception");           
        } catch (Exception e) {           
        }
       
        // Enable logging (in same bucket)
        S3BucketLoggingStatus newLoggingStatus = new S3BucketLoggingStatus(bucketName, "access-log-");
        s3Service.setBucketLoggingStatus(bucket.getName(), newLoggingStatus, true);
        loggingStatus = s3Service.getBucketLoggingStatus(bucket.getName());
        assertTrue("Expected logging to be enabled for bucket " + bucketName,
            loggingStatus.isLoggingEnabled());
        assertEquals("Target bucket", bucketName, loggingStatus.getTargetBucketName());
        assertEquals("Log file prefix", "access-log-", loggingStatus.getLogfilePrefix());
       
        // Disable logging
        newLoggingStatus = new S3BucketLoggingStatus();
        s3Service.setBucketLoggingStatus(bucket.getName(), newLoggingStatus, true);
        loggingStatus = s3Service.getBucketLoggingStatus(bucket.getName());
        assertFalse("Expected logging to be disabled for bucket " + bucketName,
            loggingStatus.isLoggingEnabled());

//        s3Service.deleteBucket(bucket.getName());
    }
View Full Code Here


    public void testUrlSigning() throws Exception {
        S3Service s3Service = getS3Service(awsCredentials);

        String bucketName = awsCredentials.getAccessKey() + ".jets3t_TestCases";

        S3Bucket bucket = s3Service.createBucket(bucketName);
       
        // Create test object, with private ACL
        String dataString = "Text for the URL Signing test object...";
        S3Object object = new S3Object(bucket, "Testing URL Signing", dataString);
        object.setContentType("text/html");
        object.addMetadata("x-amz-example-header", "example-value");
        object.setAcl(AccessControlList.REST_CANNED_PRIVATE);

        // Determine what the time will be in 5 minutes.
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE, 5);
        Date expiryDate = cal.getTime();

        // Create a signed HTTP PUT URL.
        String signedPutUrl = S3Service.createSignedPutUrl(bucket.getName(), object.getKey(),
            object.getMetadataMap(), awsCredentials, expiryDate, false);

        // Put the object in S3 using the signed URL (no AWS credentials required)
        RestS3Service restS3Service = new RestS3Service(null);
        restS3Service.putObjectWithSignedUrl(signedPutUrl, object);
       
        // Ensure the object was created.
        S3Object objects[] = s3Service.listObjects(bucket, object.getKey(), null);
        assertEquals("Signed PUT URL failed to put/create object", objects.length, 1);

        // Change the object's content-type and ensure the signed PUT URL disallows the put.
        object.setContentType("application/octet-stream");
        try {
            restS3Service.putObjectWithSignedUrl(signedPutUrl, object);
            fail("Should not be able to use a signed URL for an object with a changed content-type");
        } catch (S3ServiceException e) {           
            object.setContentType("text/html");
        }
       
        // Add an object header and ensure the signed PUT URL disallows the put.
        object.addMetadata("x-amz-example-header-2", "example-value");
        try {
            restS3Service.putObjectWithSignedUrl(signedPutUrl, object);
            fail("Should not be able to use a signed URL for an object with changed metadata");
        } catch (S3ServiceException e) {
            object.removeMetadata("x-amz-example-header-2");
        }

        // Change the object's name and ensure the signed PUT URL uses the signed name, not the object name.
        String originalName = object.getKey();
        object.setKey("Testing URL Signing 2");
        object.setDataInputStream(new ByteArrayInputStream(dataString.getBytes()));
        S3Object renamedObject = restS3Service.putObjectWithSignedUrl(signedPutUrl, object);
        assertEquals("Ensure returned object key is renamed based on signed PUT URL",
            originalName, renamedObject.getKey());

        // Ensure we can't get the object with a normal URL.
        String s3Url = "https://s3.amazonaws.com";
        URL url = new URL(s3Url + "/" + bucketName + "/" + RestUtils.encodeUrlString(object.getKey()));
        assertEquals("Expected denied access (403) error", 403, ((HttpURLConnection) url
            .openConnection()).getResponseCode());

        // Create a signed HTTP GET URL.
        String signedGetUrl = S3Service.createSignedGetUrl(bucket.getName(), object.getKey(),
            awsCredentials, expiryDate, false);

        // Ensure the signed URL can retrieve the object.
        url = new URL(signedGetUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
View Full Code Here

    public void testHashVerifiedUploads() throws Exception {
        S3Service s3Service = getS3Service(awsCredentials);

        String bucketName = awsCredentials.getAccessKey() + ".jets3t_TestCases";

        S3Bucket bucket = s3Service.createBucket(bucketName);
       
        // Create test object with an MD5 hash of the data.
        String dataString = "Text for MD5 hashing...";
        S3Object object = new S3Object(bucket, "Testing MD5 Hashing", dataString);       
        object.setContentType("text/plain");
View Full Code Here

        public void endDocument() {
        }

        public void startElement(String uri, String name, String qName, Attributes attrs) {
            if (name.equals("Bucket")) {
                currentBucket = new S3Bucket();
            } else if (name.equals("Owner")) {
                bucketsOwner = new S3Owner();
            }
        }
View Full Code Here

            }   
        }
       
        Map map = createObjectImpl(bucketName, null, null, requestEntity, metadata, acl);
       
        S3Bucket bucket = new S3Bucket(bucketName, location);
        bucket.setAcl(acl);
        bucket.replaceAllMetadata(map);
        return bucket;
    }
View Full Code Here

            ListAllMyBucketsEntry[] entries = result.getBuckets();           
            buckets = new S3Bucket[entries.length];
            int index = 0;
            for (int i = 0; i < entries.length; i++) {
                ListAllMyBucketsEntry entry = (ListAllMyBucketsEntry) entries[i];
                S3Bucket bucket = new S3Bucket();
                bucket.setName(entry.getName());
                bucket.setCreationDate(entry.getCreationDate().getTime());
                buckets[index++] = bucket;
            }
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
View Full Code Here

            String signature = ServiceUtils.signWithHmacSha1(getAWSSecretKey(),
                Constants.SOAP_SERVICE_NAME + "CreateBucket" + convertDateToString(timestamp));
            s3SoapBinding.createBucket(
                bucketName, grants, getAWSAccessKey(), timestamp, signature);
           
            S3Bucket bucket = new S3Bucket(bucketName);
            bucket.setAcl(acl);
            return bucket;           
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new S3ServiceException("Unable to Create Bucket: " + bucketName, e);  
View Full Code Here

            throw new SynchronizeException("Action string must be 'UP' or 'DOWN'");
        }       
       
        this.cryptoPassword = cryptoPassword;
               
        S3Bucket bucket = null;
        if (s3Service.getAWSCredentials() == null) {
            // Using an anonymous connection, don't check bucket ownership or attempt to create it.
            bucket = new S3Bucket(bucketName);
        } else {
            // Using an authentication connection, so check for bucket ownership and create one if necessary.
            bucket = s3Service.getBucket(bucketName);
            if (bucket == null) {
                // Bucket does not exist in this user's account, try creating it.
                try {
                    bucket = s3Service.createBucket(new S3Bucket(bucketName));
                } catch (Exception e) {
                    throw new SynchronizeException("Unable to create/connect to S3 bucket: " + bucketName, e);
                }
            }           
        }
View Full Code Here

            }   
        }
       
        Map map = createObjectImpl(bucketName, null, null, requestEntity, metadata, acl);
       
        S3Bucket bucket = new S3Bucket(bucketName, location);
        bucket.setAcl(acl);
        bucket.replaceAllMetadata(map);
        return bucket;
    }
View Full Code Here

      if (e.getCause() instanceof IOException) {
        throw (IOException) e.getCause();
      }
      throw new S3Exception(e);
    }
    bucket = new S3Bucket(uri.getHost());

    createBucket(bucket.getName());
 
View Full Code Here

TOP

Related Classes of org.jets3t.service.model.S3Bucket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.