Package org.jets3t.service

Examples of org.jets3t.service.S3Service


        return properties;
    }

    private S3Service getS3Service() {
        org.jets3t.service.security.AWSCredentials awsCredentials = new org.jets3t.service.security.AWSCredentials(awsAccessKey, awsSecretKey);
        S3Service s3Service;
        try {
            s3Service = new RestS3Service(awsCredentials);
        } catch (S3ServiceException e) {
            log.error("S3ServiceException attempting to create RestS3Service", e);
            return null;
View Full Code Here


  public String absoluteUrl(String fileName) {
    return "http://" + bucketName + "/" + fileName;
  }

  public String storeFile(FileData file) {
    S3Service s3 = createS3Service();
    S3Bucket bucket;
    try {
      bucket = s3.getBucket(bucketName);
    } catch (S3ServiceException e) {
      throw new IllegalStateException("Unable to retrieve S3 Bucket", e);
    }
    S3Object object = new S3Object(file.getName());
    object.setDataInputStream(new ByteArrayInputStream(file.getBytes()));
    object.setContentLength(file.getBytes().length);
    object.setContentType(file.getContentType());   
    AccessControlList acl = new AccessControlList();
    acl.setOwner(bucket.getOwner());
    acl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ);
    object.setAcl(acl);
    try {
      s3.putObject(bucket, object);
    } catch (S3ServiceException e) {
      throw new RuntimeException("Unable to put object into S3", e);
    }
    return absoluteUrl(file.getName());
  }
View Full Code Here

        /*
         * Generate the signed URL strings for PUT, GET, HEAD and DELETE operations, using the
         * AWS Credentials in the samples.properties file.
         */
        AWSCredentials awsCredentials = SamplesUtils.loadAWSCredentials();
        S3Service s3Service = new RestS3Service(awsCredentials);

        // Create an unsigned HTTP GET URL -- useful only for publicly-accessible objects.
        String unsignedGetUrl = s3Service.createUnsignedObjectUrl(
            bucket.getName(), object.getKey(), false, false, false);

        // Create a signed HTTP PUT URL valid for 5 minutes.
        String putUrl = s3Service.createSignedPutUrl(bucket.getName(), object.getKey(),
            object.getMetadataMap(), expiryDate, false);

        // Create a signed HTTP GET URL valid for 5 minutes.
        String getUrl = s3Service.createSignedGetUrl(bucket.getName(), object.getKey(),
            expiryDate, false);

        // Create a signed HTTP HEAD URL valid for 5 minutes.
        String headUrl = s3Service.createSignedHeadUrl(bucket.getName(), object.getKey(),
            expiryDate, false);

        // Create a signed HTTP DELETE URL valid for 5 minutes.
        String deleteUrl = s3Service.createSignedDeleteUrl(bucket.getName(), object.getKey(),
            expiryDate, false);

        System.out.println("Unsigned URL: " + unsignedGetUrl);
        System.out.println("Signed PUT URL: " + putUrl);
        System.out.println("Signed GET URL: " + getUrl);
View Full Code Here

        /*
         * Store credentials.
         */

        // Initialise an S3 Service that knows the AWS credentials.
        S3Service s3Service = new RestS3Service(awsCredentials);

        // Encrypt credentials into InputStream
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        awsCredentials.save(password, baos);
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

        // Create the target bucket
        bucket = s3Service.createBucket(bucketName);

        // Upload credentials object, which must be publicly readable.
        S3Object credsObject = new S3Object(credentialObjectName);
        credsObject.setDataInputStream(bais);
        credsObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
        s3Service.putObject(bucket, credsObject);

        /*
         * Retrieve credentials.
         */

        // Initialise an S3 Service that does not know the AWS credentials.
        s3Service = new RestS3Service(null);

        // Check whether the passphrase-based bucket exists and is accessible.
        System.out.println("Is bucket accessible? " + s3Service.isBucketAccessible(bucketName));

        // Download the encrypted credentials object.
        S3Object retrievedCredsObject = s3Service.getObject(bucket, credentialObjectName);

        // Decrypt the credentials object.
        ProviderCredentials retrievedCreds = AWSCredentials.load(password,
            new BufferedInputStream(retrievedCredsObject.getDataInputStream()));

View Full Code Here

            "YOUR_AWS_ACCESSS_KEY", "YOUR_AWS_SECRET_KEY",
            "DEVPAY_USER_TOKEN", "DEVPAY_PRODUCT_TOKEN");

        // Once you have defined your DevPay S3 credentials, you can create an
        // S3Service class based on these and access the DevPay account as usual.
        S3Service devPayService = new RestS3Service(devPayCredentials);
        devPayService.listAllBuckets();

        // You can also generate signed URLs for DevPay S3 accounts. Here is the
        // code to generate a link that makes an object in a DevPay account
        // temporary available for public download.

        cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE, 5);

        String signedDevPayUrl = devPayService.createSignedGetUrl(
            "devpay-bucket-name", "devpay-object-name", cal.getTime());

    }
