Example usage for com.amazonaws.services.s3 AmazonS3Client listBuckets

List of usage examples for com.amazonaws.services.s3 AmazonS3Client listBuckets

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3Client listBuckets.

Prototype

@Override
    public List<Bucket> listBuckets(ListBucketsRequest listBucketsRequest)
            throws SdkClientException, AmazonServiceException 

Source Link

Usage

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public ListAllMyBucketsResponseType listAllMyBuckets(ListAllMyBucketsType request) throws S3Exception {
    ListAllMyBucketsResponseType reply = request.getReply();
    OsgInternalS3Client internalS3Client = null;
    User requestUser = null;//  w  w w  . j  ava2  s .  co m
    try {
        requestUser = getRequestUser(request);
        //The euca-types
        ListAllMyBucketsList myBucketList = new ListAllMyBucketsList();
        myBucketList.setBuckets(new ArrayList<BucketListEntry>());

        //The s3 client types
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        ListBucketsRequest listRequest = new ListBucketsRequest();

        //Map s3 client result to euca response message
        List<Bucket> result = s3Client.listBuckets(listRequest);
        for (Bucket b : result) {
            myBucketList.getBuckets().add(new BucketListEntry(b.getName(),
                    DateFormatter.dateToHeaderFormattedString(b.getCreationDate())));
        }

        reply.setBucketList(myBucketList);
    } catch (AmazonServiceException ex) {
        LOG.debug("Got service error from backend: " + ex.getMessage(), ex);
        throw S3ExceptionMapper.fromAWSJavaSDK(ex);
    }
    return reply;
}