View Full Code Here

        String                          description,
        PrintStream                     info,
        PrintStream                     debug)
            throws ExecutionProblem
    {
        S3Service s3Service = null;
        boolean rw = true;
        try
        {
            AccessControlList acl = null;
            String awsAccessKey = this.args.getXferS3ID();
            s3Service = this.getService();

            String baseBucketName = this.args.getS3Bucket();

            PrintStream pr = null;
            if (info != null) {
                pr = info;
            } else if (debug != null) {
                pr = debug;
            }
            String key = this.makeKey(vmName, null);

            File file = new File(localfile);

            if (pr != null) {              
                pr.println("\nTransferring");
                pr.println("  - Source: " + file.getName());
                String destUrlString = "cumulus://" + baseBucketName + "/" + key;
                pr.println("  - Destination: " + destUrlString);
                pr.println();              
                pr.println("Preparing the file for transfer:");
            }

            CloudProgressPrinter progressWatcher =
                new CloudProgressPrinter(pr, file.length(), this.args.getNoSpinner());
            S3Object s3Object = ObjectUtils.createObjectForUpload(
                key, file, null, false, progressWatcher);
            progressWatcher.flush();
            s3Object.setContentType(Mimetypes.MIMETYPE_OCTET_STREAM);
            if (pr != null) {
                pr.println("\n\nTransferring the file:");
            }
            CumulusInputStream cis = new CumulusInputStream(
                file.length(), pr, s3Object.getDataInputStream(), this.args.getNoSpinner());
            s3Object.setDataInputStream(cis);
            if(this.args.getCommonVMSet())
            {
                if (pr != null) {
                    pr.println("Setting permissions for common use.");
                }
                rw = false;
                acl = AccessControlList.REST_CANNED_PUBLIC_READ;
                s3Object.setAcl(acl);
            }
            s3Service.putObject(baseBucketName, s3Object);
            progressWatcher.flush();
            s3Object.closeDataInputStream();
            cis.close();

            if(description != null)
            {
                String descObjName = getDescriptionFileKey(vmName, rw);

                S3Object descObj = new S3Object(descObjName, description);
                if (acl != null)
                {
                    descObj.setAcl(acl);
                }
                s3Service.putObject(baseBucketName, descObj);
            }

            if (pr != null) {
                pr.println("");
                pr.println("");
View Full Code Here

        String                          vmName,
        PrintStream                     info,
        PrintStream                     debug)
            throws ExecutionProblem
    {
        S3Service s3Service = null;
        try
        {
            String baseBucketName = this.args.getS3Bucket();
            String key = this.makeKey(vmName, null);
            File file = new File(localfile);

            PrintStream pr = null;
            if (info != null) {
                pr = info;
            } else if (debug != null) {
                pr = debug;
            }

            if (pr != null) {
                String srcUrlString = "cumulus://" + baseBucketName + "/" + key;
                pr.println("\nTransferring");
                pr.println("  - Source: " + srcUrlString);

                pr.println("  - Destination: " + file.getAbsolutePath());
                pr.println();

            }

            s3Service = this.getService();
            S3Object s3Object = s3Service.getObject(baseBucketName, key);

            BytesProgressWatcher progressWatcher =
                new CloudProgressPrinter(pr, s3Object.getContentLength(), this.args.getNoSpinner());
            byte b [] = new byte[1024*64];
            InputStream dis = s3Object.getDataInputStream();
View Full Code Here

        String                          vmName,
        PrintStream                     info,
        PrintStream                     debug)
            throws ExecutionProblem
    {
        S3Service s3Service = null;
        try
        {
            s3Service = this.getService();

            String baseBucketName = this.args.getS3Bucket();
            String keyName = this.makeKey(vmName, null);

            try
            {
                s3Service.deleteObject(baseBucketName, keyName);
            }
            catch(S3ServiceException s3ex)
            {               
                if(s3ex.getResponseCode() == 404)
                {
                    keyName = this.makeKey(vmName, "common");
                    s3Service.deleteObject(baseBucketName, keyName);
                }
                else
                {
                    throw new ExecutionProblem(s3ex.toString());
                }
View Full Code Here

            {
                throw new S3ServiceException("Could not make the self signed handler " + ex.toString(), ex);
            }
        }
        AWSCredentials awsCredentials = this.getAwsCredentail();
        S3Service s3Service = new RestS3Service(
            awsCredentials,
            "cloud-client",
            null,
            j3p,
            hc);
View Full Code Here

            String                      vmName)
                throws ExecutionProblem
    {
        String baseBucketName;
        String keyNameOwner;
        S3Service s3Service = null;
        try
        {
            s3Service = this.getService();
            int ndx = vmName.indexOf("cumulus://");
            if(ndx >= 0)
View Full Code Here

TOP

Related Classes of org.jets3t.service.S3Service

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.