diff --git a/extensions/jets3t/pom.xml b/extensions/jets3t/pom.xml deleted file mode 100644 index 3ce3166b3b..0000000000 --- a/extensions/jets3t/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - - - org.jclouds - jclouds-project - 1.0-SNAPSHOT - ../../project/pom.xml - - 4.0.0 - org.jclouds - jclouds-jets3t - jclouds JetS3t Adapter - jar - JetS3t plug-in implemented by JClouds - - - scm:svn:http://jclouds.googlecode.com/svn/trunk/extensions/jets3t - scm:svn:https://jclouds.googlecode.com/svn/trunk/extensions/jets3t - http://jclouds.googlecode.com/svn/trunk/extensions/jets3t - - - - - - - - - - net.java.dev.jets3t - jets3t - 0.7.1 - - - ${project.groupId} - jclouds-gae - ${project.version} - - - ${project.groupId} - jclouds-s3 - ${project.version} - - - ${project.groupId} - jclouds-s3 - ${project.version} - test-jar - test - - - - - - jets3t - jets3t - http://jets3t.s3.amazonaws.com/maven2 - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - jclouds.aws.accesskeyid - ${jclouds.aws.accesskeyid} - - - jclouds.aws.secretaccesskey - ${jclouds.aws.secretaccesskey} - - - - - - - diff --git a/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java b/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java deleted file mode 100644 index 128d4e6f3b..0000000000 --- a/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java +++ /dev/null @@ -1,288 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.jets3t; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.S3ContextFactory; -import org.jclouds.util.Utils; -import org.jets3t.service.S3ObjectsChunk; -import org.jets3t.service.S3Service; -import org.jets3t.service.S3ServiceException; -import org.jets3t.service.acl.AccessControlList; -import org.jets3t.service.model.S3Bucket; -import org.jets3t.service.model.S3BucketLoggingStatus; -import org.jets3t.service.model.S3Object; -import org.jets3t.service.security.AWSCredentials; - -import com.google.inject.Module; - -/** - * A JetS3t S3Service implemented by JClouds - * - * @author Adrian Cole - * - */ -public class JCloudsS3Service extends S3Service { - - private static final long serialVersionUID = 1L; - - private final S3Context context; - private final S3Connection connection; - - private final long requestTimeoutMilliseconds = 10000; - - /** - * Initializes a JClouds context to S3. - * - * @param awsCredentials - * - credentials to access S3 - * @param modules - * - Module that configures a FutureHttpClient, if not specified, - * default is URLFetchServiceClientModule - * @throws S3ServiceException - */ - protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules) - throws S3ServiceException { - super(awsCredentials); - if (modules == null || modules.length == 0) - modules = new Module[] { new org.jclouds.gae.config.URLFetchServiceClientModule() }; - context = S3ContextFactory.createS3Context(awsCredentials - .getAccessKey(), awsCredentials.getSecretKey(), modules); - connection = context.getConnection(); - } - - @Override - public int checkBucketStatus(String bucketName) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - @Override - protected Map copyObjectImpl(String sourceBucketName, - String sourceObjectKey, String destinationBucketName, - String destinationObjectKey, AccessControlList acl, - Map destinationMetadata, Calendar ifModifiedSince, - Calendar ifUnmodifiedSince, String[] ifMatchTags, - String[] ifNoneMatchTags) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected S3Bucket createBucketImpl(String bucketName, String location, - AccessControlList acl) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - /** - * {@inheritDoc} - * - * @see S3Connection#deleteBucketIfEmpty(org.jclouds.aws.s3.domain.S3Bucket) - */ - @Override - protected void deleteBucketImpl(String bucketName) - throws S3ServiceException { - try { - connection.deleteBucketIfEmpty(bucketName).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils. rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException( - "error deleting bucket: " + bucketName, e); - } - } - - /** - * {@inheritDoc} - * - * @see S3Connection#deleteObject(org.jclouds.aws.s3.domain.S3Bucket, - * String) - */ - @Override - protected void deleteObjectImpl(String bucketName, String objectKey) - throws S3ServiceException { - try { - connection.deleteObject(bucketName, objectKey).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils. rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException(String.format( - "error deleting object: %1$s:%2$s", bucketName, objectKey), - e); - } - } - - @Override - protected AccessControlList getBucketAclImpl(String bucketName) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected String getBucketLocationImpl(String bucketName) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected S3BucketLoggingStatus getBucketLoggingStatusImpl(String bucketName) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected AccessControlList getObjectAclImpl(String bucketName, - String objectKey) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected S3Object getObjectDetailsImpl(String bucketName, - String objectKey, Calendar ifModifiedSince, - Calendar ifUnmodifiedSince, String[] ifMatchTags, - String[] ifNoneMatchTags) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected S3Object getObjectImpl(String bucketName, String objectKey, - Calendar ifModifiedSince, Calendar ifUnmodifiedSince, - String[] ifMatchTags, String[] ifNoneMatchTags, - Long byteRangeStart, Long byteRangeEnd) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - public boolean isBucketAccessible(String bucketName) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected boolean isRequesterPaysBucketImpl(String bucketName) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected S3Bucket[] listAllBucketsImpl() throws S3ServiceException { - try { - List jcBucketList = connection - .listOwnedBuckets().get(requestTimeoutMilliseconds, - TimeUnit.MILLISECONDS); - - ArrayList jsBucketList = new ArrayList(); - for (org.jclouds.aws.s3.domain.S3Bucket.Metadata jcBucket : jcBucketList) { - org.jets3t.service.model.S3Bucket jsBucket = new org.jets3t.service.model.S3Bucket( - jcBucket.getName()); - jsBucket.setOwner(new org.jets3t.service.model.S3Owner(jcBucket - .getOwner().getId(), jcBucket.getOwner() - .getDisplayName())); - jsBucketList.add(jsBucket); - } - return (org.jets3t.service.model.S3Bucket[]) jsBucketList - .toArray(new org.jets3t.service.model.S3Bucket[jsBucketList - .size()]); - } catch (Exception e) { - Utils. rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException("error listing buckets", e); - } - } - - @Override - protected S3ObjectsChunk listObjectsChunkedImpl(String bucketName, - String prefix, String delimiter, long maxListingLength, - String priorLastKey, boolean completeListing) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected S3Object[] listObjectsImpl(String bucketName, String prefix, - String delimiter, long maxListingLength) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected void putBucketAclImpl(String bucketName, AccessControlList acl) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - - @Override - protected void putObjectAclImpl(String bucketName, String objectKey, - AccessControlList acl) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - - @Override - protected S3Object putObjectImpl(String bucketName, S3Object object) - throws S3ServiceException { - // TODO Unimplemented - return null; - } - - @Override - protected void setBucketLoggingStatusImpl(String bucketName, - S3BucketLoggingStatus status) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - - @Override - protected void setRequesterPaysBucketImpl(String bucketName, - boolean requesterPays) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - -} diff --git a/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceTest.java b/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceTest.java deleted file mode 100644 index 0418f4b471..0000000000 --- a/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceTest.java +++ /dev/null @@ -1,243 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.jets3t; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; - -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.S3IntegrationTest; -import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; -import org.jets3t.service.S3Service; -import org.jets3t.service.S3ServiceException; -import org.jets3t.service.model.S3Bucket; -import org.jets3t.service.security.AWSCredentials; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * Tests to cover JCloudsS3Service - * - * @author Adrian Cole - * - */ -@Test -public class JCloudsS3ServiceTest extends S3IntegrationTest { - AWSCredentials credentials; - S3Service service; - - @Override - protected boolean debugEnabled() { - return true; - } - - /** - * overridden only to get access to the amazon credentials used for jets3t - * initialization. - */ - @Override - protected S3Context createS3Context(String AWSAccessKeyId, - String AWSSecretAccessKey) { - credentials = new AWSCredentials(AWSAccessKeyId, AWSSecretAccessKey); - return super.createS3Context(AWSAccessKeyId, AWSSecretAccessKey); - } - - /** - * initialize a new JCloudsS3Service, but passing - * JavaUrlHttpFutureCommandClientModule(), as it is easier to debug in unit - * tests. - * - * @throws S3ServiceException - */ - @BeforeMethod - public void testJCloudsS3Service() throws S3ServiceException { - service = new JCloudsS3Service(credentials, - new JavaUrlHttpFutureCommandClientModule()); - } - - @Test - public void testCheckBucketStatusString() { - fail("Not yet implemented"); - } - - @Test - public void testCopyObjectImplStringStringStringStringAccessControlListMapCalendarCalendarStringArrayStringArray() { - fail("Not yet implemented"); - } - - @Test - public void testCreateBucketImplStringStringAccessControlList() { - fail("Not yet implemented"); - } - - @Test - public void testDeleteBucketImplString() throws S3ServiceException, - InterruptedException, ExecutionException, TimeoutException { - String bucketName = bucketPrefix + ".testDeleteBucketImplString"; - service.deleteBucket(bucketName); - assert !client.bucketExists(bucketName).get(10, TimeUnit.SECONDS); - } - - private void createBucket(String bucketName) throws InterruptedException, - ExecutionException, TimeoutException { - client.putBucketIfNotExists(bucketName).get(10, TimeUnit.SECONDS); - } - - @Test - public void testDeleteObjectImplStringString() throws InterruptedException, - ExecutionException, TimeoutException, S3ServiceException { - String bucketName = bucketPrefix + ".testDeleteObjectImplStringString"; - String objectKey = "key"; - String objectValue = "test"; - - addNewObject(bucketName, objectKey, objectValue); - - service.deleteObject(bucketName, objectKey); - - assertEquals(client.headObject(bucketName, objectKey).get(10, - TimeUnit.SECONDS), org.jclouds.aws.s3.domain.S3Object.NOT_FOUND); - } - - private void addNewObject(String name, String objectKey, String objectValue) - throws InterruptedException, ExecutionException, TimeoutException { - createBucket(name); - org.jclouds.aws.s3.domain.S3Object jcloudsObject = new org.jclouds.aws.s3.domain.S3Object( - objectKey); - jcloudsObject.setData(objectValue); - client.putObject(name, jcloudsObject).get(10, TimeUnit.SECONDS); - } - - @Test - public void testGetBucketAclImplString() { - fail("Not yet implemented"); - } - - @Test - public void testGetBucketLocationImplString() { - fail("Not yet implemented"); - } - - @Test - public void testGetBucketLoggingStatusImplString() { - fail("Not yet implemented"); - } - - @Test - public void testGetObjectAclImplStringString() { - fail("Not yet implemented"); - } - - @Test - public void testGetObjectDetailsImplStringStringCalendarCalendarStringArrayStringArray() { - fail("Not yet implemented"); - } - - @Test - public void testGetObjectImplStringStringCalendarCalendarStringArrayStringArrayLongLong() { - fail("Not yet implemented"); - } - - @Test - public void testIsBucketAccessibleString() { - fail("Not yet implemented"); - } - - @Test - public void testIsRequesterPaysBucketImplString() { - fail("Not yet implemented"); - } - - @Test - public void testListAllBucketsImpl() throws InterruptedException, - ExecutionException, TimeoutException, S3ServiceException { - // Ensure there is at least 1 bucket in S3 account to list and compare. - String bucketName = bucketPrefix + ".testListAllBucketsImplString"; - createBucket(bucketName); - - S3Bucket[] jsBuckets = service.listAllBuckets(); - - List jcBuckets = client - .listOwnedBuckets().get(10, TimeUnit.SECONDS); - - assert jsBuckets.length == jcBuckets.size(); - - Iterator jcBucketsIter = jcBuckets - .iterator(); - for (S3Bucket jsBucket : jsBuckets) { - assert jcBucketsIter.hasNext(); - - org.jclouds.aws.s3.domain.S3Bucket.Metadata jcBucket = jcBucketsIter - .next(); - assert jsBucket.getName().equals(jcBucket.getName()); - assert jsBucket.getOwner().getId().equals( - jcBucket.getOwner().getId()); - assert jsBucket.getOwner().getDisplayName().equals( - jcBucket.getOwner().getDisplayName()); - } - - client.deleteBucketIfEmpty(bucketName); - } - - @Test - public void testListObjectsChunkedImplStringStringStringLongStringBoolean() { - fail("Not yet implemented"); - } - - @Test - public void testListObjectsImplStringStringStringLong() { - fail("Not yet implemented"); - } - - @Test - public void testPutBucketAclImplStringAccessControlList() { - fail("Not yet implemented"); - } - - @Test - public void testPutObjectAclImplStringStringAccessControlList() { - fail("Not yet implemented"); - } - - @Test - public void testPutObjectImplStringS3Object() { - fail("Not yet implemented"); - } - - @Test - public void testSetBucketLoggingStatusImplStringS3BucketLoggingStatus() { - fail("Not yet implemented"); - } - - @Test - public void testSetRequesterPaysBucketImplStringBoolean() { - fail("Not yet implemented"); - } - -} diff --git a/s3/perftest/pom.xml b/s3/perftest/pom.xml deleted file mode 100644 index afd2a04985..0000000000 --- a/s3/perftest/pom.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - - - jclouds-project - org.jclouds - 1.0-SNAPSHOT - ../../project/pom.xml - - 4.0.0 - jclouds-s3perftest - Performance test verses Amazon samples implementation - jar - - Performance test verses Amazon samples implementation - - - - - - - - - ${project.groupId} - jclouds-s3 - ${project.version} - - - ${project.groupId} - jclouds-s3 - ${project.version} - test-jar - test - - - xstream - xstream - 1.2 - test - - - ${project.groupId} - jclouds-httpnio - ${project.version} - - - net.java.dev.jets3t - jets3t - 0.7.1 - - - - - scm:svn:http://jclouds.googlecode.com/svn/trunk/s3core/perftest - scm:svn:https://jclouds.googlecode.com/svn/trunk/s3core/perftest - http://jclouds.googlecode.com/svn/trunk/s3core/perftest - - - - - - jets3t - jets3t - http://jets3t.s3.amazonaws.com/maven2 - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - jclouds.aws.accesskeyid - ${jclouds.aws.accesskeyid} - - - jclouds.aws.secretaccesskey - ${jclouds.aws.secretaccesskey} - - - - **/Jets3tPerformanceTest.java - **/AmazonPerformanceTest.java - **/S3UtilsTest.java - - - - - - - diff --git a/s3/perftest/src/main/java/S3Driver.java b/s3/perftest/src/main/java/S3Driver.java deleted file mode 100644 index 14cf58fe6e..0000000000 --- a/s3/perftest/src/main/java/S3Driver.java +++ /dev/null @@ -1,159 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its -// affiliates. - -import java.util.Map; -import java.util.TreeMap; -import java.util.Arrays; - -import com.amazon.s3.AWSAuthConnection; -import com.amazon.s3.CallingFormat; -import com.amazon.s3.QueryStringAuthGenerator; -import com.amazon.s3.S3Object; - -public class S3Driver { - - static final String awsAccessKeyId = ""; - static final String awsSecretAccessKey = ""; - - - // convert the bucket to lowercase for vanity domains - // the bucket name must be lowercase since DNS is case-insensitive - static final String bucketName = awsAccessKeyId.toLowerCase() + "-test-bucket"; - static final String keyName = "test-key"; - static final String copiedKeyName = "copy-of-" + keyName; - - public static void main(String args[]) throws Exception { - if (awsAccessKeyId.startsWith(" "); - System.in.read(); - - System.out.println("\nNow try just the url without the query string arguments. It should fail.\n"); - System.out.println(generator.makeBareURL(bucketName, keyName)); - System.out.print("\npress enter> "); - System.in.read(); - - System.out.println("----- putting object with metadata and public read acl -----"); - - Map metadata = new TreeMap(); - metadata.put("blah", Arrays.asList(new String[] { "foo" })); - object = new S3Object("this is a publicly readable test".getBytes(), metadata); - - headers = new TreeMap(); - headers.put("x-amz-acl", Arrays.asList(new String[] { "public-read" })); - headers.put("Content-Type", Arrays.asList(new String[] { "text/plain" })); - - System.out.println( - conn.put(bucketName, keyName + "-public", object, headers).connection.getResponseMessage() - ); - - System.out.println("----- anonymous read test -----"); - System.out.println("\nYou should be able to try this in your browser\n"); - System.out.println(generator.makeBareURL(bucketName, keyName + "-public")); - System.out.print("\npress enter> "); - System.in.read(); - - System.out.println("----- path style url example -----"); - System.out.println("\nNon-location-constrained buckets can also be specified as part of the url path. (This was the original url style supported by S3.)"); - System.out.println("\nTry this url out in your browser (it will only be valid for 60 seconds)\n"); - generator.setCallingFormat(CallingFormat.getPathCallingFormat()); - // could also have been done like this: - // generator = new QueryStringAuthGenerator(awsAccessKeyId, awsSecretAccessKey, true, Utils.DEFAULT_HOST, CallingFormat.getPathCallingFormat()); - generator.setExpiresIn(60 * 1000); - System.out.println(generator.get(bucketName, keyName, null)); - System.out.print("\npress enter> "); - System.in.read(); - - System.out.println("----- getting object's acl -----"); - System.out.println(new String(conn.getACL(bucketName, keyName, null).object.data)); - - System.out.println("----- deleting objects -----"); - System.out.println( - conn.delete(bucketName, copiedKeyName, null).connection.getResponseMessage() - ); - System.out.println( - conn.delete(bucketName, keyName, null).connection.getResponseMessage() - ); - System.out.println( - conn.delete(bucketName, keyName + "-public", null).connection.getResponseMessage() - ); - - System.out.println("----- listing bucket -----"); - System.out.println(conn.listBucket(bucketName, null, null, null, null).entries); - - System.out.println("----- listing all my buckets -----"); - System.out.println(conn.listAllMyBuckets(null).entries); - - System.out.println("----- deleting bucket -----"); - System.out.println( - conn.deleteBucket(bucketName, null).connection.getResponseMessage() - ); - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/AWSAuthConnection.java b/s3/perftest/src/main/java/com/amazon/s3/AWSAuthConnection.java deleted file mode 100644 index 674f93085e..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/AWSAuthConnection.java +++ /dev/null @@ -1,633 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.text.SimpleDateFormat; -import java.io.IOException; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.TimeZone; - -/** - * An interface into the S3 system. It is initially configured with - * authentication and connection parameters and exposes methods to access and - * manipulate S3 data. - */ -public class AWSAuthConnection { - public static final String LOCATION_DEFAULT = null; - public static final String LOCATION_EU = "EU"; - - private String awsAccessKeyId; - private String awsSecretAccessKey; - private boolean isSecure; - private String server; - private int port; - private CallingFormat callingFormat; - - public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey) { - this(awsAccessKeyId, awsSecretAccessKey, true); - } - - public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey, boolean isSecure) { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, Utils.DEFAULT_HOST); - } - - public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey, boolean isSecure, - String server) - { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, server, - isSecure ? Utils.SECURE_PORT : Utils.INSECURE_PORT); - } - - public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey, boolean isSecure, - String server, int port) { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, server, port, CallingFormat.getSubdomainCallingFormat()); - - } - - public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey, boolean isSecure, - String server, CallingFormat format) { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, server, - isSecure ? Utils.SECURE_PORT : Utils.INSECURE_PORT, - format); - } - - /** - * Create a new interface to interact with S3 with the given credential and connection - * parameters - * - * @param awsAccessKeyId Your user key into AWS - * @param awsSecretAccessKey The secret string used to generate signatures for authentication. - * @param isSecure use SSL encryption - * @param server Which host to connect to. Usually, this will be s3.amazonaws.com - * @param port Which port to use. - * @param callingFormat Type of request Regular/Vanity or Pure Vanity domain - */ - public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey, boolean isSecure, - String server, int port, CallingFormat format) - { - this.awsAccessKeyId = awsAccessKeyId; - this.awsSecretAccessKey = awsSecretAccessKey; - this.isSecure = isSecure; - this.server = server; - this.port = port; - this.callingFormat = format; - } - - /** - * Creates a new bucket. - * @param bucket The name of the bucket to create. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - * @param metadata A Map of String to List of Strings representing the s3 - * metadata for this bucket (can be null). - * @deprecated use version that specifies location - */ - public Response createBucket(String bucket, Map headers) - throws MalformedURLException, IOException - { - return createBucket(bucket, null, headers); - } - - /** - * Creates a new bucket. - * @param bucket The name of the bucket to create. - * @param location Desired location ("EU") (or null for default). - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - * @param metadata A Map of String to List of Strings representing the s3 - * metadata for this bucket (can be null). - * @throws IllegalArgumentException on invalid location - */ - public Response createBucket(String bucket, String location, Map headers) - throws MalformedURLException, IOException - { - String body; - if (location == null) { - body = null; - } else if (LOCATION_EU.equals(location)) { - if (!callingFormat.supportsLocatedBuckets()) - throw new IllegalArgumentException("Creating location-constrained bucket with unsupported calling-format"); - body = "" + location + ""; - } else - throw new IllegalArgumentException("Invalid Location: "+location); - - // validate bucket name - if (!Utils.validateBucketName(bucket, callingFormat, location != null)) - throw new IllegalArgumentException("Invalid S3Bucket Name: "+bucket); - - HttpURLConnection request = makeRequest("PUT", bucket, "", null, headers); - if (body != null) - { - request.setDoOutput(true); - request.getOutputStream().write(body.getBytes("UTF-8")); - } - return new Response(request); - } - - /** - * Check if the specified bucket exists (via a HEAD request) - * @param bucket The name of the bucket to check - * @return true if HEAD access returned success - */ - public boolean checkBucketExists(String bucket) throws MalformedURLException, IOException - { - HttpURLConnection response = makeRequest("HEAD", bucket, "", null, null); - int httpCode = response.getResponseCode(); - return httpCode >= 200 && httpCode < 300; - } - - /** - * Lists the contents of a bucket. - * @param bucket The name of the bucket to create. - * @param prefix All returned keys will start with this string (can be null). - * @param marker All returned keys will be lexographically greater than - * this string (can be null). - * @param maxKeys The maximum number of keys to return (can be null). - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public ListBucketResponse listBucket(String bucket, String prefix, String marker, - Integer maxKeys, Map headers) - throws MalformedURLException, IOException - { - return listBucket(bucket, prefix, marker, maxKeys, null, headers); - } - - /** - * Lists the contents of a bucket. - * @param bucket The name of the bucket to list. - * @param prefix All returned keys will start with this string (can be null). - * @param marker All returned keys will be lexographically greater than - * this string (can be null). - * @param maxKeys The maximum number of keys to return (can be null). - * @param delimiter Keys that contain a string between the prefix and the first - * occurrence of the delimiter will be rolled up into a single element. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public ListBucketResponse listBucket(String bucket, String prefix, String marker, - Integer maxKeys, String delimiter, Map headers) - throws MalformedURLException, IOException - { - - Map pathArgs = Utils.paramsForListOptions(prefix, marker, maxKeys, delimiter); - return new ListBucketResponse(makeRequest("GET", bucket, "", pathArgs, headers)); - } - - /** - * Deletes a bucket. - * @param bucket The name of the bucket to delete. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public Response deleteBucket(String bucket, Map headers) - throws MalformedURLException, IOException - { - return new Response(makeRequest("DELETE", bucket, "", null, headers)); - } - - /** - * Writes an object to S3. - * @param bucket The name of the bucket to which the object will be added. - * @param key The name of the key to use. - * @param object An S3Object containing the data to write. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public Response put(String bucket, String key, S3Object object, Map headers) - throws MalformedURLException, IOException - { - HttpURLConnection request = - makeRequest("PUT", bucket, Utils.urlencode(key), null, headers, object); - - request.setDoOutput(true); - request.getOutputStream().write(object.data == null ? new byte[] {} : object.data); - - return new Response(request); - } - - /** - * Creates a copy of an existing S3 Object. In this signature, we will copy the - * existing metadata. The default access control policy is private; if you want - * to override it, please use x-amz-acl in the headers. - * @param sourceBucket The name of the bucket where the source object lives. - * @param sourceKey The name of the key to copy. - * @param destinationBucket The name of the bucket to which the object will be added. - * @param destinationKey The name of the key to use. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). You may wish to set the x-amz-acl header appropriately. - */ - public Response copy( String sourceBucket, String sourceKey, String destinationBucket, String destinationKey, Map headers ) - throws MalformedURLException, IOException - { - S3Object object = new S3Object(new byte[] {}, new HashMap()); - headers = headers == null ? new HashMap() : new HashMap(headers); - headers.put("x-amz-copy-source", Arrays.asList( new String[] { sourceBucket + "/" + sourceKey } ) ); - headers.put("x-amz-metadata-directive", Arrays.asList( new String[] { "COPY" } ) ); - return verifyCopy( put( destinationBucket, destinationKey, object, headers ) ); - } - - /** - * Creates a copy of an existing S3 Object. In this signature, we will replace the - * existing metadata. The default access control policy is private; if you want - * to override it, please use x-amz-acl in the headers. - * @param sourceBucket The name of the bucket where the source object lives. - * @param sourceKey The name of the key to copy. - * @param destinationBucket The name of the bucket to which the object will be added. - * @param destinationKey The name of the key to use. - * @param metadata A Map of String to List of Strings representing the S3 metadata - * for the new object. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). You may wish to set the x-amz-acl header appropriately. - */ - public Response copy( String sourceBucket, String sourceKey, String destinationBucket, String destinationKey, Map metadata, Map headers ) - throws MalformedURLException, IOException - { - S3Object object = new S3Object(new byte[] {}, metadata); - headers = headers == null ? new HashMap() : new HashMap(headers); - headers.put("x-amz-copy-source", Arrays.asList( new String[] { sourceBucket + "/" + sourceKey } ) ); - headers.put("x-amz-metadata-directive", Arrays.asList( new String[] { "REPLACE" } ) ); - return verifyCopy( put( destinationBucket, destinationKey, object, headers ) ); - } - - /** - * Copy sometimes returns a successful response and starts to send whitespace - * characters to us. This method processes those whitespace characters and - * will throw an exception if the response is either unknown or an error. - * @param response Response object from the PUT request. - * @return The response with the input stream drained. - * @throws IOException If anything goes wrong. - */ - private Response verifyCopy( Response response ) throws IOException { - if (response.connection.getResponseCode() < 400) { - byte[] body = GetResponse.slurpInputStream(response.connection.getInputStream()); - String message = new String( body ); - if ( message.indexOf( "" ) != -1 ) { - // It worked! - } else { - throw new IOException( "Unexpected response: " + message ); - } - } - return response; - } - - /** - * Reads an object from S3. - * @param bucket The name of the bucket where the object lives. - * @param key The name of the key to use. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public GetResponse get(String bucket, String key, Map headers) - throws MalformedURLException, IOException - { - return new GetResponse(makeRequest("GET", bucket, Utils.urlencode(key), null, headers)); - } - - /** - * Deletes an object from S3. - * @param bucket The name of the bucket where the object lives. - * @param key The name of the key to use. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public Response delete(String bucket, String key, Map headers) - throws MalformedURLException, IOException - { - return new Response(makeRequest("DELETE", bucket, Utils.urlencode(key), null, headers)); - } - - /** - * Get the requestPayment xml document for a given bucket - * @param bucket The name of the bucket - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public GetResponse getBucketRequestPayment(String bucket, Map headers) - throws MalformedURLException, IOException - { - Map pathArgs = new HashMap(); - pathArgs.put("requestPayment", null); - return new GetResponse(makeRequest("GET", bucket, "", pathArgs, headers)); - } - - /** - * Write a new requestPayment xml document for a given bucket - * @param loggingXMLDoc The xml representation of the requestPayment configuration as a String - * @param bucket The name of the bucket - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public Response putBucketRequestPayment(String bucket, String requestPaymentXMLDoc, Map headers) - throws MalformedURLException, IOException - { - Map pathArgs = new HashMap(); - pathArgs.put("requestPayment", null); - S3Object object = new S3Object(requestPaymentXMLDoc.getBytes(), null); - HttpURLConnection request = makeRequest("PUT", bucket, "", pathArgs, headers, object); - - request.setDoOutput(true); - request.getOutputStream().write(object.data == null ? new byte[] {} : object.data); - - return new Response(request); - } - - /** - * Get the logging xml document for a given bucket - * @param bucket The name of the bucket - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public GetResponse getBucketLogging(String bucket, Map headers) - throws MalformedURLException, IOException - { - Map pathArgs = new HashMap(); - pathArgs.put("logging", null); - return new GetResponse(makeRequest("GET", bucket, "", pathArgs, headers)); - } - - /** - * Write a new logging xml document for a given bucket - * @param loggingXMLDoc The xml representation of the logging configuration as a String - * @param bucket The name of the bucket - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public Response putBucketLogging(String bucket, String loggingXMLDoc, Map headers) - throws MalformedURLException, IOException - { - Map pathArgs = new HashMap(); - pathArgs.put("logging", null); - S3Object object = new S3Object(loggingXMLDoc.getBytes(), null); - HttpURLConnection request = makeRequest("PUT", bucket, "", pathArgs, headers, object); - - request.setDoOutput(true); - request.getOutputStream().write(object.data == null ? new byte[] {} : object.data); - - return new Response(request); - } - - /** - * Get the ACL for a given bucket - * @param bucket The name of the bucket where the object lives. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public GetResponse getBucketACL(String bucket, Map headers) - throws MalformedURLException, IOException - { - return getACL(bucket, "", headers); - } - - /** - * Get the ACL for a given object (or bucket, if key is null). - * @param bucket The name of the bucket where the object lives. - * @param key The name of the key to use. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public GetResponse getACL(String bucket, String key, Map headers) - throws MalformedURLException, IOException - { - if (key == null) key = ""; - - Map pathArgs = new HashMap(); - pathArgs.put("acl", null); - - return new GetResponse( - makeRequest("GET", bucket, Utils.urlencode(key), pathArgs, headers) - ); - } - - /** - * Write a new ACL for a given bucket - * @param aclXMLDoc The xml representation of the ACL as a String - * @param bucket The name of the bucket where the object lives. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public Response putBucketACL(String bucket, String aclXMLDoc, Map headers) - throws MalformedURLException, IOException - { - return putACL(bucket, "", aclXMLDoc, headers); - } - - /** - * Write a new ACL for a given object - * @param aclXMLDoc The xml representation of the ACL as a String - * @param bucket The name of the bucket where the object lives. - * @param key The name of the key to use. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public Response putACL(String bucket, String key, String aclXMLDoc, Map headers) - throws MalformedURLException, IOException - { - S3Object object = new S3Object(aclXMLDoc.getBytes(), null); - - Map pathArgs = new HashMap(); - pathArgs.put("acl", null); - - HttpURLConnection request = - makeRequest("PUT", bucket, Utils.urlencode(key), pathArgs, headers, object); - - request.setDoOutput(true); - request.getOutputStream().write(object.data == null ? new byte[] {} : object.data); - - return new Response(request); - } - - public LocationResponse getBucketLocation(String bucket) - throws MalformedURLException, IOException - { - Map pathArgs = new HashMap(); - pathArgs.put("location", null); - return new LocationResponse(makeRequest("GET", bucket, "", pathArgs, null)); - } - - - /** - * List all the buckets created by this account. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - public ListAllMyBucketsResponse listAllMyBuckets(Map headers) - throws MalformedURLException, IOException - { - return new ListAllMyBucketsResponse(makeRequest("GET", "", "", null, headers)); - } - - - - /** - * Make a new HttpURLConnection without passing an S3Object parameter. - * Use this method for key operations that do require arguments - * @param method The method to invoke - * @param bucketName the bucket this request is for - * @param key the key this request is for - * @param pathArgs the - * @param headers - * @return - * @throws MalformedURLException - * @throws IOException - */ - private HttpURLConnection makeRequest(String method, String bucketName, String key, Map pathArgs, Map headers) - throws MalformedURLException, IOException - { - return makeRequest(method, bucketName, key, pathArgs, headers, null); - } - - - - /** - * Make a new HttpURLConnection. - * @param method The HTTP method to use (GET, PUT, DELETE) - * @param bucketName The bucket name this request affects - * @param key The key this request is for - * @param pathArgs parameters if any to be sent along this request - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - * @param object The S3Object that is to be written (can be null). - */ - private HttpURLConnection makeRequest(String method, String bucket, String key, Map pathArgs, Map headers, - S3Object object) - throws MalformedURLException, IOException - { - CallingFormat callingFormat = Utils.getCallingFormatForBucket( this.callingFormat, bucket ); - if ( isSecure && callingFormat != CallingFormat.getPathCallingFormat() && bucket.indexOf( "." ) != -1 ) { - System.err.println( "You are making an SSL connection, however, the bucket contains periods and the wildcard certificate will not match by default. Please consider using HTTP." ); - } - - // build the domain based on the calling format - URL url = callingFormat.getURL(isSecure, server, this.port, bucket, key, pathArgs); - - HttpURLConnection connection = (HttpURLConnection)url.openConnection(); - connection.setRequestMethod(method); - - // subdomain-style urls may encounter http redirects. - // Ensure that redirects are supported. - if (!connection.getInstanceFollowRedirects() - && callingFormat.supportsLocatedBuckets()) - throw new RuntimeException("HTTP redirect support required."); - - addHeaders(connection, headers); - if (object != null) addMetadataHeaders(connection, object.metadata); - addAuthHeader(connection, method, bucket, key, pathArgs); - - return connection; - } - - /** - * Add the given headers to the HttpURLConnection. - * @param connection The HttpURLConnection to which the headers will be added. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - */ - private void addHeaders(HttpURLConnection connection, Map headers) { - addHeaders(connection, headers, ""); - } - - /** - * Add the given metadata fields to the HttpURLConnection. - * @param connection The HttpURLConnection to which the headers will be added. - * @param metadata A Map of String to List of Strings representing the s3 - * metadata for this resource. - */ - private void addMetadataHeaders(HttpURLConnection connection, Map metadata) { - addHeaders(connection, metadata, Utils.METADATA_PREFIX); - } - - /** - * Add the given headers to the HttpURLConnection with a prefix before the keys. - * @param connection The HttpURLConnection to which the headers will be added. - * @param headers A Map of String to List of Strings representing the http - * headers to pass (can be null). - * @param prefix The string to prepend to each key before adding it to the connection. - */ - private void addHeaders(HttpURLConnection connection, Map headers, String prefix) { - if (headers != null) { - for (Iterator i = headers.keySet().iterator(); i.hasNext(); ) { - String key = (String)i.next(); - for (Iterator j = ((List)headers.get(key)).iterator(); j.hasNext(); ) { - String value = (String)j.next(); - connection.addRequestProperty(prefix + key, value); - } - } - } - } - - /** - * Add the appropriate Authorization header to the HttpURLConnection. - * @param connection The HttpURLConnection to which the header will be added. - * @param method The HTTP method to use (GET, PUT, DELETE) - * @param bucket the bucket name this request is for - * @param key the key this request is for - * @param pathArgs path arguments which are part of this request - */ - private void addAuthHeader(HttpURLConnection connection, String method, String bucket, String key, Map pathArgs) { - if (connection.getRequestProperty("Date") == null) { - connection.setRequestProperty("Date", httpDate()); - } - if (connection.getRequestProperty("Content-Type") == null) { - connection.setRequestProperty("Content-Type", ""); - } - - String canonicalString = - Utils.makeCanonicalString(method, bucket, key, pathArgs, connection.getRequestProperties()); - String encodedCanonical = Utils.encode(this.awsSecretAccessKey, canonicalString, false); - connection.setRequestProperty("Authorization", - "AWS " + this.awsAccessKeyId + ":" + encodedCanonical); - } - - - /** - * Generate an rfc822 date for use in the Date HTTP header. - */ - public static String httpDate() { - final String DateFormat = "EEE, dd MMM yyyy HH:mm:ss "; - SimpleDateFormat format = new SimpleDateFormat( DateFormat, Locale.US ); - format.setTimeZone( TimeZone.getTimeZone( "GMT" ) ); - return format.format( new Date() ) + "GMT"; - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/Bucket.java b/s3/perftest/src/main/java/com/amazon/s3/Bucket.java deleted file mode 100644 index aab89a6ea2..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/Bucket.java +++ /dev/null @@ -1,41 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.util.Date; - -/** - * A class representing a single bucket. Returned as a component of ListAllMyBucketsResponse. - */ -public class Bucket { - /** - * The name of the bucket. - */ - public String name; - - /** - * The bucket's creation date. - */ - public Date creationDate; - - public Bucket() { - this.name = null; - this.creationDate = null; - } - - public Bucket(String name, Date creationDate) { - this.name = name; - this.creationDate = creationDate; - } - - public String toString() { - return this.name; - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/CallingFormat.java b/s3/perftest/src/main/java/com/amazon/s3/CallingFormat.java deleted file mode 100644 index 5be4cd70e9..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/CallingFormat.java +++ /dev/null @@ -1,103 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Map; - -public abstract class CallingFormat { - - protected static CallingFormat pathCallingFormat = new PathCallingFormat(); - protected static CallingFormat subdomainCallingFormat = new SubdomainCallingFormat(); - protected static CallingFormat vanityCallingFormat = new VanityCallingFormat(); - - public abstract boolean supportsLocatedBuckets(); - public abstract String getEndpoint(String server, int port, String bucket); - public abstract String getPathBase(String bucket, String key); - public abstract URL getURL (boolean isSecure, String server, int port, String bucket, String key, Map pathArgs) - throws MalformedURLException; - - public static CallingFormat getPathCallingFormat() { - return pathCallingFormat; - } - - public static CallingFormat getSubdomainCallingFormat() { - return subdomainCallingFormat; - } - - public static CallingFormat getVanityCallingFormat() { - return vanityCallingFormat; - } - - static private class PathCallingFormat extends CallingFormat { - public boolean supportsLocatedBuckets() { - return false; - } - - public String getPathBase(String bucket, String key) { - return isBucketSpecified(bucket) ? "/" + bucket + "/" + key : "/"; - } - - public String getEndpoint(String server, int port, String bucket) { - return server + ":" + port; - } - - public URL getURL(boolean isSecure, String server, int port, String bucket, String key, Map pathArgs) - throws MalformedURLException { - String pathBase = isBucketSpecified(bucket) ? "/" + bucket + "/" + key : "/"; - String pathArguments = Utils.convertPathArgsHashToString(pathArgs); - return new URL(isSecure ? "https": "http", server, port, pathBase + pathArguments); - } - - private boolean isBucketSpecified(String bucket) { - if(bucket == null) return false; - if(bucket.length() == 0) return false; - return true; - } - } - - static private class SubdomainCallingFormat extends CallingFormat { - public boolean supportsLocatedBuckets() { - return true; - } - - public String getServer(String server, String bucket) { - return bucket + "." + server; - } - public String getEndpoint(String server, int port, String bucket) { - return getServer(server, bucket) + ":" + port ; - } - public String getPathBase(String bucket, String key) { - return "/" + key; - } - - public URL getURL(boolean isSecure, String server, int port, String bucket, String key, Map pathArgs) - throws MalformedURLException { - if (bucket == null || bucket.length() == 0) - { - //The bucket is null, this is listAllBuckets request - String pathArguments = Utils.convertPathArgsHashToString(pathArgs); - return new URL(isSecure ? "https": "http", server, port, "/" + pathArguments); - } else { - String serverToUse = getServer(server, bucket); - String pathBase = getPathBase(bucket, key); - String pathArguments = Utils.convertPathArgsHashToString(pathArgs); - return new URL(isSecure ? "https": "http", serverToUse, port, pathBase + pathArguments); - } - } - } - - static private class VanityCallingFormat extends SubdomainCallingFormat { - public String getServer(String server, String bucket) { - return bucket; - } - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/CommonPrefixEntry.java b/s3/perftest/src/main/java/com/amazon/s3/CommonPrefixEntry.java deleted file mode 100644 index 80198bcad0..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/CommonPrefixEntry.java +++ /dev/null @@ -1,17 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -public class CommonPrefixEntry { - /** - * The prefix common to the delimited keys it represents - */ - public String prefix; -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/GetResponse.java b/s3/perftest/src/main/java/com/amazon/s3/GetResponse.java deleted file mode 100644 index 76b767346c..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/GetResponse.java +++ /dev/null @@ -1,70 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.net.HttpURLConnection; -import java.io.IOException; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeMap; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; - -/** - * A Response object returned from AWSAuthConnection.get(). Exposes the attribute object, which - * represents the retrieved object. - */ -public class GetResponse extends Response { - public S3Object object; - - /** - * Pulls a representation of an S3Object out of the HttpURLConnection response. - */ - public GetResponse(HttpURLConnection connection) throws IOException { - super(connection); - if (connection.getResponseCode() < 400) { - Map metadata = extractMetadata(connection); - byte[] body = slurpInputStream(connection.getInputStream()); - this.object = new S3Object(body, metadata); - } - } - - /** - * Examines the response's header fields and returns a Map from String to List of Strings - * representing the object's metadata. - */ - private Map extractMetadata(HttpURLConnection connection) { - TreeMap metadata = new TreeMap(); - Map headers = connection.getHeaderFields(); - for (Iterator i = headers.keySet().iterator(); i.hasNext(); ) { - String key = (String)i.next(); - if (key == null) continue; - if (key.startsWith(Utils.METADATA_PREFIX)) { - metadata.put(key.substring(Utils.METADATA_PREFIX.length()), headers.get(key)); - } - } - - return metadata; - } - - /** - * Read the input stream and dump it all into a big byte array - */ - static byte[] slurpInputStream(InputStream stream) throws IOException { - final int chunkSize = 2048; - byte[] buf = new byte[chunkSize]; - ByteArrayOutputStream byteStream = new ByteArrayOutputStream(chunkSize); - int count; - - while ((count=stream.read(buf)) != -1) byteStream.write(buf, 0, count); - - return byteStream.toByteArray(); - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/ListAllMyBucketsResponse.java b/s3/perftest/src/main/java/com/amazon/s3/ListAllMyBucketsResponse.java deleted file mode 100644 index f4d6c1e9c3..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/ListAllMyBucketsResponse.java +++ /dev/null @@ -1,106 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.SimpleTimeZone; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.DefaultHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; - -/** - * Returned by AWSAuthConnection.listAllMyBuckets(). - */ -public class ListAllMyBucketsResponse extends Response { - /** - * A list of Bucket objects, one for each of this account's buckets. Will be null if - * the request fails. - */ - public List entries; - - public ListAllMyBucketsResponse(HttpURLConnection connection) throws IOException { - super(connection); - if (connection.getResponseCode() < 400) { - try { - XMLReader xr = Utils.createXMLReader();; - ListAllMyBucketsHandler handler = new ListAllMyBucketsHandler(); - xr.setContentHandler(handler); - xr.setErrorHandler(handler); - - xr.parse(new InputSource(connection.getInputStream())); - this.entries = handler.getEntries(); - } catch (SAXException e) { - throw new RuntimeException("Unexpected error parsing ListAllMyBuckets xml", e); - } - } - } - - static class ListAllMyBucketsHandler extends DefaultHandler { - - private List entries = null; - private Bucket currBucket = null; - private StringBuffer currText = null; - private SimpleDateFormat iso8601Parser = null; - - public ListAllMyBucketsHandler() { - super(); - entries = new ArrayList(); - this.iso8601Parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - this.iso8601Parser.setTimeZone(new SimpleTimeZone(0, "GMT")); - this.currText = new StringBuffer(); - } - - public void startDocument() { - // ignore - } - - public void endDocument() { - // ignore - } - - public void startElement(String uri, String name, String qName, Attributes attrs) { - if (name.equals("Bucket")) { - this.currBucket = new Bucket(); - } - } - - public void endElement(String uri, String name, String qName) { - if (name.equals("Bucket")) { - this.entries.add(this.currBucket); - } else if (name.equals("Name")) { - this.currBucket.name = this.currText.toString(); - } else if (name.equals("CreationDate")) { - try { - this.currBucket.creationDate = this.iso8601Parser.parse(this.currText.toString()); - } catch (ParseException e) { - throw new RuntimeException("Unexpected date format in list bucket output", e); - } - } - this.currText = new StringBuffer(); - } - - public void characters(char ch[], int start, int length) { - this.currText.append(ch, start, length); - } - - public List getEntries() { - return this.entries; - } - } -} - diff --git a/s3/perftest/src/main/java/com/amazon/s3/ListBucketResponse.java b/s3/perftest/src/main/java/com/amazon/s3/ListBucketResponse.java deleted file mode 100644 index 56bbf4fb5f..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/ListBucketResponse.java +++ /dev/null @@ -1,243 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.SimpleTimeZone; - -import org.xml.sax.Attributes; -import org.xml.sax.helpers.DefaultHandler; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.SAXException; - - -/** - * Returned by AWSAuthConnection.listBucket() - */ -public class ListBucketResponse extends Response { - - /** - * The name of the bucket being listed. Null if request fails. - */ - public String name = null; - - /** - * The prefix echoed back from the request. Null if request fails. - */ - public String prefix = null; - - /** - * The marker echoed back from the request. Null if request fails. - */ - public String marker = null; - - /** - * The delimiter echoed back from the request. Null if not specified in - * the request, or if it fails. - */ - public String delimiter = null; - - /** - * The maxKeys echoed back from the request if specified. 0 if request fails. - */ - public int maxKeys = 0; - - /** - * Indicates if there are more results to the list. True if the current - * list results have been truncated. false if request fails. - */ - public boolean isTruncated = false; - - /** - * Indicates what to use as a marker for subsequent list requests in the event - * that the results are truncated. Present only when a delimiter is specified. - * Null if request fails. - */ - public String nextMarker = null; - - /** - * A List of ListEntry objects representing the objects in the given bucket. - * Null if the request fails. - */ - public List entries = null; - - /** - * A List of CommonPrefixEntry objects representing the common prefixes of the - * keys that matched up to the delimiter. Null if the request fails. - */ - public List commonPrefixEntries = null; - - public ListBucketResponse(HttpURLConnection connection) throws IOException { - super(connection); - if (connection.getResponseCode() < 400) { - try { - XMLReader xr = Utils.createXMLReader(); - ListBucketHandler handler = new ListBucketHandler(); - xr.setContentHandler(handler); - xr.setErrorHandler(handler); - - xr.parse(new InputSource(connection.getInputStream())); - - this.name = handler.getName(); - this.prefix = handler.getPrefix(); - this.marker = handler.getMarker(); - this.delimiter = handler.getDelimiter(); - this.maxKeys = handler.getMaxKeys(); - this.isTruncated = handler.getIsTruncated(); - this.nextMarker = handler.getNextMarker(); - this.entries = handler.getKeyEntries(); - this.commonPrefixEntries = handler.getCommonPrefixEntries(); - - } catch (SAXException e) { - throw new RuntimeException("Unexpected error parsing ListBucket xml", e); - } - } - } - - class ListBucketHandler extends DefaultHandler { - - private String name = null; - private String prefix = null; - private String marker = null; - private String delimiter = null; - private int maxKeys = 0; - private boolean isTruncated = false; - private String nextMarker = null; - private boolean isEchoedPrefix = false; - private List keyEntries = null; - private ListEntry keyEntry = null; - private List commonPrefixEntries = null; - private CommonPrefixEntry commonPrefixEntry = null; - private StringBuffer currText = null; - private SimpleDateFormat iso8601Parser = null; - - public ListBucketHandler() { - super(); - keyEntries = new ArrayList(); - commonPrefixEntries = new ArrayList(); - this.iso8601Parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - this.iso8601Parser.setTimeZone(new SimpleTimeZone(0, "GMT")); - this.currText = new StringBuffer(); - } - - public void startDocument() { - this.isEchoedPrefix = true; - } - - public void endDocument() { - // ignore - } - - public void startElement(String uri, String name, String qName, Attributes attrs) { - if (name.equals("Contents")) { - this.keyEntry = new ListEntry(); - } else if (name.equals("Owner")) { - this.keyEntry.owner = new Owner(); - } else if (name.equals("CommonPrefixes")){ - this.commonPrefixEntry = new CommonPrefixEntry(); - } - } - - public void endElement(String uri, String name, String qName) { - if (name.equals("Name")) { - this.name = this.currText.toString(); - } - // this prefix is the one we echo back from the request - else if (name.equals("Prefix") && this.isEchoedPrefix) { - this.prefix = this.currText.toString(); - this.isEchoedPrefix = false; - } else if (name.equals("Marker")) { - this.marker = this.currText.toString(); - } else if (name.equals("MaxKeys")) { - this.maxKeys = Integer.parseInt(this.currText.toString()); - } else if (name.equals("Delimiter")) { - this.delimiter = this.currText.toString(); - } else if (name.equals("IsTruncated")) { - this.isTruncated = Boolean.valueOf(this.currText.toString()); - } else if (name.equals("NextMarker")) { - this.nextMarker = this.currText.toString(); - } else if (name.equals("Contents")) { - this.keyEntries.add(this.keyEntry); - } else if (name.equals("Key")) { - this.keyEntry.key = this.currText.toString(); - } else if (name.equals("LastModified")) { - try { - this.keyEntry.lastModified = this.iso8601Parser.parse(this.currText.toString()); - } catch (ParseException e) { - throw new RuntimeException("Unexpected date format in list bucket output", e); - } - } else if (name.equals("ETag")) { - this.keyEntry.eTag = this.currText.toString(); - } else if (name.equals("Size")) { - this.keyEntry.size = Long.parseLong(this.currText.toString()); - } else if (name.equals("StorageClass")) { - this.keyEntry.storageClass = this.currText.toString(); - } else if (name.equals("ID")) { - this.keyEntry.owner.id = this.currText.toString(); - } else if (name.equals("DisplayName")) { - this.keyEntry.owner.displayName = this.currText.toString(); - } else if (name.equals("CommonPrefixes")) { - this.commonPrefixEntries.add(this.commonPrefixEntry); - } - // this is the common prefix for keys that match up to the delimiter - else if (name.equals("Prefix")) { - this.commonPrefixEntry.prefix = this.currText.toString(); - } - if(this.currText.length() != 0) - this.currText = new StringBuffer(); - } - - public void characters(char ch[], int start, int length) { - this.currText.append(ch, start, length); - } - - public String getName() { - return this.name; - } - - public String getPrefix() { - return this.prefix; - } - - public String getMarker() { - return this.marker; - } - - public String getDelimiter() { - return this.delimiter; - } - - public int getMaxKeys(){ - return this.maxKeys; - } - - public boolean getIsTruncated() { - return this.isTruncated; - } - - public String getNextMarker() { - return this.nextMarker; - } - - public List getKeyEntries() { - return this.keyEntries; - } - - public List getCommonPrefixEntries() { - return this.commonPrefixEntries; - } - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/ListEntry.java b/s3/perftest/src/main/java/com/amazon/s3/ListEntry.java deleted file mode 100644 index 5be8810c18..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/ListEntry.java +++ /dev/null @@ -1,51 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.util.Date; - -/** - * A structure representing a single object stored in S3. Returned as a part of ListBucketResponse. - */ -public class ListEntry { - /** - * The name of the object - */ - public String key; - - /** - * The date at which the object was last modified. - */ - public Date lastModified; - - /** - * The object's ETag, which can be used for conditional GETs. - */ - public String eTag; - - /** - * The size of the object in bytes. - */ - public long size; - - /** - * The object's storage class - */ - public String storageClass; - - /** - * The object's owner - */ - public Owner owner; - - public String toString() { - return key; - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/LocationResponse.java b/s3/perftest/src/main/java/com/amazon/s3/LocationResponse.java deleted file mode 100644 index 07661514f7..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/LocationResponse.java +++ /dev/null @@ -1,89 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.io.IOException; -import java.net.HttpURLConnection; - -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.DefaultHandler; - -/** - * A Response object returned from AWSAuthConnection.getBucketLocation(). - * Parses the response XML and exposes the location constraint - * via the geteLocation() method. - */ -public class LocationResponse extends Response { - String location; - - /** - * Parse the response to a ?location query. - */ - public LocationResponse(HttpURLConnection connection) throws IOException { - super(connection); - if (connection.getResponseCode() < 400) { - try { - XMLReader xr = Utils.createXMLReader();; - LocationResponseHandler handler = new LocationResponseHandler(); - xr.setContentHandler(handler); - xr.setErrorHandler(handler); - - xr.parse(new InputSource(connection.getInputStream())); - this.location = handler.location; - } catch (SAXException e) { - throw new RuntimeException("Unexpected error parsing ListAllMyBuckets xml", e); - } - } else { - this.location = ""; - } - } - - /** - * Report the location-constraint for a bucket. - * A value of null indicates an error; - * the empty string indicates no constraint; - * and any other value is an actual location constraint value. - */ - public String getLocation() { - return location; - } - - /** - * Helper class to parse LocationConstraint response XML - */ - static class LocationResponseHandler extends DefaultHandler { - String location = null; - private StringBuffer currText = null; - - public void startDocument() { - } - - public void startElement(String uri, String name, String qName, Attributes attrs) { - if (name.equals("LocationConstraint")) { - this.currText = new StringBuffer(); - } - } - - public void endElement(String uri, String name, String qName) { - if (name.equals("LocationConstraint")) { - location = this.currText.toString(); - this.currText = null; - } - } - - public void characters(char ch[], int start, int length) { - if (currText != null) - this.currText.append(ch, start, length); - } - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/Owner.java b/s3/perftest/src/main/java/com/amazon/s3/Owner.java deleted file mode 100644 index 4693bf740c..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/Owner.java +++ /dev/null @@ -1,18 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -/** - * A structure representing the owner of an object, used as a part of ListEntry. - */ -public class Owner { - public String id; - public String displayName; -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/QueryStringAuthGenerator.java b/s3/perftest/src/main/java/com/amazon/s3/QueryStringAuthGenerator.java deleted file mode 100644 index 4f2ee4baa6..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/QueryStringAuthGenerator.java +++ /dev/null @@ -1,264 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * This class mimics the behavior of AWSAuthConnection, except instead of actually performing - * the operation, QueryStringAuthGenerator will return URLs with query string parameters that - * can be used to do the same thing. These parameters include an expiration date, so that - * if you hand them off to someone else, they will only work for a limited amount of time. - */ -public class QueryStringAuthGenerator { - - private String awsAccessKeyId; - private String awsSecretAccessKey; - private boolean isSecure; - private String server; - private int port; - private CallingFormat callingFormat; - - private Long expiresIn = null; - private Long expires = null; - - // by default, expire in 1 minute. - private static final Long DEFAULT_EXPIRES_IN = new Long(60 * 1000); - - public QueryStringAuthGenerator(String awsAccessKeyId, String awsSecretAccessKey) { - this(awsAccessKeyId, awsSecretAccessKey, true); - } - - public QueryStringAuthGenerator(String awsAccessKeyId, String awsSecretAccessKey, - boolean isSecure) - { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, Utils.DEFAULT_HOST); - } - - public QueryStringAuthGenerator(String awsAccessKeyId, String awsSecretAccessKey, - boolean isSecure, String server) - { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, server, - isSecure ? Utils.SECURE_PORT : Utils.INSECURE_PORT); - } - - public QueryStringAuthGenerator(String awsAccessKeyId, String awsSecretAccessKey, - boolean isSecure, String server, int port) - { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, server, - port, CallingFormat.getSubdomainCallingFormat()); - } - - public QueryStringAuthGenerator(String awsAccessKeyId, String awsSecretAccessKey, - boolean isSecure, String server, CallingFormat callingFormat) - { - this(awsAccessKeyId, awsSecretAccessKey, isSecure, server, - isSecure ? Utils.SECURE_PORT : Utils.INSECURE_PORT, - callingFormat); - } - - public QueryStringAuthGenerator(String awsAccessKeyId, String awsSecretAccessKey, - boolean isSecure, String server, int port, CallingFormat callingFormat) - { - this.awsAccessKeyId = awsAccessKeyId; - this.awsSecretAccessKey = awsSecretAccessKey; - this.isSecure = isSecure; - this.server = server; - this.port = port; - this.callingFormat = callingFormat; - - this.expiresIn = DEFAULT_EXPIRES_IN; - this.expires = null; - } - - - public void setCallingFormat(CallingFormat format) { - this.callingFormat = format; - } - - public void setExpires(long millisSinceEpoch) { - expires = new Long(millisSinceEpoch); - expiresIn = null; - } - - public void setExpiresIn(long millis) { - expiresIn = new Long(millis); - expires = null; - } - - public String createBucket(String bucket, Map headers) - { - // validate bucket name - if (!Utils.validateBucketName(bucket, callingFormat, false)) - throw new IllegalArgumentException("Invalid S3Bucket Name: "+bucket); - - Map pathArgs = new HashMap(); - return generateURL("PUT", bucket, "", pathArgs, headers); - } - - public String listBucket(String bucket, String prefix, String marker, - Integer maxKeys, Map headers){ - return listBucket(bucket, prefix, marker, maxKeys, null, headers); - } - - public String listBucket(String bucket, String prefix, String marker, - Integer maxKeys, String delimiter, Map headers) - { - Map pathArgs = Utils.paramsForListOptions(prefix, marker, maxKeys, delimiter); - return generateURL("GET", bucket, "", pathArgs, headers); - } - - public String deleteBucket(String bucket, Map headers) - { - Map pathArgs = new HashMap(); - return generateURL("DELETE", bucket, "", pathArgs, headers); - } - - public String put(String bucket, String key, S3Object object, Map headers) { - Map metadata = null; - Map pathArgs = new HashMap(); - if (object != null) { - metadata = object.metadata; - } - - - return generateURL("PUT", bucket, Utils.urlencode(key), pathArgs, mergeMeta(headers, metadata)); - } - - public String get(String bucket, String key, Map headers) - { - Map pathArgs = new HashMap(); - return generateURL("GET", bucket, Utils.urlencode(key), pathArgs, headers); - } - - public String delete(String bucket, String key, Map headers) - { - Map pathArgs = new HashMap(); - return generateURL("DELETE", bucket, Utils.urlencode(key), pathArgs, headers); - } - - public String getBucketLogging(String bucket, Map headers) { - Map pathArgs = new HashMap(); - pathArgs.put("logging", null); - return generateURL("GET", bucket, "", pathArgs, headers); - } - - public String putBucketLogging(String bucket, String loggingXMLDoc, Map headers) { - Map pathArgs = new HashMap(); - pathArgs.put("logging", null); - return generateURL("PUT", bucket, "", pathArgs, headers); - } - - public String getBucketACL(String bucket, Map headers) { - return getACL(bucket, "", headers); - } - - public String getACL(String bucket, String key, Map headers) - { - Map pathArgs = new HashMap(); - pathArgs.put("acl", null); - return generateURL("GET", bucket, Utils.urlencode(key), pathArgs, headers); - } - - public String putBucketACL(String bucket, String aclXMLDoc, Map headers) { - return putACL(bucket, "", aclXMLDoc, headers); - } - - public String putACL(String bucket, String key, String aclXMLDoc, Map headers) - { - Map pathArgs = new HashMap(); - pathArgs.put("acl", null); - return generateURL("PUT", bucket, Utils.urlencode(key), pathArgs, headers); - } - - public String listAllMyBuckets(Map headers) - { - Map pathArgs = new HashMap(); - return generateURL("GET", "", "", pathArgs, headers); - } - - public String makeBareURL(String bucket, String key) { - StringBuffer buffer = new StringBuffer(); - if (this.isSecure) { - buffer.append("https://"); - } else { - buffer.append("http://"); - } - buffer.append(this.server).append(":").append(this.port).append("/").append(bucket); - buffer.append("/").append(Utils.urlencode(key)); - - return buffer.toString(); - } - - private String generateURL(String method, String bucketName, String key, Map pathArgs, Map headers) - { - long expires = 0L; - if (this.expiresIn != null) { - expires = System.currentTimeMillis() + this.expiresIn.longValue(); - } else if (this.expires != null) { - expires = this.expires.longValue(); - } else { - throw new RuntimeException("Illegal expires state"); - } - - // convert to seconds - expires /= 1000; - - String canonicalString = Utils.makeCanonicalString(method, bucketName, key, pathArgs, headers, ""+expires); - String encodedCanonical = Utils.encode(this.awsSecretAccessKey, canonicalString, true); - - pathArgs.put("Signature", encodedCanonical); - pathArgs.put("Expires", Long.toString(expires)); - pathArgs.put("AWSAccessKeyId", this.awsAccessKeyId); - - CallingFormat callingFormat = Utils.getCallingFormatForBucket( this.callingFormat, bucketName ); - if ( isSecure && callingFormat != CallingFormat.getPathCallingFormat() && bucketName.indexOf( "." ) != -1 ) { - System.err.println( "You are making an SSL connection, however, the bucket contains periods and the wildcard certificate will not match by default. Please consider using HTTP." ); - } - - String returnString; - try { - URL url = callingFormat.getURL(isSecure, server, port, bucketName, key, pathArgs); - returnString = url.toString(); - } catch (MalformedURLException e) { - returnString = "Exception generating url " + e; - } - - return returnString; - } - - private Map mergeMeta(Map headers, Map metadata) { - Map merged = new TreeMap(); - if (headers != null) { - for (Iterator i = headers.keySet().iterator(); i.hasNext(); ) { - String key = (String)i.next(); - merged.put(key, headers.get(key)); - } - } - if (metadata != null) { - for (Iterator i = metadata.keySet().iterator(); i.hasNext(); ) { - String key = (String)i.next(); - String metadataKey = Utils.METADATA_PREFIX + key; - if (merged.containsKey(metadataKey)) { - ((List)merged.get(metadataKey)).addAll((List)metadata.get(key)); - } else { - merged.put(metadataKey, metadata.get(key)); - } - } - } - return merged; - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/Response.java b/s3/perftest/src/main/java/com/amazon/s3/Response.java deleted file mode 100644 index b6b5f01c58..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/Response.java +++ /dev/null @@ -1,25 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.net.HttpURLConnection; -import java.io.IOException; - -/** - * The parent class of all other Responses. This class keeps track of the - * HttpURLConnection response. - */ -public class Response { - public HttpURLConnection connection; - - public Response(HttpURLConnection connection) throws IOException { - this.connection = connection; - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/S3Object.java b/s3/perftest/src/main/java/com/amazon/s3/S3Object.java deleted file mode 100644 index d43a3bca9f..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/S3Object.java +++ /dev/null @@ -1,30 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.util.Map; - -/** - * A representation of a single object stored in S3. - */ -public class S3Object { - - public byte[] data; - - /** - * A Map from String to List of Strings representing the object's metadata - */ - public Map metadata; - - public S3Object(byte[] data, Map metadata) { - this.data = data; - this.metadata = metadata; - } -} diff --git a/s3/perftest/src/main/java/com/amazon/s3/Utils.java b/s3/perftest/src/main/java/com/amazon/s3/Utils.java deleted file mode 100644 index e57344c47f..0000000000 --- a/s3/perftest/src/main/java/com/amazon/s3/Utils.java +++ /dev/null @@ -1,324 +0,0 @@ -// This software code is made available "AS IS" without warranties of any -// kind. You may copy, display, modify and redistribute the software -// code either by itself or as incorporated into your code; provided that -// you do not remove any proprietary notices. Your use of this software -// code is at your own risk and you waive any claim against Amazon -// Digital Services, Inc. or its affiliates with respect to your use of -// this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its -// affiliates. - -package com.amazon.s3; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; -import org.xml.sax.SAXException; - -import com.amazon.thirdparty.Base64; - -public class Utils { - static final String METADATA_PREFIX = "x-amz-meta-"; - static final String AMAZON_HEADER_PREFIX = "x-amz-"; - static final String ALTERNATIVE_DATE_HEADER = "x-amz-date"; - public static final String DEFAULT_HOST = "s3.amazonaws.com"; - - public static final int SECURE_PORT = 443; - public static final int INSECURE_PORT = 80; - - - /** - * HMAC/SHA1 Algorithm per RFC 2104. - */ - private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1"; - - static String makeCanonicalString(String method, String bucket, String key, Map pathArgs, Map headers) { - return makeCanonicalString(method, bucket, key, pathArgs, headers, null); - } - - /** - * Calculate the canonical string. When expires is non-null, it will be - * used instead of the Date header. - */ - static String makeCanonicalString(String method, String bucketName, String key, Map pathArgs, - Map headers, String expires) - { - StringBuffer buf = new StringBuffer(); - buf.append(method + "\n"); - - // Add all interesting headers to a list, then sort them. "Interesting" - // is defined as Content-MD5, Content-Type, Date, and x-amz- - SortedMap interestingHeaders = new TreeMap(); - if (headers != null) { - for (Iterator i = headers.keySet().iterator(); i.hasNext(); ) { - String hashKey = (String)i.next(); - if (hashKey == null) continue; - String lk = hashKey.toLowerCase(); - - // Ignore any headers that are not particularly interesting. - if (lk.equals("content-type") || lk.equals("content-md5") || lk.equals("date") || - lk.startsWith(AMAZON_HEADER_PREFIX)) - { - List s = (List)headers.get(hashKey); - interestingHeaders.put(lk, concatenateList(s)); - } - } - } - - if (interestingHeaders.containsKey(ALTERNATIVE_DATE_HEADER)) { - interestingHeaders.put("date", ""); - } - - // if the expires is non-null, use that for the date field. this - // trumps the x-amz-date behavior. - if (expires != null) { - interestingHeaders.put("date", expires); - } - - // these headers require that we still put a new line in after them, - // even if they don't exist. - if (! interestingHeaders.containsKey("content-type")) { - interestingHeaders.put("content-type", ""); - } - if (! interestingHeaders.containsKey("content-md5")) { - interestingHeaders.put("content-md5", ""); - } - - // Finally, add all the interesting headers (i.e.: all that startwith x-amz- ;-)) - for (Iterator i = interestingHeaders.keySet().iterator(); i.hasNext(); ) { - String headerKey = (String)i.next(); - if (headerKey.startsWith(AMAZON_HEADER_PREFIX)) { - buf.append(headerKey).append(':').append(interestingHeaders.get(headerKey)); - } else { - buf.append(interestingHeaders.get(headerKey)); - } - buf.append("\n"); - } - - // build the path using the bucket and key - if (bucketName != null && !bucketName.equals("")) { - buf.append("/" + bucketName ); - } - - // append the key (it might be an empty string) - // append a slash regardless - buf.append("/"); - if(key != null) { - buf.append(key); - } - - // if there is an acl, logging or torrent parameter - // add them to the string - if (pathArgs != null ) { - if (pathArgs.containsKey("acl")) { - buf.append("?acl"); - } else if (pathArgs.containsKey("torrent")) { - buf.append("?torrent"); - } else if (pathArgs.containsKey("logging")) { - buf.append("?logging"); - } else if (pathArgs.containsKey("location")) { - buf.append("?location"); - } - } - - return buf.toString(); - - } - - /** - * Calculate the HMAC/SHA1 on a string. - * @param data Data to sign - * @param passcode Passcode to sign it with - * @return Signature - * @throws NoSuchAlgorithmException If the algorithm does not exist. Unlikely - * @throws InvalidKeyException If the key is invalid. - */ - static String encode(String awsSecretAccessKey, String canonicalString, - boolean urlencode) - { - // The following HMAC/SHA1 code for the signature is taken from the - // AWS Platform's implementation of RFC2104 (amazon.webservices.common.Signature) - // - // Acquire an HMAC/SHA1 from the raw key bytes. - SecretKeySpec signingKey = - new SecretKeySpec(awsSecretAccessKey.getBytes(), HMAC_SHA1_ALGORITHM); - - // Acquire the MAC instance and initialize with the signing key. - Mac mac = null; - try { - mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); - } catch (NoSuchAlgorithmException e) { - // should not happen - throw new RuntimeException("Could not find sha1 algorithm", e); - } - try { - mac.init(signingKey); - } catch (InvalidKeyException e) { - // also should not happen - throw new RuntimeException("Could not initialize the MAC algorithm", e); - } - - // Compute the HMAC on the digest, and set it. - String b64 = Base64.encodeBytes(mac.doFinal(canonicalString.getBytes())); - - if (urlencode) { - return urlencode(b64); - } else { - return b64; - } - } - - static Map paramsForListOptions(String prefix, String marker, Integer maxKeys) { - return paramsForListOptions(prefix, marker, maxKeys, null); - } - - static Map paramsForListOptions(String prefix, String marker, Integer maxKeys, String delimiter) { - - Map argParams = new HashMap(); - // these three params must be url encoded - if (prefix != null) - argParams.put("prefix", urlencode(prefix)); - if (marker != null) - argParams.put("marker", urlencode(marker)); - if (delimiter != null) - argParams.put("delimiter", urlencode(delimiter)); - - if (maxKeys != null) - argParams.put("max-keys", Integer.toString(maxKeys.intValue())); - - return argParams; - - } - - /** - * Converts the Path Arguments from a map to String which can be used in url construction - * @param pathArgs a map of arguments - * @return a string representation of pathArgs - */ - public static String convertPathArgsHashToString(Map pathArgs) { - StringBuffer pathArgsString = new StringBuffer(); - String argumentValue; - boolean firstRun = true; - if (pathArgs != null) { - for (Iterator argumentIterator = pathArgs.keySet().iterator(); argumentIterator.hasNext(); ) { - String argument = (String)argumentIterator.next(); - if (firstRun) { - firstRun = false; - pathArgsString.append("?"); - } else { - pathArgsString.append("&"); - } - - argumentValue = (String)pathArgs.get(argument); - pathArgsString.append(argument); - if (argumentValue != null) { - pathArgsString.append("="); - pathArgsString.append(argumentValue); - } - } - } - - return pathArgsString.toString(); - } - - - - - static String urlencode(String unencoded) { - try { - return URLEncoder.encode(unencoded, "UTF-8"); - } catch (UnsupportedEncodingException e) { - // should never happen - throw new RuntimeException("Could not url encode to UTF-8", e); - } - } - - static XMLReader createXMLReader() { - try { - return XMLReaderFactory.createXMLReader(); - } catch (SAXException e) { - // oops, lets try doing this (needed in 1.4) - System.setProperty("org.xml.sax.driver", "org.apache.crimson.parser.XMLReaderImpl"); - } - try { - // try once more - return XMLReaderFactory.createXMLReader(); - } catch (SAXException e) { - throw new RuntimeException("Couldn't initialize a sax driver for the XMLReader"); - } - } - - /** - * Concatenates a bunch of header values, seperating them with a comma. - * @param values List of header values. - * @return String of all headers, with commas. - */ - private static String concatenateList(List values) { - StringBuffer buf = new StringBuffer(); - for (int i = 0, size = values.size(); i < size; ++ i) { - buf.append(((String)values.get(i)).replaceAll("\n", "").trim()); - if (i != (size - 1)) { - buf.append(","); - } - } - return buf.toString(); - } - - /** - * Validate bucket-name - */ - static boolean validateBucketName(String bucketName, CallingFormat callingFormat, boolean located) { - if (callingFormat == CallingFormat.getPathCallingFormat()) - { - final int MIN_BUCKET_LENGTH = 3; - final int MAX_BUCKET_LENGTH = 255; - final String BUCKET_NAME_REGEX = "^[0-9A-Za-z\\.\\-_]*$"; - - return null != bucketName && - bucketName.length() >= MIN_BUCKET_LENGTH && - bucketName.length() <= MAX_BUCKET_LENGTH && - bucketName.matches(BUCKET_NAME_REGEX); - } else { - return isValidSubdomainBucketName( bucketName ); - } - } - - static boolean isValidSubdomainBucketName( String bucketName ) { - final int MIN_BUCKET_LENGTH = 3; - final int MAX_BUCKET_LENGTH = 63; - // don't allow names that look like 127.0.0.1 - final String IPv4_REGEX = "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$"; - // dns sub-name restrictions - final String BUCKET_NAME_REGEX = "^[a-z0-9]([a-z0-9\\-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9\\-]*[a-z0-9])?)*$"; - - // If there wasn't a location-constraint, then the current actual - // restriction is just that no 'part' of the name (i.e. sequence - // of characters between any 2 '.'s has to be 63) but the recommendation - // is to keep the entire bucket name under 63. - return null != bucketName && - bucketName.length() >= MIN_BUCKET_LENGTH && - bucketName.length() <= MAX_BUCKET_LENGTH && - !bucketName.matches(IPv4_REGEX) && - bucketName.matches(BUCKET_NAME_REGEX); - } - - static CallingFormat getCallingFormatForBucket( CallingFormat desiredFormat, String bucketName ) { - CallingFormat callingFormat = desiredFormat; - if ( callingFormat == CallingFormat.getSubdomainCallingFormat() && ! Utils.isValidSubdomainBucketName( bucketName ) ) { - callingFormat = CallingFormat.getPathCallingFormat(); - } - return callingFormat; - } -} diff --git a/s3/perftest/src/main/java/com/amazon/thirdparty/Base64.java b/s3/perftest/src/main/java/com/amazon/thirdparty/Base64.java deleted file mode 100644 index bda181c9c1..0000000000 --- a/s3/perftest/src/main/java/com/amazon/thirdparty/Base64.java +++ /dev/null @@ -1,1459 +0,0 @@ -// -// NOTE: The following source code is the iHarder.net public domain -// Base64 library and is provided here as a convenience. For updates, -// problems, questions, etc. regarding this code, please visit: -// http://iharder.sourceforge.net/current/java/base64/ -// - -package com.amazon.thirdparty; - - -/** - * Encodes and decodes to and from Base64 notation. - * - *

- * Change Log: - *

- *
    - *
  • v2.1 - Cleaned up javadoc comments and unused variables and methods. Added - * some convenience methods for reading and writing to and from files.
  • - *
  • v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems - * with other encodings (like EBCDIC).
  • - *
  • v2.0.1 - Fixed an error when decoding a single byte, that is, when the - * encoded data was a single byte.
  • - *
  • v2.0 - I got rid of methods that used booleans to set options. - * Now everything is more consolidated and cleaner. The code now detects - * when data that's being decoded is gzip-compressed and will decompress it - * automatically. Generally things are cleaner. You'll probably have to - * change some method calls that you were making to support the new - * options format (ints that you "OR" together).
  • - *
  • v1.5.1 - Fixed bug when decompressing and decoding to a - * byte[] using decode( String s, boolean gzipCompressed ). - * Added the ability to "suspend" encoding in the Output Stream so - * you can turn on and off the encoding if you need to embed base64 - * data in an otherwise "normal" stream (like an XML file).
  • - *
  • v1.5 - Output stream pases on flush() command but doesn't do anything itself. - * This helps when using GZIP streams. - * Added the ability to GZip-compress objects before encoding them.
  • - *
  • v1.4 - Added helper methods to read/write files.
  • - *
  • v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.
  • - *
  • v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream - * where last buffer being read, if not completely full, was not returned.
  • - *
  • v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.
  • - *
  • v1.3.3 - Fixed I/O streams which were totally messed up.
  • - *
- * - *

- * I am placing this code in the Public Domain. Do with it as you will. - * This software comes with no guarantees or warranties but with - * plenty of well-wishing instead! - * Please visit http://iharder.net/base64 - * periodically to check for updates or to contribute improvements. - *

- * - * @author Robert Harder - * @author rob@iharder.net - * @version 2.1 - */ -public class Base64 -{ - -/* ******** P U B L I C F I E L D S ******** */ - - - /** No options specified. Value is zero. */ - public final static int NO_OPTIONS = 0; - - /** Specify encoding. */ - public final static int ENCODE = 1; - - - /** Specify decoding. */ - public final static int DECODE = 0; - - - /** Specify that data should be gzip-compressed. */ - public final static int GZIP = 2; - - - /** Don't break lines when encoding (violates strict Base64 specification) */ - public final static int DONT_BREAK_LINES = 8; - - -/* ******** P R I V A T E F I E L D S ******** */ - - - /** Maximum line length (76) of Base64 output. */ - private final static int MAX_LINE_LENGTH = 76; - - - /** The equals sign (=) as a byte. */ - private final static byte EQUALS_SIGN = (byte)'='; - - - /** The new line character (\n) as a byte. */ - private final static byte NEW_LINE = (byte)'\n'; - - - /** Preferred encoding. */ - private final static String PREFERRED_ENCODING = "UTF-8"; - - - /** The 64 valid Base64 values. */ - private final static byte[] ALPHABET; - private final static byte[] _NATIVE_ALPHABET = /* May be something funny like EBCDIC */ - { - (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', - (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', - (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', - (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', - (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', - (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', - (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', - (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z', - (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', - (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/' - }; - - /** Determine which ALPHABET to use. */ - static - { - byte[] __bytes; - try - { - __bytes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes( PREFERRED_ENCODING ); - } // end try - catch (java.io.UnsupportedEncodingException use) - { - __bytes = _NATIVE_ALPHABET; // Fall back to native encoding - } // end catch - ALPHABET = __bytes; - } // end static - - - /** - * Translates a Base64 value to either its 6-bit reconstruction value - * or a negative number indicating some other meaning. - **/ - private final static byte[] DECODABET = - { - -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8 - -5,-5, // Whitespace: Tab and Linefeed - -9,-9, // Decimal 11 - 12 - -5, // Whitespace: Carriage Return - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26 - -9,-9,-9,-9,-9, // Decimal 27 - 31 - -5, // Whitespace: Space - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42 - 62, // Plus sign at decimal 43 - -9,-9,-9, // Decimal 44 - 46 - 63, // Slash at decimal 47 - 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine - -9,-9,-9, // Decimal 58 - 60 - -1, // Equals sign at decimal 61 - -9,-9,-9, // Decimal 62 - 64 - 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N' - 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z' - -9,-9,-9,-9,-9,-9, // Decimal 91 - 96 - 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm' - 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z' - -9,-9,-9,-9 // Decimal 123 - 126 - /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243 - -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */ - }; - - // I think I end up not using the BAD_ENCODING indicator. - //private final static byte BAD_ENCODING = -9; // Indicates error in encoding - private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding - private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding - - - /** Defeats instantiation. */ - private Base64(){} - - - -/* ******** E N C O D I N G M E T H O D S ******** */ - - - /** - * Encodes up to the first three bytes of array threeBytes - * and returns a four-byte array in Base64 notation. - * The actual number of significant bytes in your array is - * given by numSigBytes. - * The array threeBytes needs only be as big as - * numSigBytes. - * Code can reuse a byte array by passing a four-byte array as b4. - * - * @param b4 A reusable byte array to reduce array instantiation - * @param threeBytes the array to convert - * @param numSigBytes the number of significant bytes in your array - * @return four byte array in Base64 notation. - * @since 1.5.1 - */ - private static byte[] encode3to4( byte[] b4, byte[] threeBytes, int numSigBytes ) - { - encode3to4( threeBytes, 0, numSigBytes, b4, 0 ); - return b4; - } // end encode3to4 - - - /** - * Encodes up to three bytes of the array source - * and writes the resulting four Base64 bytes to destination. - * The source and destination arrays can be manipulated - * anywhere along their length by specifying - * srcOffset and destOffset. - * This method does not check to make sure your arrays - * are large enough to accomodate srcOffset + 3 for - * the source array or destOffset + 4 for - * the destination array. - * The actual number of significant bytes in your array is - * given by numSigBytes. - * - * @param source the array to convert - * @param srcOffset the index where conversion begins - * @param numSigBytes the number of significant bytes in your array - * @param destination the array to hold the conversion - * @param destOffset the index where output will be put - * @return the destination array - * @since 1.3 - */ - private static byte[] encode3to4( - byte[] source, int srcOffset, int numSigBytes, - byte[] destination, int destOffset ) - { - // 1 2 3 - // 01234567890123456789012345678901 Bit position - // --------000000001111111122222222 Array position from threeBytes - // --------| || || || | Six bit groups to index ALPHABET - // >>18 >>12 >> 6 >> 0 Right shift necessary - // 0x3f 0x3f 0x3f Additional AND - - // Create buffer with zero-padding if there are only one or two - // significant bytes passed in the array. - // We have to shift left 24 in order to flush out the 1's that appear - // when Java treats a value as negative that is cast from a byte to an int. - int inBuff = ( numSigBytes > 0 ? ((source[ srcOffset ] << 24) >>> 8) : 0 ) - | ( numSigBytes > 1 ? ((source[ srcOffset + 1 ] << 24) >>> 16) : 0 ) - | ( numSigBytes > 2 ? ((source[ srcOffset + 2 ] << 24) >>> 24) : 0 ); - - switch( numSigBytes ) - { - case 3: - destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; - destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; - destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; - destination[ destOffset + 3 ] = ALPHABET[ (inBuff ) & 0x3f ]; - return destination; - - case 2: - destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; - destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; - destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ]; - destination[ destOffset + 3 ] = EQUALS_SIGN; - return destination; - - case 1: - destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ]; - destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ]; - destination[ destOffset + 2 ] = EQUALS_SIGN; - destination[ destOffset + 3 ] = EQUALS_SIGN; - return destination; - - default: - return destination; - } // end switch - } // end encode3to4 - - - - /** - * Serializes an object and returns the Base64-encoded - * version of that serialized object. If the object - * cannot be serialized or there is another error, - * the method will return null. - * The object is not GZip-compressed before being encoded. - * - * @param serializableObject The object to encode - * @return The Base64-encoded object - * @since 1.4 - */ - public static String encodeObject( java.io.Serializable serializableObject ) - { - return encodeObject( serializableObject, NO_OPTIONS ); - } // end encodeObject - - - - /** - * Serializes an object and returns the Base64-encoded - * version of that serialized object. If the object - * cannot be serialized or there is another error, - * the method will return null. - *

- * Valid options:

-     *   GZIP: gzip-compresses object before encoding it.
-     *   DONT_BREAK_LINES: don't break lines at 76 characters
-     *     Note: Technically, this makes your encoding non-compliant.
-     * 
- *

- * Example: encodeObject( myObj, Base64.GZIP ) or - *

- * Example: encodeObject( myObj, Base64.GZIP | Base64.DONT_BREAK_LINES ) - * - * @param serializableObject The object to encode - * @param options Specified options - * @return The Base64-encoded object - * @see Base64#GZIP - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public static String encodeObject( java.io.Serializable serializableObject, int options ) - { - // Streams - java.io.ByteArrayOutputStream baos = null; - java.io.OutputStream b64os = null; - java.io.ObjectOutputStream oos = null; - java.util.zip.GZIPOutputStream gzos = null; - - // Isolate options - int gzip = (options & GZIP); - int dontBreakLines = (options & DONT_BREAK_LINES); - - try - { - // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream - baos = new java.io.ByteArrayOutputStream(); - b64os = new Base64.OutputStream( baos, ENCODE | dontBreakLines ); - - // GZip? - if( gzip == GZIP ) - { - gzos = new java.util.zip.GZIPOutputStream( b64os ); - oos = new java.io.ObjectOutputStream( gzos ); - } // end if: gzip - else - oos = new java.io.ObjectOutputStream( b64os ); - - oos.writeObject( serializableObject ); - } // end try - catch( java.io.IOException e ) - { - e.printStackTrace(); - return null; - } // end catch - finally - { - try{ oos.close(); } catch( Exception e ){} - try{ gzos.close(); } catch( Exception e ){} - try{ b64os.close(); } catch( Exception e ){} - try{ baos.close(); } catch( Exception e ){} - } // end finally - - // Return value according to relevant encoding. - try - { - return new String( baos.toByteArray(), PREFERRED_ENCODING ); - } // end try - catch (java.io.UnsupportedEncodingException uue) - { - return new String( baos.toByteArray() ); - } // end catch - - } // end encode - - - - /** - * Encodes a byte array into Base64 notation. - * Does not GZip-compress data. - * - * @param source The data to convert - * @since 1.4 - */ - public static String encodeBytes( byte[] source ) - { - return encodeBytes( source, 0, source.length, NO_OPTIONS ); - } // end encodeBytes - - - - /** - * Encodes a byte array into Base64 notation. - *

- * Valid options:

-     *   GZIP: gzip-compresses object before encoding it.
-     *   DONT_BREAK_LINES: don't break lines at 76 characters
-     *     Note: Technically, this makes your encoding non-compliant.
-     * 
- *

- * Example: encodeBytes( myData, Base64.GZIP ) or - *

- * Example: encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) - * - * - * @param source The data to convert - * @param options Specified options - * @see Base64#GZIP - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public static String encodeBytes( byte[] source, int options ) - { - return encodeBytes( source, 0, source.length, options ); - } // end encodeBytes - - - /** - * Encodes a byte array into Base64 notation. - * Does not GZip-compress data. - * - * @param source The data to convert - * @param off Offset in array where conversion should begin - * @param len Length of data to convert - * @since 1.4 - */ - public static String encodeBytes( byte[] source, int off, int len ) - { - return encodeBytes( source, off, len, NO_OPTIONS ); - } // end encodeBytes - - - - /** - * Encodes a byte array into Base64 notation. - *

- * Valid options:

-     *   GZIP: gzip-compresses object before encoding it.
-     *   DONT_BREAK_LINES: don't break lines at 76 characters
-     *     Note: Technically, this makes your encoding non-compliant.
-     * 
- *

- * Example: encodeBytes( myData, Base64.GZIP ) or - *

- * Example: encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES ) - * - * - * @param source The data to convert - * @param off Offset in array where conversion should begin - * @param len Length of data to convert - * @param options Specified options - * @see Base64#GZIP - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public static String encodeBytes( byte[] source, int off, int len, int options ) - { - // Isolate options - int dontBreakLines = ( options & DONT_BREAK_LINES ); - int gzip = ( options & GZIP ); - - // Compress? - if( gzip == GZIP ) - { - java.io.ByteArrayOutputStream baos = null; - java.util.zip.GZIPOutputStream gzos = null; - Base64.OutputStream b64os = null; - - - try - { - // GZip -> Base64 -> ByteArray - baos = new java.io.ByteArrayOutputStream(); - b64os = new Base64.OutputStream( baos, ENCODE | dontBreakLines ); - gzos = new java.util.zip.GZIPOutputStream( b64os ); - - gzos.write( source, off, len ); - gzos.close(); - } // end try - catch( java.io.IOException e ) - { - e.printStackTrace(); - return null; - } // end catch - finally - { - try{ gzos.close(); } catch( Exception e ){} - try{ b64os.close(); } catch( Exception e ){} - try{ baos.close(); } catch( Exception e ){} - } // end finally - - // Return value according to relevant encoding. - try - { - return new String( baos.toByteArray(), PREFERRED_ENCODING ); - } // end try - catch (java.io.UnsupportedEncodingException uue) - { - return new String( baos.toByteArray() ); - } // end catch - } // end if: compress - - // Else, don't compress. Better not to use streams at all then. - else - { - // Convert option to boolean in way that code likes it. - boolean breakLines = dontBreakLines == 0; - - int len43 = len * 4 / 3; - byte[] outBuff = new byte[ ( len43 ) // Main 4:3 - + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding - + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines - int d = 0; - int e = 0; - int len2 = len - 2; - int lineLength = 0; - for( ; d < len2; d+=3, e+=4 ) - { - encode3to4( source, d+off, 3, outBuff, e ); - - lineLength += 4; - if( breakLines && lineLength == MAX_LINE_LENGTH ) - { - outBuff[e+4] = NEW_LINE; - e++; - lineLength = 0; - } // end if: end of line - } // en dfor: each piece of array - - if( d < len ) - { - encode3to4( source, d+off, len - d, outBuff, e ); - e += 4; - } // end if: some padding needed - - - // Return value according to relevant encoding. - try - { - return new String( outBuff, 0, e, PREFERRED_ENCODING ); - } // end try - catch (java.io.UnsupportedEncodingException uue) - { - return new String( outBuff, 0, e ); - } // end catch - - } // end else: don't compress - - } // end encodeBytes - - - - - -/* ******** D E C O D I N G M E T H O D S ******** */ - - - /** - * Decodes four bytes from array source - * and writes the resulting bytes (up to three of them) - * to destination. - * The source and destination arrays can be manipulated - * anywhere along their length by specifying - * srcOffset and destOffset. - * This method does not check to make sure your arrays - * are large enough to accomodate srcOffset + 4 for - * the source array or destOffset + 3 for - * the destination array. - * This method returns the actual number of bytes that - * were converted from the Base64 encoding. - * - * - * @param source the array to convert - * @param srcOffset the index where conversion begins - * @param destination the array to hold the conversion - * @param destOffset the index where output will be put - * @return the number of decoded bytes converted - * @since 1.3 - */ - private static int decode4to3( byte[] source, int srcOffset, byte[] destination, int destOffset ) - { - // Example: Dk== - if( source[ srcOffset + 2] == EQUALS_SIGN ) - { - // Two ways to do the same thing. Don't know which way I like best. - //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) - // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 ); - int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) - | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 ); - - destination[ destOffset ] = (byte)( outBuff >>> 16 ); - return 1; - } - - // Example: DkL= - else if( source[ srcOffset + 3 ] == EQUALS_SIGN ) - { - // Two ways to do the same thing. Don't know which way I like best. - //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) - // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) - // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ); - int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) - | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) - | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 ); - - destination[ destOffset ] = (byte)( outBuff >>> 16 ); - destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 ); - return 2; - } - - // Example: DkLE - else - { - try{ - // Two ways to do the same thing. Don't know which way I like best. - //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 ) - // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 ) - // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 ) - // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 ); - int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 ) - | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 ) - | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6) - | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) ); - - - destination[ destOffset ] = (byte)( outBuff >> 16 ); - destination[ destOffset + 1 ] = (byte)( outBuff >> 8 ); - destination[ destOffset + 2 ] = (byte)( outBuff ); - - return 3; - }catch( Exception e){ - System.out.println(""+source[srcOffset]+ ": " + ( DECODABET[ source[ srcOffset ] ] ) ); - System.out.println(""+source[srcOffset+1]+ ": " + ( DECODABET[ source[ srcOffset + 1 ] ] ) ); - System.out.println(""+source[srcOffset+2]+ ": " + ( DECODABET[ source[ srcOffset + 2 ] ] ) ); - System.out.println(""+source[srcOffset+3]+ ": " + ( DECODABET[ source[ srcOffset + 3 ] ] ) ); - return -1; - } //e nd catch - } - } // end decodeToBytes - - - - - /** - * Very low-level access to decoding ASCII characters in - * the form of a byte array. Does not support automatically - * gunzipping or any other "fancy" features. - * - * @param source The Base64 encoded data - * @param off The offset of where to begin decoding - * @param len The length of characters to decode - * @return decoded data - * @since 1.3 - */ - public static byte[] decode( byte[] source, int off, int len ) - { - int len34 = len * 3 / 4; - byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output - int outBuffPosn = 0; - - byte[] b4 = new byte[4]; - int b4Posn = 0; - int i = 0; - byte sbiCrop = 0; - byte sbiDecode = 0; - for( i = off; i < off+len; i++ ) - { - sbiCrop = (byte)(source[i] & 0x7f); // Only the low seven bits - sbiDecode = DECODABET[ sbiCrop ]; - - if( sbiDecode >= WHITE_SPACE_ENC ) // White space, Equals sign or better - { - if( sbiDecode >= EQUALS_SIGN_ENC ) - { - b4[ b4Posn++ ] = sbiCrop; - if( b4Posn > 3 ) - { - outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn ); - b4Posn = 0; - - // If that was the equals sign, break out of 'for' loop - if( sbiCrop == EQUALS_SIGN ) - break; - } // end if: quartet built - - } // end if: equals sign or better - - } // end if: white space, equals sign or better - else - { - System.err.println( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" ); - return null; - } // end else: - } // each input character - - byte[] out = new byte[ outBuffPosn ]; - System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); - return out; - } // end decode - - - - - /** - * Decodes data from Base64 notation, automatically - * detecting gzip-compressed data and decompressing it. - * - * @param s the string to decode - * @return the decoded data - * @since 1.4 - */ - public static byte[] decode( String s ) - { - byte[] bytes; - try - { - bytes = s.getBytes( PREFERRED_ENCODING ); - } // end try - catch( java.io.UnsupportedEncodingException uee ) - { - bytes = s.getBytes(); - } // end catch - // - - // Decode - bytes = decode( bytes, 0, bytes.length ); - - - // Check to see if it's gzip-compressed - // GZIP Magic Two-Byte Number: 0x8b1f (35615) - if( bytes != null && bytes.length >= 4 ) - { - - int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); - if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) - { - java.io.ByteArrayInputStream bais = null; - java.util.zip.GZIPInputStream gzis = null; - java.io.ByteArrayOutputStream baos = null; - byte[] buffer = new byte[2048]; - int length = 0; - - try - { - baos = new java.io.ByteArrayOutputStream(); - bais = new java.io.ByteArrayInputStream( bytes ); - gzis = new java.util.zip.GZIPInputStream( bais ); - - while( ( length = gzis.read( buffer ) ) >= 0 ) - { - baos.write(buffer,0,length); - } // end while: reading input - - // No error? Get new bytes. - bytes = baos.toByteArray(); - - } // end try - catch( java.io.IOException e ) - { - // Just return originally-decoded bytes - } // end catch - finally - { - try{ baos.close(); } catch( Exception e ){} - try{ gzis.close(); } catch( Exception e ){} - try{ bais.close(); } catch( Exception e ){} - } // end finally - - } // end if: gzipped - } // end if: bytes.length >= 2 - - return bytes; - } // end decode - - - - - /** - * Attempts to decode Base64 data and deserialize a Java - * Object within. Returns null if there was an error. - * - * @param encodedObject The Base64 data to decode - * @return The decoded and deserialized object - * @since 1.5 - */ - public static Object decodeToObject( String encodedObject ) - { - // Decode and gunzip if necessary - byte[] objBytes = decode( encodedObject ); - - java.io.ByteArrayInputStream bais = null; - java.io.ObjectInputStream ois = null; - Object obj = null; - - try - { - bais = new java.io.ByteArrayInputStream( objBytes ); - ois = new java.io.ObjectInputStream( bais ); - - obj = ois.readObject(); - } // end try - catch( java.io.IOException e ) - { - e.printStackTrace(); - obj = null; - } // end catch - catch( java.lang.ClassNotFoundException e ) - { - e.printStackTrace(); - obj = null; - } // end catch - finally - { - try{ bais.close(); } catch( Exception e ){} - try{ ois.close(); } catch( Exception e ){} - } // end finally - - return obj; - } // end decodeObject - - - - /** - * Convenience method for encoding data to a file. - * - * @param dataToEncode byte array of data to encode in base64 form - * @param filename Filename for saving encoded data - * @return true if successful, false otherwise - * - * @since 2.1 - */ - public static boolean encodeToFile( byte[] dataToEncode, String filename ) - { - boolean success = false; - Base64.OutputStream bos = null; - try - { - bos = new Base64.OutputStream( - new java.io.FileOutputStream( filename ), Base64.ENCODE ); - bos.write( dataToEncode ); - success = true; - } // end try - catch( java.io.IOException e ) - { - - success = false; - } // end catch: IOException - finally - { - try{ bos.close(); } catch( Exception e ){} - } // end finally - - return success; - } // end encodeToFile - - - /** - * Convenience method for decoding data to a file. - * - * @param dataToDecode Base64-encoded data as a string - * @param filename Filename for saving decoded data - * @return true if successful, false otherwise - * - * @since 2.1 - */ - public static boolean decodeToFile( String dataToDecode, String filename ) - { - boolean success = false; - Base64.OutputStream bos = null; - try - { - bos = new Base64.OutputStream( - new java.io.FileOutputStream( filename ), Base64.DECODE ); - bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) ); - success = true; - } // end try - catch( java.io.IOException e ) - { - success = false; - } // end catch: IOException - finally - { - try{ bos.close(); } catch( Exception e ){} - } // end finally - - return success; - } // end decodeToFile - - - - - /** - * Convenience method for reading a base64-encoded - * file and decoding it. - * - * @param filename Filename for reading encoded data - * @return decoded byte array or null if unsuccessful - * - * @since 2.1 - */ - public static byte[] decodeFromFile( String filename ) - { - byte[] decodedData = null; - Base64.InputStream bis = null; - try - { - // Set up some useful variables - java.io.File file = new java.io.File( filename ); - byte[] buffer = null; - int length = 0; - int numBytes = 0; - - // Check for size of file - if( file.length() > Integer.MAX_VALUE ) - { - System.err.println( "File is too big for this convenience method (" + file.length() + " bytes)." ); - return null; - } // end if: file too big for int index - buffer = new byte[ (int)file.length() ]; - - // Open a stream - bis = new Base64.InputStream( - new java.io.BufferedInputStream( - new java.io.FileInputStream( file ) ), Base64.DECODE ); - - // Read until done - while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) - length += numBytes; - - // Save in a variable to return - decodedData = new byte[ length ]; - System.arraycopy( buffer, 0, decodedData, 0, length ); - - } // end try - catch( java.io.IOException e ) - { - System.err.println( "Error decoding from file " + filename ); - } // end catch: IOException - finally - { - try{ bis.close(); } catch( Exception e) {} - } // end finally - - return decodedData; - } // end decodeFromFile - - - - /** - * Convenience method for reading a binary file - * and base64-encoding it. - * - * @param filename Filename for reading binary data - * @return base64-encoded string or null if unsuccessful - * - * @since 2.1 - */ - public static String encodeFromFile( String filename ) - { - String encodedData = null; - Base64.InputStream bis = null; - try - { - // Set up some useful variables - java.io.File file = new java.io.File( filename ); - byte[] buffer = new byte[ (int)(file.length() * 1.4) ]; - int length = 0; - int numBytes = 0; - - // Open a stream - bis = new Base64.InputStream( - new java.io.BufferedInputStream( - new java.io.FileInputStream( file ) ), Base64.ENCODE ); - - // Read until done - while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) - length += numBytes; - - // Save in a variable to return - encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING ); - - } // end try - catch( java.io.IOException e ) - { - System.err.println( "Error encoding from file " + filename ); - } // end catch: IOException - finally - { - try{ bis.close(); } catch( Exception e) {} - } // end finally - - return encodedData; - } // end encodeFromFile - - - - - /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ - - - - /** - * A {@link Base64.InputStream} will read data from another - * java.io.InputStream, given in the constructor, - * and encode/decode to/from Base64 notation on the fly. - * - * @see Base64 - * @since 1.3 - */ - public static class InputStream extends java.io.FilterInputStream - { - private boolean encode; // Encoding or decoding - private int position; // Current position in the buffer - private byte[] buffer; // Small buffer holding converted data - private int bufferLength; // Length of buffer (3 or 4) - private int numSigBytes; // Number of meaningful bytes in the buffer - private int lineLength; - private boolean breakLines; // Break lines at less than 80 characters - - - /** - * Constructs a {@link Base64.InputStream} in DECODE mode. - * - * @param in the java.io.InputStream from which to read data. - * @since 1.3 - */ - public InputStream( java.io.InputStream in ) - { - this( in, DECODE ); - } // end constructor - - - /** - * Constructs a {@link Base64.InputStream} in - * either ENCODE or DECODE mode. - *

- * Valid options:

-         *   ENCODE or DECODE: Encode or Decode as data is read.
-         *   DONT_BREAK_LINES: don't break lines at 76 characters
-         *     (only meaningful when encoding)
-         *     Note: Technically, this makes your encoding non-compliant.
-         * 
- *

- * Example: new Base64.InputStream( in, Base64.DECODE ) - * - * - * @param in the java.io.InputStream from which to read data. - * @param options Specified options - * @see Base64#ENCODE - * @see Base64#DECODE - * @see Base64#DONT_BREAK_LINES - * @since 2.0 - */ - public InputStream( java.io.InputStream in, int options ) - { - super( in ); - this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; - this.encode = (options & ENCODE) == ENCODE; - this.bufferLength = encode ? 4 : 3; - this.buffer = new byte[ bufferLength ]; - this.position = -1; - this.lineLength = 0; - } // end constructor - - /** - * Reads enough of the input stream to convert - * to/from Base64 and returns the next byte. - * - * @return next byte - * @since 1.3 - */ - public int read() throws java.io.IOException - { - // Do we need to get data? - if( position < 0 ) - { - if( encode ) - { - byte[] b3 = new byte[3]; - int numBinaryBytes = 0; - for( int i = 0; i < 3; i++ ) - { - try - { - int b = in.read(); - - // If end of stream, b is -1. - if( b >= 0 ) - { - b3[i] = (byte)b; - numBinaryBytes++; - } // end if: not end of stream - - } // end try: read - catch( java.io.IOException e ) - { - // Only a problem if we got no data at all. - if( i == 0 ) - throw e; - - } // end catch - } // end for: each needed input byte - - if( numBinaryBytes > 0 ) - { - encode3to4( b3, 0, numBinaryBytes, buffer, 0 ); - position = 0; - numSigBytes = 4; - } // end if: got data - else - { - return -1; - } // end else - } // end if: encoding - - // Else decoding - else - { - byte[] b4 = new byte[4]; - int i = 0; - for( i = 0; i < 4; i++ ) - { - // Read four "meaningful" bytes: - int b = 0; - do{ b = in.read(); } - while( b >= 0 && DECODABET[ b & 0x7f ] <= WHITE_SPACE_ENC ); - - if( b < 0 ) - break; // Reads a -1 if end of stream - - b4[i] = (byte)b; - } // end for: each needed input byte - - if( i == 4 ) - { - numSigBytes = decode4to3( b4, 0, buffer, 0 ); - position = 0; - } // end if: got four characters - else if( i == 0 ){ - return -1; - } // end else if: also padded correctly - else - { - // Must have broken out from above. - throw new java.io.IOException( "Improperly padded Base64 input." ); - } // end - - } // end else: decode - } // end else: get data - - // Got data? - if( position >= 0 ) - { - // End of relevant data? - if( /*!encode &&*/ position >= numSigBytes ) - return -1; - - if( encode && breakLines && lineLength >= MAX_LINE_LENGTH ) - { - lineLength = 0; - return '\n'; - } // end if - else - { - lineLength++; // This isn't important when decoding - // but throwing an extra "if" seems - // just as wasteful. - - int b = buffer[ position++ ]; - - if( position >= bufferLength ) - position = -1; - - return b & 0xFF; // This is how you "cast" a byte that's - // intended to be unsigned. - } // end else - } // end if: position >= 0 - - // Else error - else - { - // When JDK1.4 is more accepted, use an assertion here. - throw new java.io.IOException( "Error in Base64 code reading stream." ); - } // end else - } // end read - - - /** - * Calls {@link #read()} repeatedly until the end of stream - * is reached or len bytes are read. - * Returns number of bytes read into array or -1 if - * end of stream is encountered. - * - * @param dest array to hold values - * @param off offset for array - * @param len max number of bytes to read into array - * @return bytes read into array or -1 if end of stream is encountered. - * @since 1.3 - */ - public int read( byte[] dest, int off, int len ) throws java.io.IOException - { - int i; - int b; - for( i = 0; i < len; i++ ) - { - b = read(); - - //if( b < 0 && i == 0 ) - // return -1; - - if( b >= 0 ) - dest[off + i] = (byte)b; - else if( i == 0 ) - return -1; - else - break; // Out of 'for' loop - } // end for: each byte read - return i; - } // end read - - } // end inner class InputStream - - - - - - - /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ - - - - /** - * A {@link Base64.OutputStream} will write data to another - * java.io.OutputStream, given in the constructor, - * and encode/decode to/from Base64 notation on the fly. - * - * @see Base64 - * @since 1.3 - */ - public static class OutputStream extends java.io.FilterOutputStream - { - private boolean encode; - private int position; - private byte[] buffer; - private int bufferLength; - private int lineLength; - private boolean breakLines; - private byte[] b4; // Scratch used in a few places - private boolean suspendEncoding; - - /** - * Constructs a {@link Base64.OutputStream} in ENCODE mode. - * - * @param out the java.io.OutputStream to which data will be written. - * @since 1.3 - */ - public OutputStream( java.io.OutputStream out ) - { - this( out, ENCODE ); - } // end constructor - - - /** - * Constructs a {@link Base64.OutputStream} in - * either ENCODE or DECODE mode. - *

- * Valid options:

-         *   ENCODE or DECODE: Encode or Decode as data is read.
-         *   DONT_BREAK_LINES: don't break lines at 76 characters
-         *     (only meaningful when encoding)
-         *     Note: Technically, this makes your encoding non-compliant.
-         * 
- *

- * Example: new Base64.OutputStream( out, Base64.ENCODE ) - * - * @param out the java.io.OutputStream to which data will be written. - * @param options Specified options. - * @see Base64#ENCODE - * @see Base64#DECODE - * @see Base64#DONT_BREAK_LINES - * @since 1.3 - */ - public OutputStream( java.io.OutputStream out, int options ) - { - super( out ); - this.breakLines = (options & DONT_BREAK_LINES) != DONT_BREAK_LINES; - this.encode = (options & ENCODE) == ENCODE; - this.bufferLength = encode ? 3 : 4; - this.buffer = new byte[ bufferLength ]; - this.position = 0; - this.lineLength = 0; - this.suspendEncoding = false; - this.b4 = new byte[4]; - } // end constructor - - - /** - * Writes the byte to the output stream after - * converting to/from Base64 notation. - * When encoding, bytes are buffered three - * at a time before the output stream actually - * gets a write() call. - * When decoding, bytes are buffered four - * at a time. - * - * @param theByte the byte to write - * @since 1.3 - */ - public void write(int theByte) throws java.io.IOException - { - // Encoding suspended? - if( suspendEncoding ) - { - super.out.write( theByte ); - return; - } // end if: supsended - - // Encode? - if( encode ) - { - buffer[ position++ ] = (byte)theByte; - if( position >= bufferLength ) // Enough to encode. - { - out.write( encode3to4( b4, buffer, bufferLength ) ); - - lineLength += 4; - if( breakLines && lineLength >= MAX_LINE_LENGTH ) - { - out.write( NEW_LINE ); - lineLength = 0; - } // end if: end of line - - position = 0; - } // end if: enough to output - } // end if: encoding - - // Else, Decoding - else - { - // Meaningful Base64 character? - if( DECODABET[ theByte & 0x7f ] > WHITE_SPACE_ENC ) - { - buffer[ position++ ] = (byte)theByte; - if( position >= bufferLength ) // Enough to output. - { - int len = Base64.decode4to3( buffer, 0, b4, 0 ); - out.write( b4, 0, len ); - //out.write( Base64.decode4to3( buffer ) ); - position = 0; - } // end if: enough to output - } // end if: meaningful base64 character - else if( DECODABET[ theByte & 0x7f ] != WHITE_SPACE_ENC ) - { - throw new java.io.IOException( "Invalid character in Base64 data." ); - } // end else: not white space either - } // end else: decoding - } // end write - - - - /** - * Calls {@link #write(int)} repeatedly until len - * bytes are written. - * - * @param theBytes array from which to read bytes - * @param off offset for array - * @param len max number of bytes to read into array - * @since 1.3 - */ - public void write( byte[] theBytes, int off, int len ) throws java.io.IOException - { - // Encoding suspended? - if( suspendEncoding ) - { - super.out.write( theBytes, off, len ); - return; - } // end if: supsended - - for( int i = 0; i < len; i++ ) - { - write( theBytes[ off + i ] ); - } // end for: each byte written - - } // end write - - - - /** - * Method added by PHIL. [Thanks, PHIL. -Rob] - * This pads the buffer without closing the stream. - */ - public void flushBase64() throws java.io.IOException - { - if( position > 0 ) - { - if( encode ) - { - out.write( encode3to4( b4, buffer, position ) ); - position = 0; - } // end if: encoding - else - { - throw new java.io.IOException( "Base64 input not properly padded." ); - } // end else: decoding - } // end if: buffer partially full - - } // end flush - - - /** - * Flushes and closes (I think, in the superclass) the stream. - * - * @since 1.3 - */ - public void close() throws java.io.IOException - { - // 1. Ensure that pending characters are written - flushBase64(); - - // 2. Actually close the stream - // Base class both flushes and closes. - super.close(); - - buffer = null; - out = null; - } // end close - - - - /** - * Suspends encoding of the stream. - * May be helpful if you need to embed a piece of - * base640-encoded data in a stream. - * - * @since 1.5.1 - */ - public void suspendEncoding() throws java.io.IOException - { - flushBase64(); - this.suspendEncoding = true; - } // end suspendEncoding - - - /** - * Resumes encoding of the stream. - * May be helpful if you need to embed a piece of - * base640-encoded data in a stream. - * - * @since 1.5.1 - */ - public void resumeEncoding() - { - this.suspendEncoding = false; - } // end resumeEncoding - - - - } // end inner class OutputStream - - -} // end class Base64 diff --git a/s3/perftest/src/main/resources/README b/s3/perftest/src/main/resources/README deleted file mode 100644 index 3a8de1c414..0000000000 --- a/s3/perftest/src/main/resources/README +++ /dev/null @@ -1,84 +0,0 @@ -This is one of a collection of interface libraries that can be used to interact -with the Amazon S3 system in a number of different languages. They each expose -two main interface classes, AWSAuthConnection and QueryStringAuthGenerator. -The first actually performs all the operations using the appropriate libraries -for the language, including header signing. The second, -QueryStringAuthGenerator, has the same interface, but instead of performing -the operation, this class will return urls with the right query string -authentication parameters set. - - -Basic Operations: - -object requests: - -GetResponse get(bucketName, keyName) - retrieves an object -GetResponse getACL(bucketName, keyName) - returns the xml acl doc -Response put(bucketName, keyName, object) - writes an object -Response putACL(bucketName, keyName, aclXMLDoc) - sets the xml acl doc -Response delete(bucketName, keyName) - deletes an object - -bucket requests: - -Response createBucket(bucketName, location) - creates a bucket -ListResponse listBucket(bucketName) - lists a bucket's contents -LocationResponse getBucketLocation(bucketName) - return the location-constraint of this bucket -GetResponse getBucketACL(bucketName) - returns the xml representation of this bucket's access control list -Response putBucketAcl(bucketName, aclXMLDoc) - sets xml representation of the bucket acl -Response deleteBucket(bucketName) - delete an empty bucket -GetResponse getBucketLogging(bucketName) - returns the xml representation of this bucket's access logging configuration -Response putBucketLogging(bucketName, loggingXMLDoc) - sets the xml representation of the bucket logging configuration - -ListAllMyBucketsResponse listAllMyBuckets() - returns a list of all buckets owned by this AWS Access Key Id - - - -Dependencies: - -None, beyond the standard libraries. - - -Notes: - -Please note that this uses the public domain iHarder.net Base64 library. For updates to that library, -see http://iharder.sourceforge.net/current/java/base64/ . - -If your bucket name contains periods, you will need to use a non-HTTPS connection as the SSL certificate -presented by s3.amazonaws.com will not match if you do. - -Limitations: - -One of the main limitations of these sample AWSAuthConnection implementations -is that the interfaces are not streaming. This means that you have to pass the -data in as a string or as a byte array and the operation returns a string or a -byte array back. This is conceptually simpler, and fine for smaller objects, -but large objects, say a couple megabytes or greater, will show poor -performance, since everything is being passed around in memory. More -sophisticated libraries would pass streams in and out, and would only read the -data on-demand, rather than storing it all in memory (S3 itself would have no -problem with such streaming applications). Another upshot of this is that the -interfaces are all blocking---that is, you cannot look at the data until all of -it has downloaded. Again, this is fine for smaller objects, but unacceptable -for larger ones. - -These libraries have nearly non-existent error handling. All errors from lower -libraries are simply passed up. The response code in the connection object needs -to be checked after each request to verify whether the request succeeded. - -Only the java library has proper handling for repeated headers. The others -assume that each header will have only one value. - -It is our intention that these libraries act as a starting point for future -development. They are meant to show off the various operations and provide an -example of how to negotiate the authentication process. - - - -This software code is made available "AS IS" without warranties of any -kind. You may copy, display, modify and redistribute the software -code either by itself or as incorporated into your code; provided that -you do not remove any proprietary notices. Your use of this software -code is at your own risk and you waive any claim against Amazon -Digital Services, Inc. or its affiliates with respect to your use of -this software code. (c) 2006 Amazon Digital Services, Inc. or its -affiliates. diff --git a/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceTest.java b/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceTest.java deleted file mode 100644 index 8b0482a89f..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.jclouds.aws.s3.reference.S3Constants; -import org.testng.ITestContext; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.InputStream; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.concurrent.ExecutionException; - - -/** - * Runs operations that amazon s3 sample code is capable of performing. - * - * @author Adrian Cole - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.AmazonPerformance") -public class AmazonPerformanceTest extends BasePerformance { - private AWSAuthConnection amzClient; - - @Override - @BeforeTest - @Parameters({S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY}) - protected void setUpCredentials(@Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey, ITestContext context) throws Exception { - super.setUpCredentials(AWSAccessKeyId, AWSSecretAccessKey, context); - amzClient = new AWSAuthConnection(AWSAccessKeyId, AWSSecretAccessKey, - false); - } - - @Override - @Test(enabled = false) - public void testPutFileSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutFileParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutInputStreamSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutStringSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutStringParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean putByteArray(String bucket, String key, byte[] data, - String contentType) throws Exception { - com.amazon.s3.S3Object object = new com.amazon.s3.S3Object(data, null); - Map> headers = new TreeMap>(); - headers - .put("Content-Type", Arrays - .asList(new String[]{contentType})); - return amzClient.put(bucket, key, object, headers).connection - .getResponseMessage() != null; - } - - @Override - protected boolean putFile(String bucket, String key, File data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean putString(String bucket, String key, String data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - -} diff --git a/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java b/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java deleted file mode 100644 index db1aacf2ec..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import java.io.File; -import java.io.InputStream; -import java.util.concurrent.TimeUnit; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -public abstract class BaseJCloudsPerformance extends BasePerformance { - // boolean get - // ( - // int id) throws Exception { - // S3Bucket s3Bucket = new S3Bucket(); - // s3Bucket.setName(bucketPrefix + "-jclouds-puts"); - // org.jclouds.aws.s3.domain.S3Object object = new - // org.jclouds.aws.s3.domain.S3Object(); - // object.setKey(id + ""); - // //object.setContentType("text/plain"); - // object.setContentType("application/octetstream"); - // //object.setData("this is a test"); - // object.setData(test); - // return clientProvider.getObject(s3Bucket, - // object.getKey()).get(120,TimeUnit.SECONDS) != - // org.jclouds.aws.s3.domain.S3Object.NOT_FOUND; - - // } - - @Override - protected boolean putByteArray(String bucket, String key, byte[] data, - String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } - - @Override - protected boolean putFile(String bucket, String key, File data, - String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } - - @Override - protected boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - object.getMetadata().setSize(data.available()); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } - - @Override - protected boolean putString(String bucket, String key, String data, - String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } -} diff --git a/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java b/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java deleted file mode 100644 index 1724b24aba..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java +++ /dev/null @@ -1,252 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import com.google.inject.Provider; -import org.jclouds.aws.s3.S3IntegrationTest; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import org.testng.ITestContext; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -@Test -public abstract class BasePerformance extends S3IntegrationTest { - protected boolean debugEnabled() { - return false; - } - - protected static int LOOP_COUNT = 100; - - protected ExecutorService exec; - protected final String BUCKET_BYTES = bucketPrefix + "-bytes"; - protected final String BUCKET_INPUTSTREAM = bucketPrefix + "-inputstream"; - protected final String BUCKET_STRING = bucketPrefix + "-string"; - protected final String BUCKET_FILE = bucketPrefix + "-file"; - protected final String[] BUCKETS = {BUCKET_BYTES, BUCKET_INPUTSTREAM, - BUCKET_STRING, BUCKET_FILE}; - protected PutBytesCallable putBytesCallable; - protected PutFileCallable putFileCallable; - protected PutInputStreamCallable putInputStreamCallable; - protected PutStringCallable putStringCallable; - - protected CompletionService completer; - - @BeforeTest - protected void setUpCallables() { - putBytesCallable = new PutBytesCallable(); - putFileCallable = new PutFileCallable(); - putInputStreamCallable = new PutInputStreamCallable(); - putStringCallable = new PutStringCallable(); - exec = Executors.newCachedThreadPool(); - completer = new ExecutorCompletionService(exec); - } - - @Override - @BeforeTest - protected void setUpClient(ITestContext context) throws Exception { - super.setUpClient(context); - for (String bucket : BUCKETS) { - client.putBucketIfNotExists(bucket).get(10, TimeUnit.SECONDS); - } - } - - @AfterTest - protected void tearDownExecutor() throws Exception { - exec.shutdownNow(); - exec = null; - } - - @Test(enabled = true) - public void testPutBytesSerial() throws Exception { - doSerial(putBytesCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutBytesParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putBytesCallable, LOOP_COUNT); - } - - @Test(enabled = true) - public void testPutFileSerial() throws Exception { - doSerial(putFileCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutFileParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putFileCallable, LOOP_COUNT); - } - - @Test(enabled = true) - public void testPutInputStreamSerial() throws Exception { - doSerial(putInputStreamCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putInputStreamCallable, LOOP_COUNT); - } - - @Test(enabled = true) - public void testPutStringSerial() throws Exception { - doSerial(putStringCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutStringParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putStringCallable, LOOP_COUNT); - } - - private void doSerial(Provider> provider, int loopCount) - throws Exception, ExecutionException { - for (int i = 0; i < loopCount; i++) - assert provider.get().call(); - } - - private void doParallel(Provider> provider, int loopCount) - throws InterruptedException, ExecutionException, TimeoutException { - for (int i = 0; i < loopCount; i++) - completer.submit(provider.get()); - for (int i = 0; i < loopCount; i++) - assert completer.take().get(10, TimeUnit.SECONDS); - } - - class PutBytesCallable implements Provider> { - final AtomicInteger key = new AtomicInteger(0); - protected byte[] test = new byte[1024 * 2]; - - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putByteArray(BUCKET_BYTES, key.getAndIncrement() - + "", test, "application/octetstring"); - } - }; - - } - } - - class PutFileCallable implements Provider> { - final AtomicInteger key = new AtomicInteger(0); - protected File file = new File("pom.xml"); - - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putFile(BUCKET_FILE, key.getAndIncrement() + "", - file, "text/xml"); - } - }; - - } - } - - class PutInputStreamCallable extends PutBytesCallable { - final AtomicInteger key = new AtomicInteger(0); - - @Override - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putInputStream(BUCKET_INPUTSTREAM, key - .getAndIncrement() - + "", new ByteArrayInputStream(test), - "application/octetstring"); - } - }; - - } - } - - class PutStringCallable implements Provider> { - final AtomicInteger key = new AtomicInteger(0); - protected String testString = "hello world!"; - - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putString(BUCKET_STRING, key.getAndIncrement() + "", - testString, "text/plain"); - } - }; - - } - } - - protected abstract boolean putByteArray(String bucket, String key, - byte[] data, String contentType) throws Exception; - - protected abstract boolean putFile(String bucket, String key, File data, - String contentType) throws Exception; - - protected abstract boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception; - - protected abstract boolean putString(String bucket, String key, - String data, String contentType) throws Exception; - - // private class BucketDeleter implements Callable { - // private BucketDeleter(S3Bucket bucket) { - // this.bucket = bucket; - // } - // - // private S3Bucket bucket; - // - // @Override - // public String toString() { - // return "BucketDeleter{" + "bucket=" + bucket + '}'; - // } - // - // public Boolean call() throws Exception { - // bucket = - // clientProvider.get(10,TimeUnit.SECONDS).getBucket(bucket).get(10,TimeUnit.SECONDS); - // List> deletes = new ArrayList>(); - // for (org.jclouds.aws.s3.domain.S3Object object : bucket - // .getContents()) { - // deletes.add(clientProvider.get(10,TimeUnit.SECONDS).deleteObject(bucket, - // object.getKey())); - // } - // for (Future isdeleted : deletes) - // assert isdeleted.get(10,TimeUnit.SECONDS) : - // String.format("failed to delete %1$ss", - // isdeleted); - // return - // clientProvider.get(10,TimeUnit.SECONDS).deleteBucket(bucket).get(10,TimeUnit.SECONDS); - // } - // } -} diff --git a/s3/perftest/src/test/java/com/amazon/s3/DateServiceTest.java b/s3/perftest/src/test/java/com/amazon/s3/DateServiceTest.java deleted file mode 100644 index e0fb57a9d3..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/DateServiceTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import org.jclouds.aws.PerformanceTest; -import org.jclouds.aws.s3.util.DateService; -import org.joda.time.DateTime; -import org.testng.annotations.Test; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.SimpleTimeZone; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; - -/** - * Compares performance of date operations - * - * @author Adrian Cole - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.DateTest") -public class DateServiceTest extends PerformanceTest { - Injector i = Guice.createInjector(); - - DateService utils = i.getInstance(DateService.class); - SimpleDateFormat dateParser; - - public DateServiceTest() { - this.dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - this.dateParser.setTimeZone(new SimpleTimeZone(0, "GMT")); - } - - Date amazonDateFromString(String toParse) throws ParseException { - return this.dateParser.parse(toParse); - } - - private static String toParse = "2009-03-12T02:00:07.000Z"; - - @Test - public void testParseDateSameAsAmazon() throws ParseException, - ExecutionException, InterruptedException { - Date java = dateParser.parse(toParse); - DateTime joda = utils.dateTimeFromXMLFormat(toParse); - assert java.equals(joda.toDate()); - } - - @Test - public void testTimeStampDateSameAsAmazon() throws ExecutionException, - InterruptedException { - String java = AWSAuthConnection.httpDate(); - String joda = utils.timestampAsHeaderString(); - assert java.equals(joda); - } - - @Test - public void testToHeaderString() throws ExecutionException, - InterruptedException { - String joda1 = utils.toHeaderString(new DateTime()); - String joda = utils.timestampAsHeaderString(); - assert joda1.equals(joda); - } - - @Test - void testTimeStampSerialResponseTime() throws ExecutionException, - InterruptedException { - for (int i = 0; i < LOOP_COUNT; i++) - utils.timestampAsHeaderString(); - } - - @Test - void testAmazonTimeStampSerialResponseTime() { - for (int i = 0; i < LOOP_COUNT; i++) - AWSAuthConnection.httpDate(); - } - - @Test - void testTimeStampParallelResponseTime() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() throws ExecutionException, - InterruptedException { - utils.timestampAsHeaderString(); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get(); - } - - @Test - void testAmazonTimeStampParallelResponseTime() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() { - AWSAuthConnection.httpDate(); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get(); - } - - @Test - void testParseDateSerialResponseTime() throws ExecutionException, - InterruptedException { - for (int i = 0; i < LOOP_COUNT; i++) - utils.dateTimeFromXMLFormat(toParse); - } - - @Test - void testAmazonParseDateSerialResponseTime() { - for (int i = 0; i < LOOP_COUNT; i++) - AWSAuthConnection.httpDate(); - } - - @Test - void testParseDateParallelResponseTime() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() throws ExecutionException, - InterruptedException { - utils.dateTimeFromXMLFormat(toParse); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get(); - } - - @Test - void testAmazonParseDateParallelResponseTime() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() { - AWSAuthConnection.httpDate(); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get(); - } - -} \ No newline at end of file diff --git a/s3/perftest/src/test/java/com/amazon/s3/JCloudsNioPerformanceTest.java b/s3/perftest/src/test/java/com/amazon/s3/JCloudsNioPerformanceTest.java deleted file mode 100644 index ba37b83893..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/JCloudsNioPerformanceTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - - -import java.util.Properties; - -import org.jclouds.http.httpnio.config.HttpNioConnectionPoolClientModule; -import org.testng.annotations.Test; - -import com.google.inject.Module; - -@Test(sequential=true, testName = "s3.JCloudsNioPerformance") -public class JCloudsNioPerformanceTest extends BaseJCloudsPerformance { - - @Override - protected Properties buildS3Properties(String AWSAccessKeyId, - String AWSSecretAccessKey) { - Properties properties = super.buildS3Properties(AWSAccessKeyId, AWSSecretAccessKey); - properties.setProperty("jclouds.http.pool.max_connection_reuse", "75"); - properties.setProperty("jclouds.http.pool.max_session_failures", "2"); - properties.setProperty("jclouds.http.pool.request_invoker_threads", "1"); - properties.setProperty("jclouds.http.pool.io_worker_threads", "2"); - properties.setProperty("jclouds.pool.max_connections", "12"); - return properties; - } - - @Override - protected Module createHttpModule() { - return new HttpNioConnectionPoolClientModule(); - } -} \ No newline at end of file diff --git a/s3/perftest/src/test/java/com/amazon/s3/JCloudsPerformanceTest.java b/s3/perftest/src/test/java/com/amazon/s3/JCloudsPerformanceTest.java deleted file mode 100644 index 05d7149bb6..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/JCloudsPerformanceTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.testng.annotations.Test; - -/** - * Tests the default JClouds client. - * - * @author Adrian Cole - * - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.JCloudsPerformance") -public class JCloudsPerformanceTest extends BaseJCloudsPerformance { - -} \ No newline at end of file diff --git a/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceTest.java b/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceTest.java deleted file mode 100644 index a8518d6f19..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.jets3t.service.S3Service; -import org.jets3t.service.impl.rest.httpclient.RestS3Service; -import org.jets3t.service.security.AWSCredentials; -import org.testng.ITestContext; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.InputStream; -import java.util.concurrent.ExecutionException; - -/** - * Runs operations that jets3t is capable of performing. - * - * @author Adrian Cole - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.Jets3tPerformance") -public class Jets3tPerformanceTest extends BasePerformance { - private S3Service jetClient; - - @Override - protected void setUpCredentials(String AWSAccessKeyId, String AWSSecretAccessKey, ITestContext context) - throws Exception { - super.setUpCredentials(AWSAccessKeyId, AWSSecretAccessKey, context); - jetClient = new RestS3Service(new AWSCredentials(AWSAccessKeyId, - AWSSecretAccessKey)); - } - - @Override - @Test(enabled = false) - public void testPutStringSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - - @Override - @Test(enabled = false) - public void testPutBytesSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutStringParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutBytesParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutFileParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - protected boolean putByteArray(String bucket, String key, byte[] data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - - } - - @Override - protected boolean putFile(String bucket, String key, File data, - String contentType) throws Exception { - org.jets3t.service.model.S3Object object = new org.jets3t.service.model.S3Object( - key); - object.setContentType(contentType); - object.setDataInputFile(data); - object.setContentLength(data.length()); - return jetClient.putObject(bucket, object) != null; - } - - @Override - protected boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception { - org.jets3t.service.model.S3Object object = new org.jets3t.service.model.S3Object( - key); - object.setContentType(contentType); - object.setDataInputStream(data); - object.setContentLength(data.available()); - return jetClient.putObject(bucket, object) != null; - } - - @Override - protected boolean putString(String bucket, String key, String data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - -} \ No newline at end of file diff --git a/s3/perftest/src/test/java/com/amazon/s3/S3ParserTest.java b/s3/perftest/src/test/java/com/amazon/s3/S3ParserTest.java deleted file mode 100644 index 49dbf71cde..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/S3ParserTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.apache.commons.io.IOUtils; -import org.joda.time.DateTime; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.util.Date; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; - -/** - * Compares performance of xml parsing apis. - * - * @author Adrian Cole - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.S3ParserTest") -public class S3ParserTest extends org.jclouds.aws.s3.commands.S3ParserTest { - - class MockHttpURLConnection extends HttpURLConnection { - private String content; - - @Override - public InputStream getInputStream() throws IOException { - return IOUtils.toInputStream(content); - } - - protected MockHttpURLConnection(String content) { - super(null); - this.content = content; - } - - public void disconnect() { - } - - public boolean usingProxy() { - return false; - } - - @Override - public int getResponseCode() throws IOException { - return 200; - } - - public void connect() throws IOException { - } - } - - @Test - void testAmazonParseListAllMyBucketsSerialResponseTime() throws IOException { - for (int i = 0; i < LOOP_COUNT; i++) - runAmazonParseListAllMyBuckets(); - } - - @Test - void testAmazonParseListAllMyBucketsParallelResponseTime() - throws InterruptedException, ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() throws IOException { - runAmazonParseListAllMyBuckets(); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get(); - } - - @SuppressWarnings("unchecked") - @Test(enabled = false) - public void testAmazonCanParseListAllMyBuckets() throws IOException { - ListAllMyBucketsResponse response = runAmazonParseListAllMyBuckets(); - List buckets = response.entries; - Bucket bucket1 = (Bucket) buckets.get(0); - assert bucket1.name.equals("adrianjbosstest"); - Date expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z").toDate(); - Date date1 = bucket1.creationDate; - assert date1.toString().equals(expectedDate1.toString()); - Bucket bucket2 = (Bucket) buckets.get(1); - assert bucket2.name.equals("adrianjbosstest2"); - Date expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z").toDate(); - Date date2 = bucket2.creationDate; - assert date2.toString().equals(expectedDate2.toString()); - assert buckets.size() == 2; - } - - private ListAllMyBucketsResponse runAmazonParseListAllMyBuckets() - throws IOException { - ListAllMyBucketsResponse response = new ListAllMyBucketsResponse( - new MockHttpURLConnection(listAllMyBucketsResultOn200)); - return response; - } - - public void testAmazonCanParseListBucketResult() throws IOException { - ListBucketResponse response = runAmazonParseListBucketResult(); - ListEntry content = (ListEntry) response.entries.get(0); - assert content.key.equals("3366"); - assert content.lastModified.equals(new DateTime( - "2009-03-12T02:00:13.000Z").toDate()); - assert content.eTag.equals("\"9d7bb64e8e18ee34eec06dd2cf37b766\""); - assert content.size == 136; - assert content.owner.id - .equals("e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0"); - assert content.owner.displayName.equals("ferncam"); - assert content.storageClass.equals("STANDARD"); - } - - private ListBucketResponse runAmazonParseListBucketResult() - throws IOException { - ListBucketResponse response = new ListBucketResponse( - new MockHttpURLConnection(listBucketResult)); - return response; - } - - @Test - void testAmazonParseListBucketResultSerialResponseTime() throws IOException { - for (int i = 0; i < LOOP_COUNT; i++) - runAmazonParseListBucketResult(); - } - - @Test - void testAmazonParseListBucketResultParallelResponseTime() - throws InterruptedException, ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() throws IOException { - runAmazonParseListBucketResult(); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get(); - } - -} diff --git a/s3/perftest/src/test/java/com/amazon/s3/S3UtilsTest.java b/s3/perftest/src/test/java/com/amazon/s3/S3UtilsTest.java deleted file mode 100644 index 403ece911f..0000000000 --- a/s3/perftest/src/test/java/com/amazon/s3/S3UtilsTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.testng.annotations.Test; - -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; - -/** - * Compares performance of encryption operations. - * - * @author Adrian Cole - * - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.S3UtilsTest") -public class S3UtilsTest extends org.jclouds.aws.s3.S3UtilsTest { - - @Test(dataProvider = "hmacsha1") - void testAmazonSampleDigestSerialResponseTime(byte[] key, String message, String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException { - for (int i = 0; i < 10000; i++) - testAmazonSampleDigest(key, message, base64Digest); - } - - @Test(dataProvider = "hmacsha1") - public void testAmazonSampleDigest(byte[] key, String message, String base64Digest) { - String encoded = Utils.encode(new String(key), message, false); - assert encoded.equals(base64Digest); - } - - @Test(dataProvider = "hmacsha1") - void testAmazonSampleDigestParallelResponseTime(final byte[] key, final String message, final String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, InterruptedException, ExecutionException { - CompletionService completer = new ExecutorCompletionService(exec); - for (int i = 0; i < 10000; i++) - completer.submit(new Callable() { - public Boolean call() { - try { - testAmazonSampleDigest(key, message, base64Digest); - return true; - } catch (Exception e) { - return false; - } - } - }); - for (int i = 0; i < 10000; i++) assert completer.take().get(); - } -} \ No newline at end of file diff --git a/s3/pom.xml b/s3/pom.xml deleted file mode 100644 index 1cc9c68760..0000000000 --- a/s3/pom.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - - org.jclouds - jclouds-project - 1.0-SNAPSHOT - ../project/pom.xml - - 4.0.0 - org.jclouds - jclouds-s3 - jclouds Amazon S3 Components Core - jar - jclouds Core components to access Amazon S3 - - - scm:svn:http://jclouds.googlecode.com/svn/trunk/s3 - scm:svn:https://jclouds.googlecode.com/svn/trunk/s3 - http://jclouds.googlecode.com/svn/trunk/s3 - - - - - - http://apache.rediris.es/maven/binaries/apache-maven-2.1.0-bin.tar.bz2 - - 9268c9de2cccfd0d8fbcdbcfaf517a87 - - - - - ${project.groupId} - jclouds-core - ${project.version} - - - joda-time - joda-time - 1.6 - - - bouncycastle - bcprov-jdk15 - 140 - - - xstream - xstream - 1.2 - test - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.4.3 - - - integration - integration-test - - test - - - - - **/*LiveTest.java - - - **/*IntegrationTest.java - - - - jclouds.s3.httpstream.url - ${jclouds.s3.httpstream.url} - - - jclouds.s3.httpstream.md5 - ${jclouds.s3.httpstream.md5} - - - - - - - - - **/*IntegrationTest.java - **/*LiveTest.java - - - - - - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.4.3 - - - integration - integration-test - - test - - - - - none - - - **/*IntegrationTest.java - **/*LiveTest.java - - - - jclouds.aws.accesskeyid - ${jclouds.aws.accesskeyid} - - - jclouds.aws.secretaccesskey - ${jclouds.aws.secretaccesskey} - - - jclouds.s3.httpstream.url - ${jclouds.s3.httpstream.url} - - - jclouds.s3.httpstream.md5 - ${jclouds.s3.httpstream.md5} - - - - - - - - - - - diff --git a/s3/samples/googleappengine/README.txt b/s3/samples/googleappengine/README.txt deleted file mode 100644 index 6221dd9b45..0000000000 --- a/s3/samples/googleappengine/README.txt +++ /dev/null @@ -1,54 +0,0 @@ -==== - - Copyright (C) 2009 Adrian Cole - - ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ==================================================================== -==== -This samples uses the Google App Engine for Java SDK located at http://googleappengine.googlecode.com/files/appengine-java-sdk-1.2.0.zip - -Please unzip the above file and modify your maven settings.xml like below before attempting to run 'mvn install' - - - appengine - - true - - - /path/to/appengine-java-sdk-1.2.0 - - - - - aws - - true - - - YOUR_ACCESS_KEY_ID - YOUR_SECRET_KEY - - - - - - jclouds - http://jclouds.googlecode.com/svn/trunk/repo - - diff --git a/s3/samples/googleappengine/pom.xml b/s3/samples/googleappengine/pom.xml deleted file mode 100644 index 235cadfc70..0000000000 --- a/s3/samples/googleappengine/pom.xml +++ /dev/null @@ -1,194 +0,0 @@ - - - - - jclouds-project - org.jclouds - 1.0-SNAPSHOT - ../../../project/pom.xml - - 4.0.0 - jclouds-gae-s3-example - war - JClouds Sample for Google App Engine - JClouds Sample for Google App Engine - - - - /Users/adriancole/Desktop/appengine-java-sdk-1.2.0 - localhost - 8088 - - - - - - - guice-snapshot - http://guice-maven.googlecode.com/svn/trunk - - - - - - Main Maven Repo - http://repo1.maven.org/maven2/ - - - - - - ${project.groupId} - jclouds-gae - ${project.version} - - - ${project.groupId} - jclouds-s3 - ${project.version} - - - ${project.groupId} - jclouds-s3 - ${project.version} - test - test-jar - - - com.google.code.guice - guice-servlet - 2.0-r943 - - - standard - taglibs - 1.1.2 - jar - runtime - - - jstl - javax.servlet - 1.1.2 - jar - compile - - - org.apache.geronimo.specs - geronimo-el_1.0_spec - 1.0.1 - compile - - - org.apache.geronimo.specs - geronimo-jsp_2.1_spec - 1.0.1 - provided - - - org.apache.geronimo.specs - geronimo-servlet_2.5_spec - 1.2 - provided - - - - com.google.appengine - appengine-tools-api - 1.2.0 - system - ${appengine.home}/lib/appengine-tools-api.jar - - - - - ${project.artifactId} - src/it/java - - - org.apache.maven.plugins - maven-surefire-plugin - 2.4.3 - - - integration - integration-test - - test - - - target/test-classes - - - jclouds.aws.accesskeyid - ${jclouds.aws.accesskeyid} - - - jclouds.aws.secretaccesskey - ${jclouds.aws.secretaccesskey} - - - appengine.home - ${appengine.home} - - - devappserver.address - ${devappserver.address} - - - devappserver.port - ${devappserver.port} - - - warfile - ${project.build.directory}/${project.artifactId} - - - - ${appengine.home}/lib/appengine-tools-api.jar - - - - true - ${appengine.home}/bin - ${appengine.home}/lib - ${appengine.home}/config/sdk - - - - - - - target/classes - - - - - - diff --git a/s3/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java b/s3/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java deleted file mode 100644 index d96d535231..0000000000 --- a/s3/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.samples.googleappengine.functest; - -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Properties; - -import org.testng.annotations.AfterTest; - -import com.google.appengine.tools.KickStart; - -/** - * Basic functionality to start a local google app engine instance. - * - * @author Adrian Cole - * - */ -public abstract class BaseGoogleAppEngineTest { - - Thread server; - URL url; - - protected void writePropertiesAndStartServer(final String address, - final String port, final String warfile, Properties props) - throws IOException, FileNotFoundException, InterruptedException { - url = new URL(String.format("http://%1$s:%2$s", address, port)); - - props.store(new FileOutputStream(String.format( - "%1$s/WEB-INF/jclouds.properties", warfile)), "test"); - this.server = new Thread(new Runnable() { - public void run() { - KickStart - .main(new String[] { - "com.google.appengine.tools.development.DevAppServerMain", - "--disable_update_check", "-a", address, "-p", - port, warfile }); - - } - - }); - server.start(); - Thread.sleep(7 * 1000); - } - - @SuppressWarnings("deprecation") - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); - } - -} \ No newline at end of file diff --git a/s3/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineTest.java b/s3/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineTest.java deleted file mode 100644 index 51240ae7f3..0000000000 --- a/s3/samples/googleappengine/src/it/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.samples.googleappengine.functest; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Properties; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.reference.S3Constants; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - - -/** - * Starts up the Google App Engine for Java Development environment and deploys - * an application which tests S3. - * - * @author Adrian Cole - * - */ -@Test(groups = "integration", enabled = true, sequential = true, testName = "functionalTests") -public class GoogleAppEngineTest extends BaseGoogleAppEngineTest { - - private static final String sysAWSAccessKeyId = System - .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); - private static final String sysAWSSecretAccessKey = System - .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); - - @BeforeTest - @Parameters( { "warfile", "devappserver.address", "devappserver.port", - S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) - public void startDevAppServer(final String warfile, final String address, - final String port, @Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey) throws Exception { - AWSAccessKeyId = AWSAccessKeyId != null ? AWSAccessKeyId - : sysAWSAccessKeyId; - AWSSecretAccessKey = AWSSecretAccessKey != null ? AWSSecretAccessKey - : sysAWSSecretAccessKey; - - checkNotNull(AWSAccessKeyId, "AWSAccessKeyId"); - checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey"); - - Properties props = new Properties(); - props.put(S3Constants.PROPERTY_AWS_ACCESSKEYID, AWSAccessKeyId); - props.put(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, AWSSecretAccessKey); - writePropertiesAndStartServer(address, port, warfile, props); - } - - @Test - public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = IOUtils.toString(i); - assert string.indexOf("Hello World!") >= 0 : string; - } - - @Test(invocationCount = 5, enabled = true) - public void testGuiceJCloudsSerial() throws InterruptedException, - IOException { - URL gurl = new URL(url, "/guice/listbuckets.s3"); - InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); - assert string.indexOf("List") >= 0 : string; - } - - @Test(invocationCount = 50, enabled = true, threadPoolSize = 10) - public void testGuiceJCloudsParallel() throws InterruptedException, - IOException { - URL gurl = new URL(url, "/guice/listbuckets.s3"); - InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); - assert string.indexOf("List") >= 0 : string; - } -} diff --git a/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java b/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java deleted file mode 100644 index aac9157983..0000000000 --- a/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.samples.googleappengine; - -import java.io.IOException; -import java.io.Writer; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.annotation.Resource; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.S3ResponseException; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.logging.Logger; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - -/** - * Shows an example of how to use @{link S3Connection} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class JCloudsServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - - @Inject - S3Context context; - - @Resource - protected Logger logger = Logger.NULL; - - @Override - protected void doGet(HttpServletRequest httpServletRequest, - HttpServletResponse httpServletResponse) throws ServletException, - IOException { - httpServletResponse.setContentType("text/plain"); - Writer writer = httpServletResponse.getWriter(); - try { - List myBuckets = context.getConnection() - .listOwnedBuckets().get(10, TimeUnit.SECONDS); - writer.write("List:\n"); - for (S3Bucket.Metadata bucket : myBuckets) { - writer.write(String.format(" %1$s", bucket)); - try { - writer.write(String.format(": %1$s entries%n", context - .createInputStreamMap(bucket.getName()).size())); - } catch (S3ResponseException e) { - String message = String.format( - ": unable to list entries due to: %1$s%n", e - .getError().getCode()); - writer.write(message); - logger.warn(e, "message"); - } - - } - } catch (Exception e) { - throw new ServletException(e); - } - writer.flush(); - writer.close(); - } -} \ No newline at end of file diff --git a/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java b/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java deleted file mode 100644 index e5e0900c89..0000000000 --- a/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.samples.googleappengine.config; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContextEvent; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.S3ContextFactory; -import org.jclouds.aws.s3.reference.S3Constants; -import org.jclouds.gae.config.URLFetchServiceClientModule; -import org.jclouds.samples.googleappengine.JCloudsServlet; - - -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.servlet.GuiceServletContextListener; -import com.google.inject.servlet.ServletModule; - -/** - * Setup Logging and create Injector for use in testing S3. - * - * @author Adrian Cole - * - */ -public class GuiceServletConfig extends GuiceServletContextListener { - @Inject - S3Context context; - String accessKeyId; - String secretAccessKey; - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - Properties props = loadJCloudsProperties(servletContextEvent); - this.accessKeyId = props - .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); - this.secretAccessKey = props - .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); - super.contextInitialized(servletContextEvent); - } - - private Properties loadJCloudsProperties( - ServletContextEvent servletContextEvent) { - InputStream input = servletContextEvent.getServletContext() - .getResourceAsStream("/WEB-INF/jclouds.properties"); - Properties props = new Properties(); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - IOUtils.closeQuietly(input); - } - return props; - } - - @Override - protected Injector getInjector() { - return S3ContextFactory.createInjector(accessKeyId, secretAccessKey, - false, new URLFetchServiceClientModule(), - new ServletModule() { - @Override - protected void configureServlets() { - serve("*.s3").with(JCloudsServlet.class); - requestInjection(this); - } - }); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - context.close(); - super.contextDestroyed(servletContextEvent); - } -} \ No newline at end of file diff --git a/s3/samples/googleappengine/src/main/webapp/WEB-INF/appengine-web.xml b/s3/samples/googleappengine/src/main/webapp/WEB-INF/appengine-web.xml deleted file mode 100644 index 8f17694b44..0000000000 --- a/s3/samples/googleappengine/src/main/webapp/WEB-INF/appengine-web.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - jclouds-s3-example - 1 - diff --git a/s3/samples/googleappengine/src/main/webapp/WEB-INF/web.xml b/s3/samples/googleappengine/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 73a4a41c95..0000000000 --- a/s3/samples/googleappengine/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - jclouds-s3-example - - - - guiceFilter - com.google.inject.servlet.GuiceFilter - - - - guiceFilter - /guice/* - - - - - org.jclouds.samples.googleappengine.config.GuiceServletConfig - - diff --git a/s3/samples/googleappengine/src/main/webapp/index.jsp b/s3/samples/googleappengine/src/main/webapp/index.jsp deleted file mode 100644 index 6529d030ec..0000000000 --- a/s3/samples/googleappengine/src/main/webapp/index.jsp +++ /dev/null @@ -1,30 +0,0 @@ -<%-- - - - Copyright (C) 2009 Adrian Cole - - ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ==================================================================== - ---%> - - -

Hello World!

- - diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3Connection.java b/s3/src/main/java/org/jclouds/aws/s3/S3Connection.java deleted file mode 100644 index 12bde45437..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/S3Connection.java +++ /dev/null @@ -1,214 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import org.jclouds.aws.s3.commands.options.*; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; - -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -/** - * Provides access to S3 via their REST API. - *

- * All commands return a Future of the result from S3. Any exceptions incurred - * during processing will be wrapped in an {@link ExecutionException} as - * documented in {@link Future#get()}. - * - * @author Adrian Cole - * @see - */ -public interface S3Connection { - - /** - * Retrieve a complete S3Object. - * - * @param bucketName namespace of the object you are retrieving - * @param key unique key in the s3Bucket identifying the object - * @return Future reference to a fully populated S3Object including data - * stored in S3 or {@link S3Object#NOT_FOUND} if not present. - * @see org.jclouds.aws.s3.commands.GetObject - */ - Future getObject(String bucketName, String key); - - /** - * Like {@link #getObject(String, String)} except you can use - * {@link GetObjectOptions} to control delivery. - * - * @return S3Object containing data relevant to the - * options specified or {@link S3Object#NOT_FOUND} if not present. - * @throws org.jclouds.http.HttpResponseException - * if the conditions requested set were not satisfied by the - * object on the server. - * @see #getObject(String, String) - * @see GetObjectOptions - */ - Future getObject(String bucketName, String key, - GetObjectOptions options); - - /** - * Retrieves the {@link org.jclouds.aws.s3.domain.S3Object.Metadata metadata} of the object associated - * with the key. - * - * @param bucketName namespace of the metadata you are retrieving - * @param key unique key in the s3Bucket identifying the object - * @return metadata associated with the key or - * {@link org.jclouds.aws.s3.domain.S3Object.Metadata#NOT_FOUND} if not present; - * @see org.jclouds.aws.s3.commands.HeadObject - */ - Future headObject(String bucketName, String key); - - /** - * Removes the object and metadata associated with the key. - * - * @param bucketName namespace of the object you are deleting - * @param key unique key in the s3Bucket identifying the object - * @return true if deleted - * @throws org.jclouds.http.HttpResponseException - * if the bucket is not available - * @see org.jclouds.aws.s3.commands.DeleteObject - */ - Future deleteObject(String bucketName, String key); - - /** - * Store data by creating or overwriting an object. - *

- * This method will store the object with the default private - * acl. - * - * @param bucketName namespace of the object you are storing - * @param object contains the data and metadata to create or overwrite - * @return MD5 hash of the content uploaded - * @see org.jclouds.aws.s3.domain.acl.CannedAccessPolicy#PRIVATE - * @see org.jclouds.aws.s3.commands.PutObject - */ - Future putObject(String bucketName, S3Object object); - - /** - * Like {@link #putObject(String, S3Object)} except you can use - * {@link CopyObjectOptions} to specify an alternate - * {@link org.jclouds.aws.s3.domain.acl.CannedAccessPolicy acl}, override - * {@link org.jclouds.aws.s3.domain.S3Object.Metadata#getUserMetadata() userMetadata}, or specify - * conditions for copying the object. - * - * @param options options for creating the object - * @throws org.jclouds.http.HttpResponseException - * if the conditions requested set are not satisfied by the - * object on the server. - * @see S3Connection#putObject(String, S3Object) - * @see PutObjectOptions - */ - Future putObject(String bucketName, S3Object object, - PutObjectOptions options); - - /** - * Create and name your own bucket in which to store your objects. - * - * @return true, if the bucket was created or already exists - * @see org.jclouds.aws.s3.commands.PutBucket - */ - Future putBucketIfNotExists(String name); - - /** - * Like {@link #putBucketIfNotExists(String)} except that you can use - * {@link PutBucketOptions} to create the bucket in EU. Create and name your - * - * @param options for creating your bucket - * @see PutBucketOptions - */ - Future putBucketIfNotExists(String name, PutBucketOptions options); - - /** - * Deletes the bucket, if it is empty. - * - * @param s3Bucket what to delete - * @return false, if the bucket was not empty and therefore not deleted - * @see org.jclouds.aws.s3.commands.DeleteBucket - */ - Future deleteBucketIfEmpty(String s3Bucket); - - /** - * Copies one object to another bucket, retaining UserMetadata from the - * source. The destination will have a private acl. - * - * @return metadata populated with lastModified and md5 of the new object - * @see org.jclouds.aws.s3.commands.CopyObject - */ - Future copyObject(String sourceBucket, - String sourceObject, String destinationBucket, - String destinationObject); - - /** - * Like {@link #putObject(String, S3Object)} except you can use - * {@link PutObjectOptions} to specify an alternate - * {@link org.jclouds.aws.s3.domain.acl.CannedAccessPolicy acl}. - * - * @param options options for creating the object - * @throws org.jclouds.http.HttpResponseException - * if the conditions requested set are not satisfied by the - * object on the server. - * @see S3Connection#putObject(String, S3Object) - * @see PutObjectOptions - */ - Future copyObject(String sourceBucket, - String sourceObject, String destinationBucket, - String destinationObject, CopyObjectOptions options); - - /** - * @see org.jclouds.aws.s3.commands.BucketExists - */ - Future bucketExists(String name); - - /** - * Retrieve a complete S3Bucket listing. - * - * @param bucketName namespace of the objects you wish to list - * @return Future reference to a fully populated S3Bucket including metadata - * of the S3Objects it contains or {@link S3Bucket#NOT_FOUND} if not - * present. - * @see org.jclouds.aws.s3.commands.ListBucket - */ - Future listBucket(String bucketName); - - /** - * Like {@link #listBucket(String)} except you can use - * {@link ListBucketOptions} to control the amount of S3Objects to return. - * - * @return S3Bucket containing a subset of {@link org.jclouds.aws.s3.domain.S3Object.Metadata} - * depending on - * options specified or {@link S3Bucket#NOT_FOUND} if not present. - * @see #listBucket(String) - * @see ListBucketOptions - */ - Future listBucket(String name, ListBucketOptions options); - - /** - * @return list of all of the buckets owned by the authenticated sender of - * the request. - * @see org.jclouds.aws.s3.commands.ListOwnedBuckets - */ - Future> listOwnedBuckets(); -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3Context.java b/s3/src/main/java/org/jclouds/aws/s3/S3Context.java deleted file mode 100644 index c30ed21981..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/S3Context.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -/** - * Represents an authenticated context to S3. - * - *

Note

Please issue {@link #close()} when you are finished with this - * context in order to release resources. - * - * - * @see S3Connection - * @see S3InputStreamMap - * @see S3ObjectMap - * @author Adrian Cole - * - */ -public interface S3Context { - - /** - * low-level api to S3. Threadsafe implementations will return a singleton. - * - * @return a connection to S3 - */ - S3Connection getConnection(); - - /** - * Creates a Map view of the specified - * bucket. - * - * @param bucket - */ - S3InputStreamMap createInputStreamMap(String bucket); - - /** - * Creates a Map view of the specified bucket. - * - * @param bucket - */ - S3ObjectMap createS3ObjectMap(String bucket); - - /** - * Closes all connections to S3. - */ - void close(); - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3ContextFactory.java b/s3/src/main/java/org/jclouds/aws/s3/S3ContextFactory.java deleted file mode 100644 index 12ca56047f..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/S3ContextFactory.java +++ /dev/null @@ -1,236 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import com.google.common.annotations.VisibleForTesting; -import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.name.Names; -import org.jclouds.aws.s3.config.LiveS3ConnectionModule; -import org.jclouds.aws.s3.config.S3ConnectionModule; -import org.jclouds.aws.s3.config.S3ContextModule; -import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_AWS_ACCESSKEYID; -import static org.jclouds.aws.s3.reference.S3Constants.PROPERTY_AWS_SECRETACCESSKEY; -import org.jclouds.aws.s3.internal.LiveS3Connection; -import static org.jclouds.command.pool.PoolConstants.*; -import static org.jclouds.http.HttpConstants.*; -import org.jclouds.http.config.HttpFutureCommandClientModule; -import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; -import org.jclouds.logging.config.LoggingModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; - -import java.util.List; -import java.util.Properties; - -/** - * Creates {@link S3Context} or {@link Injector} instances based on the most - * commonly requested arguments. - *

- * Note that Threadsafe objects will be bound as singletons to the Injector or - * Context provided. - *

- *

- * If no Modules are specified, the default - * {@link JDKLoggingModule logging} and - * {@link JavaUrlHttpFutureCommandClientModule http transports} will be - * installed. - * - * @author Adrian Cole - * @see S3Context - */ -public class S3ContextFactory { - - public static final Properties DEFAULT_PROPERTIES; - - static { - DEFAULT_PROPERTIES = new Properties(); - DEFAULT_PROPERTIES.setProperty(PROPERTY_HTTP_ADDRESS, - "s3.amazonaws.com"); - DEFAULT_PROPERTIES.setProperty(PROPERTY_HTTP_PORT, "443"); - DEFAULT_PROPERTIES.setProperty(PROPERTY_HTTP_SECURE, "true"); - DEFAULT_PROPERTIES - .setProperty(PROPERTY_POOL_MAX_CONNECTION_REUSE, "75"); - DEFAULT_PROPERTIES.setProperty(PROPERTY_POOL_MAX_SESSION_FAILURES, "2"); - DEFAULT_PROPERTIES.setProperty(PROPERTY_POOL_REQUEST_INVOKER_THREADS, - "1"); - DEFAULT_PROPERTIES.setProperty(PROPERTY_POOL_IO_WORKER_THREADS, "2"); - DEFAULT_PROPERTIES.setProperty(PROPERTY_POOL_MAX_CONNECTIONS, "12"); - } - - public static Injector createInjector(String awsAccessKeyId, - String awsSecretAccessKey, Module... modules) { - Properties properties = new Properties(DEFAULT_PROPERTIES); - properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId); - properties - .setProperty(PROPERTY_AWS_SECRETACCESSKEY, awsSecretAccessKey); - return createInjector(properties, modules); - } - - public static S3Context createS3Context(String awsAccessKeyId, - String awsSecretAccessKey, Module... modules) { - return createInjector(awsAccessKeyId, awsSecretAccessKey, modules) - .getInstance(S3Context.class); - } - - public static Injector createInjector(String awsAccessKeyId, - String awsSecretAccessKey, boolean isSecure, Module... modules) { - Properties properties = new Properties(DEFAULT_PROPERTIES); - properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId); - properties - .setProperty(PROPERTY_AWS_SECRETACCESSKEY, awsSecretAccessKey); - properties - .setProperty(PROPERTY_HTTP_SECURE, Boolean.toString(isSecure)); - if (!isSecure) - properties.setProperty(PROPERTY_HTTP_PORT, "80"); - return createInjector(properties, modules); - } - - public static S3Context createS3Context(String awsAccessKeyId, - String awsSecretAccessKey, boolean isSecure, Module... modules) { - return createInjector(awsAccessKeyId, awsSecretAccessKey, isSecure, - modules).getInstance(S3Context.class); - } - - public static Injector createInjector(String awsAccessKeyId, - String awsSecretAccessKey, boolean isSecure, String server, - Module... modules) { - Properties properties = new Properties(DEFAULT_PROPERTIES); - properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId); - properties - .setProperty(PROPERTY_AWS_SECRETACCESSKEY, awsSecretAccessKey); - properties - .setProperty(PROPERTY_HTTP_SECURE, Boolean.toString(isSecure)); - properties.setProperty(PROPERTY_HTTP_ADDRESS, server); - if (!isSecure) - properties.setProperty(PROPERTY_HTTP_PORT, "80"); - return createInjector(properties, modules); - } - - public static S3Context createS3Context(String awsAccessKeyId, - String awsSecretAccessKey, boolean isSecure, String server, - Module... modules) { - return createInjector(awsAccessKeyId, awsSecretAccessKey, isSecure, - server, modules).getInstance(S3Context.class); - } - - public static S3Context createS3Context(String awsAccessKeyId, - String awsSecretAccessKey, boolean isSecure, String server, - int port, Module... modules) { - return createInjector(awsAccessKeyId, awsSecretAccessKey, isSecure, - server, port, modules).getInstance(S3Context.class); - } - - public static Injector createInjector(String awsAccessKeyId, - String awsSecretAccessKey, boolean isSecure, String server, - int port, Module... modules) { - Properties properties = new Properties(DEFAULT_PROPERTIES); - properties.setProperty(PROPERTY_AWS_ACCESSKEYID, awsAccessKeyId); - properties - .setProperty(PROPERTY_AWS_SECRETACCESSKEY, awsSecretAccessKey); - properties - .setProperty(PROPERTY_HTTP_SECURE, Boolean.toString(isSecure)); - properties.setProperty(PROPERTY_HTTP_ADDRESS, server); - properties.setProperty(PROPERTY_HTTP_PORT, port + ""); - return createInjector(properties, modules); - } - - public static S3Context createS3Context(Properties properties, - Module... modules) { - return createInjector(properties, modules).getInstance(S3Context.class); - } - - /** - * Bind the given properties and install the list of modules. If no modules - * are specified, install the default {@link JDKLoggingModule} - * {@link JavaUrlHttpFutureCommandClientModule} - * - * @param properties - contains constants used by jclouds - * {@link #DEFAULT_PROPERTIES} - * @param configModules - alternative configuration modules - */ - public static Injector createInjector(final Properties properties, - Module... configModules) { - final List modules = Lists.newArrayList(configModules); - - addLoggingModuleIfNotPresent(modules); - - addHttpModuleIfNeededAndNotPresent(modules); - - addS3ConnectionModuleIfNotPresent(modules); - - return Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - Names.bindProperties(binder(), checkNotNull(properties, - "properties")); - for (Module module : modules) - install(module); - } - }, new S3ContextModule()); - } - - @VisibleForTesting - static void addHttpModuleIfNeededAndNotPresent(final List modules) { - if (Iterables.any(modules, new Predicate() { - public boolean apply(Module input) { - return input instanceof LiveS3ConnectionModule; - } - - }) && (!Iterables.any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent( - HttpFutureCommandClientModule.class); - } - - }))) - modules.add(new JavaUrlHttpFutureCommandClientModule()); - } - - @VisibleForTesting - static void addS3ConnectionModuleIfNotPresent(final List modules) { - if (!Iterables.any(modules, new Predicate() { - public boolean apply(Module input) { - return input.getClass().isAnnotationPresent( - S3ConnectionModule - .class); - } - - })){ - modules.add(new LiveS3ConnectionModule()); - } - } - - @VisibleForTesting - static void addLoggingModuleIfNotPresent(final List modules) { - if (!Iterables.any(modules, Predicates.instanceOf(LoggingModule.class))) - modules.add(new JDKLoggingModule()); - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3InputStreamMap.java b/s3/src/main/java/org/jclouds/aws/s3/S3InputStreamMap.java deleted file mode 100644 index f2b8194576..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/S3InputStreamMap.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import java.io.File; -import java.io.InputStream; -import java.util.Map; - -/** - * Map view of an {@link org.jclouds.aws.s3.domain.S3Bucket}. Provides additional methods for inserting - * common object types. - *

- *

Note

All put operations will invoke - * {@link org.jclouds.aws.s3.domain.S3Object#generateMd5}. By extension, {@link #put(Object, Object)} - * will result in the InputStream being converted to a byte array. For this - * reason, do not use {@link #put(Object, Object)} to store files. Use - * {@link #putFile(String, File)} or {@link S3ObjectMap} instead. - * - * @author Adrian Cole - */ -public interface S3InputStreamMap extends S3Map { - InputStream putString(String key, String value); - - InputStream putFile(String key, File value); - - InputStream putBytes(String key, byte[] value); - - void putAllStrings(Map map); - - void putAllBytes(Map map); - - void putAllFiles(Map map); - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3Map.java b/s3/src/main/java/org/jclouds/aws/s3/S3Map.java deleted file mode 100644 index b1ffd03970..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/S3Map.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import java.util.Map; - -import org.jclouds.aws.s3.domain.S3Bucket; - -/** - * All Map views of {@link S3Bucket}s provide means to access the underlying S3 - * object. - * - * @author Adrian Cole - * - */ -public interface S3Map extends Map { - - /** - * - * @return s3 bucket listing that this map represents - */ - S3Bucket getBucket(); - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3ObjectMap.java b/s3/src/main/java/org/jclouds/aws/s3/S3ObjectMap.java deleted file mode 100644 index 2eda5a170d..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/S3ObjectMap.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; - -/** - * Map view of an {@link S3Bucket}. - * - *

- * When copying an object, you can preserve all metadata (default) or - * {@link CopyObjectOptions#overrideMetadataWith(com.google.common.collect.Multimap) - * specify new metadata}. However, the ACL is not preserved and is set to - * private for the user making the request. To override the default ACL setting, - * {@link CopyObjectOptions#overrideAcl(org.jclouds.aws.s3.domain.acl.CannedAccessPolicy) - * specify a new ACL} when generating a copy request. - * - * @see - * @see CopyObjectOptions - * @see org.jclouds.aws.s3.domain.acl.CannedAccessPolicy - * @author Adrian Cole - * - */ -public class CopyObject extends S3FutureCommand { - - @Inject - public CopyObject(@Named("jclouds.http.address") String amazonHost, - ParseSax callable, - @Assisted("sourceBucket") String sourceBucket, - @Assisted("sourceObject") String sourceObject, - @Assisted("destinationBucket") String destinationBucket, - @Assisted("destinationObject") String destinationObject, - @Assisted CopyObjectOptions options) { - super("PUT", - "/" + checkNotNull(destinationObject, "destinationObject"), - callable, amazonHost, destinationBucket); - CopyObjectHandler handler = (CopyObjectHandler) callable.getHandler(); - handler.setKey(destinationObject); - getRequest().getHeaders().put( - "x-amz-copy-source", - String.format("/%1$s/%2$s", checkNotNull(sourceBucket, - "sourceBucket"), checkNotNull(sourceObject, - "sourceObject"))); - getRequest().getHeaders().putAll(options.buildRequestHeaders()); - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteBucket.java b/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteBucket.java deleted file mode 100644 index f553cff325..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteBucket.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.aws.s3.S3ResponseException; -import org.jclouds.http.HttpResponseException; -import org.jclouds.http.commands.callables.ReturnTrueIf2xx; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * The DELETE request operation deletes the bucket named in the URI. All objects - * in the bucket must be deleted before the bucket itself can be deleted. - *

- * Only the owner of a bucket can delete it, regardless of the bucket's access - * control policy. - * - * @see - * @author Adrian Cole - */ -public class DeleteBucket extends S3FutureCommand { - - @Inject - public DeleteBucket(@Named("jclouds.http.address") String amazonHost, - ReturnTrueIf2xx callable, @Assisted String s3Bucket) { - super("DELETE", "/", callable, amazonHost, s3Bucket); - } - - @Override - public Boolean get() throws InterruptedException, ExecutionException { - try { - return super.get(); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } - - @VisibleForTesting - Boolean attemptNotFound(ExecutionException e) throws ExecutionException { - if (e.getCause() != null - && e.getCause() instanceof HttpResponseException) { - S3ResponseException responseException = (S3ResponseException) e - .getCause(); - if (responseException.getResponse().getStatusCode() == 404) { - return true; - } else if ("BucketNotEmpty".equals(responseException.getError() - .getCode())) { - return false; - } - } - throw e; - } - - @Override - public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, - ExecutionException, TimeoutException { - try { - return super.get(l, timeUnit); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteObject.java b/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteObject.java deleted file mode 100644 index ade7067868..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteObject.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.http.commands.callables.ReturnTrueIf2xx; - -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * The DELETE request operation removes the specified object from Amazon S3. - * Once deleted, there is no method to restore or undelete an object. - * - * @see - * @author Adrian Cole - */ -public class DeleteObject extends S3FutureCommand { - - @Inject - public DeleteObject(@Named("jclouds.http.address") String amazonHost, - ReturnTrueIf2xx callable, @Assisted("bucketName") String bucket, - @Assisted("key") String key) { - super("DELETE", "/" + checkNotNull(key), callable, amazonHost, bucket); - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/GetObject.java b/s3/src/main/java/org/jclouds/aws/s3/commands/GetObject.java deleted file mode 100644 index b51008d050..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/GetObject.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.aws.s3.S3ResponseException; -import org.jclouds.aws.s3.commands.callables.ParseObjectFromHeadersAndHttpContent; -import org.jclouds.aws.s3.commands.options.GetObjectOptions; -import org.jclouds.aws.s3.domain.S3Object; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * Retrieves the S3Object associated with the Key or {@link S3Object#NOT_FOUND} - * if not available; - * - *

- * To use GET, you must have READ access to the object. If READ access is - * granted to the anonymous user, you can request the object without an - * authorization header. - *

- *

- * This command allows you to specify {@link GetObjectOptions} to control - * delivery of content. - * - *

Note

If you specify any of the below options, you will receive - * partial content: - *
    - *
  • {@link GetObjectOptions#range}
  • - *
  • {@link GetObjectOptions#startAt}
  • - *
  • {@link GetObjectOptions#tail}
  • - *
- * - * @see GetObjectOptions - * @see
- * @author Adrian Cole - */ -public class GetObject extends S3FutureCommand { - - @Inject - public GetObject(@Named("jclouds.http.address") String amazonHost, - ParseObjectFromHeadersAndHttpContent callable, - @Assisted("bucketName") String s3Bucket, - @Assisted("key") String key, @Assisted GetObjectOptions options) { - super("GET", "/" + checkNotNull(key), callable, amazonHost, s3Bucket); - this.getRequest().getHeaders().putAll(options.buildRequestHeaders()); - callable.setKey(key); - } - - @Override - public S3Object get() throws InterruptedException, ExecutionException { - try { - return super.get(); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } - - @VisibleForTesting - S3Object attemptNotFound(ExecutionException e) throws ExecutionException { - if (e.getCause() != null && e.getCause() instanceof S3ResponseException) { - S3ResponseException responseException = (S3ResponseException) e - .getCause(); - if ("NoSuchKey".equals(responseException.getError().getCode())) { - return S3Object.NOT_FOUND; - } - } - throw e; - } - - @Override - public S3Object get(long l, TimeUnit timeUnit) throws InterruptedException, - ExecutionException, TimeoutException { - try { - return super.get(l, timeUnit); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/HeadObject.java b/s3/src/main/java/org/jclouds/aws/s3/commands/HeadObject.java deleted file mode 100644 index fba9352a08..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/HeadObject.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.aws.s3.commands.callables.ParseMetadataFromHeaders; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.http.HttpResponseException; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * Retrieves the metadata associated with the Key or - * {@link org.jclouds.aws.s3.domain.S3Object.Metadata#NOT_FOUND} if not available. - * - *

- * The HEAD operation is used to retrieve information about a specific object or - * object size, without actually fetching the object itself. This is useful if - * you're only interested in the object metadata, and don't want to waste - * bandwidth on the object data. - * - * @see GetObject - * @see - * @author Adrian Cole - * - */ -public class HeadObject extends S3FutureCommand { - - @Inject - public HeadObject(@Named("jclouds.http.address") String amazonHost, - ParseMetadataFromHeaders callable, - @Assisted("bucketName") String bucket, @Assisted("key") String key) { - super("HEAD", "/" + checkNotNull(key), callable, amazonHost, bucket); - callable.setKey(key); - } - - @Override - public S3Object.Metadata get() throws InterruptedException, - ExecutionException { - try { - return super.get(); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } - - @VisibleForTesting - S3Object.Metadata attemptNotFound(ExecutionException e) - throws ExecutionException { - if (e.getCause() != null - && e.getCause() instanceof HttpResponseException) { - HttpResponseException responseException = (HttpResponseException) e - .getCause(); - if (responseException.getResponse().getStatusCode() == 404) { - return S3Object.Metadata.NOT_FOUND; - } - } - throw e; - } - - @Override - public S3Object.Metadata get(long l, TimeUnit timeUnit) - throws InterruptedException, ExecutionException, TimeoutException { - try { - return super.get(l, timeUnit); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/ListBucket.java b/s3/src/main/java/org/jclouds/aws/s3/commands/ListBucket.java deleted file mode 100644 index 7405ac1e24..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/ListBucket.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.aws.s3.S3ResponseException; -import org.jclouds.aws.s3.commands.options.ListBucketOptions; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.xml.ListBucketHandler; -import org.jclouds.http.HttpResponseException; -import org.jclouds.http.commands.callables.xml.ParseSax; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * A GET request operation using a bucket URI lists information about the - * objects in the bucket. - *

- * To list the keys of a bucket, you must have READ access to the bucket. - *

- * List output is controllable via {@link ListBucketOptions} - * - * @see ListBucketOptions - * @see - * @author Adrian Cole - * - */ -public class ListBucket extends S3FutureCommand { - - @Inject - public ListBucket(@Named("jclouds.http.address") String amazonHost, - ParseSax bucketParser, @Assisted String bucket, - @Assisted ListBucketOptions options) { - super("GET", "/" + options.buildQueryString(), bucketParser, - amazonHost, bucket); - ListBucketHandler handler = (ListBucketHandler) bucketParser - .getHandler(); - handler.setBucketName(bucket); - } - - @Override - public S3Bucket get() throws InterruptedException, ExecutionException { - try { - return super.get(); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } - - @VisibleForTesting - S3Bucket attemptNotFound(ExecutionException e) throws ExecutionException { - if (e.getCause() != null - && e.getCause() instanceof HttpResponseException) { - S3ResponseException responseException = (S3ResponseException) e - .getCause(); - if ("NoSuchBucket".equals(responseException.getError().getCode())) { - return S3Bucket.NOT_FOUND; - } - } - throw e; - } - - @Override - public S3Bucket get(long l, TimeUnit timeUnit) throws InterruptedException, - ExecutionException, TimeoutException { - try { - return super.get(l, timeUnit); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/ListOwnedBuckets.java b/s3/src/main/java/org/jclouds/aws/s3/commands/ListOwnedBuckets.java deleted file mode 100644 index 53e9fb3c68..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/ListOwnedBuckets.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import java.util.List; - -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.commands.callables.xml.ParseSax; - -import com.google.inject.Inject; -import com.google.inject.name.Named; - -/** - * Returns a list of all of the buckets owned by the authenticated sender of the - * request. - * - * @see - * @author Adrian Cole - * - */ -public class ListOwnedBuckets extends S3FutureCommand> { - - @Inject - public ListOwnedBuckets(@Named("jclouds.http.address") String amazonHost, - ParseSax> callable) { - super("GET", "/", callable, amazonHost); - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/PutBucket.java b/s3/src/main/java/org/jclouds/aws/s3/commands/PutBucket.java deleted file mode 100644 index 870693922c..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/PutBucket.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.commands.options.PutBucketOptions; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpHeaders; -import org.jclouds.http.commands.callables.ReturnTrueIf2xx; - -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * Create and name your own bucket in which to store your objects. - *

- * The PUT request operation with a bucket URI creates a new bucket. Depending - * on your latency and legal requirements, you can specify a location constraint - * that will affect where your data physically resides. You can currently - * specify a Europe (EU) location constraint via {@link PutBucketOptions}. - * - * @see PutBucketOptions - * @see - * @author Adrian Cole - * - */ -public class PutBucket extends S3FutureCommand { - - @Inject - public PutBucket(@Named("jclouds.http.address") String amazonHost, - ReturnTrueIf2xx callable, @Assisted String bucketName, - @Assisted PutBucketOptions options) { - super("PUT", "/", callable, amazonHost, S3Utils - .validateBucketName(bucketName)); - getRequest().getHeaders().putAll(options.buildRequestHeaders()); - String payload = options.buildPayload(); - if (payload != null) { - getRequest().setPayload(payload); - getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, - payload.getBytes().length + ""); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/PutObject.java b/s3/src/main/java/org/jclouds/aws/s3/commands/PutObject.java deleted file mode 100644 index 853fd3772f..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/PutObject.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.aws.s3.commands.callables.ParseMd5FromETagHeader; -import org.jclouds.aws.s3.commands.options.PutObjectOptions; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpHeaders; - -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * Store data by creating or overwriting an object. - * - *

- * This returns a byte[] of the md5 hash of what Amazon S3 received - *

- *

- * This command allows you to specify {@link PutObjectOptions} to control - * delivery of content. - * - * - * @see PutObjectOptions - * @see - * @author Adrian Cole - */ -public class PutObject extends S3FutureCommand { - - @Inject - public PutObject(@Named("jclouds.http.address") String amazonHost, - ParseMd5FromETagHeader callable, @Assisted String s3Bucket, - @Assisted S3Object object, @Assisted PutObjectOptions options) { - super("PUT", "/" + checkNotNull(object.getKey()), callable, amazonHost, - s3Bucket); - checkArgument(object.getMetadata().getSize() >= 0, "size must be set"); - - getRequest().setPayload( - checkNotNull(object.getData(), "object.getContent()")); - - getRequest().getHeaders().put( - HttpHeaders.CONTENT_TYPE, - checkNotNull(object.getMetadata().getContentType(), - "object.metadata.contentType()")); - - getRequest().getHeaders().put(HttpHeaders.CONTENT_LENGTH, - object.getMetadata().getSize() + ""); - - if (object.getMetadata().getCacheControl() != null) { - getRequest().getHeaders().put(HttpHeaders.CACHE_CONTROL, - object.getMetadata().getCacheControl()); - } - if (object.getMetadata().getContentDisposition() != null) { - getRequest().getHeaders().put(HttpHeaders.CONTENT_DISPOSITION, - object.getMetadata().getContentDisposition()); - } - if (object.getMetadata().getContentEncoding() != null) { - getRequest().getHeaders().put(HttpHeaders.CONTENT_ENCODING, - object.getMetadata().getContentEncoding()); - } - - if (object.getMetadata().getMd5() != null) - getRequest().getHeaders().put(HttpHeaders.CONTENT_MD5, - S3Utils.toBase64String(object.getMetadata().getMd5())); - - getRequest().getHeaders() - .putAll(object.getMetadata().getUserMetadata()); - getRequest().getHeaders().putAll(options.buildRequestHeaders()); - - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/S3CommandFactory.java b/s3/src/main/java/org/jclouds/aws/s3/commands/S3CommandFactory.java deleted file mode 100644 index 1cddd73e9a..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/S3CommandFactory.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.commands.options.CopyObjectOptions; -import org.jclouds.aws.s3.commands.options.GetObjectOptions; -import org.jclouds.aws.s3.commands.options.ListBucketOptions; -import org.jclouds.aws.s3.commands.options.PutBucketOptions; -import org.jclouds.aws.s3.commands.options.PutObjectOptions; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.xml.S3ParserFactory; - -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * Assembles the command objects for S3. - * - * @author Adrian Cole - */ -public class S3CommandFactory { - @Inject - private S3ParserFactory parserFactory; - - @Inject - private DeleteBucketFactory deleteBucketFactory; - - public static interface DeleteBucketFactory { - DeleteBucket create(String bucket); - } - - public DeleteBucket createDeleteBucket(String bucket) { - return deleteBucketFactory.create(bucket); - } - - @Inject - private DeleteObjectFactory deleteObjectFactory; - - public static interface DeleteObjectFactory { - DeleteObject create(@Assisted("bucketName") String bucket, - @Assisted("key") String key); - } - - public DeleteObject createDeleteObject(String bucket, String key) { - return deleteObjectFactory.create(bucket, key); - } - - @Inject - private BucketExistsFactory headBucketFactory; - - public static interface BucketExistsFactory { - BucketExists create(String bucket); - } - - public BucketExists createHeadBucket(String bucket) { - return headBucketFactory.create(bucket); - } - - @Inject - private PutBucketFactory putBucketFactoryOptions; - - public static interface PutBucketFactory { - PutBucket create(String bucket, PutBucketOptions options); - } - - public PutBucket createPutBucket(String bucket, PutBucketOptions options) { - return putBucketFactoryOptions.create(bucket, options); - } - - @Inject - private PutObjectFactory putObjectFactory; - - public static interface PutObjectFactory { - PutObject create(String bucket, S3Object object, - PutObjectOptions options); - } - - public PutObject createPutObject(String bucket, S3Object s3Object, - PutObjectOptions options) { - return putObjectFactory.create(bucket, s3Object, options); - } - - @Inject - private GetObjectFactory getObjectFactory; - - public static interface GetObjectFactory { - GetObject create(@Assisted("bucketName") String bucket, - @Assisted("key") String key, GetObjectOptions options); - } - - public GetObject createGetObject(String bucket, String key, - GetObjectOptions options) { - return getObjectFactory.create(bucket, key, options); - } - - @Inject - private HeadMetadataFactory headMetadataFactory; - - public static interface HeadMetadataFactory { - HeadObject create(@Assisted("bucketName") String bucket, - @Assisted("key") String key); - } - - public HeadObject createHeadMetadata(String bucket, String key) { - return headMetadataFactory.create(bucket, key); - } - - @Inject - @Named("jclouds.http.address") - String amazonHost; - - public ListOwnedBuckets createGetMetadataForOwnedBuckets() { - return new ListOwnedBuckets(amazonHost, parserFactory - .createListBucketsParser()); - } - - public ListBucket createListBucket(String bucket, ListBucketOptions options) { - return new ListBucket(amazonHost, parserFactory - .createListBucketParser(), bucket, options); - } - - public CopyObject createCopyObject(String sourceBucket, - String sourceObject, String destinationBucket, - String destinationObject, CopyObjectOptions options) { - return new CopyObject(amazonHost, parserFactory - .createCopyObjectParser(), sourceBucket, sourceObject, - destinationBucket, destinationObject, options); - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/S3FutureCommand.java b/s3/src/main/java/org/jclouds/aws/s3/commands/S3FutureCommand.java deleted file mode 100644 index 947cf79f65..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/S3FutureCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.http.HttpFutureCommand; - -/** - * Conditionally adds the amazon host header to requests. - * - * @author Adrian Cole - * - * @param - */ -public class S3FutureCommand extends HttpFutureCommand { - - public S3FutureCommand(String method, String uri, - ResponseCallable responseCallable, String amazonHost, - String bucketName) { - super(method, uri, responseCallable); - addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull( - bucketName, "bucketName")); - } - - public S3FutureCommand(String method, String uri, - ResponseCallable responseCallable, String amazonHost) { - super(method, uri, responseCallable); - addHostHeader(checkNotNull(amazonHost, "amazonHost")); - } - - protected void addHostHeader(String amazonHost, String bucketName) { - addHostHeader(checkNotNull(bucketName) + "." + amazonHost); - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseMd5FromETagHeader.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseMd5FromETagHeader.java deleted file mode 100644 index 6d17882cef..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseMd5FromETagHeader.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.callables; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpFutureCommand; - - -/** - * Parses an MD5 checksum from the header {@link S3Headers#ETAG}. - * - * @author Adrian Cole - */ -public class ParseMd5FromETagHeader extends - HttpFutureCommand.ResponseCallable { - - public byte[] call() throws HttpException { - checkCode(); - IOUtils.closeQuietly(getResponse().getContent()); - - String eTag = getResponse().getFirstHeaderOrNull(S3Headers.ETAG); - if (eTag != null) { - return S3Utils.fromHexString(eTag.replaceAll("\"", "")); - } - throw new HttpException("did not receive ETag"); - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseMetadataFromHeaders.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseMetadataFromHeaders.java deleted file mode 100644 index dc07bae42c..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseMetadataFromHeaders.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.callables; - -import java.util.Map.Entry; - -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.S3Object.Metadata; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpFutureCommand; -import org.jclouds.http.HttpHeaders; - -import com.google.inject.Inject; - -/** - * This parses @{link {@link org.jclouds.aws.s3.domain.S3Object.Metadata} from HTTP headers. - * - * @see - * @author Adrian Cole - */ -public class ParseMetadataFromHeaders extends - HttpFutureCommand.ResponseCallable { - private final DateService dateParser; - private String key; - - @Inject - public ParseMetadataFromHeaders(DateService dateParser) { - this.dateParser = dateParser; - } - - /** - * parses the http response headers to create a new - * {@link org.jclouds.aws.s3.domain.S3Object.Metadata} object. - */ - public S3Object.Metadata call() throws HttpException { - checkCode(); - - S3Object.Metadata metadata = new S3Object.Metadata(key); - addAllHeadersTo(metadata); - - addUserMetadataTo(metadata); - addMd5To(metadata); - - parseLastModifiedOrThrowException(metadata); - setContentTypeOrThrowException(metadata); - setContentLengthOrThrowException(metadata); - - metadata.setCacheControl(getResponse().getFirstHeaderOrNull( - HttpHeaders.CACHE_CONTROL)); - metadata.setContentDisposition(getResponse().getFirstHeaderOrNull( - HttpHeaders.CONTENT_DISPOSITION)); - metadata.setContentEncoding(getResponse().getFirstHeaderOrNull( - HttpHeaders.CONTENT_ENCODING)); - return metadata; - - } - - private void addAllHeadersTo(Metadata metadata) { - metadata.getAllHeaders().putAll(getResponse().getHeaders()); - } - - private void setContentTypeOrThrowException(S3Object.Metadata metadata) - throws HttpException { - String contentType = getResponse().getFirstHeaderOrNull( - HttpHeaders.CONTENT_TYPE); - if (contentType == null) - throw new HttpException(HttpHeaders.CONTENT_TYPE - + " not found in headers"); - else - metadata.setContentType(contentType); - } - - private void setContentLengthOrThrowException(S3Object.Metadata metadata) - throws HttpException { - String contentLength = getResponse().getFirstHeaderOrNull( - HttpHeaders.CONTENT_LENGTH); - if (contentLength == null) - throw new HttpException(HttpHeaders.CONTENT_LENGTH - + " not found in headers"); - else - metadata.setSize(Long.parseLong(contentLength)); - } - - private void parseLastModifiedOrThrowException(S3Object.Metadata metadata) - throws HttpException { - String lastModified = getResponse().getFirstHeaderOrNull( - HttpHeaders.LAST_MODIFIED); - metadata.setLastModified(dateParser - .dateTimeFromHeaderFormat(lastModified)); - if (metadata.getLastModified() == null) - throw new HttpException("could not parse: " - + HttpHeaders.LAST_MODIFIED + ": " + lastModified); - } - - private void addMd5To(S3Object.Metadata metadata) { - String md5Header = getResponse() - .getFirstHeaderOrNull(S3Headers.AMZ_MD5); - if (md5Header != null) { - metadata.setMd5(S3Utils.fromHexString(md5Header)); - } - String eTag = getResponse().getFirstHeaderOrNull(S3Headers.ETAG); - if (metadata.getMd5() == null && eTag != null) { - metadata.setMd5(S3Utils.fromHexString(eTag.replaceAll("\"", ""))); - } - } - - private void addUserMetadataTo(S3Object.Metadata metadata) { - for (Entry header : getResponse().getHeaders() - .entries()) { - if (header.getKey() != null - && header.getKey().startsWith( - S3Headers.USER_METADATA_PREFIX)) - metadata.getUserMetadata().put(header.getKey(), - header.getValue()); - } - } - - public void setKey(String key) { - this.key = key; - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContent.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContent.java deleted file mode 100644 index 99af0b9020..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContent.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.callables; - -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpFutureCommand; -import org.jclouds.http.HttpHeaders; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; - -/** - * Parses response headers and creates a new S3Object from them and the HTTP - * content. - * - * @see ParseMetadataFromHeaders - * @author Adrian Cole - */ -public class ParseObjectFromHeadersAndHttpContent extends - HttpFutureCommand.ResponseCallable { - private final ParseMetadataFromHeaders metadataParser; - - @Inject - public ParseObjectFromHeadersAndHttpContent( - ParseMetadataFromHeaders metadataParser) { - this.metadataParser = metadataParser; - } - - /** - * First, calls {@link ParseMetadataFromHeaders}. - * - * Then, sets the object size based on the Content-Length header and adds - * the content to the {@link S3Object} result. - * - * @throws org.jclouds.http.HttpException - */ - public S3Object call() throws HttpException { - checkCode(); - metadataParser.setResponse(getResponse()); - S3Object.Metadata metadata = metadataParser.call(); - S3Object object = new S3Object(metadata, getResponse().getContent()); - parseContentLengthOrThrowException(object); - return object; - } - - @VisibleForTesting - void parseContentLengthOrThrowException(S3Object object) - throws HttpException { - String contentLength = getResponse().getFirstHeaderOrNull( - HttpHeaders.CONTENT_LENGTH); - String contentRange = getResponse().getFirstHeaderOrNull( - HttpHeaders.CONTENT_RANGE); - if (contentLength == null) - throw new HttpException(HttpHeaders.CONTENT_LENGTH - + " header not present in headers: " - + getResponse().getHeaders()); - object.setContentLength(Long.parseLong(contentLength)); - - if (contentRange == null) { - object.getMetadata().setSize(object.getContentLength()); - } else { - object.setContentRange(contentRange); - object.getMetadata().setSize( - Long.parseLong(contentRange.substring(contentRange - .lastIndexOf('/') + 1))); - } - } - - public void setKey(String key) { - this.metadataParser.setKey(key); - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/package-info.java deleted file mode 100644 index a88a03aa07..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains response handlers for S3 commands. - * @author Adrian Cole - */ -package org.jclouds.aws.s3.commands.callables; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/config/S3CommandsModule.java b/s3/src/main/java/org/jclouds/aws/s3/commands/config/S3CommandsModule.java deleted file mode 100644 index ca8895b54c..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/config/S3CommandsModule.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.config; - -import org.jclouds.aws.s3.commands.BucketExists; -import org.jclouds.aws.s3.commands.DeleteBucket; -import org.jclouds.aws.s3.commands.DeleteObject; -import org.jclouds.aws.s3.commands.GetObject; -import org.jclouds.aws.s3.commands.HeadObject; -import org.jclouds.aws.s3.commands.PutBucket; -import org.jclouds.aws.s3.commands.PutObject; -import org.jclouds.aws.s3.commands.S3CommandFactory; -import org.jclouds.aws.s3.xml.config.S3ParserModule; - -import com.google.inject.AbstractModule; -import com.google.inject.assistedinject.FactoryProvider; - -/** - * Creates the factories needed to produce S3 commands - * - * @author Adrian Cole - */ -public class S3CommandsModule extends AbstractModule { - @Override - protected void configure() { - install(new S3ParserModule()); - - bind(S3CommandFactory.DeleteBucketFactory.class).toProvider( - FactoryProvider.newFactory( - S3CommandFactory.DeleteBucketFactory.class, - DeleteBucket.class)); - - bind(S3CommandFactory.DeleteObjectFactory.class).toProvider( - FactoryProvider.newFactory( - S3CommandFactory.DeleteObjectFactory.class, - DeleteObject.class)); - - bind(S3CommandFactory.BucketExistsFactory.class).toProvider( - FactoryProvider.newFactory( - S3CommandFactory.BucketExistsFactory.class, - BucketExists.class)); - - bind(S3CommandFactory.PutBucketFactory.class).toProvider( - FactoryProvider.newFactory( - S3CommandFactory.PutBucketFactory.class, - PutBucket.class)); - - bind(S3CommandFactory.PutObjectFactory.class).toProvider( - FactoryProvider.newFactory( - S3CommandFactory.PutObjectFactory.class, - PutObject.class)); - - bind(S3CommandFactory.GetObjectFactory.class).toProvider( - FactoryProvider.newFactory( - S3CommandFactory.GetObjectFactory.class, - GetObject.class)); - - bind(S3CommandFactory.HeadMetadataFactory.class).toProvider( - FactoryProvider.newFactory( - S3CommandFactory.HeadMetadataFactory.class, - HeadObject.class)); - - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/config/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/commands/config/package-info.java deleted file mode 100644 index 6e5c252858..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/config/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains modules who manage the dependencies of S3 command objects. - * @author Adrian Cole - */ -package org.jclouds.aws.s3.commands.config; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/options/CopyObjectOptions.java b/s3/src/main/java/org/jclouds/aws/s3/commands/options/CopyObjectOptions.java deleted file mode 100644 index a0e72b25c5..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/options/CopyObjectOptions.java +++ /dev/null @@ -1,327 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import com.google.common.base.Preconditions; -import static com.google.common.base.Preconditions.*; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.options.BaseHttpRequestOptions; -import org.joda.time.DateTime; - -import java.io.UnsupportedEncodingException; - -/** - * Contains options supported in the REST API for the COPY object operation. - *

- *

Usage

The recommended way to instantiate a CopyObjectOptions object - * is to statically import CopyObjectOptions.Builder.* and invoke a static - * creation method followed by an instance mutator (if needed): - *

- * - * import static org.jclouds.aws.s3.commands.options.CopyObjectOptions.Builder.* - *

- * S3Connection connection = // get connection - *

- * Multimap metadata = HashMultimap.create(); - * metadata.put("x-amz-meta-adrian", "foo"); - *

- * // this will copy the object, provided it wasn't modified since yesterday. - * // it will not use metadata from the source, and instead use what we pass in. - * Future object = connection.copyObject("sourceBucket", "objectName", - * "destinationBucket", "destinationName", - * overrideMetadataWith(meta). - * ifSourceModifiedSince(new DateTime().minusDays(1)) - * ); - * - * - * @author Adrian Cole - * @see - */ -public class CopyObjectOptions extends BaseHttpRequestOptions { - private final static DateService dateService = new DateService(); - - public static final CopyObjectOptions NONE = new CopyObjectOptions(); - - private Multimap metadata; - - private CannedAccessPolicy acl = CannedAccessPolicy.PRIVATE; - - /** - * Override the default ACL (private) with the specified one. - * - * @see CannedAccessPolicy - */ - public CopyObjectOptions overrideAcl(CannedAccessPolicy acl) { - this.acl = checkNotNull(acl, "acl"); - if (!acl.equals(CannedAccessPolicy.PRIVATE)) - this.replaceHeader(S3Headers.CANNED_ACL, acl.toString()); - return this; - } - - /** - * @see CopyObjectOptions#overrideAcl(CannedAccessPolicy) - */ - public CannedAccessPolicy getAcl() { - return acl; - } - - /** - * For use in the header x-amz-copy-source-if-unmodified-since - *

- * Copies the object if it hasn't been modified since the specified time; - * otherwise returns a 412 (precondition failed). - *

- * This header can be used with x-amz-copy-source-if-match, but cannot be - * used with other conditional copy headers. - * - * @return valid HTTP date - * @see - * @see CopyObjectOptions#ifSourceModifiedSince(DateTime) - */ - public String getIfModifiedSince() { - return getFirstHeaderOrNull("x-amz-copy-source-if-modified-since"); - } - - /** - * For use in the header x-amz-copy-source-if-modified-since - *

- * Copies the object if it has been modified since the specified time; - * otherwise returns a 412 (failed condition). - *

- * This header can be used with x-amz-copy-source-if-none-match, but cannot - * be used with other conditional copy headers. - * - * @return valid HTTP date - * @see - * @see CopyObjectOptions#ifSourceUnmodifiedSince(DateTime) - */ - public String getIfUnmodifiedSince() { - return getFirstHeaderOrNull("x-amz-copy-source-if-unmodified-since"); - } - - /** - * For use in the request header: x-amz-copy-source-if-match - *

- * Copies the object if its entity tag (ETag) matches the specified tag; - * otherwise return a 412 (precondition failed). - *

- * This header can be used with x-amz-copy-source-if-unmodified-since, but - * cannot be used with other conditional copy headers. - * - * @see CopyObjectOptions#ifSourceMd5Matches(byte[]) - */ - public String getIfMatch() { - return getFirstHeaderOrNull("x-amz-copy-source-if-match"); - } - - /** - * For use in the request header: x-amz-copy-source-if-none-match - *

- * Copies the object if its entity tag (ETag) is different than the - * specified Etag; otherwise returns a 412 (failed condition). - *

- * This header can be used with x-amz-copy-source-if-modified-since, but - * cannot be used with other conditional copy headers. - * - * @see CopyObjectOptions#ifSourceMd5DoesntMatch(byte[]) - */ - public String getIfNoneMatch() { - return getFirstHeaderOrNull("x-amz-copy-source-if-none-match"); - } - - /** - * When not null, contains the header - * [x-amz-copy-source-if-unmodified-since] -> [REPLACE] and metadata headers - * passed in from the users. - * - * @see #overrideMetadataWith(Multimap) - */ - public Multimap getMetadata() { - return metadata; - } - - /** - * Only return the object if it has changed since this time. - *

- * Not compatible with {@link #ifSourceMd5Matches(byte[])} or - * {@link #ifSourceUnmodifiedSince(DateTime)} - */ - public CopyObjectOptions ifSourceModifiedSince(DateTime ifModifiedSince) { - checkState(getIfMatch() == null, - "ifMd5Matches() is not compatible with ifModifiedSince()"); - checkState(getIfUnmodifiedSince() == null, - "ifUnmodifiedSince() is not compatible with ifModifiedSince()"); - replaceHeader("x-amz-copy-source-if-modified-since", - dateService.toHeaderString(checkNotNull(ifModifiedSince, - "ifModifiedSince"))); - return this; - } - - /** - * Only return the object if it hasn't changed since this time. - *

- * Not compatible with {@link #ifSourceMd5DoesntMatch(byte[])} or - * {@link #ifSourceModifiedSince(DateTime)} - */ - public CopyObjectOptions ifSourceUnmodifiedSince(DateTime ifUnmodifiedSince) { - checkState(getIfNoneMatch() == null, - "ifMd5DoesntMatch() is not compatible with ifUnmodifiedSince()"); - checkState(getIfModifiedSince() == null, - "ifModifiedSince() is not compatible with ifUnmodifiedSince()"); - replaceHeader("x-amz-copy-source-if-unmodified-since", dateService - .toHeaderString(checkNotNull(ifUnmodifiedSince, - "ifUnmodifiedSince"))); - return this; - } - - /** - * The object's md5 hash should match the parameter md5. - *

- *

- * Not compatible with {@link #ifSourceMd5DoesntMatch(byte[])} or - * {@link #ifSourceModifiedSince(DateTime)} - * - * @param md5 hash representing the entity - * @throws UnsupportedEncodingException if there was a problem converting this into an S3 eTag string - */ - public CopyObjectOptions ifSourceMd5Matches(byte[] md5) - throws UnsupportedEncodingException { - checkState(getIfNoneMatch() == null, - "ifMd5DoesntMatch() is not compatible with ifMd5Matches()"); - checkState(getIfModifiedSince() == null, - "ifModifiedSince() is not compatible with ifMd5Matches()"); - replaceHeader("x-amz-copy-source-if-match", String.format("\"%1$s\"", - S3Utils.toHexString(checkNotNull(md5, "md5")))); - return this; - } - - /** - * The object should not have a md5 hash corresponding with the parameter - * md5. - *

- * Not compatible with {@link #ifSourceMd5Matches(byte[])} or - * {@link #ifSourceUnmodifiedSince(DateTime)} - * - * @param md5 hash representing the entity - * @throws UnsupportedEncodingException if there was a problem converting this into an S3 eTag string - */ - public CopyObjectOptions ifSourceMd5DoesntMatch(byte[] md5) - throws UnsupportedEncodingException { - checkState(getIfMatch() == null, - "ifMd5Matches() is not compatible with ifMd5DoesntMatch()"); - Preconditions - .checkState(getIfUnmodifiedSince() == null, - "ifUnmodifiedSince() is not compatible with ifMd5DoesntMatch()"); - replaceHeader("x-amz-copy-source-if-none-match", String.format( - "\"%1$s\"", S3Utils.toHexString(checkNotNull(md5, - "ifMd5DoesntMatch")))); - return this; - } - - @Override - public Multimap buildRequestHeaders() { - Multimap returnVal = HashMultimap.create(); - returnVal.putAll(headers); - if (metadata != null) { - returnVal.putAll(metadata); - returnVal.put("x-amz-metadata-directive", "REPLACE"); - } - return returnVal; - } - - /** - * Use the provided metadata instead of what is on the source object. - */ - public CopyObjectOptions overrideMetadataWith( - Multimap metadata) { - checkNotNull(metadata, "metadata"); - for (String header : metadata.keySet()) { - checkArgument(header.startsWith("x-amz-meta-"), - "Metadata keys must start with x-amz-meta-"); - } - this.metadata = metadata; - return this; - } - - public static class Builder { - /** - * @see CopyObjectOptions#overrideAcl(CannedAccessPolicy) - */ - public static CopyObjectOptions overrideAcl(CannedAccessPolicy acl) { - CopyObjectOptions options = new CopyObjectOptions(); - return options.overrideAcl(acl); - } - - /** - * @see CopyObjectOptions#getIfModifiedSince() - */ - public static CopyObjectOptions ifSourceModifiedSince( - DateTime ifModifiedSince) { - CopyObjectOptions options = new CopyObjectOptions(); - return options.ifSourceModifiedSince(ifModifiedSince); - } - - /** - * @see CopyObjectOptions#ifSourceUnmodifiedSince(DateTime) - */ - public static CopyObjectOptions ifSourceUnmodifiedSince( - DateTime ifUnmodifiedSince) { - CopyObjectOptions options = new CopyObjectOptions(); - return options.ifSourceUnmodifiedSince(ifUnmodifiedSince); - } - - /** - * @see CopyObjectOptions#ifSourceMd5Matches(byte[]) - */ - public static CopyObjectOptions ifSourceMd5Matches(byte[] md5) - throws UnsupportedEncodingException { - CopyObjectOptions options = new CopyObjectOptions(); - return options.ifSourceMd5Matches(md5); - } - - /** - * @see CopyObjectOptions#ifSourceMd5DoesntMatch(byte[]) - */ - public static CopyObjectOptions ifSourceMd5DoesntMatch(byte[] md5) - throws UnsupportedEncodingException { - CopyObjectOptions options = new CopyObjectOptions(); - return options.ifSourceMd5DoesntMatch(md5); - } - - /** - * @see #overrideMetadataWith(Multimap) - */ - public static CopyObjectOptions overrideMetadataWith( - Multimap metadata) { - CopyObjectOptions options = new CopyObjectOptions(); - return options.overrideMetadataWith(metadata); - } - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/options/GetObjectOptions.java b/s3/src/main/java/org/jclouds/aws/s3/commands/options/GetObjectOptions.java deleted file mode 100644 index c50d7a2389..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/options/GetObjectOptions.java +++ /dev/null @@ -1,306 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkArgument; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; - -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpHeaders; -import org.jclouds.http.options.BaseHttpRequestOptions; -import org.joda.time.DateTime; - -import com.google.common.base.Joiner; -import com.google.common.collect.Multimap; - -/** - * Contains options supported in the REST API for the GET object operation.

- * Usage

The recommended way to instantiate a GetObjectOptions object is to - * statically import GetObjectOptions.Builder.* and invoke a static creation - * method followed by an instance mutator (if needed): - *

- * - * import static org.jclouds.aws.s3.commands.options.GetObjectOptions.Builder.* - * - * S3Connection connection = // get connection - * - * // this will get the first megabyte of an object, provided it wasn't modified since yesterday - * Future object = connection.getObject("bucket","objectName",range(0,1024).ifUnmodifiedSince(new DateTime().minusDays(1))); - * - * - * @see - * @author Adrian Cole - * - * - */ -public class GetObjectOptions extends BaseHttpRequestOptions { - private final static DateService dateService = new DateService(); - public static final GetObjectOptions NONE = new GetObjectOptions(); - private final List ranges = new ArrayList(); - - @Override - public Multimap buildRequestHeaders() { - Multimap headers = super.buildRequestHeaders(); - String range = getRange(); - if (range != null) - headers.put(HttpHeaders.RANGE, this.getRange()); - return headers; - } - - /** - * download the specified range of the object. - */ - public GetObjectOptions range(long start, long end) { - checkArgument(start >= 0, "start must be >= 0"); - checkArgument(end >= 0, "end must be >= 0"); - ranges.add(String.format("%d-%d", start, end)); - return this; - } - - /** - * download the object offset at start - */ - public GetObjectOptions startAt(long start) { - checkArgument(start >= 0, "start must be >= 0"); - ranges.add(String.format("%d-", start)); - return this; - } - - /** - * download the last count bytes of the object - */ - public GetObjectOptions tail(long count) { - checkArgument(count > 0, "count must be > 0"); - ranges.add(String.format("-%d", count)); - return this; - } - - /** - * For use in the header Range - *

- * - * @see GetObjectOptions#range(long, long) - */ - public String getRange() { - return (ranges.size() > 0) ? String.format("bytes=%s", Joiner.on(",") - .join(ranges)) : null; - } - - /** - * Only return the object if it has changed since this time. - *

- * Not compatible with {@link #ifMd5Matches(byte[])} or - * {@link #ifUnmodifiedSince(DateTime)} - */ - public GetObjectOptions ifModifiedSince(DateTime ifModifiedSince) { - checkArgument(getIfMatch() == null, - "ifMd5Matches() is not compatible with ifModifiedSince()"); - checkArgument(getIfUnmodifiedSince() == null, - "ifUnmodifiedSince() is not compatible with ifModifiedSince()"); - this.headers.put(HttpHeaders.IF_MODIFIED_SINCE, - dateService.toHeaderString(checkNotNull(ifModifiedSince, - "ifModifiedSince"))); - return this; - } - - /** - * For use in the header If-Modified-Since - *

- * Return the object only if it has been modified since the specified time, - * otherwise return a 304 (not modified). - * - * @see GetObjectOptions#ifModifiedSince(DateTime) - */ - public String getIfModifiedSince() { - return this.getFirstHeaderOrNull(HttpHeaders.IF_MODIFIED_SINCE); - } - - /** - * Only return the object if it hasn't changed since this time. - *

- * Not compatible with {@link #ifMd5DoesntMatch(byte[])} or - * {@link #ifModifiedSince(DateTime)} - */ - public GetObjectOptions ifUnmodifiedSince(DateTime ifUnmodifiedSince) { - checkArgument(getIfNoneMatch() == null, - "ifMd5DoesntMatch() is not compatible with ifUnmodifiedSince()"); - checkArgument(getIfModifiedSince() == null, - "ifModifiedSince() is not compatible with ifUnmodifiedSince()"); - this.headers.put(HttpHeaders.IF_UNMODIFIED_SINCE, dateService - .toHeaderString(checkNotNull(ifUnmodifiedSince, - "ifUnmodifiedSince"))); - return this; - } - - /** - * For use in the header If-Unmodified-Since - *

- * Return the object only if it has not been modified since the specified - * time, otherwise return a 412 (precondition failed). - * - * @see GetObjectOptions#ifUnmodifiedSince(DateTime) - */ - public String getIfUnmodifiedSince() { - return this.getFirstHeaderOrNull(HttpHeaders.IF_UNMODIFIED_SINCE); - } - - /** - * The object's md5 hash should match the parameter md5. - * - *

- * Not compatible with {@link #ifMd5DoesntMatch(byte[])} or - * {@link #ifModifiedSince(DateTime)} - * - * @param md5 - * hash representing the entity - * @throws UnsupportedEncodingException - * if there was a problem converting this into an S3 eTag string - */ - public GetObjectOptions ifMd5Matches(byte[] md5) - throws UnsupportedEncodingException { - checkArgument(getIfNoneMatch() == null, - "ifMd5DoesntMatch() is not compatible with ifMd5Matches()"); - checkArgument(getIfModifiedSince() == null, - "ifModifiedSince() is not compatible with ifMd5Matches()"); - this.headers.put(HttpHeaders.IF_MATCH, String.format("\"%1$s\"", - S3Utils.toHexString(checkNotNull(md5, "md5")))); - return this; - } - - /** - * For use in the request header: If-Match - *

- * Return the object only if its entity tag (ETag) is the same as the md5 - * specified, otherwise return a 412 (precondition failed). - * - * @see GetObjectOptions#ifMd5Matches(byte[]) - */ - public String getIfMatch() { - return this.getFirstHeaderOrNull(HttpHeaders.IF_MATCH); - } - - /** - * The object should not have a md5 hash corresponding with the parameter - * md5. - *

- * Not compatible with {@link #ifMd5Matches(byte[])} or - * {@link #ifUnmodifiedSince(DateTime)} - * - * @param md5 - * hash representing the entity - * @throws UnsupportedEncodingException - * if there was a problem converting this into an S3 eTag string - */ - public GetObjectOptions ifMd5DoesntMatch(byte[] md5) - throws UnsupportedEncodingException { - checkArgument(getIfMatch() == null, - "ifMd5Matches() is not compatible with ifMd5DoesntMatch()"); - checkArgument(getIfUnmodifiedSince() == null, - "ifUnmodifiedSince() is not compatible with ifMd5DoesntMatch()"); - this.headers.put(HttpHeaders.IF_NONE_MATCH, String.format("\"%1$s\"", - S3Utils.toHexString(checkNotNull(md5, "ifMd5DoesntMatch")))); - return this; - } - - /** - * For use in the request header: If-None-Match - *

- * Return the object only if its entity tag (ETag) is different from the one - * specified, otherwise return a 304 (not modified). - * - * @see GetObjectOptions#ifMd5DoesntMatch(byte[]) - */ - public String getIfNoneMatch() { - return this - .getFirstHeaderOrNull(org.jclouds.http.HttpHeaders.IF_NONE_MATCH); - } - - public static class Builder { - - /** - * @see GetObjectOptions#range(long, long) - */ - public static GetObjectOptions range(long start, long end) { - GetObjectOptions options = new GetObjectOptions(); - return options.range(start, end); - } - - /** - * @see GetObjectOptions#startAt(long) - */ - public static GetObjectOptions startAt(long start) { - GetObjectOptions options = new GetObjectOptions(); - return options.startAt(start); - } - - /** - * @see GetObjectOptions#tail(long) - */ - public static GetObjectOptions tail(long count) { - GetObjectOptions options = new GetObjectOptions(); - return options.tail(count); - } - - /** - * @see GetObjectOptions#getIfModifiedSince() - */ - public static GetObjectOptions ifModifiedSince(DateTime ifModifiedSince) { - GetObjectOptions options = new GetObjectOptions(); - return options.ifModifiedSince(ifModifiedSince); - } - - /** - * @see GetObjectOptions#ifUnmodifiedSince(DateTime) - */ - public static GetObjectOptions ifUnmodifiedSince( - DateTime ifUnmodifiedSince) { - GetObjectOptions options = new GetObjectOptions(); - return options.ifUnmodifiedSince(ifUnmodifiedSince); - } - - /** - * @see GetObjectOptions#ifMd5Matches(byte[]) - */ - public static GetObjectOptions ifMd5Matches(byte[] md5) - throws UnsupportedEncodingException { - GetObjectOptions options = new GetObjectOptions(); - return options.ifMd5Matches(md5); - } - - /** - * @see GetObjectOptions#ifMd5DoesntMatch(byte[]) - */ - public static GetObjectOptions ifMd5DoesntMatch(byte[] md5) - throws UnsupportedEncodingException { - GetObjectOptions options = new GetObjectOptions(); - return options.ifMd5DoesntMatch(md5); - } - - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/options/ListBucketOptions.java b/s3/src/main/java/org/jclouds/aws/s3/commands/options/ListBucketOptions.java deleted file mode 100644 index c4d1ee3399..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/options/ListBucketOptions.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import org.jclouds.http.options.BaseHttpRequestOptions; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - -/** - * Contains options supported in the REST API for the GET bucket operation.

- * Usage

The recommended way to instantiate a GetBucketOptions object is to - * statically import GetBucketOptions.Builder.* and invoke a static creation - * method followed by an instance mutator (if needed): - *

- * - * import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.* - *

- * S3Connection connection = // get connection - * Future bucket = connection.listBucket("bucketName",withPrefix("home/users").maxKeys(1000)); - * - * - * @author Adrian Cole - * @see - */ -public class ListBucketOptions extends BaseHttpRequestOptions { - public static final ListBucketOptions NONE = new ListBucketOptions(); - - /** - * Limits the response to keys which begin with the indicated prefix. You - * can use prefixes to separate a bucket into different sets of keys in a - * way similar to how a file system uses folders. - * - * @throws UnsupportedEncodingException - */ - public ListBucketOptions withPrefix(String prefix) - throws UnsupportedEncodingException { - options.put("prefix", URLEncoder.encode(checkNotNull(prefix, "prefix"), - "UTF-8")); - return this; - } - - /** - * @see ListBucketOptions#withPrefix(String) - */ - public String getPrefix() { - return options.get("prefix"); - } - - /** - * Indicates where in the bucket to begin listing. The list will only - * include keys that occur lexicographically after marker. This is - * convenient for pagination: To get the next page of results use the last - * key of the current page as the marker. - * - * @throws UnsupportedEncodingException - */ - public ListBucketOptions afterMarker(String marker) - throws UnsupportedEncodingException { - options.put("marker", URLEncoder.encode(checkNotNull(marker, "marker"), - "UTF-8")); - return this; - } - - /** - * @see ListBucketOptions#afterMarker(String) - */ - public String getMarker() { - return options.get("marker"); - } - - /** - * The maximum number of keys you'd like to see in the response body. The - * server might return fewer than this many keys, but will not return more. - */ - public ListBucketOptions maxResults(long maxKeys) { - checkState(maxKeys >= 0, "maxKeys must be >= 0"); - options.put("max-keys", Long.toString(maxKeys)); - return this; - } - - /** - * @see ListBucketOptions#maxResults(long) - */ - public String getMaxKeys() { - return options.get("max-keys"); - } - - /** - * Causes keys that contain the same string between the prefix and the first - * occurrence of the delimiter to be rolled up into a single result element - * in the CommonPrefixes collection. These rolled-up keys are not returned - * elsewhere in the response. - * - * @throws UnsupportedEncodingException - */ - public ListBucketOptions delimiter(String delimiter) - throws UnsupportedEncodingException { - options.put("delimiter", URLEncoder.encode(checkNotNull(delimiter, - "delimiter"), "UTF-8")); - return this; - } - - /** - * @see ListBucketOptions#delimiter(String) - */ - public String getDelimiter() { - return options.get("delimiter"); - } - - public static class Builder { - - /** - * @throws UnsupportedEncodingException - * @see ListBucketOptions#withPrefix(String) - */ - public static ListBucketOptions withPrefix(String prefix) - throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - return options.withPrefix(prefix); - } - - /** - * @throws UnsupportedEncodingException - * @see ListBucketOptions#afterMarker(String) - */ - public static ListBucketOptions afterMarker(String marker) - throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - return options.afterMarker(marker); - } - - /** - * @see ListBucketOptions#maxResults(long) - */ - public static ListBucketOptions maxResults(long maxKeys) { - ListBucketOptions options = new ListBucketOptions(); - return options.maxResults(maxKeys); - } - - /** - * @throws UnsupportedEncodingException - * @see ListBucketOptions#delimiter(String) - */ - public static ListBucketOptions delimiter(String delimiter) - throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - return options.delimiter(delimiter); - } - - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/options/PutBucketOptions.java b/s3/src/main/java/org/jclouds/aws/s3/commands/options/PutBucketOptions.java deleted file mode 100644 index 9b2c9bb22c..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/options/PutBucketOptions.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import static com.google.common.base.Preconditions.checkNotNull; -import org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.http.options.BaseHttpRequestOptions; - -/** - * Contains options supported in the REST API for the PUT bucket operation.

- * Usage

The recommended way to instantiate a PutBucketOptions object is to - * statically import PutBucketOptions.Builder.* and invoke a static creation - * method followed by an instance mutator (if needed): - *

- * - * import static org.jclouds.aws.s3.commands.options.PutBucketOptions.Builder.* - * import static org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint.*; - * import org.jclouds.aws.s3.S3Connection; - *

- * S3Connection connection = // get connection - * Future createdInEu = connection.putBucketIfNotExists("bucketName",createIn(EU)); - * - * - * @author Adrian Cole - * @see - */ -public class PutBucketOptions extends BaseHttpRequestOptions { - public static final PutBucketOptions NONE = new PutBucketOptions(); - private CannedAccessPolicy acl = CannedAccessPolicy.PRIVATE; - private LocationConstraint constraint; - - /** - * Depending on your latency and legal requirements, you can specify a - * location constraint that will affect where your data physically resides. - * You can currently specify a Europe (EU) location constraint. - */ - public PutBucketOptions createIn(LocationConstraint constraint) { - this.constraint = checkNotNull(constraint, "constraint"); - this.payload = String - .format( - "%1$s", - constraint.toString()); - return this; - } - - /** - * Override the default ACL (private) with the specified one. - * - * @see CannedAccessPolicy - */ - public PutBucketOptions withBucketAcl(CannedAccessPolicy acl) { - this.acl = checkNotNull(acl, "acl"); - if (!acl.equals(CannedAccessPolicy.PRIVATE)) - this.replaceHeader(S3Headers.CANNED_ACL, acl.toString()); - return this; - } - - /** - * @see PutBucketOptions#withBucketAcl(CannedAccessPolicy) - */ - public CannedAccessPolicy getAcl() { - return acl; - } - - /** - * @see PutBucketOptions#createIn(org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint) - */ - public LocationConstraint getLocationConstraint() { - return constraint; - } - - public static class Builder { - /** - * @see PutBucketOptions#createIn(org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint) - */ - public static PutBucketOptions createIn(LocationConstraint constraint) { - PutBucketOptions options = new PutBucketOptions(); - return options.createIn(constraint); - } - - /** - * @see PutBucketOptions#withBucketAcl(CannedAccessPolicy) - */ - public static PutBucketOptions withBucketAcl(CannedAccessPolicy acl) { - PutBucketOptions options = new PutBucketOptions(); - return options.withBucketAcl(acl); - } - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/options/PutObjectOptions.java b/s3/src/main/java/org/jclouds/aws/s3/commands/options/PutObjectOptions.java deleted file mode 100644 index 74e68ad7be..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/options/PutObjectOptions.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.http.options.BaseHttpRequestOptions; - -import static com.google.common.base.Preconditions.*; - -/** - * Contains options supported in the REST API for the PUT object operation. - *

- *

- * Usage

The recommended way to instantiate a PutObjectOptions object is to - * statically import PutObjectOptions.Builder.* and invoke a static creation - * method followed by an instance mutator (if needed): - *

- * - * import static org.jclouds.aws.s3.commands.options.PutObjectOptions.Builder.* - * import org.jclouds.aws.s3.S3Connection; - * - * S3Connection connection = // get connection - * Future publicly readable = connection.putObject("bucketName",new S3Object("key","value"), withAcl(CannedAccessPolicy.PUBLIC_READ)); - * - * - * @see - * - * @author Adrian Cole - * - */ -public class PutObjectOptions extends BaseHttpRequestOptions { - public static final PutObjectOptions NONE = new PutObjectOptions(); - - private CannedAccessPolicy acl = CannedAccessPolicy.PRIVATE; - - /** - * Override the default ACL (private) with the specified one. - * - * @see CannedAccessPolicy - */ - public PutObjectOptions withAcl(CannedAccessPolicy acl) { - this.acl = checkNotNull(acl, "acl"); - if (!acl.equals(CannedAccessPolicy.PRIVATE)) - this.replaceHeader(S3Headers.CANNED_ACL, acl.toString()); - return this; - } - - /** - * @see PutObjectOptions#withAcl(CannedAccessPolicy) - */ - public CannedAccessPolicy getAcl() { - return acl; - } - - public static class Builder { - - /** - * @see PutObjectOptions#withAcl(CannedAccessPolicy) - */ - public static PutObjectOptions withAcl(CannedAccessPolicy acl) { - PutObjectOptions options = new PutObjectOptions(); - return options.withAcl(acl); - } - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/options/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/commands/options/package-info.java deleted file mode 100644 index 2af21b6c28..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/options/package-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains request options for S3 REST commands. - * - * @see - * @author Adrian Cole - */ -package org.jclouds.aws.s3.commands.options; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/commands/package-info.java deleted file mode 100644 index 3ce8ee7fd2..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains all currently supported commands in the Amazon S3 REST Api. - * @see - * @author Adrian Cole - */ -package org.jclouds.aws.s3.commands; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/config/LiveS3ConnectionModule.java b/s3/src/main/java/org/jclouds/aws/s3/config/LiveS3ConnectionModule.java deleted file mode 100644 index a8ea7adfe1..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/config/LiveS3ConnectionModule.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.config; - -import com.google.inject.*; -import com.google.inject.assistedinject.FactoryProvider; -import com.google.inject.name.Named; -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.commands.config.S3CommandsModule; -import org.jclouds.aws.s3.filters.RequestAuthorizeSignature; -import org.jclouds.aws.s3.handlers.ParseS3ErrorFromXmlContent; -import org.jclouds.aws.s3.internal.GuiceS3Context; -import org.jclouds.aws.s3.internal.LiveS3Connection; -import org.jclouds.aws.s3.internal.LiveS3InputStreamMap; -import org.jclouds.aws.s3.internal.LiveS3ObjectMap; -import org.jclouds.http.HttpConstants; -import org.jclouds.http.HttpRequestFilter; -import org.jclouds.http.HttpResponseHandler; -import org.jclouds.http.annotation.ClientErrorHandler; -import org.jclouds.http.annotation.RedirectHandler; -import org.jclouds.http.annotation.ServerErrorHandler; -import org.jclouds.http.handlers.CloseContentAndSetExceptionHandler; -import org.jclouds.logging.Logger; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; - -/** - * Configures the S3 connection, including logging and http transport. - * - * @author Adrian Cole - */ -@S3ConnectionModule -public class LiveS3ConnectionModule extends AbstractModule { - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @Named(HttpConstants.PROPERTY_HTTP_ADDRESS) - String address; - @Inject - @Named(HttpConstants.PROPERTY_HTTP_PORT) - int port; - @Inject - @Named(HttpConstants.PROPERTY_HTTP_SECURE) - boolean isSecure; - - @Override - protected void configure() { - bind(S3Connection.class).to(LiveS3Connection.class) - .in(Scopes.SINGLETON); - bind(HttpResponseHandler.class).annotatedWith(RedirectHandler.class) - .to(CloseContentAndSetExceptionHandler.class).in( - Scopes.SINGLETON); - bind(HttpResponseHandler.class).annotatedWith(ClientErrorHandler.class) - .to(ParseS3ErrorFromXmlContent.class).in(Scopes.SINGLETON); - bind(HttpResponseHandler.class).annotatedWith(ServerErrorHandler.class) - .to(ParseS3ErrorFromXmlContent.class).in(Scopes.SINGLETON); - requestInjection(this); - logger.info("S3 Context = %1$s://%2$s:%3$s", (isSecure ? "https" - : "http"), address, port); - } - - @Provides - @Singleton - List provideRequestFilters( - RequestAuthorizeSignature requestAuthorizeSignature) { - List filters = new ArrayList(); - filters.add(requestAuthorizeSignature); - return filters; - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/config/S3ConnectionModule.java b/s3/src/main/java/org/jclouds/aws/s3/config/S3ConnectionModule.java deleted file mode 100644 index 5cccf024d1..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/config/S3ConnectionModule.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.jclouds.aws.s3.config; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.jclouds.http.HttpFutureCommandClient; - -/** - * designates the the module configures a {@link org.jclouds.aws.s3.S3Connection} - * - * @author Adrian Cole - * - */ -@Retention(RUNTIME) -@Target(TYPE) -public @interface S3ConnectionModule { - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java b/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java deleted file mode 100644 index b158233e5b..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.config; - -import com.google.inject.AbstractModule; -import com.google.inject.assistedinject.FactoryProvider; -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.commands.config.S3CommandsModule; -import org.jclouds.aws.s3.internal.GuiceS3Context; -import org.jclouds.aws.s3.internal.LiveS3InputStreamMap; -import org.jclouds.aws.s3.internal.LiveS3ObjectMap; - -/** - * Configures the {@link S3Context}; requires {@link S3Connection} bound. - * - * @author Adrian Cole - */ -public class S3ContextModule extends AbstractModule { - - - @Override - protected void configure() { - this.requireBinding(S3Connection.class); - install(new S3CommandsModule()); - bind(GuiceS3Context.S3ObjectMapFactory.class).toProvider( - FactoryProvider.newFactory( - GuiceS3Context.S3ObjectMapFactory.class, - LiveS3ObjectMap.class)); - bind(GuiceS3Context.S3InputStreamMapFactory.class).toProvider( - FactoryProvider.newFactory( - GuiceS3Context.S3InputStreamMapFactory.class, - LiveS3InputStreamMap.class)); - bind(S3Context.class).to(GuiceS3Context.class); - - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/config/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/config/package-info.java deleted file mode 100644 index 69fb6a5de0..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/config/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains modules who manage the dependencies of the S3Context, S3Connection, and S3 Map views. - * @author Adrian Cole - */ -package org.jclouds.aws.s3.config; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/CanonicalUser.java b/s3/src/main/java/org/jclouds/aws/s3/domain/CanonicalUser.java deleted file mode 100644 index 08a81d3622..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/CanonicalUser.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.domain; - -/** - * Every bucket and object in Amazon S3 has an owner, the user that created the - * bucket or object. The owner of a bucket or object cannot be changed. However, - * if the object is overwritten by another user (deleted and rewritten), the new - * object will have a new owner. - *

- * - * @see - * @author Adrian Cole - */ -public class CanonicalUser { - private final String id; - private String displayName; - - public CanonicalUser(String id) { - this.id = id; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("S3Owner"); - sb.append("{id='").append(id).append('\''); - sb.append(", displayName='").append(displayName).append('\''); - sb.append('}'); - return sb.toString(); - } - - /** - * To locate the CanonicalUser ID for a user, the user must perform the - * {@link org.jclouds.aws.s3.S3Connection#listBucket(String)} and retrieve - * {@link S3Bucket.Metadata#getOwner()} - */ - public String getId() { - return id; - } - - /** - * read-only as is maintained by Amazon. - */ - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof CanonicalUser)) - return false; - - CanonicalUser s3Owner = (CanonicalUser) o; - - if (displayName != null ? !displayName.equals(s3Owner.displayName) - : s3Owner.displayName != null) - return false; - if (!id.equals(s3Owner.id)) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = id.hashCode(); - result = 31 * result - + (displayName != null ? displayName.hashCode() : 0); - return result; - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java deleted file mode 100644 index af8ddea48d..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java +++ /dev/null @@ -1,336 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.domain; - -import static com.google.common.base.Preconditions.checkNotNull; -import org.joda.time.DateTime; - -import java.util.HashSet; -import java.util.Set; - -/** - * A container that provides namespace, access control and aggregation of - * {@link S3Object}s - *

- *

- * Every object stored in Amazon S3 is contained in a bucket. Buckets partition - * the namespace of objects stored in Amazon S3 at the top level. Within a - * bucket, you can use any names for your objects, but bucket names must be - * unique across all of Amazon S3. - *

- * Buckets are similar to Internet domain names. Just as Amazon is the only - * owner of the domain name Amazon.com, only one person or organization can own - * a bucket within Amazon S3. Once you create a uniquely named bucket in Amazon - * S3, you can organize and name the objects within the bucket in any way you - * like and the bucket will remain yours for as long as you like and as long as - * you have the Amazon S3 account. - *

- * The similarities between buckets and domain names is not a coincidenceÑthere - * is a direct mapping between Amazon S3 buckets and subdomains of - * s3.amazonaws.com. Objects stored in Amazon S3 are addressable using the REST - * API under the domain bucketname.s3.amazonaws.com. For example, if the object - * homepage.html?is stored in the Amazon S3 bucket mybucket its address would be - * http://mybucket.s3.amazonaws.com/homepage.html? - * - * @author Adrian Cole - * @see - */ -public class S3Bucket { - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("S3Bucket"); - sb.append("{metadata=").append(metadata); - sb.append(", isTruncated=").append(isTruncated); - sb.append('}'); - return sb.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof S3Bucket)) - return false; - - S3Bucket s3Bucket = (S3Bucket) o; - - if (isTruncated != s3Bucket.isTruncated) - return false; - if (!metadata.equals(s3Bucket.metadata)) - return false; - if (objects != null ? !objects.equals(s3Bucket.objects) - : s3Bucket.objects != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = objects != null ? objects.hashCode() : 0; - result = 31 * result + metadata.hashCode(); - result = 31 * result + (isTruncated ? 1 : 0); - return result; - } - - /** - * System metadata of the S3Bucket - * - * @author Adrian Cole - */ - public static class Metadata { - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("Metadata"); - sb.append("{name='").append(name).append('\''); - sb.append(", creationDate=").append(creationDate); - sb.append(", canonicalUser=").append(canonicalUser); - sb.append('}'); - return sb.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof Metadata)) - return false; - - Metadata metadata = (Metadata) o; - if (canonicalUser != null ? !canonicalUser - .equals(metadata.canonicalUser) - : metadata.canonicalUser != null) - return false; - if (!name.equals(metadata.name)) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = name.hashCode(); - result = 31 * result - + (canonicalUser != null ? canonicalUser.hashCode() : 0); - return result; - } - - /** - * Location constraint of the bucket. - * - * @author Adrian Cole - * @see - */ - public static enum LocationConstraint { - EU - } - - private final String name; - private DateTime creationDate; - private CanonicalUser canonicalUser; - - /** - * @see #getName() - */ - public Metadata(String name) { - this.name = checkNotNull(name, "name"); - } - - /** - * To comply with Amazon S3 requirements, bucket names must: - *

- * Contain lowercase letters, numbers, periods (.), underscores (_), and - * dashes (-) - *

- * Start with a number or letter - *

- * Be between 3 and 255 characters long - *

- * Not be in an IP address style (e.g., "192.168.5.4") - */ - public String getName() { - return name; - } - - public DateTime getCreationDate() { - return creationDate; - } - - public void setCreationDate(DateTime creationDate) { - this.creationDate = creationDate; - } - - /** - * Every bucket and object in Amazon S3 has an owner, the user that - * created the bucket or object. The owner of a bucket or object cannot - * be changed. However, if the object is overwritten by another user - * (deleted and rewritten), the new object will have a new owner. - */ - public CanonicalUser getOwner() { - return canonicalUser; - } - - public void setOwner(CanonicalUser canonicalUser) { - this.canonicalUser = canonicalUser; - } - - } - - public static final S3Bucket NOT_FOUND = new S3Bucket("NOT_FOUND"); - - private Set objects = new HashSet(); - private Set commonPrefixes = new HashSet(); - private String prefix; - private String marker; - private String delimiter; - private long maxKeys; - private final Metadata metadata; - - private boolean isTruncated; - - public S3Bucket(String name) { - this.metadata = new Metadata(name); - } - - public String getName() { - return this.metadata.getName(); - } - - public S3Bucket(Metadata metadata) { - this.metadata = checkNotNull(metadata, "metadata"); - } - - /** - * @see org.jclouds.aws.s3.S3Connection#listBucket(String) - */ - public Set getContents() { - return objects; - } - - public void setContents(Set objects) { - this.objects = objects; - } - - /** - * @return true, if the list contains all objects. - */ - public boolean isTruncated() { - return isTruncated; - } - - public void setTruncated(boolean truncated) { - isTruncated = truncated; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setCommonPrefixes(Set commonPrefixes) { - this.commonPrefixes = commonPrefixes; - } - - /** - * Example: - *

- * if the following keys are in the bucket - *

- * a/1/a
- * a/1/b
- * a/2/a
- * a/2/b
- *

- * and prefix is set to a/ and delimiter is set to - * / then commonprefixes would return 1,2 - * - * @see org.jclouds.aws.s3.commands.options.ListBucketOptions#getPrefix() - */ - public Set getCommonPrefixes() { - return commonPrefixes; - } - - public void setPrefix(String prefix) { - this.prefix = prefix; - } - - /** - * return keys that start with this. - * - * @see org.jclouds.aws.s3.commands.options.ListBucketOptions#getPrefix() - */ - public String getPrefix() { - return prefix; - } - - public void setMaxKeys(long maxKeys) { - this.maxKeys = maxKeys; - } - - /** - * @return maximum results of the bucket. - * @see org.jclouds.aws.s3.commands.options.ListBucketOptions#getMaxKeys() - */ - public long getMaxKeys() { - return maxKeys; - } - - public void setMarker(String marker) { - this.marker = marker; - } - - /** - * when set, bucket contains results whose keys are lexigraphically after - * marker. - * - * @see org.jclouds.aws.s3.commands.options.ListBucketOptions#getMarker() - */ - public String getMarker() { - return marker; - } - - public void setDelimiter(String delimiter) { - this.delimiter = delimiter; - } - - /** - * when set, bucket results will not contain keys that have text following - * this delimiter. - *

- * note that delimiter has no effect on prefix. prefix can contain the - * delimiter many times, or not at all. delimiter only restricts after the - * prefix. - * - * @see org.jclouds.aws.s3.commands.options.ListBucketOptions#getMarker() - */ - public String getDelimiter() { - return delimiter; - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Error.java b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Error.java deleted file mode 100644 index bc201beae5..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Error.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.domain; - -import java.util.HashMap; -import java.util.Map; - -/** - * When an Amazon S3 request is in error, the client receives an error response. - * - * @see - * @author Adrian Cole - * - */ -public class S3Error { - private String code; - private String message; - private String requestId; - private String requestToken; - private Map details = new HashMap(); - private String stringSigned; - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("S3Error"); - sb.append("{code='").append(code).append('\''); - sb.append(", message='").append(message).append('\''); - sb.append(", requestId='").append(requestId).append('\''); - sb.append(", requestToken='").append(requestToken).append('\''); - if (stringSigned != null) - sb.append(", stringSigned='").append(stringSigned).append('\''); - sb.append(", context='").append(details.toString()).append('\'') - .append('}'); - return sb.toString(); - } - - public void setCode(String code) { - this.code = code; - } - - /** - * The error code is a string that uniquely identifies an error condition. - * It is meant to be read and understood by programs that detect and handle - * errors by type - * - * @see - */ - public String getCode() { - return code; - } - - public void setMessage(String message) { - this.message = message; - } - - /** - * The error message contains a generic description of the error condition - * in English. - * - * @see - */ - public String getMessage() { - return message; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - /** - * * A unique ID assigned to each request by the system. In the unlikely - * event that you have problems with Amazon S3, Amazon can use this to help - * troubleshoot the problem. - * - */ - public String getRequestId() { - return requestId; - } - - public void setStringSigned(String stringSigned) { - this.stringSigned = stringSigned; - } - - /** - * @return what jclouds signed before sending the request. - */ - public String getStringSigned() { - return stringSigned; - } - - public void setDetails(Map context) { - this.details = context; - } - - /** - * @return additional details surrounding the error. - */ - public Map getDetails() { - return details; - } - - public void setRequestToken(String requestToken) { - this.requestToken = requestToken; - } - - public String getRequestToken() { - return requestToken; - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java deleted file mode 100644 index 2b0caf867e..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java +++ /dev/null @@ -1,458 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.domain; - -import static com.google.common.base.Preconditions.*; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import org.jclouds.aws.s3.commands.options.GetObjectOptions; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.aws.s3.util.S3Utils.Md5InputStreamResult; -import org.jclouds.http.ContentTypes; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; - -/** - * Amazon S3 is designed to store objects. Objects are stored in - * {@link S3Bucket buckets} and consist of a {@link org.jclouds.aws.s3.domain.S3Object#getData() value}, - * a {@link S3Object#getKey key}, {@link S3Object.Metadata#getUserMetadata() - * metadata}, and an access control policy. - * - * @author Adrian Cole - * @see - */ -public class S3Object { - public static final S3Object NOT_FOUND = new S3Object(Metadata.NOT_FOUND); - - private Object data; - private Metadata metadata; - private long contentLength = -1; - private String contentRange; - - public S3Object(String key) { - this(new Metadata(key)); - } - - public S3Object(Metadata metadata) { - this.metadata = metadata; - } - - public S3Object(Metadata metadata, Object data) { - this(metadata); - setData(data); - } - - public S3Object(String key, Object data) { - this(key); - setData(data); - } - - /** - * System and user Metadata for the {@link S3Object}. - * - * @author Adrian Cole - * @see - */ - public static class Metadata implements Comparable { - public static final Metadata NOT_FOUND = new Metadata("NOT_FOUND"); - - // parsed during list, head, or get - private final String key; - private byte[] md5; - private volatile long size = -1; - - // only parsed during head or get - private Multimap allHeaders = HashMultimap.create(); - private Multimap userMetadata = HashMultimap.create(); - private DateTime lastModified; - private String dataType = ContentTypes.BINARY; - private String cacheControl; - private String dataDisposition; - private String dataEncoding; - - // only parsed on list - private CanonicalUser owner = null; - private String storageClass = null; - - /** - * @param key - * @see #getKey() - */ - public Metadata(String key) { - checkNotNull(key, "key"); - checkArgument(!key.startsWith("/"), "keys cannot start with /"); - this.key = key; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("Metadata"); - sb.append("{key='").append(key).append('\''); - sb.append(", lastModified=").append(lastModified); - sb.append(", md5=").append( - getMd5() == null ? "null" : Arrays.asList(getMd5()) - .toString()); - sb.append(", size=").append(size); - sb.append(", dataType='").append(dataType).append('\''); - sb.append('}'); - return sb.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof Metadata)) - return false; - - Metadata metadata = (Metadata) o; - - if (size != metadata.size) - return false; - if (dataType != null ? !dataType.equals(metadata.dataType) - : metadata.dataType != null) - return false; - if (!key.equals(metadata.key)) - return false; - if (lastModified != null ? !lastModified - .equals(metadata.lastModified) - : metadata.lastModified != null) - return false; - if (!Arrays.equals(getMd5(), metadata.getMd5())) - return false; - return true; - } - - @Override - public int hashCode() { - int result = key.hashCode(); - result = 31 * result - + (lastModified != null ? lastModified.hashCode() : 0); - result = 31 * result - + (getMd5() != null ? Arrays.hashCode(getMd5()) : 0); - result = 31 * result + (int) (size ^ (size >>> 32)); - result = 31 * result + (dataType != null ? dataType.hashCode() : 0); - return result; - } - - /** - * The key is the handle that you assign to an object that allows you - * retrieve it later. A key is a sequence of Unicode characters whose - * UTF-8 encoding is at most 1024 bytes long. Each object in a bucket - * must have a unique key. - * - * @see - */ - public String getKey() { - return key; - } - - public DateTime getLastModified() { - return lastModified; - } - - public void setLastModified(DateTime lastModified) { - this.lastModified = lastModified; - } - - /** - * The size of the object, in bytes. - * - * @see - */ - public long getSize() { - return size; - } - - public void setSize(long size) { - this.size = size; - } - - /** - * A standard MIME type describing the format of the contents. If none - * is provided, the default is binary/octet-stream. - * @see - */ - public String getContentType() { - return dataType; - } - - public void setContentType(String dataType) { - this.dataType = dataType; - } - - public void setMd5(byte[] md5) { - this.md5 = Arrays.copyOf(md5, md5.length); - } - - /** - * @return the md5 value stored in the Etag header returned by S3. - */ - public byte[] getMd5() { - return (md5 == null) ? null : Arrays.copyOf(md5, md5.length); - } - - public void setUserMetadata(Multimap userMetadata) { - this.userMetadata = userMetadata; - } - - /** - * Any header starting with x-amz-meta- is considered user - * metadata. It will be stored with the object and returned when you - * retrieve the object. The total size of the HTTP request, not - * including the body, must be less than 8 KB. - */ - public Multimap getUserMetadata() { - return userMetadata; - } - - public void setOwner(CanonicalUser owner) { - this.owner = owner; - } - - /** - * Every bucket and object in Amazon S3 has an owner, the user that - * created the bucket or object. The owner of a bucket or object cannot - * be changed. However, if the object is overwritten by another user - * (deleted and rewritten), the new object will have a new owner. - */ - public CanonicalUser getOwner() { - return owner; - } - - public void setStorageClass(String storageClass) { - this.storageClass = storageClass; - } - - /** - * Currently defaults to 'STANDARD' and not used. - */ - public String getStorageClass() { - return storageClass; - } - - public void setCacheControl(String cacheControl) { - this.cacheControl = cacheControl; - } - - /** - * Can be used to specify caching behavior along the request/reply - * chain. - * - * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html?sec14.9. - */ - public String getCacheControl() { - return cacheControl; - } - - public void setContentDisposition(String dataDisposition) { - this.dataDisposition = dataDisposition; - } - - /** - * Specifies presentational information for the object. - * - * @see - */ - public String getContentDisposition() { - return dataDisposition; - } - - public void setContentEncoding(String dataEncoding) { - this.dataEncoding = dataEncoding; - } - - /** - * Specifies what content encodings have been applied to the object and - * thus what decoding mechanisms must be applied in order to obtain the - * media-type referenced by the Content-Type header field. - * - * @see - */ - public String getContentEncoding() { - return dataEncoding; - } - - public void setAllHeaders(Multimap allHeaders) { - this.allHeaders = allHeaders; - } - - /** - * @return all http response headers associated with this S3Object - */ - public Multimap getAllHeaders() { - return allHeaders; - } - - public int compareTo(Metadata o) { - return (this == o) ? 0 : getKey().compareTo(o.getKey()); - } - } - - /** - * @see Metadata#getKey() - */ - public String getKey() { - return metadata.getKey(); - } - - /** - * Sets payload for the request or the content from the response. If size - * isn't set, this will attempt to discover it. - * - * @param data typically InputStream for downloads, or File, byte [], String, - * or InputStream for uploads. - */ - public void setData(Object data) { - this.data = checkNotNull(data, "data"); - if (getMetadata().getSize() == -1) - this.getMetadata().setSize(S3Utils.calculateSize(data)); - } - - /** - * generate an MD5 Hash for the current data. - *

- *

Note

- *

- * If this is an InputStream, it will be converted to a byte array first. - * - * @throws IOException if there is a problem generating the hash. - */ - public void generateMd5() throws IOException { - checkState(data != null, "data"); - if (data instanceof InputStream) { - Md5InputStreamResult result = S3Utils - .generateMd5Result((InputStream) data); - getMetadata().setSize(result.length); - getMetadata().setMd5(result.md5); - setData(result.data); - } else { - getMetadata().setMd5(S3Utils.md5(data)); - } - } - - /** - * @return InputStream, if downloading, or whatever was set during - * {@link #setData(Object)} - */ - public Object getData() { - return data; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - - /** - * @return System and User metadata relevant to this object. - */ - public Metadata getMetadata() { - return metadata; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("S3Object"); - sb.append("{metadata=").append(metadata); - sb.append('}'); - return sb.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof S3Object)) - return false; - - S3Object s3Object = (S3Object) o; - - if (data != null ? !data.equals(s3Object.data) : s3Object.data != null) - return false; - if (!metadata.equals(s3Object.metadata)) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = data != null ? data.hashCode() : 0; - result = 31 * result + metadata.hashCode(); - return result; - } - - public void setContentLength(long contentLength) { - this.contentLength = contentLength; - } - - /** - * Returns the total size of the downloaded object, or the chunk that's - * available. - *

- * Chunking is only used when - * {@link org.jclouds.aws.s3.S3Connection#getObject(String, String, org.jclouds.aws.s3.commands.options.GetObjectOptions) } - * is called with options like tail, range, or startAt. - * - * @return the length in bytes that can be be obtained from - * {@link #getData()} - * @see org.jclouds.http.HttpHeaders#CONTENT_LENGTH - * @see GetObjectOptions - */ - public long getContentLength() { - return contentLength; - } - - public void setContentRange(String contentRange) { - this.contentRange = contentRange; - } - - /** - * If this is not-null, {@link #getContentLength() } will the size of chunk - * of the S3Object available via {@link #getData()} - * - * @see org.jclouds.http.HttpHeaders#CONTENT_RANGE - * @see GetObjectOptions - */ - public String getContentRange() { - return contentRange; - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/acl/CannedAccessPolicy.java b/s3/src/main/java/org/jclouds/aws/s3/domain/acl/CannedAccessPolicy.java deleted file mode 100644 index 49f097946f..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/acl/CannedAccessPolicy.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.domain.acl; - -/** - * Description from Amazon's documentation: - * - *

- * Because of restrictions in what can be sent via http headers, Amazon S3 - * supports the concept of canned access policies for REST. A canned access - * policy can be included with the x-amz-acl header as part of a PUT operation - * to provide shorthand representation of a full access policy. When Amazon S3 - * sees the x-amz-acl header as part of a PUT operation, it will assign the - * respective access policy to the resource created as a result of the PUT. If - * no x-amz-acl header is included with a PUT request, then the bucket or object - * is written with the private access control policy (even if, in the case of an - * object, the object already exists with some other pre-existing access control - * policy). - * - * @see - * @author Adrian Cole - * - */ -public enum CannedAccessPolicy { - - /** - * Owner gets FULL_CONTROL. No one else has access rights (default). - */ - PRIVATE("private"), - /** - * Owner gets FULL_CONTROL and the anonymous principal is granted READ - * access. If this policy is used on an object, it can be read from a - * browser with no authentication. - */ - PUBLIC_READ("public-read"), - /** - * Owner gets FULL_CONTROL, the anonymous principal is granted READ and - * WRITE access. This can be a useful policy to apply to a bucket, but is - * generally not recommended. - */ - PUBLIC_READ_WRITE("public-read-write"), - /** - * Owner gets FULL_CONTROL, and any principal authenticated as a registered - * Amazon S3 user is granted READ access. - */ - AUTHENTICATED_READ("authenticated-read"); - - private String policyName; - - CannedAccessPolicy(String policyName) { - this.policyName = policyName; - } - - @Override - public String toString() { - return policyName; - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/acl/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/domain/acl/package-info.java deleted file mode 100644 index 0c3b684bce..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/acl/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains components that represent authorization state. - * @see - * @author Adrian Cole - */ -package org.jclouds.aws.s3.domain.acl; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/domain/package-info.java deleted file mode 100644 index e5cd0c6deb..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains the core components of S3. - * @see - * @author Adrian Cole - */ -package org.jclouds.aws.s3.domain; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java b/s3/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java deleted file mode 100644 index b1ddb1cbb1..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignature.java +++ /dev/null @@ -1,192 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.filters; - -import java.util.Collection; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - -import org.jclouds.aws.s3.reference.S3Constants; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpHeaders; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpRequestFilter; - -import com.google.inject.Inject; -import com.google.inject.name.Named; - -/** - * Signs the S3 request. This will update timestamps at most once per second. - * - * @see - * @author Adrian Cole - * - */ -public class RequestAuthorizeSignature implements HttpRequestFilter { - private static final String[] firstHeadersToSign = new String[] { - HttpHeaders.CONTENT_MD5, HttpHeaders.CONTENT_TYPE, HttpHeaders.DATE }; - - private final String accessKey; - private final String secretKey; - private final DateService dateService; - - public static final long BILLION = 1000000000; - private final AtomicReference timeStamp; - private final AtomicLong trigger = new AtomicLong(System.nanoTime() + 1 - * BILLION); - - /** - * Start the time update service. Amazon clocks need to be within 900 - * seconds of the request time. This method updates the clock every second. - * This is not performed per-request, as creation of the date object is a - * slow, synchronized command. - */ - synchronized void updateIfTimeOut() { - - if (trigger.get() - System.nanoTime() <= 0) { - timeStamp.set(createNewStamp()); - trigger.set(System.nanoTime() + 1 * BILLION); - } - - } - - // this is a hotspot when submitted concurrently, so be lazy. - // amazon is ok with up to 15 minutes off their time, so let's - // be as lazy as possible. - String createNewStamp() { - return dateService.timestampAsHeaderString(); - } - - public String timestampAsHeaderString() { - updateIfTimeOut(); - return timeStamp.get(); - } - - @Inject - public RequestAuthorizeSignature( - @Named(S3Constants.PROPERTY_AWS_ACCESSKEYID) String accessKey, - @Named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY) String secretKey, - DateService dateService) { - this.accessKey = accessKey; - this.secretKey = secretKey; - this.dateService = dateService; - timeStamp = new AtomicReference(createNewStamp()); - } - - public void filter(HttpRequest request) throws HttpException { - // re-sign the request - removeOldHeaders(request); - - addDateHeader(request); - - String toSign = createStringToSign(request); - - addAuthHeader(request, toSign); - } - - public static String createStringToSign(HttpRequest request) { - StringBuilder buffer = new StringBuilder(); - appendMethod(request, buffer); - appendHttpHeaders(request, buffer); - appendAmzHeaders(request, buffer); - appendBucketName(request, buffer); - appendUriPath(request, buffer); - return buffer.toString(); - } - - private void removeOldHeaders(HttpRequest request) { - request.getHeaders().removeAll(S3Constants.AUTHORIZATION); - request.getHeaders().removeAll(HttpHeaders.CONTENT_TYPE); - request.getHeaders().removeAll(HttpHeaders.DATE); - } - - private void addAuthHeader(HttpRequest request, String toSign) - throws HttpException { - String signature; - try { - signature = S3Utils.hmacSha1Base64(toSign, secretKey.getBytes()); - } catch (Exception e) { - throw new HttpException("error signing request", e); - } - request.getHeaders().put(S3Constants.AUTHORIZATION, - "AWS " + accessKey + ":" + signature); - } - - private static void appendMethod(HttpRequest request, StringBuilder toSign) { - toSign.append(request.getMethod()).append("\n"); - } - - private void addDateHeader(HttpRequest request) { - request.getHeaders().put(HttpHeaders.DATE, timestampAsHeaderString()); - } - - private static void appendAmzHeaders(HttpRequest request, - StringBuilder toSign) { - Set headers = new TreeSet(request.getHeaders().keySet()); - for (String header : headers) { - if (header.startsWith("x-amz-")) { - toSign.append(header).append(":"); - for (String value : request.getHeaders().get(header)) - toSign.append(value.replaceAll("\r?\n", "")).append(","); - toSign.deleteCharAt(toSign.lastIndexOf(",")); - toSign.append("\n"); - } - } - } - - private static void appendHttpHeaders(HttpRequest request, - StringBuilder toSign) { - for (String header : firstHeadersToSign) - toSign.append(valueOrEmpty(request.getHeaders().get(header))) - .append("\n"); - } - - private static void appendBucketName(HttpRequest request, - StringBuilder toSign) { - String hostHeader = request.getHeaders().get(HttpHeaders.HOST) - .iterator().next(); - if (hostHeader.endsWith(".s3.amazonaws.com")) - toSign.append("/").append( - hostHeader.substring(0, hostHeader.length() - 17)); - } - - private static void appendUriPath(HttpRequest request, StringBuilder toSign) { - int queryIndex = request.getUri().indexOf('?'); - if (queryIndex >= 0) - toSign.append(request.getUri().substring(0, queryIndex)); - else - toSign.append(request.getUri()); - } - - private static String valueOrEmpty(Collection collection) { - return (collection != null && collection.size() >= 1) ? collection - .iterator().next() : ""; - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/filters/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/filters/package-info.java deleted file mode 100644 index 327f2e9230..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/filters/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains HttpRequestFilters needed to operate the REST api. - * @see - * @author Adrian Cole - */ -package org.jclouds.aws.s3.filters; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/handlers/ParseS3ErrorFromXmlContent.java b/s3/src/main/java/org/jclouds/aws/s3/handlers/ParseS3ErrorFromXmlContent.java deleted file mode 100644 index c0a6a072b9..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/handlers/ParseS3ErrorFromXmlContent.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.handlers; - -import java.io.InputStream; - -import javax.annotation.Resource; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.S3ResponseException; -import org.jclouds.aws.s3.domain.S3Error; -import org.jclouds.aws.s3.filters.RequestAuthorizeSignature; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.aws.s3.xml.S3ParserFactory; -import org.jclouds.http.HttpFutureCommand; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseHandler; -import org.jclouds.logging.Logger; - - -import com.google.inject.Inject; - -/** - * This will parse and set an appropriate exception on the command object. - * - * @see S3Error - * @author Adrian Cole - * - */ -public class ParseS3ErrorFromXmlContent implements HttpResponseHandler { - @Resource - protected Logger logger = Logger.NULL; - - private final S3ParserFactory parserFactory; - - @Inject - public ParseS3ErrorFromXmlContent(S3ParserFactory parserFactory) { - this.parserFactory = parserFactory; - } - - public void handle(HttpFutureCommand command, HttpResponse response) { - S3Error error = new S3Error(); - error.setRequestId(response.getFirstHeaderOrNull(S3Headers.REQUEST_ID)); - error.setRequestToken(response - .getFirstHeaderOrNull(S3Headers.REQUEST_TOKEN)); - InputStream errorStream = response.getContent(); - try { - if (errorStream != null) { - error = parserFactory.createErrorParser().parse(errorStream); - if ("SignatureDoesNotMatch".equals(error.getCode())) - error.setStringSigned(RequestAuthorizeSignature - .createStringToSign(command.getRequest())); - error.setRequestToken(response - .getFirstHeaderOrNull(S3Headers.REQUEST_TOKEN)); - } - } catch (Exception e) { - logger.warn(e, "error parsing XML reponse: %1$s", response); - } finally { - command.setException(new S3ResponseException(command, response, - error)); - IOUtils.closeQuietly(errorStream); - } - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/handlers/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/handlers/package-info.java deleted file mode 100644 index 4a6d03a147..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/handlers/package-info.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains HttpResponseHandlers needed to operate the REST api. - * @see - * @author Adrian Cole - */ -package org.jclouds.aws.s3.handlers; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/internal/BaseS3Map.java b/s3/src/main/java/org/jclouds/aws/s3/internal/BaseS3Map.java deleted file mode 100644 index 84ea134b1d..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/BaseS3Map.java +++ /dev/null @@ -1,236 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.S3Map; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.reference.S3Constants; -import org.jclouds.util.Utils; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * Implements core Map functionality with an {@link S3Connection} - *

- * All commands will wait a maximum of ${jclouds.s3.map.timeout} milliseconds to - * complete before throwing an exception. - * - * @author Adrian Cole - * @param - * value of the map - */ -public abstract class BaseS3Map implements S3Map { - - protected final S3Connection connection; - protected final String bucket; - - /** - * maximum duration of an S3 Request - */ - @Inject(optional = true) - @Named(S3Constants.PROPERTY_S3_MAP_TIMEOUT) - protected long requestTimeoutMilliseconds = 10000; - - @Inject - public BaseS3Map(S3Connection connection, @Assisted String bucket) { - this.connection = checkNotNull(connection, "connection"); - this.bucket = checkNotNull(bucket, "bucketName"); - } - - /** - * {@inheritDoc} - *

- * This returns the number of keys in the {@link S3Bucket} - * - * @see S3Bucket#getContents() - */ - public int size() { - try { - S3Bucket bucket = refreshBucket(); - Set contents = bucket.getContents(); - return contents.size(); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error getting size of bucketName" - + bucket, e); - } - } - - protected boolean containsMd5(byte[] md5) throws InterruptedException, - ExecutionException, TimeoutException { - for (S3Object.Metadata metadata : refreshBucket().getContents()) { - if (Arrays.equals(md5, metadata.getMd5())) - return true; - } - return false; - } - - protected byte[] getMd5(Object value) throws IOException, - FileNotFoundException, InterruptedException, ExecutionException, - TimeoutException { - S3Object object = null; - if (value instanceof S3Object) { - object = (S3Object) value; - } else { - object = new S3Object("dummy", value); - } - if (object.getMetadata().getMd5() == null) - object.generateMd5(); - return object.getMetadata().getMd5(); - } - - /** - * attempts asynchronous gets on all objects. - * - * @see S3Connection#getObject(String, String) - */ - protected Set getAllObjects() { - Set objects = new HashSet(); - Set> futureObjects = new HashSet>(); - for (String key : keySet()) { - futureObjects.add(connection.getObject(bucket, key)); - } - for (Future futureObject : futureObjects) { - S3Object object = null; - try { - object = futureObject.get(requestTimeoutMilliseconds, - TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error getting value from bucket %1$s", bucket), e); - } - if (object != S3Object.NOT_FOUND) - objects.add(object); - } - return objects; - } - - /** - * {@inheritDoc} - *

- * Note that if value is an instance of InputStream, it will be read and - * closed following this method. To reuse data from InputStreams, pass - * {@link java.io.InputStream}s inside {@link S3Object}s - */ - public boolean containsValue(Object value) { - try { - byte[] md5 = getMd5(value); - return containsMd5(md5); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error searching for ETAG of value: [%2$s] in bucketName:%1$s", - bucket, value), e); - } - } - - public static class S3RuntimeException extends RuntimeException { - private static final long serialVersionUID = 1L; - - S3RuntimeException(String s) { - super(s); - } - - public S3RuntimeException(String s, Throwable throwable) { - super(s, throwable); - } - } - - public void clear() { - try { - List> deletes = new ArrayList>(); - for (String key : keySet()) { - deletes.add(connection.deleteObject(bucket, key)); - } - for (Future isdeleted : deletes) - if (!isdeleted.get(requestTimeoutMilliseconds, - TimeUnit.MILLISECONDS)) { - throw new S3RuntimeException("failed to delete entry"); - } - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error clearing bucketName" + bucket, e); - } - } - - protected S3Bucket refreshBucket() throws InterruptedException, - ExecutionException, TimeoutException { - S3Bucket currentBucket = connection.listBucket(bucket).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - if (currentBucket == S3Bucket.NOT_FOUND) - throw new S3RuntimeException("bucketName not found: " + bucket); - else - return currentBucket; - } - - public Set keySet() { - try { - Set keys = new HashSet(); - for (S3Object.Metadata object : refreshBucket().getContents()) - keys.add(object.getKey()); - return keys; - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error getting keys in bucketName: " - + bucket, e); - } - } - - public boolean containsKey(Object key) { - try { - return connection.headObject(bucket, key.toString()).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS) != S3Object.Metadata.NOT_FOUND; - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error searching for %1$s:%2$s", bucket, key), e); - } - } - - public boolean isEmpty() { - return keySet().size() == 0; - } - - public S3Bucket getBucket() { - try { - return refreshBucket(); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error getting bucketName" + bucket, e); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/internal/GuiceS3Context.java b/s3/src/main/java/org/jclouds/aws/s3/internal/GuiceS3Context.java deleted file mode 100644 index 8cf0e427b2..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/GuiceS3Context.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.internal; - -import com.google.inject.Inject; -import com.google.inject.Injector; -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.S3InputStreamMap; -import org.jclouds.aws.s3.S3ObjectMap; -import org.jclouds.lifecycle.Closer; -import org.jclouds.logging.Logger; - -import javax.annotation.Resource; -import java.io.IOException; - -/** - * Uses a Guice Injector to configure the objects served by S3Context methods. - * - * @author Adrian Cole - * @see Injector - */ -public class GuiceS3Context implements S3Context { - public interface S3ObjectMapFactory { - S3ObjectMap createMapView(String bucket); - } - - public interface S3InputStreamMapFactory { - S3InputStreamMap createMapView(String bucket); - } - - @Resource - private Logger logger = Logger.NULL; - private final Injector injector; - private final S3InputStreamMapFactory s3InputStreamMapFactory; - private final S3ObjectMapFactory s3ObjectMapFactory; - private final Closer closer; - - @Inject - private GuiceS3Context(Injector injector, Closer closer, - S3ObjectMapFactory s3ObjectMapFactory, - S3InputStreamMapFactory s3InputStreamMapFactory) { - this.injector = injector; - this.s3InputStreamMapFactory = s3InputStreamMapFactory; - this.s3ObjectMapFactory = s3ObjectMapFactory; - this.closer = closer; - } - - /** - * {@inheritDoc} - */ - public S3Connection getConnection() { - return injector.getInstance(S3Connection.class); - } - - /** - * {@inheritDoc} - */ - public S3InputStreamMap createInputStreamMap(String bucket) { - getConnection().putBucketIfNotExists(bucket); - return s3InputStreamMapFactory.createMapView(bucket); - } - - /** - * {@inheritDoc} - */ - public S3ObjectMap createS3ObjectMap(String bucket) { - getConnection().putBucketIfNotExists(bucket); - return s3ObjectMapFactory.createMapView(bucket); - } - - /** - * {@inheritDoc} - * - * @see Closer - */ - public void close() { - try { - closer.close(); - } catch (IOException e) { - logger.error(e, "error closing content"); - } - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3Connection.java b/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3Connection.java deleted file mode 100644 index 8a28fb2ceb..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3Connection.java +++ /dev/null @@ -1,243 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.internal; - -import java.util.List; -import java.util.concurrent.Future; - -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.commands.BucketExists; -import org.jclouds.aws.s3.commands.CopyObject; -import org.jclouds.aws.s3.commands.DeleteBucket; -import org.jclouds.aws.s3.commands.DeleteObject; -import org.jclouds.aws.s3.commands.ListOwnedBuckets; -import org.jclouds.aws.s3.commands.GetObject; -import org.jclouds.aws.s3.commands.HeadObject; -import org.jclouds.aws.s3.commands.ListBucket; -import org.jclouds.aws.s3.commands.PutBucket; -import org.jclouds.aws.s3.commands.PutObject; -import org.jclouds.aws.s3.commands.S3CommandFactory; -import org.jclouds.aws.s3.commands.options.CopyObjectOptions; -import org.jclouds.aws.s3.commands.options.GetObjectOptions; -import org.jclouds.aws.s3.commands.options.ListBucketOptions; -import org.jclouds.aws.s3.commands.options.PutBucketOptions; -import org.jclouds.aws.s3.commands.options.PutObjectOptions; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.S3Bucket.Metadata; -import org.jclouds.http.HttpFutureCommandClient; - -import com.google.inject.Inject; - -/** - * Uses {@link HttpFutureCommandClient} to invoke the REST API of S3. - * - * @see - * @author Adrian Cole - */ -public class LiveS3Connection implements S3Connection { - - private final HttpFutureCommandClient client; - /** - * creates command objects that can be submitted to the client - */ - private final S3CommandFactory factory; - - @Inject - public LiveS3Connection(HttpFutureCommandClient client, - S3CommandFactory factory) { - this.client = client; - this.factory = factory; - } - - /** - * {@inheritDoc} - * - * @see GetObject - */ - public Future getObject(String s3Bucket, String key) { - return getObject(s3Bucket, key, GetObjectOptions.NONE); - } - - /** - * {@inheritDoc} - * - * @see GetObject - */ - public Future getObject(String s3Bucket, String key, - GetObjectOptions options) { - GetObject getObject = factory.createGetObject(s3Bucket, key, options); - client.submit(getObject); - return getObject; - } - - /** - * {@inheritDoc} - * - * @see HeadObject - */ - public Future headObject(String s3Bucket, String key) { - HeadObject headMetadata = factory.createHeadMetadata(s3Bucket, key); - client.submit(headMetadata); - return headMetadata; - } - - /** - * {@inheritDoc} - * - * @see DeleteObject - */ - public Future deleteObject(String s3Bucket, String key) { - DeleteObject deleteObject = factory.createDeleteObject(s3Bucket, key); - client.submit(deleteObject); - return deleteObject; - } - - /** - * {@inheritDoc} - * - * @see PutObject - */ - public Future putObject(String s3Bucket, S3Object object) { - return putObject(s3Bucket, object, PutObjectOptions.NONE); - } - - /** - * {@inheritDoc} - * - * @see PutObject - */ - public Future putObject(String bucketName, S3Object object, - PutObjectOptions options) { - PutObject putObject = factory.createPutObject(bucketName, object, - options); - client.submit(putObject); - return putObject; - } - - /** - * {@inheritDoc} - * - * @see PutBucket - */ - public Future putBucketIfNotExists(String s3Bucket) { - return putBucketIfNotExists(s3Bucket, PutBucketOptions.NONE); - } - - /** - * {@inheritDoc} - * - * @see PutBucket - */ - public Future putBucketIfNotExists(String s3Bucket, - PutBucketOptions options) { - PutBucket putBucket = factory.createPutBucket(s3Bucket, options); - client.submit(putBucket); - return putBucket; - } - - /** - * {@inheritDoc} - * - * @see DeleteBucket - */ - public Future deleteBucketIfEmpty(String s3Bucket) { - DeleteBucket deleteBucket = factory.createDeleteBucket(s3Bucket); - client.submit(deleteBucket); - return deleteBucket; - } - - /** - * {@inheritDoc} - * - * @see CopyObject - */ - public Future copyObject(String sourceBucket, - String sourceObject, String destinationBucket, - String destinationObject) { - return copyObject(sourceBucket, sourceObject, destinationBucket, - destinationObject, new CopyObjectOptions()); - } - - /** - * {@inheritDoc} - * - * @see CopyObject - */ - public Future copyObject(String sourceBucket, - String sourceObject, String destinationBucket, - String destinationObject, CopyObjectOptions options) { - CopyObject copy = factory.createCopyObject(sourceBucket, sourceObject, - destinationBucket, destinationObject, options); - client.submit(copy); - return copy; - } - - /** - * {@inheritDoc} - * - * @see BucketExists - */ - public Future bucketExists(String s3Bucket) { - BucketExists headRequestObject = factory.createHeadBucket(s3Bucket); - client.submit(headRequestObject); - return headRequestObject; - } - - /** - * {@inheritDoc} - * - * @see ListBucket - */ - public Future listBucket(String s3Bucket) { - return listBucket(s3Bucket, ListBucketOptions.NONE); - } - - /** - * {@inheritDoc} - * - * @see ListBucket - */ - public Future listBucket(String s3Bucket, - ListBucketOptions options) { - ListBucket getBucket = factory.createListBucket(s3Bucket, options); - client.submit(getBucket); - return getBucket; - } - - /** - * {@inheritDoc} - * - * @see ListOwnedBuckets - */ - public Future> listOwnedBuckets() { - ListOwnedBuckets listRequest = factory - .createGetMetadataForOwnedBuckets(); - client.submit(listRequest); - return listRequest; - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3InputStreamMap.java b/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3InputStreamMap.java deleted file mode 100644 index 974cc79e5e..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3InputStreamMap.java +++ /dev/null @@ -1,271 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.internal; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.S3InputStreamMap; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.util.Utils; - -import java.io.File; -import java.io.InputStream; -import java.util.*; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -/** - * Map representation of a live connection to S3. All put operations will result - * in Md5 calculation. If this is not desired, use {@link LiveS3ObjectMap} - * instead. - * - * @author Adrian Cole - * @see S3Connection - * @see BaseS3Map - */ -public class LiveS3InputStreamMap extends BaseS3Map implements - S3InputStreamMap { - - @Inject - public LiveS3InputStreamMap(S3Connection connection, @Assisted String bucket) { - super(connection, bucket); - } - - /** - * {@inheritDoc} - * - * @see S3Connection#getObject(String, String) - */ - public InputStream get(Object o) { - try { - return (InputStream) (connection.getObject(bucket, o.toString()) - .get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)) - .getData(); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error geting object %1$s:%2$s", bucket, o), e); - } - } - - /** - * {@inheritDoc} - * - * @see S3Connection#deleteObject(String, String) - */ - public InputStream remove(Object o) { - InputStream old = get(o); - try { - connection.deleteObject(bucket, o.toString()).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error removing object %1$s:%2$s", bucket, o), e); - } - return old; - } - - /** - * {@inheritDoc} - * - * @see #getAllObjects() - */ - public Collection values() { - Collection values = new LinkedList(); - Set objects = getAllObjects(); - for (S3Object object : objects) { - values.add((InputStream) object.getData()); - } - return values; - } - - /** - * {@inheritDoc} - * - * @see #getAllObjects() - */ - public Set> entrySet() { - Set> entrySet = new HashSet>(); - for (S3Object object : getAllObjects()) { - entrySet.add(new Entry(object.getKey(), (InputStream) object - .getData())); - } - return entrySet; - } - - public class Entry implements java.util.Map.Entry { - - private InputStream value; - private String key; - - Entry(String key, InputStream value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public InputStream getValue() { - return value; - } - - /** - * {@inheritDoc} - * - * @see LiveS3InputStreamMap#put(String, InputStream) - */ - public InputStream setValue(InputStream value) { - return put(key, value); - } - - } - - /** - * {@inheritDoc} - * - * @see #putAllInternal(Map) - */ - public void putAll(Map map) { - putAllInternal(map); - } - - /** - * {@inheritDoc} - * - * @see #putAllInternal(Map) - */ - public void putAllBytes(Map map) { - putAllInternal(map); - } - - /** - * {@inheritDoc} - * - * @see #putAllInternal(Map) - */ - public void putAllFiles(Map map) { - putAllInternal(map); - } - - /** - * {@inheritDoc} - * - * @see #putAllInternal(Map) - */ - public void putAllStrings(Map map) { - putAllInternal(map); - } - - /** - * submits requests to add all objects and collects the results later. All - * values will have md5 calculated first. As a side-effect of this, the - * content will be copied into a byte []. - * - * @see S3Connection#putObject(String, S3Object) - */ - @VisibleForTesting - void putAllInternal(Map map) { - try { - List> puts = new ArrayList>(); - for (Map.Entry entry : map.entrySet()) { - S3Object object = new S3Object(entry.getKey()); - object.setData(entry.getValue()); - object.generateMd5(); - puts.add(connection.putObject(bucket, object)); - } - for (Future put : puts) - // this will throw an exception if there was a problem - put.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error putting into bucketName" + bucket, - e); - } - } - - /** - * {@inheritDoc} - * - * @see #putInternal(String, Object) - */ - public InputStream putString(String key, String value) { - return putInternal(key, value); - } - - /** - * {@inheritDoc} - * - * @see #putInternal(String, Object) - */ - public InputStream putFile(String key, File value) { - return putInternal(key, value); - } - - /** - * {@inheritDoc} - * - * @see #putInternal(String, Object) - */ - public InputStream putBytes(String key, byte[] value) { - return putInternal(key, value); - } - - /** - * {@inheritDoc} - * - * @see #putInternal(String, Object) - */ - public InputStream put(String key, InputStream value) { - return putInternal(key, value); - } - - /** - * calculates md5 before adding the object to s3. As a side-effect of this, - * the content will be copied into a byte []. * - * - * @see S3Connection#putObject(String, S3Object) - */ - @VisibleForTesting - InputStream putInternal(String s, Object o) { - S3Object object = new S3Object(s); - try { - InputStream returnVal = containsKey(s) ? get(s) : null; - object.setData(o); - object.generateMd5(); - connection.putObject(bucket, object).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - return returnVal; - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error adding object %1$s:%2$s", bucket, object), e); - } - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3ObjectMap.java b/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3ObjectMap.java deleted file mode 100644 index 5aa17ce560..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3ObjectMap.java +++ /dev/null @@ -1,184 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.S3ObjectMap; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.util.Utils; - -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; - -/** - * Map representation of a live connection to S3. - * - * @see S3Connection - * @see BaseS3Map - * - * @author Adrian Cole - */ -public class LiveS3ObjectMap extends BaseS3Map implements S3ObjectMap { - - @Inject - public LiveS3ObjectMap(S3Connection connection, @Assisted String bucket) { - super(connection, bucket); - } - - /** - * {@inheritDoc} - * - * @see #values() - */ - public Set> entrySet() { - Set> entrySet = new HashSet>(); - for (S3Object value : values()) { - Map.Entry entry = new Entry(value.getKey(), value); - entrySet.add(entry); - } - return entrySet; - } - - public class Entry implements java.util.Map.Entry { - - private S3Object value; - private String key; - - Entry(String key, S3Object value) { - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public S3Object getValue() { - return value; - } - - /** - * {@inheritDoc} - * - * @see LiveS3ObjectMap#put(String, S3Object) - */ - public S3Object setValue(S3Object value) { - return put(key, value); - } - - } - - /** - * {@inheritDoc} - * - * @see S3Connection#getObject(String, String) - */ - public S3Object get(Object key) { - try { - return connection.getObject(bucket, key.toString()).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils. rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error geting object %1$s:%2$s", bucket, key), e); - } - } - - /** - * {@inheritDoc} - * - * @see S3Connection#putObject(String, S3Object) - */ - public S3Object put(String key, S3Object value) { - S3Object returnVal = get(key); - try { - connection.putObject(bucket, value).get(requestTimeoutMilliseconds, - TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils. rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException( - String.format("Error putting object %1$s:%2$s%n%3$s", - bucket, key, value), e); - } - return returnVal; - } - - /** - * {@inheritDoc} attempts to put all objects asynchronously. - * - * @see S3Connection#putObject(String, S3Object) - */ - public void putAll(Map map) { - try { - List> puts = new ArrayList>(); - for (S3Object object : map.values()) { - puts.add(connection.putObject(bucket, object)); - } - for (Future put : puts) - // this will throw an exception if there was a problem - put.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils. rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error putting into bucketName" + bucket, - e); - } - } - - /** - * {@inheritDoc} - * - * @see S3Connection#deleteObject(String, String) - */ - public S3Object remove(Object key) { - S3Object old = get(key); - try { - connection.deleteObject(bucket, key.toString()).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils. rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error removing object %1$s:%2$s", bucket, key), e); - } - return old; - } - - /** - * {@inheritDoc} - * - * @see #getAllObjects() - */ - public Collection values() { - return getAllObjects(); - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/internal/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/internal/package-info.java deleted file mode 100644 index 13660be584..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains implementation classes for the jclouds-s3 public api - * @author Adrian Cole - */ -package org.jclouds.aws.s3.internal; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/package-info.java deleted file mode 100644 index 8ca082f558..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/package-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains an Amazon S3 client implemented by {@link org.jclouds.http.HttpFutureCommandClient} commands. - * - * @see - * @author Adrian Cole - */ -package org.jclouds.aws.s3; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java b/s3/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java deleted file mode 100644 index bdc188380e..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.reference; - -import org.jclouds.command.pool.PoolConstants; -import org.jclouds.http.HttpConstants; - -/** - * Configuration properties and constants used in S3 connections. - * - * @author Adrian Cole - */ -public interface S3Constants extends HttpConstants, PoolConstants, S3Headers { - - public static final String PROPERTY_AWS_SECRETACCESSKEY = "jclouds.aws.secretaccesskey"; - public static final String PROPERTY_AWS_ACCESSKEYID = "jclouds.aws.accesskeyid"; - /** - * longest time a single Map operation can take before throwing an - * exception. - */ - public static final String PROPERTY_S3_MAP_TIMEOUT = "jclouds.s3.map.timeout"; - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/reference/S3Headers.java b/s3/src/main/java/org/jclouds/aws/s3/reference/S3Headers.java deleted file mode 100644 index 7891d0d319..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/reference/S3Headers.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.reference; - -import org.jclouds.http.HttpHeaders; - -/** - * Additional headers specified by Amazon S3 REST API. - * - * @see - * @author Adrian Cole - * - */ -public interface S3Headers extends HttpHeaders { - - /** - * The canned ACL to apply to the object. Options include private, - * public-read, public-read-write, and authenticated-read. For more - * information, see REST Access Control Policy. - */ - public static final String CANNED_ACL = "x-amz-acl"; - /** - * Any header starting with this prefix is considered user metadata. It will - * be stored with the object and returned when you retrieve the object. The - * total size of the HTTP request, not including the body, must be less than - * 8 KB. - */ - public static final String USER_METADATA_PREFIX = "x-amz-meta-"; - public static final String AMZ_MD5 = "x-amz-meta-object-md5"; - public static final String REQUEST_ID = "x-amz-request-id"; - public static final String REQUEST_TOKEN = "x-amz-id-2"; - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/reference/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/reference/package-info.java deleted file mode 100644 index b6b6679a4f..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/reference/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains properties and reference data used in S3. - * @author Adrian Cole - */ -package org.jclouds.aws.s3.reference; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/util/DateService.java b/s3/src/main/java/org/jclouds/aws/s3/util/DateService.java deleted file mode 100644 index 94ff1eae99..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/util/DateService.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.util; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; - -/** - * Parses dates found in XML responses and HTTP response headers. - * - * @author Adrian Cole - * - */ -public class DateService { - private DateTimeFormatter headerDateFormat = DateTimeFormat - .forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'"); - - public DateTime dateTimeFromXMLFormat(String toParse) { - // the format is natively parseable from the DateTime constructor - return new DateTime(toParse); - } - - public DateTime dateTimeFromHeaderFormat(String toParse) { - return headerDateFormat.parseDateTime(toParse); - } - - public String timestampAsHeaderString() { - return toHeaderString(new DateTime()); - } - - public String toHeaderString(DateTime date) { - return headerDateFormat.print(date.withZone(DateTimeZone.UTC)); - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/util/S3Utils.java b/s3/src/main/java/org/jclouds/aws/s3/util/S3Utils.java deleted file mode 100644 index 0587e0c4be..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/util/S3Utils.java +++ /dev/null @@ -1,245 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.util; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.output.ByteArrayOutputStream; -import org.bouncycastle.crypto.digests.MD5Digest; -import org.bouncycastle.crypto.digests.SHA1Digest; -import org.bouncycastle.crypto.macs.HMac; -import org.bouncycastle.crypto.params.KeyParameter; -import org.bouncycastle.util.encoders.Base64; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.util.Utils; - -import java.io.*; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.util.regex.Pattern; - -/** - * Encryption, Hashing, and IO Utilities needed to sign and verify S3 requests - * and responses. - * - * @author Adrian Cole - */ -public class S3Utils extends Utils { - - private static final Pattern IP_PATTERN = Pattern - .compile("b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).)" - + "{3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)b"); - - public static String validateBucketName(String bucketName) { - checkNotNull(bucketName, "bucketName"); - checkArgument(bucketName.matches("^[a-z0-9].*"), - "bucketName name must start with a number or letter"); - checkArgument( - bucketName.matches("^[-_.a-z0-9]+"), - "bucketName name can only contain lowercase letters, numbers, periods (.), underscores (_), and dashes (-)"); - checkArgument(bucketName.length() > 2 && bucketName.length() < 256, - "bucketName name must be between 3 and 255 characters long"); - checkArgument(!IP_PATTERN.matcher(bucketName).matches(), - "bucketName name cannot be ip address style"); - return bucketName; - } - - static final byte[] HEX_CHAR_TABLE = {(byte) '0', (byte) '1', (byte) '2', - (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', - (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', - (byte) 'd', (byte) 'e', (byte) 'f'}; - - public static String toHexString(byte[] raw) - throws UnsupportedEncodingException { - byte[] hex = new byte[2 * raw.length]; - int index = 0; - - for (byte b : raw) { - int v = b & 0xFF; - hex[index++] = HEX_CHAR_TABLE[v >>> 4]; - hex[index++] = HEX_CHAR_TABLE[v & 0xF]; - } - return new String(hex, "ASCII"); - } - - public static long calculateSize(Object data) { - long size = -1; - if (data instanceof byte[]) { - size = ((byte[]) data).length; - } else if (data instanceof String) { - size = ((String) data).length(); - } else if (data instanceof File) { - size = ((File) data).length(); - } - return size; - } - - /** - * @throws IOException - */ - public static byte[] md5(Object data) throws IOException { - checkNotNull(data, "data must be set before calling generateMd5()"); - byte[] md5 = null; - if (data == null) { - } else if (data instanceof byte[]) { - md5 = S3Utils.md5((byte[]) data); - } else if (data instanceof String) { - md5 = S3Utils.md5(((String) data).getBytes()); - } else if (data instanceof File) { - md5 = S3Utils.md5(((File) data)); - } else { - throw new UnsupportedOperationException("Content not supported " - + data.getClass()); - } - return md5; - - } - - public static byte[] fromHexString(String hex) { - byte[] bytes = new byte[hex.length() / 2]; - for (int i = 0; i < bytes.length; i++) { - bytes[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), - 16); - } - return bytes; - } - - public static String hmacSha1Base64(String toEncode, byte[] key) - throws NoSuchAlgorithmException, NoSuchProviderException, - InvalidKeyException { - HMac hmac = new HMac(new SHA1Digest()); - byte[] resBuf = new byte[hmac.getMacSize()]; - byte[] plainBytes = toEncode.getBytes(); - byte[] keyBytes = key; - hmac.init(new KeyParameter(keyBytes)); - hmac.update(plainBytes, 0, plainBytes.length); - hmac.doFinal(resBuf, 0); - return toBase64String(resBuf); - } - - public static String md5Hex(byte[] toEncode) - throws NoSuchAlgorithmException, NoSuchProviderException, - InvalidKeyException, UnsupportedEncodingException { - byte[] resBuf = md5(toEncode); - return toHexString(resBuf); - } - - public static String md5Base64(byte[] toEncode) - throws NoSuchAlgorithmException, NoSuchProviderException, - InvalidKeyException { - byte[] resBuf = md5(toEncode); - return toBase64String(resBuf); - } - - public static String toBase64String(byte[] resBuf) { - return new String(Base64.encode(resBuf)); - } - - public static byte[] md5(byte[] plainBytes) { - MD5Digest md5 = new MD5Digest(); - byte[] resBuf = new byte[md5.getDigestSize()]; - md5.update(plainBytes, 0, plainBytes.length); - md5.doFinal(resBuf, 0); - return resBuf; - } - - public static byte[] md5(File toEncode) throws IOException { - MD5Digest md5 = new MD5Digest(); - byte[] resBuf = new byte[md5.getDigestSize()]; - byte[] buffer = new byte[1024]; - int numRead = -1; - InputStream i = new FileInputStream(toEncode); - try { - do { - numRead = i.read(buffer); - if (numRead > 0) { - md5.update(buffer, 0, numRead); - } - } while (numRead != -1); - } finally { - IOUtils.closeQuietly(i); - } - md5.doFinal(resBuf, 0); - return resBuf; - } - - public static Md5InputStreamResult generateMd5Result(InputStream toEncode) - throws IOException { - MD5Digest md5 = new MD5Digest(); - byte[] resBuf = new byte[md5.getDigestSize()]; - byte[] buffer = new byte[1024]; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - long length = 0; - int numRead = -1; - try { - do { - numRead = toEncode.read(buffer); - if (numRead > 0) { - length += numRead; - md5.update(buffer, 0, numRead); - out.write(buffer, 0, numRead); - } - } while (numRead != -1); - } finally { - out.close(); - IOUtils.closeQuietly(toEncode); - } - md5.doFinal(resBuf, 0); - return new Md5InputStreamResult(out.toByteArray(), resBuf, length); - } - - public static class Md5InputStreamResult { - public final byte[] data; - public final byte[] md5; - public final long length; - - Md5InputStreamResult(byte[] data, byte[] md5, long length) { - this.data = checkNotNull(data, "data"); - this.md5 = checkNotNull(md5, "md5"); - checkArgument(length >= 0, "length cannot me negative"); - this.length = length; - } - - } - - public static String getContentAsStringAndClose(S3Object object) - throws IOException { - checkNotNull(object, "s3Object"); - checkNotNull(object.getData(), "s3Object.content"); - Object o = object.getData(); - - if (o instanceof InputStream) { - String returnVal = toStringAndClose((InputStream) o); - if (object.getMetadata().getContentType().indexOf("xml") >= 0) { - - } - return returnVal; - } else { - throw new IllegalArgumentException("Object type not supported: " - + o.getClass().getName()); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/util/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/util/package-info.java deleted file mode 100644 index 98fe6f9ff0..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/util/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains utilities needed for S3. - * @author Adrian Cole - */ -package org.jclouds.aws.s3.util; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/CopyObjectHandler.java b/s3/src/main/java/org/jclouds/aws/s3/xml/CopyObjectHandler.java deleted file mode 100644 index 0249eda532..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/CopyObjectHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.commands.callables.xml.ParseSax; - -import com.google.inject.Inject; - -/** - * Parses the response from Amazon S3 COPY Object command. - *

- * CopyObjectResult is the document we expect to parse. - * - * @see - * @author Adrian Cole - */ -public class CopyObjectHandler extends - ParseSax.HandlerWithResult { - - private S3Object.Metadata metadata; - private StringBuilder currentText = new StringBuilder(); - @Inject - private DateService dateParser; - - public void setKey(String key) { - metadata = new S3Object.Metadata(key); - } - - public S3Object.Metadata getResult() { - return metadata; - } - - public void endElement(String uri, String name, String qName) { - if (qName.equals("ETag")) { - metadata.setMd5(S3Utils.fromHexString(currentText.toString() - .replaceAll("\"", ""))); - } else if (qName.equals("LastModified")) { - metadata.setLastModified(dateParser - .dateTimeFromXMLFormat(currentText.toString())); - } - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/ErrorHandler.java b/s3/src/main/java/org/jclouds/aws/s3/xml/ErrorHandler.java deleted file mode 100644 index fc42d045ea..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/ErrorHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import org.jclouds.aws.s3.domain.S3Error; -import org.jclouds.http.commands.callables.xml.ParseSax; - -/** - * Parses the error from the Amazon S3 REST API. - * - * @see - * @author Adrian Cole - */ -public class ErrorHandler extends ParseSax.HandlerWithResult { - - private S3Error error = new S3Error(); - private StringBuilder currentText = new StringBuilder(); - - public S3Error getResult() { - return error; - } - - public void endElement(String uri, String name, String qName) { - - if (qName.equals("Code")) { - error.setCode(currentText.toString()); - } else if (qName.equals("Message")) { - error.setMessage(currentText.toString()); - } else if (qName.equals("RequestId")) { - error.setRequestId(currentText.toString()); - } else if (!qName.equals("Error")) { - error.getDetails().put(qName, currentText.toString()); - } - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/ListAllMyBucketsHandler.java b/s3/src/main/java/org/jclouds/aws/s3/xml/ListAllMyBucketsHandler.java deleted file mode 100644 index 4906fdb94b..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/ListAllMyBucketsHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import java.util.ArrayList; -import java.util.List; - -import org.jclouds.aws.s3.domain.CanonicalUser; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.http.commands.callables.xml.ParseSax; - -import com.google.inject.Inject; - -/** - * Parses the following XML document: - *

- * ListAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01" - * - * @see - * @author Adrian Cole - */ -public class ListAllMyBucketsHandler extends - ParseSax.HandlerWithResult> { - - private List buckets = new ArrayList(); - private S3Bucket.Metadata currentS3Bucket; - private CanonicalUser currentOwner; - private StringBuilder currentText = new StringBuilder(); - - private final DateService dateParser; - - @Inject - public ListAllMyBucketsHandler(DateService dateParser) { - this.dateParser = dateParser; - } - - public List getResult() { - return buckets; - } - - public void endElement(String uri, String name, String qName) { - if (qName.equals("ID")) { // owner stuff - currentOwner = new CanonicalUser(currentText.toString()); - } else if (qName.equals("DisplayName")) { - currentOwner.setDisplayName(currentText.toString()); - } else if (qName.equals("Bucket")) { - currentS3Bucket.setOwner(currentOwner); - buckets.add(currentS3Bucket); - } else if (qName.equals("Name")) { - currentS3Bucket = new S3Bucket.Metadata(currentText.toString()); - } else if (qName.equals("CreationDate")) { - currentS3Bucket.setCreationDate(dateParser - .dateTimeFromXMLFormat(currentText.toString())); - } - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java b/s3/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java deleted file mode 100644 index bdd68235e9..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import static com.google.common.base.Preconditions.checkNotNull; -import com.google.inject.Inject; -import org.jclouds.aws.s3.domain.CanonicalUser; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.commands.callables.xml.ParseSax; -import org.xml.sax.Attributes; - -/** - * Parses the following XML document: - *

- * ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01" - * - * @author Adrian Cole - * @see - */ -public class ListBucketHandler extends ParseSax.HandlerWithResult { - private S3Bucket s3Bucket; - private S3Object.Metadata currentObjectMetadata; - private CanonicalUser currentOwner; - private StringBuilder currentText = new StringBuilder(); - - private final DateService dateParser; - - @Inject - public ListBucketHandler(DateService dateParser) { - this.dateParser = dateParser; - } - - public S3Bucket getResult() { - return s3Bucket; - } - - public void setBucketName(String bucketName) { - this.s3Bucket = new S3Bucket(checkNotNull(bucketName, "bucketName")); - } - - private boolean inCommonPrefixes; - - public void startElement(String uri, String name, String qName, - Attributes attrs) { - if (qName.equals("CommonPrefixes")) { - inCommonPrefixes = true; - } - } - - public void endElement(String uri, String name, String qName) { - if (qName.equals("ID")) { - currentOwner = new CanonicalUser(currentText.toString()); - } else if (qName.equals("DisplayName")) { - currentOwner.setDisplayName(currentText.toString()); - } else if (qName.equals("Key")) { // content stuff - currentObjectMetadata = new S3Object.Metadata(currentText - .toString()); - } else if (qName.equals("LastModified")) { - currentObjectMetadata.setLastModified(dateParser - .dateTimeFromXMLFormat(currentText.toString())); - } else if (qName.equals("ETag")) { - currentObjectMetadata.setMd5(S3Utils.fromHexString(currentText - .toString().replaceAll("\"", ""))); - } else if (qName.equals("Size")) { - currentObjectMetadata.setSize(Long - .parseLong(currentText.toString())); - } else if (qName.equals("Owner")) { - currentObjectMetadata.setOwner(currentOwner); - } else if (qName.equals("StorageClass")) { - currentObjectMetadata.setStorageClass(currentText.toString()); - } else if (qName.equals("Contents")) { - s3Bucket.getContents().add(currentObjectMetadata); - } else if (qName.equals("Name")) {// bucketName stuff last, as least likely - } else if (qName.equals("Prefix")) { - String prefix = currentText.toString().trim(); - if (inCommonPrefixes) - s3Bucket.getCommonPrefixes().add(prefix); - else - s3Bucket.setPrefix(prefix); - } else if (qName.equals("Delimiter")) { - if (!currentText.toString().equals("")) - s3Bucket.setDelimiter(currentText.toString().trim()); - } else if (qName.equals("Marker")) { - if (!currentText.toString().equals("")) - s3Bucket.setMarker(currentText.toString()); - } else if (qName.equals("MaxKeys")) { - s3Bucket.setMaxKeys(Long.parseLong(currentText.toString())); - } else if (qName.equals("IsTruncated")) { - boolean isTruncated = Boolean.parseBoolean(currentText.toString()); - s3Bucket.setTruncated(isTruncated); - } - currentText = new StringBuilder(); - } - - public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/S3ParserFactory.java b/s3/src/main/java/org/jclouds/aws/s3/xml/S3ParserFactory.java deleted file mode 100644 index b7ddda2377..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/S3ParserFactory.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; -import com.google.inject.Provider; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Error; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.http.commands.callables.xml.ParseSax; - -import java.util.List; - -/** - * Creates Parsers needed to interpret S3 Server messages. This class uses guice - * assisted inject, which mandates the creation of many single-method - * interfaces. These interfaces are not intended for public api. - * - * @author Adrian Cole - */ -public class S3ParserFactory { - - @Inject - private GenericParseFactory> parseListAllMyBucketsFactory; - - @VisibleForTesting - public static interface GenericParseFactory { - ParseSax create(ParseSax.HandlerWithResult handler); - } - - @Inject - Provider ListAllMyBucketsHandlerprovider; - - /** - * @return a parser used to handle {@link org.jclouds.aws.s3.commands.ListOwnedBuckets} responses - */ - public ParseSax> createListBucketsParser() { - return parseListAllMyBucketsFactory - .create(ListAllMyBucketsHandlerprovider.get()); - } - - @Inject - private GenericParseFactory parseListBucketFactory; - - @Inject - Provider ListBucketHandlerprovider; - - /** - * @return a parser used to handle {@link org.jclouds.aws.s3.commands.ListBucket} responses - */ - public ParseSax createListBucketParser() { - return parseListBucketFactory.create(ListBucketHandlerprovider.get()); - } - - @Inject - private GenericParseFactory parseCopyObjectFactory; - - @Inject - Provider copyObjectHandlerProvider; - - /** - * @return a parser used to handle {@link org.jclouds.aws.s3.commands.CopyObject} responses - */ - public ParseSax createCopyObjectParser() { - return parseCopyObjectFactory.create(copyObjectHandlerProvider.get()); - } - - @Inject - private GenericParseFactory parseErrorFactory; - - @Inject - Provider errorHandlerProvider; - - /** - * @return a parser used to handle error conditions. - */ - public ParseSax createErrorParser() { - return parseErrorFactory.create(errorHandlerProvider.get()); - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/config/S3ParserModule.java b/s3/src/main/java/org/jclouds/aws/s3/xml/config/S3ParserModule.java deleted file mode 100644 index 11ab8fca59..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/config/S3ParserModule.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml.config; - -import java.util.List; - -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Error; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.xml.CopyObjectHandler; -import org.jclouds.aws.s3.xml.ErrorHandler; -import org.jclouds.aws.s3.xml.ListAllMyBucketsHandler; -import org.jclouds.aws.s3.xml.ListBucketHandler; -import org.jclouds.aws.s3.xml.S3ParserFactory; -import org.jclouds.http.commands.callables.xml.ParseSax; -import org.jclouds.http.commands.callables.xml.config.SaxModule; - -import com.google.inject.AbstractModule; -import com.google.inject.TypeLiteral; -import com.google.inject.assistedinject.FactoryProvider; - -/** - * Creates the factories needed to interpret S3 responses - * - * @author Adrian Cole - */ -public class S3ParserModule extends AbstractModule { - private final TypeLiteral>> listBucketsTypeLiteral = new TypeLiteral>>() { - }; - private final TypeLiteral> bucketTypeLiteral = new TypeLiteral>() { - }; - private final TypeLiteral> objectMetadataTypeLiteral = new TypeLiteral>() { - }; - private final TypeLiteral> errorTypeLiteral = new TypeLiteral>() { - }; - - @Override - protected void configure() { - install(new SaxModule()); - bindCallablesThatReturnParseResults(); - bindParserImplementationsToReturnTypes(); - } - - private void bindParserImplementationsToReturnTypes() { - bind( - new TypeLiteral>>() { - }).to(ListAllMyBucketsHandler.class); - bind(new TypeLiteral>() { - }).to(ListBucketHandler.class); - bind(new TypeLiteral>() { - }).to(CopyObjectHandler.class); - bind(new TypeLiteral>() { - }).to(ErrorHandler.class); - } - - private void bindCallablesThatReturnParseResults() { - bind(listBucketsTypeLiteral).toProvider( - FactoryProvider.newFactory(listBucketsTypeLiteral, - new TypeLiteral>>() { - })); - bind(bucketTypeLiteral).toProvider( - FactoryProvider.newFactory(bucketTypeLiteral, - new TypeLiteral>() { - })); - bind(objectMetadataTypeLiteral).toProvider( - FactoryProvider.newFactory(objectMetadataTypeLiteral, - new TypeLiteral>() { - })); - bind(errorTypeLiteral).toProvider( - FactoryProvider.newFactory(errorTypeLiteral, - new TypeLiteral>() { - })); - } - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/config/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/xml/config/package-info.java deleted file mode 100644 index 89c30ec34b..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/config/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains logic that assembles xml parsing callables. - * @author Adrian Cole - */ -package org.jclouds.aws.s3.xml.config; \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/package-info.java b/s3/src/main/java/org/jclouds/aws/s3/xml/package-info.java deleted file mode 100644 index 8d65fcb59a..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -/** - * This package contains xml logic that parses S3 responses. - * @author Adrian Cole - */ -package org.jclouds.aws.s3.xml; \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/PerformanceTest.java b/s3/src/test/java/org/jclouds/aws/PerformanceTest.java deleted file mode 100644 index fc19a4e7ac..0000000000 --- a/s3/src/test/java/org/jclouds/aws/PerformanceTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws; - -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -@Test(groups = "performance", sequential = true, testName = "s3.PerformanceTest") -public class PerformanceTest { - protected static int LOOP_COUNT = 1000; - protected ExecutorService exec; - - @BeforeMethod - public void setupExecutorService() { - exec = Executors.newCachedThreadPool(); - } - - @AfterMethod - public void teardownExecutorService() { - exec.shutdownNow(); - exec = null; - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/BaseS3MapIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/BaseS3MapIntegrationTest.java deleted file mode 100644 index 2ac23a08e4..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/BaseS3MapIntegrationTest.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.internal.BaseS3Map; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import java.io.*; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.TreeSet; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -@Test -public abstract class BaseS3MapIntegrationTest extends S3IntegrationTest { - - public abstract void testPutAll(); - - public abstract void testEntrySet() throws IOException; - - public abstract void testValues() throws IOException; - - protected BaseS3Map map; - protected Map fiveStrings = ImmutableMap.of("one", "apple", - "two", "bear", "three", "candy", "four", "dogma", "five", "emma"); - protected Map fiveBytes = ImmutableMap.of("one", "apple" - .getBytes(), "two", "bear".getBytes(), "three", "candy".getBytes(), - "four", "dogma".getBytes(), "five", "emma".getBytes()); - protected Map fiveInputs; - protected Map fiveFiles; - String tmpDirectory; - - @BeforeMethod(dependsOnMethods = "setUpBucket", groups = {"integration", "live"}) - @Parameters({"basedir"}) - protected void setUpTempDir(String basedir) throws InterruptedException, - ExecutionException, FileNotFoundException, IOException, - TimeoutException { - tmpDirectory = basedir + File.separator + "target" + File.separator - + "testFiles" + File.separator + getClass().getSimpleName(); - new File(tmpDirectory).mkdirs(); - - fiveFiles = ImmutableMap.of("one", new File(tmpDirectory, "apple"), - "two", new File(tmpDirectory, "bear"), "three", new File( - tmpDirectory, "candy"), "four", new File(tmpDirectory, - "dogma"), "five", new File(tmpDirectory, "emma")); - - for (File file : fiveFiles.values()) { - IOUtils.write(file.getName(), new FileOutputStream(file)); - } - - fiveInputs = ImmutableMap.of("one", IOUtils.toInputStream("apple"), - "two", IOUtils.toInputStream("bear"), "three", IOUtils - .toInputStream("candy"), "four", IOUtils - .toInputStream("dogma"), "five", IOUtils - .toInputStream("emma")); - map = createMap(context, bucketName); - map.clear(); - } - - protected abstract BaseS3Map createMap(S3Context context, String bucket); - - @Test(groups = {"integration", "live"}) - public void testClear() { - map.clear(); - assertEquals(map.size(), 0); - putString("one", "apple"); - assertEquals(map.size(), 1); - map.clear(); - assertEquals(map.size(), 0); - } - - @Test(groups = {"integration", "live"}) - public abstract void testRemove() throws IOException; - - @Test(groups = {"integration", "live"}) - public void testKeySet() { - assertEquals(map.keySet().size(), 0); - putString("one", "two"); - assertEquals(map.keySet(), ImmutableSet.of("one")); - } - - @Test(groups = {"integration", "live"}) - public void testContainsKey() { - assert !map.containsKey("one"); - putString("one", "apple"); - assert map.containsKey("one"); - } - - @Test(groups = {"integration", "live"}) - public void testIsEmpty() { - assert map.isEmpty(); - putString("one", "apple"); - assert !map.isEmpty(); - } - - abstract protected void putString(String key, String value); - - protected void fourLeftRemovingOne() { - map.remove("one"); - assertEquals(map.size(), 4); - assertEquals(new TreeSet(map.keySet()), new TreeSet( - ImmutableSet.of("two", "three", "four", "five"))); - } - - @Test(groups = {"integration", "live"}) - public abstract void testPut() throws IOException; - - @Test(groups = {"integration", "live"}) - public void testGetBucket() { - assertEquals(map.getBucket().getName(), bucketName); - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3ConnectionIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3ConnectionIntegrationTest.java deleted file mode 100644 index 204b78b6f8..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/S3ConnectionIntegrationTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import static com.google.common.base.Preconditions.checkNotNull; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.util.S3Utils; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.util.List; -import java.util.concurrent.TimeUnit; - -/** - * Tests connection by listing all the buckets and their size - * - * @author Adrian Cole - */ -@Test(testName = "s3.S3ConnectionIntegrationTest") -public class S3ConnectionIntegrationTest extends S3IntegrationTest { - - @Test(groups = {"integration"}) - void testListBuckets() throws Exception { - List myBuckets = client.listOwnedBuckets().get(10, - TimeUnit.SECONDS); - for (S3Bucket.Metadata bucket : myBuckets) { - context.createInputStreamMap(bucket.getName()).size(); - } - } - - private static final String sysHttpStreamUrl = System - .getProperty("jclouds.s3.httpstream.url"); - private static final String sysHttpStreamMd5 = System - .getProperty("jclouds.s3.httpstream.md5"); - - @Test(groups = {"integration"}) - @Parameters({"jclouds.s3.httpstream.url", "jclouds.s3.httpstream.md5"}) - public void testCopyUrl(@Optional String httpStreamUrl, - @Optional String httpStreamMd5) throws Exception { - httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl - : sysHttpStreamUrl, "httpStreamUrl"); - - httpStreamMd5 = checkNotNull(httpStreamMd5 != null ? httpStreamMd5 - : sysHttpStreamMd5, "httpStreamMd5"); - - String bucketName = bucketPrefix + "tcu"; - createBucketAndEnsureEmpty(bucketName); - String key = "hello"; - - URL url = new URL(httpStreamUrl); - byte[] md5 = S3Utils - .fromHexString(httpStreamMd5); - - URLConnection connection = url.openConnection(); - int length = connection.getContentLength(); - InputStream input = connection.getInputStream(); - - S3Object object = new S3Object(key, input); - object.setContentLength(length); - object.getMetadata().setMd5(md5); - object.getMetadata().setSize(length); - - byte[] newMd5 = client.putObject(bucketName, object).get(30, - TimeUnit.SECONDS); - assertEquals(newMd5, md5); - } -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3ContextFactoryTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3ContextFactoryTest.java deleted file mode 100644 index c3bd1d44b4..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/S3ContextFactoryTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import org.jclouds.aws.s3.config.LiveS3ConnectionModule; -import org.jclouds.http.config.HttpFutureCommandClientModule; -import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; -import org.jclouds.logging.config.LoggingModule; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.logging.jdk.config.JDKLoggingModule; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.List; - -/** - * Tests behavior of modules configured in S3ContextFactory - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.S3ContextFactoryTest") -public class S3ContextFactoryTest { - - @HttpFutureCommandClientModule - static class HttpModule extends AbstractModule { - - @Override - protected void configure() { - - } - } - - @Test - public void testAddHttpModuleIfNotPresent() { - List modules = new ArrayList(); - HttpModule module = new HttpModule(); - modules.add(module); - S3ContextFactory.addHttpModuleIfNeededAndNotPresent(modules); - assertEquals(modules.size(), 1); - assertEquals(modules.remove(0), module); - } - - @Test - public void testAddLoggingModuleIfNotPresent() { - List modules = new ArrayList(); - LoggingModule module = new NullLoggingModule(); - modules.add(module); - S3ContextFactory.addLoggingModuleIfNotPresent(modules); - assertEquals(modules.size(), 1); - assertEquals(modules.remove(0), module); - } - - @Test - public void testAddNone() { - List modules = new ArrayList(); - LoggingModule loggingModule = new NullLoggingModule(); - modules.add(loggingModule); - HttpModule httpModule = new HttpModule(); - modules.add(httpModule); - S3ContextFactory.addHttpModuleIfNeededAndNotPresent(modules); - S3ContextFactory.addLoggingModuleIfNotPresent(modules); - assertEquals(modules.size(), 2); - assertEquals(modules.remove(0), loggingModule); - assertEquals(modules.remove(0), httpModule); - } - - @Test - public void testAddBothWhenNotLive() { - List modules = new ArrayList(); - S3ContextFactory.addHttpModuleIfNeededAndNotPresent(modules); - S3ContextFactory.addLoggingModuleIfNotPresent(modules); - assertEquals(modules.size(), 1); - assert modules.remove(0) instanceof JDKLoggingModule; - } - - @Test - public void testAddBothWhenLive() { - List modules = new ArrayList(); - modules.add(new LiveS3ConnectionModule()); - S3ContextFactory.addHttpModuleIfNeededAndNotPresent(modules); - S3ContextFactory.addLoggingModuleIfNotPresent(modules); - assertEquals(modules.size(), 3); - assert modules.remove(0) instanceof LiveS3ConnectionModule; - assert modules.remove(0) instanceof JavaUrlHttpFutureCommandClientModule; - assert modules.remove(0) instanceof JDKLoggingModule; - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3InputStreamMapIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3InputStreamMapIntegrationTest.java deleted file mode 100644 index ed13295cbc..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/S3InputStreamMapIntegrationTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.internal.BaseS3Map; -import org.jclouds.util.Utils; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeSet; - -/** - * Tests to cover @{link LiveS3ObjectMap} - * - * @author Adrian Cole - */ -@Test(testName = "s3.S3InputStreamMapIntegrationTest") -public class S3InputStreamMapIntegrationTest extends BaseS3MapIntegrationTest { - S3InputStreamMap map = null; - - @SuppressWarnings("unchecked") - protected BaseS3Map createMap(S3Context context, String bucket) { - map = context.createInputStreamMap(bucket); - return (BaseS3Map) map; - } - - @Override - @Test(groups = {"integration", "live"}) - public void testValues() throws IOException { - map.putAll(this.fiveInputs); - Collection values = map.values(); - assertEquals(values.size(), 5); - Set valuesAsString = new HashSet(); - for (InputStream stream : values) { - valuesAsString.add(Utils.toStringAndClose(stream)); - } - valuesAsString.removeAll(fiveStrings.values()); - assert valuesAsString.size() == 0; - } - - @Test(groups = {"integration", "live"}) - public void testRemove() throws IOException { - putString("one", "two"); - InputStream old = map.remove("one"); - assertEquals(Utils.toStringAndClose(old), "two"); - old = map.remove("one"); - assert old == null; - old = map.get("one"); - assert old == null; - assertEquals(map.keySet().size(), 0); - } - - @Override - @Test(groups = {"integration", "live"}) - public void testEntrySet() throws IOException { - map.putAllStrings(this.fiveStrings); - Set> entries = map.entrySet(); - assertEquals(entries.size(), 5); - for (Entry entry : entries) { - assertEquals(IOUtils.toString(entry.getValue()), fiveStrings - .get(entry.getKey())); - entry.setValue(IOUtils.toInputStream("")); - } - assertEquals(map.size(), 5); - for (InputStream value : map.values()) { - assertEquals(IOUtils.toString(value), ""); - } - } - - @Test(groups = {"integration", "live"}) - public void testContainsStringValue() { - map.putString("one", "apple"); - assert map.containsValue(fiveStrings.get("one")); - } - - @Test(groups = {"integration", "live"}) - public void testContainsFileValue() { - map.putString("one", "apple"); - assert map.containsValue(fiveFiles.get("one")); - } - - @Test(groups = {"integration", "live"}) - public void testContainsInputStreamValue() { - map.putString("one", "apple"); - assert map.containsValue(this.fiveInputs.get("one")); - } - - @Test(groups = {"integration", "live"}) - public void testContainsBytesValue() { - map.putString("one", "apple"); - assert map.containsValue(this.fiveBytes.get("one")); - } - - @Override - @Test(groups = {"integration", "live"}) - public void testPutAll() { - map.putAll(this.fiveInputs); - assertEquals(map.size(), 5); - assertEquals(new TreeSet(map.keySet()), new TreeSet( - fiveInputs.keySet())); - fourLeftRemovingOne(); - } - - @Test(groups = {"integration", "live"}) - public void testPutAllBytes() { - map.putAllBytes(this.fiveBytes); - assertEquals(map.size(), 5); - assertEquals(new TreeSet(map.keySet()), new TreeSet( - fiveBytes.keySet())); - fourLeftRemovingOne(); - } - - @Test(groups = {"integration", "live"}) - public void testPutAllFiles() { - map.putAllFiles(this.fiveFiles); - assertEquals(map.size(), 5); - assertEquals(new TreeSet(map.keySet()), new TreeSet( - fiveFiles.keySet())); - fourLeftRemovingOne(); - } - - @Test(groups = {"integration", "live"}) - public void testPutAllStrings() { - map.putAllStrings(this.fiveStrings); - assertEquals(map.size(), 5); - assertEquals(new TreeSet(map.keySet()), new TreeSet( - fiveStrings.keySet())); - fourLeftRemovingOne(); - } - - @Test(groups = {"integration", "live"}) - public void testPutString() throws IOException { - InputStream old = map.putString("one", "apple"); - getOneReturnsAppleAndOldValueIsNull(old); - InputStream apple = map.putString("one", "bear"); - getOneReturnsBearAndOldValueIsApple(apple); - } - - void getOneReturnsAppleAndOldValueIsNull(InputStream old) - throws IOException { - assert old == null; - assertEquals(Utils.toStringAndClose(map.get("one")), "apple"); - assertEquals(map.size(), 1); - } - - void getOneReturnsBearAndOldValueIsApple(InputStream oldValue) - throws IOException { - assertEquals(Utils.toStringAndClose(map.get("one")), "bear"); - assertEquals(Utils.toStringAndClose(oldValue), "apple"); - assertEquals(map.size(), 1); - } - - @Test(groups = {"integration", "live"}) - public void testPutFile() throws IOException { - InputStream old = map.putFile("one", fiveFiles.get("one")); - getOneReturnsAppleAndOldValueIsNull(old); - InputStream apple = map.putFile("one", fiveFiles.get("two")); - getOneReturnsBearAndOldValueIsApple(apple); - } - - @Test(groups = {"integration", "live"}) - public void testPutBytes() throws IOException { - InputStream old = map.putBytes("one", "apple".getBytes()); - getOneReturnsAppleAndOldValueIsNull(old); - InputStream apple = map.putBytes("one", "bear".getBytes()); - getOneReturnsBearAndOldValueIsApple(apple); - } - - @Test(groups = {"integration", "live"}) - public void testPut() throws IOException { - InputStream old = map.put("one", IOUtils.toInputStream("apple")); - getOneReturnsAppleAndOldValueIsNull(old); - InputStream apple = map.put("one", IOUtils.toInputStream("bear")); - getOneReturnsBearAndOldValueIsApple(apple); - } - - @Override - protected void putString(String key, String value) { - map.putString(key, value); - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java deleted file mode 100644 index 00c61961b6..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import static com.google.common.base.Preconditions.checkNotNull; -import com.google.inject.Module; -import org.jclouds.aws.s3.config.StubS3ConnectionModule; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.reference.S3Constants; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpConstants; -import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; -import static org.testng.Assert.assertEquals; -import org.testng.ITestContext; -import org.testng.annotations.*; - -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.*; -import java.util.logging.*; -import java.util.logging.Formatter; - -public class S3IntegrationTest { - protected static final String TEST_STRING = " "; - - protected byte[] goodMd5; - protected byte[] badMd5; - protected String bucketName; - - protected void createBucketAndEnsureEmpty(String sourceBucket) - throws InterruptedException, ExecutionException, TimeoutException { - client.putBucketIfNotExists(sourceBucket).get(10, TimeUnit.SECONDS); - assertEquals(client.listBucket(sourceBucket).get(10, TimeUnit.SECONDS) - .getContents().size(), 0); - } - - protected void addObjectToBucket(String sourceBucket, String key) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - S3Object sourceObject = new S3Object(key); - sourceObject.getMetadata().setContentType("text/xml"); - sourceObject.setData(TEST_STRING); - addObjectToBucket(sourceBucket, sourceObject); - } - - protected void addObjectToBucket(String sourceBucket, S3Object object) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - client.putObject(sourceBucket, object).get(10, TimeUnit.SECONDS); - } - - protected S3Object validateContent(String sourceBucket, String key) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - assertEquals(client.listBucket(sourceBucket).get(10, TimeUnit.SECONDS) - .getContents().size(), 1); - S3Object newObject = client.getObject(sourceBucket, key).get(10, - TimeUnit.SECONDS); - assert newObject != S3Object.NOT_FOUND; - assertEquals(S3Utils.getContentAsStringAndClose(newObject), TEST_STRING); - return newObject; - } - - @BeforeClass(groups = {"integration", "live"}) - void enableDebug() { - if (debugEnabled()) { - Handler HANDLER = new ConsoleHandler() { - { - setLevel(Level.ALL); - setFormatter(new Formatter() { - - @Override - public String format(LogRecord record) { - return String.format( - "[%tT %-7s] [%-7s] [%s]: %s %s\n", - new Date(record.getMillis()), record - .getLevel(), Thread.currentThread() - .getName(), record.getLoggerName(), - record.getMessage(), - record.getThrown() == null ? "" : record - .getThrown()); - } - }); - } - }; - Logger guiceLogger = Logger.getLogger("org.jclouds"); - guiceLogger.addHandler(HANDLER); - guiceLogger.setLevel(Level.ALL); - } - } - - protected S3Connection client; - protected S3Context context = null; - - protected String bucketPrefix = (System.getProperty("user.name") + "." + this - .getClass().getSimpleName()).toLowerCase(); - - private static final String sysAWSAccessKeyId = System - .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); - private static final String sysAWSSecretAccessKey = System - .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); - - @BeforeClass(inheritGroups = false, groups = {"integration", "live"}) - @Parameters({S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY}) - protected void setUpCredentials(@Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey, ITestContext testContext) throws Exception { - AWSAccessKeyId = AWSAccessKeyId != null ? AWSAccessKeyId - : sysAWSAccessKeyId; - AWSSecretAccessKey = AWSSecretAccessKey != null ? AWSSecretAccessKey - : sysAWSSecretAccessKey; - if (AWSAccessKeyId != null) - testContext.setAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID, AWSAccessKeyId); - if (AWSSecretAccessKey != null) - testContext.setAttribute(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, AWSSecretAccessKey); - } - - @BeforeClass(dependsOnMethods = {"setUpCredentials"}, groups = {"integration", "live"}) - protected void setUpClient(ITestContext testContext) throws Exception { - if (testContext.getAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID) != null) { - String AWSAccessKeyId = (String) testContext.getAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID); - String AWSSecretAccessKey = (String) testContext.getAttribute(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); - context = S3ContextFactory.createS3Context(buildS3Properties( - checkNotNull(AWSAccessKeyId, "AWSAccessKeyId"), - checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey")), - createHttpModule()); - } else { - Properties props = new Properties(); - props.setProperty(S3Constants.PROPERTY_HTTP_ADDRESS, "stub"); - context = S3ContextFactory.createS3Context(props, new StubS3ConnectionModule()); - } - client = context.getConnection(); - assert client != null; - deleteEverything(); - goodMd5 = S3Utils.md5(TEST_STRING); - badMd5 = S3Utils.md5("alf"); - } - - @BeforeMethod(dependsOnMethods = "deleteBucket", groups = {"integration", "live"}) - public void setUpBucket(Method method) throws TimeoutException, ExecutionException, InterruptedException { - bucketName = (bucketPrefix + method.getName()).toLowerCase(); - createBucketAndEnsureEmpty(bucketName); - } - - @BeforeMethod(groups = {"integration", "live"}) - @AfterMethod(groups = {"integration", "live"}) - public void deleteBucket() throws TimeoutException, ExecutionException, InterruptedException { - if (bucketName != null) - deleteBucket(bucketName); - } - - protected boolean debugEnabled() { - return false; - } - - protected Properties buildS3Properties(String AWSAccessKeyId, - String AWSSecretAccessKey) { - Properties properties = new Properties( - S3ContextFactory.DEFAULT_PROPERTIES); - properties.setProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID, - checkNotNull(AWSAccessKeyId, "AWSAccessKeyId")); - properties.setProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, - checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey")); - properties.setProperty(HttpConstants.PROPERTY_HTTP_SECURE, "false"); - properties.setProperty(HttpConstants.PROPERTY_HTTP_PORT, "80"); - return properties; - } - - protected Module createHttpModule() { - return new JavaUrlHttpFutureCommandClientModule(); - } - - protected void deleteEverything() throws Exception { - try { - List metadata = client.listOwnedBuckets().get( - 10, TimeUnit.SECONDS); - for (S3Bucket.Metadata metaDatum : metadata) { - if (metaDatum.getName().startsWith(bucketPrefix.toLowerCase())) { - deleteBucket(metaDatum.getName()); - } - - } - } catch (CancellationException e) { - throw e; - } - } - - private void deleteBucket(String name) throws InterruptedException, ExecutionException, TimeoutException { - if (client.bucketExists(name).get(10, TimeUnit.SECONDS)) { - List> results = new ArrayList>(); - - S3Bucket bucket = client.listBucket(name) - .get(10, TimeUnit.SECONDS); - for (S3Object.Metadata objectMeta : bucket.getContents()) { - results.add(client.deleteObject(name, - objectMeta.getKey())); - } - Iterator> iterator = results.iterator(); - while (iterator.hasNext()) { - iterator.next().get(10, TimeUnit.SECONDS); - iterator.remove(); - } - client.deleteBucketIfEmpty(name).get(10, - TimeUnit.SECONDS); - } - } - - @AfterClass - protected void tearDownClient() throws Exception { - deleteEverything(); - context.close(); - context = null; - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3ObjectMapIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3ObjectMapIntegrationTest.java deleted file mode 100644 index 688472e624..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/S3ObjectMapIntegrationTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.internal.BaseS3Map; -import org.jclouds.aws.s3.util.S3Utils; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; - -/** - * Tests to cover @{link LiveS3ObjectMap} - * - * @author Adrian Cole - */ -@Test(testName = "s3.S3ObjectMapIntegrationTest") -public class S3ObjectMapIntegrationTest extends BaseS3MapIntegrationTest { - S3ObjectMap map = null; - - @SuppressWarnings("unchecked") - protected BaseS3Map createMap(S3Context context, String bucket) { - map = context.createS3ObjectMap(bucket); - return (BaseS3Map) map; - } - - @Override - @Test(groups = {"integration", "live"}) - public void testValues() throws IOException { - putFiveStrings(); - Collection values = map.values(); - assertEquals(values.size(), 5); - Set valuesAsString = new HashSet(); - for (S3Object object : values) { - valuesAsString.add(S3Utils.getContentAsStringAndClose(object)); - } - valuesAsString.removeAll(fiveStrings.values()); - assert valuesAsString.size() == 0; - } - - @Test(groups = {"integration", "live"}) - public void testRemove() throws IOException { - putString("one", "two"); - S3Object old = map.remove("one"); - assertEquals(S3Utils.getContentAsStringAndClose(old), "two"); - old = map.remove("one"); - assert old == S3Object.NOT_FOUND; - old = map.get("one"); - assert old == S3Object.NOT_FOUND; - assertEquals(map.keySet().size(), 0); - } - - @Override - @Test(groups = {"integration", "live"}) - public void testEntrySet() throws IOException { - putFiveStrings(); - Set> entries = map.entrySet(); - assertEquals(entries.size(), 5); - for (Entry entry : entries) { - assertEquals(S3Utils.getContentAsStringAndClose(entry.getValue()), - fiveStrings.get(entry.getKey())); - S3Object value = entry.getValue(); - value.setData(""); - value.generateMd5(); - entry.setValue(value); - } - assertEquals(map.size(), 5); - for (S3Object value : map.values()) { - assertEquals(S3Utils.getContentAsStringAndClose(value), ""); - } - } - - @Test(groups = {"integration", "live"}) - public void testContains() { - putString("one", "apple"); - S3Object object = new S3Object("one"); - object.setData("apple"); - assert map.containsValue(object); - } - - void getOneReturnsAppleAndOldValueIsNull(S3Object old) throws IOException { - assert old == S3Object.NOT_FOUND; - assertEquals(S3Utils.getContentAsStringAndClose(map.get("one")), - "apple"); - assert map.size() == 1; - } - - void getOneReturnsBearAndOldValueIsApple(S3Object oldValue) - throws IOException { - assertEquals(S3Utils.getContentAsStringAndClose(map.get("one")), "bear"); - assertEquals(S3Utils.getContentAsStringAndClose(oldValue), "apple"); - assert map.size() == 1; - } - - @Test(groups = {"integration", "live"}) - public void testPut() throws IOException { - S3Object object = new S3Object("one"); - object.setData(IOUtils.toInputStream("apple")); - object.generateMd5(); - S3Object old = map.put(object.getKey(), object); - getOneReturnsAppleAndOldValueIsNull(old); - object.setData(IOUtils.toInputStream("bear")); - object.generateMd5(); - S3Object apple = map.put(object.getKey(), object); - getOneReturnsBearAndOldValueIsApple(apple); - } - - @Test(groups = {"integration", "live"}) - public void testPutAll() { - Map newMap = new HashMap(); - for (String key : fiveInputs.keySet()) { - S3Object object = new S3Object(key); - object.setData(fiveInputs.get(key)); - object.getMetadata().setSize(fiveBytes.get(key).length); - newMap.put(key, object); - } - map.putAll(newMap); - assertEquals(map.size(), 5); - assertEquals(new TreeSet(map.keySet()), new TreeSet( - fiveInputs.keySet())); - fourLeftRemovingOne(); - } - - @Override - protected void putString(String key, String value) { - S3Object object = new S3Object(key); - object.setData(value); - map.put(key, object); - } - - protected void putFiveStrings() { - Map newMap = new HashMap(); - for (Map.Entry entry : fiveStrings.entrySet()) { - S3Object object = new S3Object(entry.getKey()); - object.setData(entry.getValue()); - newMap.put(entry.getKey(), object); - } - map.putAll(newMap); - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java deleted file mode 100644 index 071c3cad28..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import org.bouncycastle.util.encoders.Base64; -import org.jclouds.aws.PerformanceTest; -import org.jclouds.aws.s3.util.S3Utils; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; - -/** - * This tests the performance of Digest commands. - * - * @author Adrian Cole - */ -@Test(groups = "performance", sequential = true, testName = "s3.PerformanceTest") -public class S3UtilsTest extends PerformanceTest { - - @Test(dataProvider = "hmacsha1") - void testBouncyCastleDigestSerialResponseTime(byte[] key, String message, - String base64Digest) throws NoSuchProviderException, - NoSuchAlgorithmException, InvalidKeyException { - for (int i = 0; i < 10000; i++) - testBouncyCastleHmacSha1Base64(key, message, base64Digest); - } - - @Test(dataProvider = "hmacsha1") - void testBouncyCastleDigestParallelResponseTime(final byte[] key, - final String message, final String base64Digest) - throws NoSuchProviderException, NoSuchAlgorithmException, - InvalidKeyException, InterruptedException, ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - for (int i = 0; i < 10000; i++) - completer.submit(new Callable() { - public Boolean call() throws Exception { - testBouncyCastleHmacSha1Base64(key, message, base64Digest); - return true; - } - }); - for (int i = 0; i < 10000; i++) - assert completer.take().get(); - } - - @DataProvider(name = "md5") - public Object[][] createMD5Data() { - return base64MD5MessageDigest; - } - - public final static Object[][] base64MD5MessageDigest = { - {"apple", "1f3870be274f6c49b3e31a0c6728957f"}, - {"bear", "893b56e3cfe153fb770a120b83bac20c"}, - {"candy", "c48ba993d35c3abe0380f91738fe2a34"}, - {"dogma", "95eb470e4faee302e9cd3063b1923dab"}, - {"emma", "00a809937eddc44521da9521269e75c6"}}; - - public final static Object[][] base64KeyMessageDigest = { - {Base64.decode("CwsLCwsLCwsLCwsLCwsLCwsLCws="), "Hi There", - "thcxhlUFcmTii8C2+zeMjvFGvgA="}, - {Base64.decode("SmVmZQ=="), "what do ya want for nothing?", - "7/zfauXrL6LSdBbV8YTfnCWafHk="}, - {Base64.decode("DAwMDAwMDAwMDAwMDAwMDAwMDAw="), - "Test With Truncation", "TBoDQktV4H/n8nvh1Yu5MkqaWgQ="}, - { - Base64 - .decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="), - "Test Using Larger Than Block-Size Key - Hash Key First", - "qkrl4VJy0A6VcFY3zoo7Ve1AIRI="}, - { - Base64 - .decode("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo="), - "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data", - "6OmdD0UjfXhta7qnllx4CLv/GpE="}}; - - @DataProvider(name = "hmacsha1") - public Object[][] createData1() { - return base64KeyMessageDigest; - } - - @Test(dataProvider = "hmacsha1") - public void testBouncyCastleHmacSha1Base64(byte[] key, String message, - String base64Digest) throws NoSuchProviderException, - NoSuchAlgorithmException, InvalidKeyException { - String b64 = S3Utils.hmacSha1Base64(message, key); - assertEquals(b64, base64Digest); - } - - @Test(dataProvider = "md5") - public void testBouncyCastleMD5Digest(String message, - String base64Digest) throws NoSuchProviderException, - NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException { - String b64 = S3Utils.md5Hex(message.getBytes()); - assertEquals(base64Digest, b64); - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/SecureS3ConnectionIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/SecureS3ConnectionIntegrationTest.java deleted file mode 100644 index 8abc6acd45..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/SecureS3ConnectionIntegrationTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import org.testng.annotations.Test; - -import java.util.Properties; - -/** - * This performs the same test as {@link S3ConnectionIntegrationTest}, except using SSL. - * - * @author Adrian Cole - */ -@Test(groups = {"live"}, testName = "s3.SecureS3ConnectionIntegrationTest") -public class SecureS3ConnectionIntegrationTest extends S3ConnectionIntegrationTest { - @Override - protected Properties buildS3Properties(String AWSAccessKeyId, - String AWSSecretAccessKey) { - Properties properties = super.buildS3Properties(AWSAccessKeyId, - AWSSecretAccessKey); - properties.setProperty("jclouds.http.secure", Boolean.toString(true)); - properties.setProperty("jclouds.http.port", "443"); - return properties; - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java b/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java deleted file mode 100644 index 634510f998..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java +++ /dev/null @@ -1,481 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import com.google.common.base.Function; -import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.thoughtworks.xstream.XStream; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.output.ByteArrayOutputStream; -import static org.easymock.classextension.EasyMock.createNiceMock; -import org.jclouds.aws.s3.commands.CopyObject; -import org.jclouds.aws.s3.commands.options.*; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Bucket.Metadata; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.joda.time.DateTime; - -import java.io.*; -import java.net.URLDecoder; -import java.util.*; -import java.util.concurrent.*; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -public class StubS3Connection implements S3Connection { - private static Map> bucketToContents = new ConcurrentHashMap>(); - private static Map bucketToLocation = new ConcurrentHashMap(); - private static Map keyToAcl = new ConcurrentHashMap(); - - /** - * @throws java.io.IOException - */ - public static byte[] toByteArray(Object data) throws IOException { - checkNotNull(data, "data must be set before calling generateMd5()"); - byte[] bytes = null; - if (data == null || data instanceof byte[]) { - bytes = (byte[]) data; - } else if (data instanceof String) { - bytes = ((String) data).getBytes(); - } else if (data instanceof File || data instanceof InputStream) { - InputStream io = (data instanceof InputStream) ? (InputStream) data : new FileInputStream((File) data); - bytes = IOUtils.toByteArray(io); - IOUtils.closeQuietly(io); - } else { - throw new UnsupportedOperationException("Content not supported " - + data.getClass()); - } - return bytes; - - } - - public Future getObject(final String s3Bucket, final String key) { - return getObject(s3Bucket, key, new GetObjectOptions()); - - } - - public S3Object.Metadata copy(S3Object.Metadata in) { - return (S3Object.Metadata) xstream.fromXML(xstream.toXML(in)); - } - - public S3Object.Metadata copy(S3Object.Metadata in, String newKey) { - return (S3Object.Metadata) xstream.fromXML(xstream.toXML(in).replaceAll(in.getKey(), newKey)); - } - - public Future headObject(final String s3Bucket, - final String key) { - return new FutureBase() { - public S3Object.Metadata get() throws InterruptedException, - ExecutionException { - if (!bucketToContents.containsKey(s3Bucket)) - return S3Object.Metadata.NOT_FOUND; - Map realContents = bucketToContents - .get(s3Bucket); - if (!realContents.containsKey(key)) - return S3Object.Metadata.NOT_FOUND; - return realContents.get(key).getMetadata(); - } - }; - } - - public Future deleteObject(final String s3Bucket, final String key) { - return new FutureBase() { - public Boolean get() throws InterruptedException, - ExecutionException { - if (bucketToContents.containsKey(s3Bucket)) { - bucketToContents.get(s3Bucket).remove(key); - } - return true; - } - }; - } - - public Future putObject(final String s3Bucket, final S3Object object) { - return putObject(s3Bucket, object, new PutObjectOptions()); - } - - public Future putBucketIfNotExists(final String s3Bucket) { - return new FutureBase() { - public Boolean get() throws InterruptedException, - ExecutionException { - if (!bucketToContents.containsKey(s3Bucket)) { - bucketToContents.put(s3Bucket, - new ConcurrentHashMap()); - } - return bucketToContents.containsKey(s3Bucket); - } - }; - } - - public Future deleteBucketIfEmpty(final String s3Bucket) { - return new FutureBase() { - public Boolean get() throws InterruptedException, - ExecutionException { - if (bucketToContents.containsKey(s3Bucket)) { - if (bucketToContents.get(s3Bucket).size() == 0) - bucketToContents.remove(s3Bucket); - else - return false; - } - return true; - } - }; - } - - XStream xstream = new XStream(); - - public Future copyObject(final String sourceBucket, - final String sourceObject, final String destinationBucket, - final String destinationObject) { - return copyObject(sourceBucket, sourceObject, destinationBucket, destinationObject, new CopyObjectOptions()); - } - - public Future bucketExists(final String s3Bucket) { - return new FutureBase() { - public Boolean get() throws InterruptedException, - ExecutionException { - return bucketToContents.containsKey(s3Bucket); - } - }; - } - - public Future listBucket(final String s3Bucket) { - return listBucket(s3Bucket, new ListBucketOptions()); - } - - private abstract class FutureBase implements Future { - public boolean cancel(boolean b) { - return false; - } - - public boolean isCancelled() { - return false; - } - - public boolean isDone() { - return true; - } - - public V get(long l, TimeUnit timeUnit) throws InterruptedException, - ExecutionException, TimeoutException { - return get(); - } - } - - public Future> listOwnedBuckets() { - return new FutureBase>() { - public List get() throws InterruptedException, - ExecutionException { - return Lists.newArrayList(Iterables.transform( - bucketToContents.keySet(), - new Function() { - public Metadata apply(String name) { - return new S3Bucket.Metadata(name); - } - })); - } - }; - } - - public Future putBucketIfNotExists(String name, - PutBucketOptions options) { - if (options.getLocationConstraint() != null) - bucketToLocation.put(name, options.getLocationConstraint()); - keyToAcl.put(name, options.getAcl()); - return putBucketIfNotExists(name); - } - - class DelimiterFilter implements Predicate { - private final String prefix; - private final String delimiter; - - DelimiterFilter(String prefix, String delimiter) { - this.prefix = prefix; - this.delimiter = delimiter; - } - - public boolean apply(S3Object.Metadata metadata) { - if (prefix == null) - return metadata.getKey().indexOf(delimiter) == -1; - if (metadata.getKey().startsWith(prefix)) - return metadata.getKey().replaceFirst(prefix, "").indexOf(delimiter) == -1; - return false; - } - } - - class CommonPrefixes implements Function { - private final String prefix; - private final String delimiter; - static final String NO_PREFIX = "NO_PREFIX"; - - CommonPrefixes(String prefix, String delimiter) { - this.prefix = prefix; - this.delimiter = delimiter; - } - - public String apply(S3Object.Metadata metadata) { - String working = metadata.getKey(); - - if (prefix != null) { - if (working.startsWith(prefix)) { - working = working.replaceFirst(prefix, ""); - } - } - if (working.contains(delimiter)) { - return working.substring(0, working.indexOf(delimiter)); - } - return NO_PREFIX; - } - } - - public Future listBucket(final String name, final ListBucketOptions options) { - return new FutureBase() { - public S3Bucket get() throws InterruptedException, - ExecutionException { - final Map realContents = bucketToContents - .get(name); - - if (realContents == null) return S3Bucket.NOT_FOUND; - SortedSet contents = Sets.newTreeSet( - Iterables.transform(realContents.keySet(), - new Function() { - public S3Object.Metadata apply(String key) { - return realContents.get(key).getMetadata(); - } - })); - S3Bucket returnVal = new S3Bucket(name); - - if (options.getMarker() != null) { - contents = contents.tailSet(new S3Object.Metadata(URLDecoder.decode(options.getMarker()))); - // amazon spec means after the marker, not including it. - contents.remove(new S3Object.Metadata(options.getMarker())); - returnVal.setMarker(URLDecoder.decode(options.getMarker())); - } - - - if (options.getPrefix() != null) { - contents = Sets.newTreeSet(Iterables.filter(contents, new Predicate() { - - public boolean apply(S3Object.Metadata o) { - return (o != null && o.getKey().startsWith(URLDecoder.decode(options.getPrefix()))); - } - })); - returnVal.setPrefix(URLDecoder.decode(options.getPrefix())); - } - - if (options.getDelimiter() != null) { - Iterable iterable = Iterables.transform(contents, new CommonPrefixes( - options.getPrefix() != null ? URLDecoder.decode(options.getPrefix()) : null, URLDecoder.decode(options.getDelimiter()))); - Set commonPrefixes = iterable != null ? Sets.newTreeSet(iterable) : new HashSet(); - commonPrefixes.remove(CommonPrefixes.NO_PREFIX); - - contents = Sets.newTreeSet(Iterables.filter(contents, new DelimiterFilter( - options.getPrefix() != null ? URLDecoder.decode(options.getPrefix()) : null, URLDecoder.decode(options.getDelimiter())))); - - returnVal.setCommonPrefixes(commonPrefixes); - returnVal.setDelimiter(URLDecoder.decode(options.getDelimiter())); - } - if (options.getMaxKeys() != null) { - contents = firstSliceOfSize(contents, Integer.parseInt(options.getMaxKeys())); - returnVal.setMaxKeys(Integer.parseInt(options.getMaxKeys())); - returnVal.setTruncated(true); - } - - returnVal.setContents(contents); - return returnVal; - } - }; - } - - public static SortedSet firstSliceOfSize(Iterable elements, int size) { - List> slices = Lists.partition( - Lists.newArrayList(elements), size); - return Sets.newTreeSet(slices.get(0)); - } - - public Future copyObject( - final String sourceBucket, final String sourceObject, final String destinationBucket, - final String destinationObject, final CopyObjectOptions options) { - - return new FutureBase() { - public S3Object.Metadata get() throws InterruptedException, - ExecutionException { - Map source = bucketToContents.get(sourceBucket); - Map dest = bucketToContents - .get(destinationBucket); - if (source.containsKey(sourceObject)) { - S3Object object = source.get(sourceObject); - if (options.getIfMatch() != null) { - if (!Arrays.equals(object.getMetadata().getMd5(), S3Utils.fromHexString(options.getIfMatch().replaceAll("\"", "")))) - throwResponseException(412); - - } - if (options.getIfNoneMatch() != null) { - if (Arrays.equals(object.getMetadata().getMd5(), S3Utils.fromHexString(options.getIfNoneMatch().replaceAll("\"", "")))) - throwResponseException(412); - } - if (options.getIfModifiedSince() != null) { - DateTime modifiedSince = dateService.dateTimeFromHeaderFormat(options.getIfModifiedSince()); - if (modifiedSince.isAfter(object.getMetadata().getLastModified())) - throw new ExecutionException(new RuntimeException("after")); - - } - if (options.getIfUnmodifiedSince() != null) { - DateTime unmodifiedSince = dateService.dateTimeFromHeaderFormat(options.getIfUnmodifiedSince()); - if (unmodifiedSince.isAfter(object.getMetadata().getLastModified())) - throw new ExecutionException(new RuntimeException("after")); - } - S3Object sourceS3 = source.get(sourceObject); - S3Object.Metadata newMd = copy(sourceS3.getMetadata(), destinationObject); - if (options.getAcl() != null) - keyToAcl.put(destinationBucket + destinationObject, options.getAcl()); - if (options.getMetadata() != null) { - newMd.setUserMetadata(options.getMetadata()); - } - newMd.setLastModified(new DateTime()); - dest.put(destinationObject, new S3Object(newMd, - sourceS3.getData())); - return copy(newMd); - } - return S3Object.Metadata.NOT_FOUND; - } - }; - } - - private void throwResponseException(int code) throws ExecutionException { - HttpResponse response = new HttpResponse(); - response.setStatusCode(code); - throw new ExecutionException( - new HttpResponseException(createNiceMock(CopyObject.class), response)); - } - - public Future putObject(final String bucketName, final S3Object object, - final PutObjectOptions options) { - if (!bucketToContents.containsKey(bucketName)) { - new RuntimeException( - "bucketName not found: " + bucketName); - } - try { - S3Object.Metadata newMd = copy(object.getMetadata()); - newMd.setLastModified(new DateTime()); - byte[] data = toByteArray(object.getData()); - final byte[] md5 = S3Utils.md5(data); - newMd.setMd5(md5); - newMd.setContentType("binary/octet-stream"); - if (options.getAcl() != null) - keyToAcl.put(bucketName + object, options.getAcl()); - bucketToContents.get(bucketName).put(object.getKey(), - new S3Object(newMd, data)); - return new FutureBase() { - public byte[] get() throws InterruptedException, ExecutionException { - return md5; - } - }; - } catch (IOException e) { - throw new RuntimeException(e); - } - - } - - DateService dateService = new DateService(); - - public Future getObject(final String bucketName, final String key, - final GetObjectOptions options) { - return new FutureBase() { - public S3Object get() throws InterruptedException, - ExecutionException { - if (!bucketToContents.containsKey(bucketName)) - return S3Object.NOT_FOUND; - Map realContents = bucketToContents - .get(bucketName); - if (!realContents.containsKey(key)) - return S3Object.NOT_FOUND; - - S3Object object = realContents.get(key); - - if (options.getIfMatch() != null) { - if (!Arrays.equals(object.getMetadata().getMd5(), S3Utils.fromHexString(options.getIfMatch().replaceAll("\"", "")))) - throwResponseException(412); - } - if (options.getIfNoneMatch() != null) { - if (Arrays.equals(object.getMetadata().getMd5(), S3Utils.fromHexString(options.getIfNoneMatch().replaceAll("\"", "")))) - throwResponseException(304); - } - if (options.getIfModifiedSince() != null) { - DateTime modifiedSince = dateService.dateTimeFromHeaderFormat(options.getIfModifiedSince()); - if (modifiedSince.isAfter(object.getMetadata().getLastModified())) - throw new ExecutionException(new RuntimeException("after")); - - } - if (options.getIfUnmodifiedSince() != null) { - DateTime unmodifiedSince = dateService.dateTimeFromHeaderFormat(options.getIfUnmodifiedSince()); - if (unmodifiedSince.isAfter(object.getMetadata().getLastModified())) - throw new ExecutionException(new RuntimeException("after")); - } - S3Object returnVal = new S3Object(copy(object.getMetadata()), object.getData()); - if (options.getRange() != null) { - byte[] data = (byte[]) returnVal.getData(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - for (String s : options.getRange().replaceAll("bytes=", "").split(",")) { - if (s.startsWith("-")) { - int length = Integer.parseInt(s.replaceAll("\\-", "")); - out.write(data, data.length - length, length); - } else if (s.endsWith("-")) { - int offset = Integer.parseInt(s.replaceAll("\\-", "")); - out.write(data, offset, data.length - offset); - } else if (s.contains("-")) { - String[] firstLast = s.split("\\-"); - int offset = Integer.parseInt(firstLast[0]); - int last = Integer.parseInt(firstLast[1]); - int length = (last < data.length) ? last + 1 : data.length - offset; - - out.write(data, offset, length); - } else { - throw new IllegalArgumentException("first and last were null!"); - } - - } - returnVal.setData(out.toByteArray()); - returnVal.setContentLength(out.size()); - returnVal.getMetadata().setSize(data.length); - } - returnVal.setData(new ByteArrayInputStream((byte[]) returnVal.getData())); - return returnVal; - } - }; - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/BucketExistsIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/BucketExistsIntegrationTest.java deleted file mode 100644 index 29e45591b6..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/BucketExistsIntegrationTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import org.testng.annotations.Test; -import org.testng.annotations.BeforeMethod; - -import java.util.concurrent.TimeUnit; - -/** - * Tests integrated functionality of all bucketExists commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(groups = {"integration", "live"}, testName = "s3.BucketExistsIntegrationTest") -public class BucketExistsIntegrationTest extends S3IntegrationTest { - - @Test - void bucketDoesntExist() throws Exception { - String bucketName= bucketPrefix+"be"; - assert !client.bucketExists(bucketName).get(10, TimeUnit.SECONDS); - } - - @Test - void bucketExists() throws Exception { - String bucketName= bucketPrefix+"bde"; - assert client.putBucketIfNotExists(bucketName).get(10, - TimeUnit.SECONDS); - assert client.bucketExists(bucketName).get(10, TimeUnit.SECONDS); - - } -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/CopyObjectIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/CopyObjectIntegrationTest.java deleted file mode 100644 index 160ecc01de..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/CopyObjectIntegrationTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import org.jclouds.aws.s3.S3IntegrationTest; -import static org.jclouds.aws.s3.commands.options.CopyObjectOptions.Builder.*; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpResponseException; -import org.joda.time.DateTime; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.net.URL; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * Tests integrated functionality of all copyObject commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(testName = "s3.CopyObjectIntegrationTest") -public class CopyObjectIntegrationTest extends S3IntegrationTest { - String sourceKey = "apples"; - String destinationKey = "pears"; - - @Test(groups = {"integration","live"}) - void testCopyObject() throws Exception { - - String destinationBucket = bucketName + "dest"; - - addToBucketAndValidate(bucketName, sourceKey); - - createBucketAndEnsureEmpty(destinationBucket); - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey).get(10, TimeUnit.SECONDS); - - validateContent(destinationBucket, destinationKey); - - } - - - private void addToBucketAndValidate(String bucketName, String sourceKey) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - addObjectToBucket(bucketName, sourceKey); - validateContent(bucketName, sourceKey); - } - - @Test(groups = {"integration","live"}) - void testCopyIfModifiedSince() throws InterruptedException, - ExecutionException, TimeoutException, IOException { - - String destinationBucket = bucketName + "dest"; - - DateTime before = new DateTime(); - addToBucketAndValidate(bucketName, sourceKey); - DateTime after = new DateTime().plusSeconds(1); - - createBucketAndEnsureEmpty(destinationBucket); - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceModifiedSince(before)).get(10, - TimeUnit.SECONDS); - validateContent(destinationBucket, destinationKey); - - try { - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceModifiedSince(after)).get(10, - TimeUnit.SECONDS); - } catch (ExecutionException e) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 412); - } - } - - @Test(groups = {"integration","live"}) - void testCopyIfUnmodifiedSince() throws InterruptedException, - ExecutionException, TimeoutException, IOException { - - String destinationBucket = bucketName + "dest"; - - DateTime before = new DateTime(); - addToBucketAndValidate(bucketName, sourceKey); - DateTime after = new DateTime().plusSeconds(1); - - createBucketAndEnsureEmpty(destinationBucket); - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceUnmodifiedSince(after)).get(10, - TimeUnit.SECONDS); - validateContent(destinationBucket, destinationKey); - - try { - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceModifiedSince(before)).get(10, - TimeUnit.SECONDS); - } catch (ExecutionException e) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 412); - } - } - - @Test(groups = {"integration","live"}) - void testCopyIfMatch() throws InterruptedException, ExecutionException, - TimeoutException, IOException { - - - String destinationBucket = bucketName + "dest"; - - addToBucketAndValidate(bucketName, sourceKey); - - createBucketAndEnsureEmpty(destinationBucket); - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceMd5Matches(goodMd5)).get(10, - TimeUnit.SECONDS); - validateContent(destinationBucket, destinationKey); - - try { - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceMd5Matches(badMd5)).get(10, - TimeUnit.SECONDS); - } catch (ExecutionException e) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 412); - } - } - - @Test(groups = {"integration","live"}) - void testCopyIfNoneMatch() throws IOException, InterruptedException, - ExecutionException, TimeoutException { - - - String destinationBucket = bucketName + "dest"; - - addToBucketAndValidate(bucketName, sourceKey); - - createBucketAndEnsureEmpty(destinationBucket); - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceMd5DoesntMatch(badMd5)).get(10, - TimeUnit.SECONDS); - validateContent(destinationBucket, destinationKey); - - try { - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, ifSourceMd5DoesntMatch(goodMd5)).get(10, - TimeUnit.SECONDS); - } catch (ExecutionException e) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 412); - } - } - - @Test(groups = {"integration","live"}) - void testCopyWithMetadata() throws InterruptedException, - ExecutionException, TimeoutException, IOException { - - String destinationBucket = bucketName + "dest"; - - addToBucketAndValidate(bucketName, sourceKey); - - Multimap metadata = HashMultimap.create(); - metadata.put(S3Headers.USER_METADATA_PREFIX + "adrian", "cole"); - - createBucketAndEnsureEmpty(destinationBucket); - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, overrideMetadataWith(metadata)).get(10, - TimeUnit.SECONDS); - - validateContent(destinationBucket, destinationKey); - - S3Object.Metadata objectMeta = client.headObject(destinationBucket, - destinationKey).get(10, TimeUnit.SECONDS); - - assertEquals(objectMeta.getUserMetadata(), metadata); - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/CopyObjectLiveTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/CopyObjectLiveTest.java deleted file mode 100644 index e2e8838418..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/CopyObjectLiveTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import static org.jclouds.aws.s3.commands.options.CopyObjectOptions.Builder.overrideAcl; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.util.S3Utils; -import org.testng.annotations.Test; - -import java.net.URL; -import java.util.concurrent.TimeUnit; - -/** - * Tests integrated functionality of all copyObject commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(testName = "s3.CopyObjectLiveTest") -public class CopyObjectLiveTest extends S3IntegrationTest { - String sourceKey = "apples"; - String destinationKey = "pears"; - - - @Test(groups = "live") - void testCannedAccessPolicyPublic() throws Exception { - String destinationBucket = bucketName + "dest"; - - addObjectToBucket(bucketName, sourceKey); - validateContent(bucketName, sourceKey); - - createBucketAndEnsureEmpty(destinationBucket); - client.copyObject(bucketName, sourceKey, destinationBucket, - destinationKey, overrideAcl(CannedAccessPolicy.PUBLIC_READ)).get(10, TimeUnit.SECONDS); - - validateContent(destinationBucket, destinationKey); - - URL url = new URL(String.format("http://%1$s.s3.amazonaws.com/%2$s", - destinationBucket, destinationKey)); - S3Utils.toStringAndClose(url.openStream()); - - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/DeleteBucketIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/DeleteBucketIntegrationTest.java deleted file mode 100644 index e9bf28228a..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/DeleteBucketIntegrationTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import org.testng.annotations.Test; - -import java.util.concurrent.TimeUnit; - -/** - * Tests integrated functionality of all deleteBucket commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(groups = {"integration", "live"}, testName = "s3.DeleteBucketIntegrationTest") -public class DeleteBucketIntegrationTest extends S3IntegrationTest { - - @Test - /** - * this method overrides bucketName to ensure it isn't found - */ - void deleteBucketIfEmptyNotFound() throws Exception { - String bucketName = bucketPrefix + "dbienf"; - assert client.deleteBucketIfEmpty(bucketName).get(10, TimeUnit.SECONDS); - } - - @Test() - void deleteBucketIfEmptyButHasContents() throws Exception { - addObjectToBucket(bucketName, "test"); - assert !client.deleteBucketIfEmpty(bucketName).get(10, TimeUnit.SECONDS); - } - - @Test() - void deleteBucketIfEmpty() throws Exception { - assert client.deleteBucketIfEmpty(bucketName).get(10, TimeUnit.SECONDS); - assert !client.bucketExists(bucketName).get(10, TimeUnit.SECONDS); - } -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/DeleteObjectIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/DeleteObjectIntegrationTest.java deleted file mode 100644 index 947fd0cbe6..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/DeleteObjectIntegrationTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import org.jclouds.aws.s3.S3ResponseException; -import org.jclouds.aws.s3.domain.S3Object; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -/** - * Tests integrated functionality of all deleteObject commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(groups = {"integration", "live"}, testName = "s3.DeleteObjectIntegrationTest") -public class DeleteObjectIntegrationTest extends S3IntegrationTest { - - @Test() - void deleteObjectNotFound() throws Exception { - String bucketName = bucketPrefix + "donf"; - createBucketAndEnsureEmpty(bucketName); - addObjectToBucket(bucketName, "test"); - assert client.deleteObject(bucketName, "test") - .get(10, TimeUnit.SECONDS); - } - - @Test - void deleteObjectNoBucket() throws Exception { - String bucketName = bucketPrefix + "donb"; - try { - client.deleteObject(bucketName, "test").get(10, TimeUnit.SECONDS); - } catch (ExecutionException e) { - assert e.getCause() instanceof S3ResponseException; - assertEquals(((S3ResponseException) e.getCause()).getResponse() - .getStatusCode(), 404); - } - } - - @Test() - void deleteObject() throws Exception { - String bucketName = bucketPrefix + "do"; - createBucketAndEnsureEmpty(bucketName); - addObjectToBucket(bucketName, "test"); - assert client.deleteObject(bucketName, "test") - .get(10, TimeUnit.SECONDS); - assert client.headObject(bucketName, "test").get(10, TimeUnit.SECONDS) == S3Object.Metadata.NOT_FOUND; - - } -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/GetObjectIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/GetObjectIntegrationTest.java deleted file mode 100644 index 8ecc00bf45..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/GetObjectIntegrationTest.java +++ /dev/null @@ -1,231 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http:www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import org.jclouds.aws.s3.S3ResponseException; -import static org.jclouds.aws.s3.commands.options.GetObjectOptions.Builder.*; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.http.HttpResponseException; -import org.joda.time.DateTime; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * Tests integrated functionality of all GetObject commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(groups = {"integration", "live"}, testName = "s3.GetObjectIntegrationTest") -public class GetObjectIntegrationTest extends S3IntegrationTest { - - @Test - void testGetIfModifiedSince() throws InterruptedException, - ExecutionException, TimeoutException, IOException { - - String key = "apples"; - - DateTime before = new DateTime(); - addObjectAndValidateContent(bucketName, key); - DateTime after = new DateTime().plusSeconds(1); - - client.getObject(bucketName, key, ifModifiedSince(before)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - - try { - client.getObject(bucketName, key, ifModifiedSince(after)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - } catch (ExecutionException e) { - if (e.getCause() instanceof HttpResponseException) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 304); - } else { - throw e; - } - } - - } - - @Test - void testGetIfUnmodifiedSince() throws InterruptedException, - ExecutionException, TimeoutException, IOException { - - String key = "apples"; - - DateTime before = new DateTime(); - addObjectAndValidateContent(bucketName, key); - DateTime after = new DateTime().plusSeconds(1); - - client.getObject(bucketName, key, ifUnmodifiedSince(after)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - - try { - client.getObject(bucketName, key, ifUnmodifiedSince(before)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - } catch (ExecutionException e) { - if (e.getCause() instanceof HttpResponseException) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 412); - } else { - throw e; - } - } - - } - - @Test - void testGetIfMatch() throws InterruptedException, ExecutionException, - TimeoutException, IOException { - - String key = "apples"; - - addObjectAndValidateContent(bucketName, key); - - client.getObject(bucketName, key, ifMd5Matches(goodMd5)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - - try { - client.getObject(bucketName, key, ifMd5Matches(badMd5)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - } catch (ExecutionException e) { - if (e.getCause() instanceof HttpResponseException) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 412); - } else { - throw e; - } - } - } - - @Test - void testGetIfNoneMatch() throws InterruptedException, ExecutionException, - TimeoutException, IOException { - - String key = "apples"; - - addObjectAndValidateContent(bucketName, key); - - client.getObject(bucketName, key, ifMd5DoesntMatch(badMd5)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - - try { - client.getObject(bucketName, key, ifMd5DoesntMatch(goodMd5)).get(10, - TimeUnit.SECONDS); - validateContent(bucketName, key); - } catch (ExecutionException e) { - if (e.getCause() instanceof HttpResponseException) { - HttpResponseException ex = (HttpResponseException) e.getCause(); - assertEquals(ex.getResponse().getStatusCode(), 304); - } else { - throw e; - } - } - } - - @Test - void testGetRange() throws InterruptedException, ExecutionException, - TimeoutException, IOException { - - String key = "apples"; - - addObjectAndValidateContent(bucketName, key); - S3Object object1 = client.getObject(bucketName, key, range(0, 5)).get(10, - TimeUnit.SECONDS); - assertEquals(S3Utils.getContentAsStringAndClose(object1), TEST_STRING - .substring(0, 6)); - - S3Object object2 = client.getObject(bucketName, key, - range(6, TEST_STRING.length())).get(10, TimeUnit.SECONDS); - assertEquals(S3Utils.getContentAsStringAndClose(object2), TEST_STRING - .substring(6, TEST_STRING.length())); - } - - @Test - void testGetTwoRanges() throws InterruptedException, ExecutionException, - TimeoutException, IOException { - - String key = "apples"; - - addObjectAndValidateContent(bucketName, key); - S3Object object = client.getObject(bucketName, key, - range(0, 5).range(6, TEST_STRING.length())).get(10, - TimeUnit.SECONDS); - - assertEquals(S3Utils.getContentAsStringAndClose(object), TEST_STRING); - } - - @Test - void testGetTail() throws InterruptedException, ExecutionException, - TimeoutException, IOException { - - String key = "apples"; - - addObjectAndValidateContent(bucketName, key); - S3Object object = client.getObject(bucketName, key, tail(5)).get(10, - TimeUnit.SECONDS); - assertEquals(S3Utils.getContentAsStringAndClose(object), TEST_STRING - .substring(TEST_STRING.length() - 5)); - assertEquals(object.getContentLength(), 5); - assertEquals(object.getMetadata().getSize(), TEST_STRING.length()); - - } - - @Test - void testGetStartAt() throws InterruptedException, ExecutionException, - TimeoutException, IOException { - - String key = "apples"; - - addObjectAndValidateContent(bucketName, key); - S3Object object = client.getObject(bucketName, key, startAt(5)).get(10, - TimeUnit.SECONDS); - assertEquals(S3Utils.getContentAsStringAndClose(object), TEST_STRING - .substring(5, TEST_STRING.length())); - assertEquals(object.getContentLength(), TEST_STRING.length() - 5); - assertEquals(object.getMetadata().getSize(), TEST_STRING.length()); - } - - private void addObjectAndValidateContent(String sourcebucketName, String sourceKey) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - addObjectToBucket(sourcebucketName, sourceKey); - validateContent(sourcebucketName, sourceKey); - } -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/ListBucketIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/ListBucketIntegrationTest.java deleted file mode 100644 index f86b622a43..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/ListBucketIntegrationTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import static org.jclouds.aws.s3.commands.options.ListBucketOptions.Builder.*; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -/** - * Tests integrated functionality of all getBucket commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(groups = {"integration", "live"}, testName = "s3.ListBucketIntegrationTest") -public class ListBucketIntegrationTest extends S3IntegrationTest { - - @Test() - void testListBucketDelimiter() throws InterruptedException, - ExecutionException, TimeoutException, UnsupportedEncodingException { - String prefix = "apps"; - addTenObjectsUnderPrefix(bucketName, prefix); - add15UnderRoot(bucketName); - S3Bucket bucket = client.listBucket(bucketName, delimiter("/")).get(10, - TimeUnit.SECONDS); - assertEquals(bucket.getDelimiter(), "/"); - assert !bucket.isTruncated(); - assertEquals(bucket.getContents().size(), 15); - assertEquals(bucket.getCommonPrefixes().size(), 1); - } - - private void addAlphabetUnderRoot(String bucketName) - throws InterruptedException, ExecutionException, TimeoutException { - for (char letter = 'a'; letter <= 'z'; letter++) { - client.putObject(bucketName, - new S3Object(letter + "", letter + "content")).get(10, - TimeUnit.SECONDS); - } - } - - @Test - void testListBucketMarker() throws InterruptedException, - ExecutionException, TimeoutException, UnsupportedEncodingException { - addAlphabetUnderRoot(bucketName); - S3Bucket bucket = client.listBucket(bucketName, afterMarker("y")).get( - 10, TimeUnit.SECONDS); - assertEquals(bucket.getMarker(), "y"); - assert !bucket.isTruncated(); - assertEquals(bucket.getContents().size(), 1); - } - - @Test - void testListBucketMaxResults() throws InterruptedException, - ExecutionException, TimeoutException, UnsupportedEncodingException { - addAlphabetUnderRoot(bucketName); - S3Bucket bucket = client.listBucket(bucketName, maxResults(5)).get(10, - TimeUnit.SECONDS); - assertEquals(bucket.getMaxKeys(), 5); - assert bucket.isTruncated(); - assertEquals(bucket.getContents().size(), 5); - } - - @Test() - void testListBucketPrefix() throws InterruptedException, - ExecutionException, TimeoutException, UnsupportedEncodingException { - String prefix = "apps"; - addTenObjectsUnderPrefix(bucketName, prefix); - add15UnderRoot(bucketName); - - S3Bucket bucket = client.listBucket(bucketName, withPrefix("apps/")) - .get(10, TimeUnit.SECONDS); - assert !bucket.isTruncated(); - assertEquals(bucket.getContents().size(), 10); - assertEquals(bucket.getPrefix(), "apps/"); - - } - - @Test() - void testListBucket() throws InterruptedException, - ExecutionException, TimeoutException, UnsupportedEncodingException { - String prefix = "apps"; - addTenObjectsUnderPrefix(bucketName, prefix); - S3Bucket bucket = client.listBucket(bucketName) - .get(10, TimeUnit.SECONDS); - assertEquals(bucket.getContents().size(), 10); - } - - private void add15UnderRoot(String bucketName) throws InterruptedException, - ExecutionException, TimeoutException { - for (int i = 0; i < 15; i++) - client.putObject(bucketName, new S3Object(i + "", i + "content")) - .get(10, TimeUnit.SECONDS); - } - - private void addTenObjectsUnderPrefix(String bucketName, String prefix) - throws InterruptedException, ExecutionException, TimeoutException { - for (int i = 0; i < 10; i++) - client.putObject(bucketName, - new S3Object(prefix + "/" + i, i + "content")).get(10, - TimeUnit.SECONDS); - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/ListOwnedBucketsIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/ListOwnedBucketsIntegrationTest.java deleted file mode 100644 index 843d05be9f..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/ListOwnedBucketsIntegrationTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.testng.annotations.Test; - -import java.util.List; -import java.util.concurrent.TimeUnit; - -/** - * Tests integrated functionality of all listOwnedBucket commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(groups = {"integration", "live"}, testName = "s3.ListOwnedBucketsIntegrationTest") -public class ListOwnedBucketsIntegrationTest extends S3IntegrationTest { - - @Test() - void bucketDoesntExist() throws Exception { - String bucketName = bucketPrefix + "shouldntexist"; - List list = client.listOwnedBuckets().get(10, - TimeUnit.SECONDS); - assert !list.contains(new S3Bucket(bucketName)); - } - - @Test() - void bucketExists() throws Exception { - String bucketName = bucketPrefix + "needstoexist"; - assert client.putBucketIfNotExists(bucketName) - .get(10, TimeUnit.SECONDS); - List list = client.listOwnedBuckets().get(10, - TimeUnit.SECONDS); - S3Bucket.Metadata firstBucket = list.get(0); - S3Bucket.Metadata toMatch = new S3Bucket.Metadata(bucketName); - toMatch.setOwner(firstBucket.getOwner()); - - assert list.contains(toMatch); - } -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/PutBucketLiveTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/PutBucketLiveTest.java deleted file mode 100644 index 4edd59744e..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/PutBucketLiveTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import static org.jclouds.aws.s3.commands.options.PutBucketOptions.Builder.createIn; -import static org.jclouds.aws.s3.commands.options.PutBucketOptions.Builder.withBucketAcl; -import org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.util.S3Utils; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.net.URL; -import java.util.concurrent.TimeUnit; - -/** - * Tests integrated functionality of all PutBucket commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(testName = "s3.PutBucketLiveTest") -public class PutBucketLiveTest extends S3IntegrationTest { - - /** - * overriding bucketName as we are changing access permissions - */ - @Test(groups = {"live"}) - void testPublicReadAccessPolicy() throws Exception { - String bucketName = bucketPrefix + "public"; - - client.putBucketIfNotExists(bucketName, - withBucketAcl(CannedAccessPolicy.PUBLIC_READ)).get(10, - TimeUnit.SECONDS); - URL url = new URL(String.format("http://%1$s.s3.amazonaws.com", - bucketName)); - S3Utils.toStringAndClose(url.openStream()); - } - - @Test(expectedExceptions = IOException.class, groups = {"live"}) - void testDefaultAccessPolicy() throws Exception { - URL url = new URL(String.format("http://%1$s.s3.amazonaws.com", - bucketName)); - S3Utils.toStringAndClose(url.openStream()); - } - - /** - * overriding bucketName as we are changing location - */ - @Test(groups = "live") - void testEu() throws Exception { - String bucketName = (bucketPrefix + "wow").toLowerCase(); - client.putBucketIfNotExists( - bucketName, - createIn(LocationConstraint.EU).withBucketAcl( - CannedAccessPolicy.PUBLIC_READ)).get(10, - TimeUnit.SECONDS); - - URL url = new URL(String.format("http://%1$s.s3.amazonaws.com", - bucketName)); - S3Utils.toStringAndClose(url.openStream()); - } -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/PutObjectIntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/PutObjectIntegrationTest.java deleted file mode 100644 index 18a4f02280..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/PutObjectIntegrationTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.S3IntegrationTest; -import static org.jclouds.aws.s3.commands.options.PutBucketOptions.Builder.withBucketAcl; -import static org.jclouds.aws.s3.commands.options.PutObjectOptions.Builder.withAcl; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.aws.s3.util.S3Utils; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.concurrent.TimeUnit; - - -/** - * Tests integrated functionality of all PutObject commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(testName = "s3.PutObjectIntegrationTest") -public class PutObjectIntegrationTest extends S3IntegrationTest { - @DataProvider(name = "putTests") - public Object[][] createData1() throws IOException { - - String realObject = IOUtils.toString(new FileInputStream("pom.xml")); - - return new Object[][]{ - {"file", "text/xml", new File("pom.xml"), realObject}, - {"string", "text/xml", realObject, realObject}, - {"bytes", "application/octet-stream", realObject.getBytes(), - realObject}}; - } - - @Test(dataProvider = "putTests", groups = {"integration", "live"}) - void testPutObject(String key, String type, Object content, - Object realObject) throws Exception { - String bucketName = bucketPrefix + "tpo"; - client.putBucketIfNotExists(bucketName).get(10, TimeUnit.SECONDS); - context.createS3ObjectMap(bucketName).clear(); - assertEquals(client.listBucket(bucketName).get(10, TimeUnit.SECONDS) - .getContents().size(), 0); - S3Object object = new S3Object(key); - object.getMetadata().setContentType(type); - object.setData(content); - if (content instanceof InputStream) { - object.generateMd5(); - } - assertNotNull(client.putObject(bucketName, object).get(10, - TimeUnit.SECONDS)); - object = client.getObject(bucketName, object.getKey()).get(10, - TimeUnit.SECONDS); - String returnedString = S3Utils.getContentAsStringAndClose(object); - assertEquals(returnedString, realObject); - assertEquals(client.listBucket(bucketName).get(10, TimeUnit.SECONDS) - .getContents().size(), 1); - } - - @Test(groups = {"integration", "live"}) - void testMetadata() throws Exception { - String bucketName = bucketPrefix + "tmd"; - createBucketAndEnsureEmpty(bucketName); - String key = "hello"; - - S3Object object = new S3Object(key, TEST_STRING); - object.getMetadata().setCacheControl("no-cache"); - object.getMetadata().setContentType("text/plain"); - object.getMetadata().setContentEncoding("x-compress"); - object.getMetadata().setSize(TEST_STRING.length()); - object.getMetadata().setContentDisposition( - "attachment; filename=hello.txt"); - object.getMetadata().getUserMetadata().put( - S3Headers.USER_METADATA_PREFIX + "adrian", "powderpuff"); - object.getMetadata().setMd5(S3Utils.md5(TEST_STRING.getBytes())); - - addObjectToBucket(bucketName, object); - S3Object newObject = validateContent(bucketName, key); - - // TODO.. why does this come back as binary/octetstring - assertEquals(newObject.getMetadata().getContentType(), - "binary/octet-stream"); - assertEquals(newObject.getMetadata().getContentEncoding(), "x-compress"); - assertEquals(newObject.getMetadata().getContentDisposition(), - "attachment; filename=hello.txt"); - assertEquals(newObject.getMetadata().getCacheControl(), "no-cache"); - assertEquals(newObject.getMetadata().getSize(), TEST_STRING.length()); - assertEquals(newObject.getMetadata().getUserMetadata().values() - .iterator().next(), "powderpuff"); - assertEquals(newObject.getMetadata().getMd5(), S3Utils.md5(TEST_STRING - .getBytes())); - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/PutObjectLiveTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/PutObjectLiveTest.java deleted file mode 100644 index 35e47c1e3c..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/PutObjectLiveTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import org.jclouds.aws.s3.S3IntegrationTest; -import static org.jclouds.aws.s3.commands.options.PutBucketOptions.Builder.withBucketAcl; -import static org.jclouds.aws.s3.commands.options.PutObjectOptions.Builder.withAcl; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.util.S3Utils; -import org.testng.annotations.Test; - -import java.net.URL; -import java.util.concurrent.TimeUnit; - - -/** - * Tests integrated functionality of all PutObject commands. - *

- * Each test uses a different bucket name, so it should be perfectly fine to run - * in parallel. - * - * @author Adrian Cole - */ -@Test(testName = "s3.PutObjectLiveTest") -public class PutObjectLiveTest extends S3IntegrationTest { - - - @Test(groups = {"live"}) - void testCannedAccessPolicyPublic() throws Exception { - String bucketName = bucketPrefix + "tcapp"; - createBucketAndEnsureEmpty(bucketName); - String key = "hello"; - - client.putBucketIfNotExists(bucketName, - withBucketAcl(CannedAccessPolicy.PUBLIC_READ)).get(10, - TimeUnit.SECONDS); - client.putObject(bucketName, new S3Object(key, TEST_STRING), - - withAcl(CannedAccessPolicy.PUBLIC_READ)).get(10, TimeUnit.SECONDS); - - URL url = new URL(String.format("http://%1$s.s3.amazonaws.com/%2$s", - bucketName, key)); - S3Utils.toStringAndClose(url.openStream()); - - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java deleted file mode 100644 index 029a9b1cfb..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.name.Names; -import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import org.jclouds.aws.s3.commands.config.S3CommandsModule; -import org.jclouds.aws.s3.commands.options.*; -import org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint; -import org.jclouds.aws.s3.domain.S3Object; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -@Test(groups = {"unit"}, testName = "s3.S3CommandFactoryTest") -public class S3CommandFactoryTest { - - Injector injector = null; - S3CommandFactory commandFactory = null; - - @BeforeMethod - void setUpInjector() { - injector = Guice.createInjector(new S3CommandsModule() { - @Override - protected void configure() { - bindConstant().annotatedWith( - Names.named("jclouds.http.address")).to("localhost"); - super.configure(); - } - }); - commandFactory = injector.getInstance(S3CommandFactory.class); - } - - @AfterMethod - void tearDownInjector() { - commandFactory = null; - injector = null; - } - - @Test - void testCreateCopyObject() { - assert commandFactory.createCopyObject("sourcebucket", "sourceObject", - "destbucket", "destObject", CopyObjectOptions.NONE) != null; - } - - @Test - void testCreateCopyObjectOptions() { - assert commandFactory.createCopyObject("sourcebucket", "sourceObject", - "destbucket", "destObject", new CopyObjectOptions()) != null; - } - - @Test - void testCreateDeleteBucket() { - assert commandFactory.createDeleteBucket("test") != null; - } - - @Test - void testCreateDeleteObject() { - assert commandFactory.createDeleteObject("test", "blah") != null; - } - - @Test - void testCreateHeadBucket() { - assert commandFactory.createHeadBucket("test") != null; - } - - @Test - void testCreatePutBucket() { - assert commandFactory.createPutBucket("test", PutBucketOptions.NONE) != null; - } - - @Test - void testCreatePutBucketOptions() { - assert commandFactory.createPutBucket("test", PutBucketOptions.Builder - .createIn(LocationConstraint.EU)) != null; - } - - @Test - void testCreatePutObject() { - S3Object.Metadata metadata = createMock(S3Object.Metadata.class); - S3Object object = new S3Object(metadata); - expect(metadata.getSize()).andReturn(4L).atLeastOnce(); - expect(metadata.getKey()).andReturn("rawr"); - expect(metadata.getContentType()).andReturn("text/xml").atLeastOnce(); - expect(metadata.getCacheControl()).andReturn("no-cache").atLeastOnce(); - expect(metadata.getContentDisposition()).andReturn("disposition") - .atLeastOnce(); - expect(metadata.getContentEncoding()).andReturn("encoding") - .atLeastOnce(); - expect(metadata.getMd5()).andReturn("encoding".getBytes()) - .atLeastOnce(); - Multimap userMdata = HashMultimap.create(); - expect(metadata.getUserMetadata()).andReturn(userMdata).atLeastOnce(); - - replay(metadata); - object.setData(""); - - assert commandFactory.createPutObject("test", object, - PutObjectOptions.NONE) != null; - } - - @Test - void testCreateGetObject() { - assert commandFactory.createGetObject("test", "blah", - GetObjectOptions.NONE) != null; - } - - @Test - void testCreateHeadMetadata() { - assert commandFactory.createHeadMetadata("test", "blah") != null; - } - - @Test - void testCreateListAllMyBuckets() { - assert commandFactory.createGetMetadataForOwnedBuckets() != null; - } - - @Test - void testCreateListBucket() { - assert commandFactory.createListBucket("test", ListBucketOptions.NONE) != null; - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java deleted file mode 100644 index e41efecdf5..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java +++ /dev/null @@ -1,202 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.PerformanceTest; -import org.jclouds.aws.s3.domain.CanonicalUser; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.util.S3Utils; -import org.jclouds.aws.s3.xml.CopyObjectHandler; -import org.jclouds.aws.s3.xml.ListBucketHandler; -import org.jclouds.aws.s3.xml.S3ParserFactory; -import org.jclouds.aws.s3.xml.config.S3ParserModule; -import org.jclouds.http.HttpException; -import org.jclouds.http.commands.callables.xml.ParseSax; -import org.joda.time.DateTime; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.xml.sax.SAXException; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; - -/** - * Tests parsing of S3 responses - * - * @author Adrian Cole - */ -@Test(groups = {"performance"}, testName = "s3.S3ParserTest") -public class S3ParserTest extends PerformanceTest { - Injector injector = null; - - public static final String listAllMyBucketsResultOn200 = "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0adrianjbosstest2009-03-12T02:00:07.000Zadrianjbosstest22009-03-12T02:00:09.000Z"; - - S3ParserFactory parserFactory = null; - - @BeforeMethod - protected void setUpInjector() { - injector = Guice.createInjector(new S3ParserModule()); - parserFactory = injector.getInstance(S3ParserFactory.class); - assert parserFactory != null; - } - - @AfterMethod - protected void tearDownInjector() { - parserFactory = null; - injector = null; - } - - @Test - void testParseListAllMyBucketsSerialResponseTime() throws HttpException { - for (int i = 0; i < LOOP_COUNT; i++) - runParseListAllMyBuckets(); - } - - private List runParseListAllMyBuckets() - throws HttpException { - return parserFactory.createListBucketsParser().parse( - IOUtils.toInputStream(listAllMyBucketsResultOn200)); - } - - @Test - void testParseListAllMyBucketsParallelResponseTime() - throws InterruptedException, ExecutionException { - CompletionService> completer = new ExecutorCompletionService>( - exec); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable>() { - public List call() throws IOException, - SAXException, HttpException { - return runParseListAllMyBuckets(); - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get() != null; - } - - @Test - public void testCanParseListAllMyBuckets() throws HttpException { - List s3Buckets = runParseListAllMyBuckets(); - S3Bucket.Metadata bucket1 = s3Buckets.get(0); - assert bucket1.getName().equals("adrianjbosstest"); - DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z"); - DateTime date1 = bucket1.getCreationDate(); - assert date1.equals(expectedDate1); - S3Bucket.Metadata bucket2 = s3Buckets.get(1); - assert bucket2.getName().equals("adrianjbosstest2"); - DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z"); - DateTime date2 = bucket2.getCreationDate(); - assert date2.equals(expectedDate2); - assert s3Buckets.size() == 2; - CanonicalUser owner = new CanonicalUser( - "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0"); - assert bucket1.getOwner().equals(owner); - assert bucket2.getOwner().equals(owner); - } - - public static final String listBucketResult = "adrianjbosstest1000false33662009-03-12T02:00:13.000Z"9d7bb64e8e18ee34eec06dd2cf37b766"136e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; - - public void testCanParseListBucketResult() throws HttpException, - UnsupportedEncodingException { - S3Bucket bucket = runParseListBucketResult(); - assert !bucket.isTruncated(); - assert bucket.getName().equals("adrianjbosstest"); - assert bucket.getContents().size() == 1; - S3Object.Metadata object = bucket.getContents().iterator().next(); - assert object.getKey().equals("3366"); - DateTime expected = new DateTime("2009-03-12T02:00:13.000Z"); - assert object.getLastModified().equals(expected) : String.format( - "expected %1$s, but got %1$s", expected, object - .getLastModified()); - assertEquals(S3Utils.toHexString(object.getMd5()), - "9d7bb64e8e18ee34eec06dd2cf37b766"); - assert object.getSize() == 136; - CanonicalUser owner = new CanonicalUser( - "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0"); - owner.setDisplayName("ferncam"); - assert object.getOwner().equals(owner); - assert object.getStorageClass().equals("STANDARD"); - } - - private S3Bucket runParseListBucketResult() throws HttpException { - ParseSax parser = parserFactory.createListBucketParser(); - ListBucketHandler handler = (ListBucketHandler) parser.getHandler(); - handler.setBucketName("adrianjbosstest"); - return parser.parse(IOUtils.toInputStream(listBucketResult)); - } - - public static final String successfulCopyObject200 = "2009-03-19T13:23:27.000Z\"92836a3ea45a6984d1b4d23a747d46bb\""; - - private S3Object.Metadata runParseCopyObjectResult() throws HttpException { - ParseSax parser = parserFactory - .createCopyObjectParser(); - CopyObjectHandler handler = (CopyObjectHandler) parser.getHandler(); - handler.setKey("adrianjbosstest"); - return parser.parse(IOUtils.toInputStream(successfulCopyObject200)); - } - - public void testCanParseCopyObjectResult() throws HttpException, - UnsupportedEncodingException { - S3Object.Metadata metadata = runParseCopyObjectResult(); - DateTime expected = new DateTime("2009-03-19T13:23:27.000Z"); - assertEquals(metadata.getLastModified(), expected); - assertEquals(S3Utils.toHexString(metadata.getMd5()), - "92836a3ea45a6984d1b4d23a747d46bb"); - assertEquals(metadata.getKey(), "adrianjbosstest"); - } - - @Test - void testParseListBucketResultSerialResponseTime() throws HttpException { - for (int i = 0; i < LOOP_COUNT; i++) - runParseListBucketResult(); - } - - @Test - void testParseListBucketResultParallelResponseTime() - throws InterruptedException, ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public S3Bucket call() throws IOException, SAXException, - HttpException { - return runParseListBucketResult(); - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get() != null; - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContentTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContentTest.java deleted file mode 100644 index 6277448f91..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContentTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.callables; - -import org.apache.commons.io.IOUtils; -import static org.easymock.classextension.EasyMock.*; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.domain.S3Object.Metadata; -import org.jclouds.http.HttpException; -import org.jclouds.http.HttpHeaders; -import org.jclouds.http.HttpResponse; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.ParseObjectFromHeadersAndHttpContentTest") -public class ParseObjectFromHeadersAndHttpContentTest { - ParseObjectFromHeadersAndHttpContent callable; - ParseMetadataFromHeaders metadataParser; - - @BeforeMethod - void setUp() { - metadataParser = createMock(ParseMetadataFromHeaders.class); - callable = new ParseObjectFromHeadersAndHttpContent(metadataParser); - } - - @AfterMethod - void tearDown() { - callable = null; - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testCall() throws HttpException { - HttpResponse response = createMock(HttpResponse.class); - expect(response.getStatusCode()).andReturn(409).atLeastOnce(); - expect(response.getContent()).andReturn(null); - replay(response); - callable.setResponse(response); - callable.call(); - } - - @Test - public void testParseContentLengthWhenContentRangeSet() - throws HttpException { - HttpResponse response = createMock(HttpResponse.class); - metadataParser.setResponse(response); - Metadata meta = createMock(Metadata.class); - expect(metadataParser.call()).andReturn(meta); - expect(meta.getSize()).andReturn(-1l); - meta.setSize(-1l); - expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH)) - .andReturn("10485760").atLeastOnce(); - expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_RANGE)) - .andReturn("0-10485759/20232760").atLeastOnce(); - meta.setSize(20232760l); - expect(meta.getSize()).andReturn(20232760l); - - expect(response.getStatusCode()).andReturn(200).atLeastOnce(); - expect(response.getContent()).andReturn(IOUtils.toInputStream("test")); - replay(response); - replay(metadataParser); - replay(meta); - - callable.setResponse(response); - S3Object object = callable.call(); - assertEquals(object.getContentLength(), 10485760); - assertEquals(object.getMetadata().getSize(), 20232760); - assertEquals(object.getContentRange(), "0-10485759/20232760"); - - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/options/CopyObjectOptionsTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/options/CopyObjectOptionsTest.java deleted file mode 100644 index b16c31baf9..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/options/CopyObjectOptionsTest.java +++ /dev/null @@ -1,331 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import static org.jclouds.aws.s3.commands.options.CopyObjectOptions.Builder.*; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.joda.time.DateTime; -import static org.testng.Assert.*; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; - -/** - * Tests possible uses of CopyObjectOptions and CopyObjectOptions.Builder.* - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.CopyObjectOptionsTest") -public class CopyObjectOptionsTest { - - private byte[] testBytes; - private DateTime now; - private String nowExpected; - private Multimap goodMeta; - private Multimap badMeta; - - @BeforeMethod - void setUp() { - goodMeta = HashMultimap.create(); - goodMeta.put("x-amz-meta-adrian", "foo"); - badMeta = HashMultimap.create(); - badMeta.put("x-google-meta-adrian", "foo"); - - now = new DateTime(); - nowExpected = new DateService().toHeaderString(now); - testBytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; - } - - @Test - void testGoodMetaStatic() { - CopyObjectOptions options = overrideMetadataWith(goodMeta); - assertGoodMeta(options); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testMetaNPE() { - overrideMetadataWith(null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testBadMeta() { - overrideMetadataWith(badMeta); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testBadMetaStatic() { - overrideMetadataWith(badMeta); - } - - private void assertGoodMeta(CopyObjectOptions options) { - assert options != null; - assert options.getMetadata() != null; - Multimap headers = options.buildRequestHeaders(); - assertEquals(headers.size(), 2); - assertEquals(headers.get( - "x-amz-metadata-directive").iterator().next(), - "REPLACE"); - assertEquals(options.getMetadata().size(), 1); - assertEquals(headers.get("x-amz-meta-adrian").iterator() - .next(), "foo"); - assertEquals(options.getMetadata().get("x-amz-meta-adrian").iterator() - .next(), "foo"); - } - - @Test - void testGoodMeta() { - CopyObjectOptions options = new CopyObjectOptions(); - options.overrideMetadataWith(goodMeta); - assertGoodMeta(options); - } - - @Test - public void testIfModifiedSince() { - CopyObjectOptions options = new CopyObjectOptions(); - options.ifSourceModifiedSince(now); - assertEquals(options.getIfModifiedSince(), nowExpected); - } - - @Test - public void testNullIfModifiedSince() { - CopyObjectOptions options = new CopyObjectOptions(); - assertNull(options.getIfModifiedSince()); - } - - @Test - public void testIfModifiedSinceStatic() { - CopyObjectOptions options = ifSourceModifiedSince(now); - assertEquals(options.getIfModifiedSince(), nowExpected); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfModifiedSinceNPE() { - ifSourceModifiedSince(null); - } - - @Test - public void testIfUnmodifiedSince() { - CopyObjectOptions options = new CopyObjectOptions(); - options.ifSourceUnmodifiedSince(now); - isNowExpected(options); - } - - @Test - public void testNullIfUnmodifiedSince() { - CopyObjectOptions options = new CopyObjectOptions(); - assertNull(options.getIfUnmodifiedSince()); - } - - @Test - public void testIfUnmodifiedSinceStatic() { - CopyObjectOptions options = ifSourceUnmodifiedSince(now); - isNowExpected(options); - } - - private void isNowExpected(CopyObjectOptions options) { - assertEquals(options.getIfUnmodifiedSince(), nowExpected); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfUnmodifiedSinceNPE() { - ifSourceUnmodifiedSince(null); - } - - @Test - public void testIfMd5Matches() throws UnsupportedEncodingException { - CopyObjectOptions options = new CopyObjectOptions(); - options.ifSourceMd5Matches(testBytes); - matchesHex(options.getIfMatch()); - } - - @Test - public void testNullIfMd5Matches() { - CopyObjectOptions options = new CopyObjectOptions(); - assertNull(options.getIfMatch()); - } - - @Test - public void testIfMd5MatchesStatic() throws UnsupportedEncodingException { - CopyObjectOptions options = ifSourceMd5Matches(testBytes); - matchesHex(options.getIfMatch()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfMd5MatchesNPE() throws UnsupportedEncodingException { - ifSourceMd5Matches(null); - } - - @Test - public void testIfMd5DoesntMatch() throws UnsupportedEncodingException { - CopyObjectOptions options = new CopyObjectOptions(); - options.ifSourceMd5DoesntMatch(testBytes); - matchesHex(options.getIfNoneMatch()); - } - - @Test - public void testNullIfMd5DoesntMatch() { - CopyObjectOptions options = new CopyObjectOptions(); - assertNull(options.getIfNoneMatch()); - } - - @Test - public void testIfMd5DoesntMatchStatic() - throws UnsupportedEncodingException { - CopyObjectOptions options = ifSourceMd5DoesntMatch(testBytes); - matchesHex(options.getIfNoneMatch()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfMd5DoesntMatchNPE() throws UnsupportedEncodingException { - ifSourceMd5DoesntMatch(null); - } - - private void matchesHex(String match) throws UnsupportedEncodingException { - String expected = "\"" + S3Utils.toHexString(testBytes) + "\""; - assertEquals(match, expected); - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testIfUnmodifiedAfterModified() { - ifSourceModifiedSince(now).ifSourceUnmodifiedSince(now); - - } - - public void testIfUnmodifiedAfterMd5Matches() - throws UnsupportedEncodingException { - ifSourceMd5Matches(testBytes).ifSourceUnmodifiedSince(now); - - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testIfUnmodifiedAfterMd5DoesntMatch() - throws UnsupportedEncodingException { - ifSourceMd5DoesntMatch(testBytes).ifSourceUnmodifiedSince(now); - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testIfModifiedAfterUnmodified() { - ifSourceUnmodifiedSince(now).ifSourceModifiedSince(now); - - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testIfModifiedAfterMd5Matches() - throws UnsupportedEncodingException { - ifSourceMd5Matches(testBytes).ifSourceModifiedSince(now); - - } - - public void testIfModifiedAfterMd5DoesntMatch() - throws UnsupportedEncodingException { - ifSourceMd5DoesntMatch(testBytes).ifSourceModifiedSince(now); - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testMd5MatchesAfterIfModified() - throws UnsupportedEncodingException { - ifSourceModifiedSince(now).ifSourceMd5Matches(testBytes); - - } - - public void testMd5MatchesAfterIfUnmodified() - throws UnsupportedEncodingException { - ifSourceUnmodifiedSince(now).ifSourceMd5Matches(testBytes); - - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testMd5MatchesAfterMd5DoesntMatch() - throws UnsupportedEncodingException { - ifSourceMd5DoesntMatch(testBytes).ifSourceMd5Matches(testBytes); - } - - public void testMd5DoesntMatchAfterIfModified() - throws UnsupportedEncodingException { - ifSourceModifiedSince(now).ifSourceMd5DoesntMatch(testBytes); - - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testMd5DoesntMatchAfterIfUnmodified() - throws UnsupportedEncodingException { - ifSourceUnmodifiedSince(now).ifSourceMd5DoesntMatch(testBytes); - - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testMd5DoesntMatchAfterMd5Matches() - throws UnsupportedEncodingException { - ifSourceMd5Matches(testBytes).ifSourceMd5DoesntMatch(testBytes); - } - - @Test - void testBuildRequestHeadersWhenMetadataNull() - throws UnsupportedEncodingException { - assert new CopyObjectOptions().buildRequestHeaders() != null; - } - - @Test - void testBuildRequestHeaders() throws UnsupportedEncodingException { - - Multimap headers = ifSourceModifiedSince(now) - .ifSourceMd5DoesntMatch(testBytes).overrideMetadataWith( - goodMeta).buildRequestHeaders(); - assertEquals(headers.get("x-amz-copy-source-if-modified-since") - .iterator().next(), new DateService().toHeaderString(now)); - assertEquals(headers.get("x-amz-copy-source-if-none-match").iterator() - .next(), "\"" + S3Utils.toHexString(testBytes) + "\""); - for (String value : goodMeta.values()) - assertTrue(headers.containsValue(value)); - - } - - - @Test - public void testAclDefault() { - CopyObjectOptions options = new CopyObjectOptions(); - assertEquals(options.getAcl(), CannedAccessPolicy.PRIVATE); - } - - @Test - public void testAclStatic() { - CopyObjectOptions options = overrideAcl(CannedAccessPolicy.AUTHENTICATED_READ); - assertEquals(options.getAcl(), CannedAccessPolicy.AUTHENTICATED_READ); - } - - @Test - void testBuildRequestHeadersACL() throws UnsupportedEncodingException { - - Multimap headers = overrideAcl( - CannedAccessPolicy.AUTHENTICATED_READ).buildRequestHeaders(); - assertEquals(headers.get(S3Headers.CANNED_ACL).iterator().next(), - CannedAccessPolicy.AUTHENTICATED_READ.toString()); - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/options/GetObjectOptionsTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/options/GetObjectOptionsTest.java deleted file mode 100644 index 88eda9b97a..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/options/GetObjectOptionsTest.java +++ /dev/null @@ -1,334 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import static org.jclouds.aws.s3.commands.options.GetObjectOptions.Builder.*; -import org.jclouds.aws.s3.util.DateService; -import org.jclouds.aws.s3.util.S3Utils; -import org.joda.time.DateTime; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; - -/** - * Tests possible uses of GetObjectOptions and GetObjectOptions.Builder.* - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.GetObjectOptionsTest") -public class GetObjectOptionsTest { - - private byte[] testBytes; - private DateTime now; - private String nowExpected; - - @BeforeTest - void setUp() { - now = new DateTime(); - nowExpected = new DateService().toHeaderString(now); - testBytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; - } - - @Test - public void testIfModifiedSince() { - GetObjectOptions options = new GetObjectOptions(); - options.ifModifiedSince(now); - assertEquals(options.getIfModifiedSince(), nowExpected); - } - - @Test - public void testNullIfModifiedSince() { - GetObjectOptions options = new GetObjectOptions(); - assertNull(options.getIfModifiedSince()); - } - - @Test - public void testIfModifiedSinceStatic() { - GetObjectOptions options = ifModifiedSince(now); - assertEquals(options.getIfModifiedSince(), nowExpected); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfModifiedSinceNPE() { - ifModifiedSince(null); - } - - @Test - public void testIfUnmodifiedSince() { - GetObjectOptions options = new GetObjectOptions(); - options.ifUnmodifiedSince(now); - isNowExpected(options); - } - - @Test - public void testNullIfUnmodifiedSince() { - GetObjectOptions options = new GetObjectOptions(); - assertNull(options.getIfUnmodifiedSince()); - } - - @Test - public void testIfUnmodifiedSinceStatic() { - GetObjectOptions options = ifUnmodifiedSince(now); - isNowExpected(options); - } - - private void isNowExpected(GetObjectOptions options) { - assertEquals(options.getIfUnmodifiedSince(), nowExpected); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfUnmodifiedSinceNPE() { - ifUnmodifiedSince(null); - } - - public void testModifiedSinceAndRange() { - GetObjectOptions options = new GetObjectOptions(); - options.ifModifiedSince(now); - options.range(0, 1024); - assertEquals(options.getIfModifiedSince(), nowExpected); - bytes1to1024(options); - } - - @Test - public void testRange() { - GetObjectOptions options = new GetObjectOptions(); - options.range(0, 1024); - bytes1to1024(options); - } - - private void bytes1to1024(GetObjectOptions options) { - assertEquals(options.getRange(), "bytes=0-1024"); - } - - @Test - public void testRangeZeroToFive() { - GetObjectOptions options = new GetObjectOptions(); - options.range(0, 5); - assertEquals(options.getRange(), "bytes=0-5"); - } - - @Test - public void testTail() { - GetObjectOptions options = new GetObjectOptions(); - options.tail(100); - assertEquals(options.getRange(), "bytes=-100"); - } - - @Test - public void testTailStatic() { - GetObjectOptions options = tail(100); - assertEquals(options.getRange(), "bytes=-100"); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testTailFail() { - GetObjectOptions options = new GetObjectOptions(); - options.tail(0); - } - - @Test - public void testStartAt() { - GetObjectOptions options = new GetObjectOptions(); - options.startAt(100); - assertEquals(options.getRange(), "bytes=100-"); - } - - @Test - public void testStartAtStatic() { - GetObjectOptions options = startAt(100); - assertEquals(options.getRange(), "bytes=100-"); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testStartAtFail() { - GetObjectOptions options = new GetObjectOptions(); - options.startAt(-1); - } - - @Test - public void testRangeZeroToFiveAnd10through100() { - GetObjectOptions options = new GetObjectOptions(); - options.range(0, 5).range(10, 100); - assertEquals(options.getRange(), "bytes=0-5,10-100"); - } - - @Test - public void testNullRange() { - GetObjectOptions options = new GetObjectOptions(); - assertNull(options.getRange()); - } - - @Test - public void testRangeStatic() { - GetObjectOptions options = range(0, 1024); - bytes1to1024(options); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testRangeNegative1() { - range(-1, 0); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testRangeNegative2() { - range(0, -1); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testRangeNegative() { - range(-1, -1); - } - - @Test - public void testIfMd5Matches() throws UnsupportedEncodingException { - GetObjectOptions options = new GetObjectOptions(); - options.ifMd5Matches(testBytes); - matchesHex(options.getIfMatch()); - } - - @Test - public void testNullIfMd5Matches() { - GetObjectOptions options = new GetObjectOptions(); - assertNull(options.getIfMatch()); - } - - @Test - public void testIfMd5MatchesStatic() throws UnsupportedEncodingException { - GetObjectOptions options = ifMd5Matches(testBytes); - matchesHex(options.getIfMatch()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfMd5MatchesNPE() throws UnsupportedEncodingException { - ifMd5Matches(null); - } - - @Test - public void testIfMd5DoesntMatch() throws UnsupportedEncodingException { - GetObjectOptions options = new GetObjectOptions(); - options.ifMd5DoesntMatch(testBytes); - matchesHex(options.getIfNoneMatch()); - } - - @Test - public void testNullIfMd5DoesntMatch() { - GetObjectOptions options = new GetObjectOptions(); - assertNull(options.getIfNoneMatch()); - } - - @Test - public void testIfMd5DoesntMatchStatic() - throws UnsupportedEncodingException { - GetObjectOptions options = ifMd5DoesntMatch(testBytes); - matchesHex(options.getIfNoneMatch()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testIfMd5DoesntMatchNPE() throws UnsupportedEncodingException { - ifMd5DoesntMatch(null); - } - - private void matchesHex(String match) throws UnsupportedEncodingException { - String expected = "\"" + S3Utils.toHexString(testBytes) + "\""; - assertEquals(match, expected); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testIfUnmodifiedAfterModified() { - ifModifiedSince(now).ifUnmodifiedSince(now); - - } - - public void testIfUnmodifiedAfterMd5Matches() - throws UnsupportedEncodingException { - ifMd5Matches(testBytes).ifUnmodifiedSince(now); - - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testIfUnmodifiedAfterMd5DoesntMatch() - throws UnsupportedEncodingException { - ifMd5DoesntMatch(testBytes).ifUnmodifiedSince(now); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testIfModifiedAfterUnmodified() { - ifUnmodifiedSince(now).ifModifiedSince(now); - - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testIfModifiedAfterMd5Matches() - throws UnsupportedEncodingException { - ifMd5Matches(testBytes).ifModifiedSince(now); - - } - - public void testIfModifiedAfterMd5DoesntMatch() - throws UnsupportedEncodingException { - ifMd5DoesntMatch(testBytes).ifModifiedSince(now); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testMd5MatchesAfterIfModified() - throws UnsupportedEncodingException { - ifModifiedSince(now).ifMd5Matches(testBytes); - - } - - public void testMd5MatchesAfterIfUnmodified() - throws UnsupportedEncodingException { - ifUnmodifiedSince(now).ifMd5Matches(testBytes); - - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testMd5MatchesAfterMd5DoesntMatch() - throws UnsupportedEncodingException { - ifMd5DoesntMatch(testBytes).ifMd5Matches(testBytes); - } - - public void testMd5DoesntMatchAfterIfModified() - throws UnsupportedEncodingException { - ifModifiedSince(now).ifMd5DoesntMatch(testBytes); - - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testMd5DoesntMatchAfterIfUnmodified() - throws UnsupportedEncodingException { - ifUnmodifiedSince(now).ifMd5DoesntMatch(testBytes); - - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testMd5DoesntMatchAfterMd5Matches() - throws UnsupportedEncodingException { - ifMd5Matches(testBytes).ifMd5DoesntMatch(testBytes); - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/options/ListBucketOptionsTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/options/ListBucketOptionsTest.java deleted file mode 100644 index 88e5b432fb..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/options/ListBucketOptionsTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.aws.s3.commands.options.ListBucketOptions.Builder.*; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import java.io.UnsupportedEncodingException; - -import org.jclouds.http.options.HttpRequestOptions; -import org.testng.annotations.Test; - -/** - * Tests possible uses of ListBucketOptions and ListBucketOptions.Builder.* - * - * @author Adrian Cole - */ -public class ListBucketOptionsTest { - - @Test - public void testPrefix() throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - options.withPrefix("test"); - assertEquals(options.getPrefix(), "test"); - } - - @Test - public void testNoOptionsQueryString() { - HttpRequestOptions options = new ListBucketOptions(); - assertEquals(options.buildQueryString(), ""); - } - - @Test - public void testOneOptionQueryString() throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - options.withPrefix("test"); - assertEquals(options.buildQueryString(), "?prefix=test"); - } - - @Test - public void testTwoOptionQueryString() throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - options.withPrefix("test").maxResults(1); - String query = options.buildQueryString(); - checkQuery(query); - checkQuery(checkNotNull(query)); - - } - - private void checkQuery(String query) { - try { - assertEquals(query, "?prefix=test&max-keys=1"); - } catch (AssertionError e) { - assertEquals(query, "?max-keys=1&prefix=test"); - } - } - - @Test - public void testPrefixAndDelimiterUrlEncodingQueryString() - throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - options.withPrefix("/test").delimiter("/"); - String query = options.buildQueryString(); - checkEncodedQuery(query); - checkEncodedQuery(checkNotNull(query)); - - } - - private void checkEncodedQuery(String query) { - try { - assertEquals(query, "?prefix=%2Ftest&delimiter=%2F"); - } catch (AssertionError e) { - assertEquals(query, "?delimiter=%2F&prefix=%2Ftest"); - } - } - - @Test - public void testNullPrefix() { - ListBucketOptions options = new ListBucketOptions(); - assertNull(options.getPrefix()); - } - - @Test - public void testPrefixStatic() throws UnsupportedEncodingException { - ListBucketOptions options = withPrefix("test"); - assertEquals(options.getPrefix(), "test"); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testPrefixNPE() throws UnsupportedEncodingException { - withPrefix(null); - } - - @Test - public void testMarker() throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - options.afterMarker("test"); - assertEquals(options.getMarker(), "test"); - } - - @Test - public void testNullMarker() { - ListBucketOptions options = new ListBucketOptions(); - assertNull(options.getMarker()); - } - - @Test - public void testMarkerStatic() throws UnsupportedEncodingException { - ListBucketOptions options = afterMarker("test"); - assertEquals(options.getMarker(), "test"); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testMarkerNPE() throws UnsupportedEncodingException { - afterMarker(null); - } - - @Test - public void testMaxKeys() { - ListBucketOptions options = new ListBucketOptions(); - options.maxResults(1000); - assertEquals(options.getMaxKeys(), "1000"); - } - - @Test - public void testNullMaxKeys() { - ListBucketOptions options = new ListBucketOptions(); - assertNull(options.getMaxKeys()); - } - - @Test - public void testMaxKeysStatic() { - ListBucketOptions options = maxResults(1000); - assertEquals(options.getMaxKeys(), "1000"); - } - - @Test(expectedExceptions = IllegalStateException.class) - public void testMaxKeysNegative() { - maxResults(-1); - } - - @Test - public void testDelimiter() throws UnsupportedEncodingException { - ListBucketOptions options = new ListBucketOptions(); - options.delimiter("test"); - assertEquals(options.getDelimiter(), "test"); - } - - @Test - public void testNullDelimiter() { - ListBucketOptions options = new ListBucketOptions(); - assertNull(options.getDelimiter()); - } - - @Test - public void testDelimiterStatic() throws UnsupportedEncodingException { - ListBucketOptions options = delimiter("test"); - assertEquals(options.getDelimiter(), "test"); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testDelimiterNPE() throws UnsupportedEncodingException { - delimiter(null); - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/options/PutBucketOptionsTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/options/PutBucketOptionsTest.java deleted file mode 100644 index 30a010839d..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/options/PutBucketOptionsTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import com.google.common.collect.Multimap; -import static org.jclouds.aws.s3.commands.options.PutBucketOptions.Builder.createIn; -import static org.jclouds.aws.s3.commands.options.PutBucketOptions.Builder.withBucketAcl; -import org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; - -/** - * Tests possible uses of PutBucketOptions and PutBucketOptions.Builder.* - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.PutBucketOptionsTest") -public class PutBucketOptionsTest { - - @Test - public void testLocationConstraint() { - PutBucketOptions options = new PutBucketOptions(); - options.createIn(LocationConstraint.EU); - assertEquals(options.getLocationConstraint(), LocationConstraint.EU); - } - - @Test - public void testPayload() { - PutBucketOptions options = new PutBucketOptions(); - options.createIn(LocationConstraint.EU); - assertEquals( - options.buildPayload(), - "EU"); - } - - @Test - public void testNullLocationConstraint() { - PutBucketOptions options = new PutBucketOptions(); - assertNull(options.getLocationConstraint()); - } - - @Test - public void testLocationConstraintStatic() { - PutBucketOptions options = createIn(LocationConstraint.EU); - assertEquals(options.getLocationConstraint(), LocationConstraint.EU); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testNPE() { - createIn(null); - } - - @Test - public void testAclDefault() { - PutBucketOptions options = new PutBucketOptions(); - assertEquals(options.getAcl(), CannedAccessPolicy.PRIVATE); - } - - @Test - public void testAclStatic() { - PutBucketOptions options = withBucketAcl(CannedAccessPolicy.AUTHENTICATED_READ); - assertEquals(options.getAcl(), CannedAccessPolicy.AUTHENTICATED_READ); - } - - @Test - void testBuildRequestHeaders() throws UnsupportedEncodingException { - - Multimap headers = withBucketAcl( - CannedAccessPolicy.AUTHENTICATED_READ).buildRequestHeaders(); - assertEquals(headers.get(S3Headers.CANNED_ACL).iterator().next(), - CannedAccessPolicy.AUTHENTICATED_READ.toString()); - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/options/PutObjectOptionsTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/options/PutObjectOptionsTest.java deleted file mode 100644 index 49f9bd78ea..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/options/PutObjectOptionsTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands.options; - -import com.google.common.collect.Multimap; -import static org.jclouds.aws.s3.commands.options.PutObjectOptions.Builder.withAcl; -import org.jclouds.aws.s3.domain.acl.CannedAccessPolicy; -import org.jclouds.aws.s3.reference.S3Headers; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; - -/** - * Tests possible uses of PutObjectOptions and PutObjectOptions.Builder.* - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.PutObjectOptionsTest") -public class PutObjectOptionsTest { - - @Test - public void testAclDefault() { - PutObjectOptions options = new PutObjectOptions(); - assertEquals(options.getAcl(), CannedAccessPolicy.PRIVATE); - } - - @Test - public void testAclStatic() { - PutObjectOptions options = withAcl(CannedAccessPolicy.AUTHENTICATED_READ); - assertEquals(options.getAcl(), CannedAccessPolicy.AUTHENTICATED_READ); - } - - @Test - void testBuildRequestHeaders() throws UnsupportedEncodingException { - - Multimap headers = withAcl( - CannedAccessPolicy.AUTHENTICATED_READ).buildRequestHeaders(); - assertEquals(headers.get(S3Headers.CANNED_ACL).iterator().next(), - CannedAccessPolicy.AUTHENTICATED_READ.toString()); - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/config/S3ContextModuleTest.java b/s3/src/test/java/org/jclouds/aws/s3/config/S3ContextModuleTest.java deleted file mode 100644 index c67711dc8c..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/config/S3ContextModuleTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.config; - -import com.google.inject.Guice; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.name.Names; -import org.jclouds.aws.s3.handlers.ParseS3ErrorFromXmlContent; -import org.jclouds.aws.s3.reference.S3Constants; -import org.jclouds.http.HttpResponseHandler; -import org.jclouds.http.annotation.ClientErrorHandler; -import org.jclouds.http.annotation.RedirectHandler; -import org.jclouds.http.annotation.ServerErrorHandler; -import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; -import org.jclouds.http.handlers.CloseContentAndSetExceptionHandler; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.S3ContextModuleTest") -public class S3ContextModuleTest { - - Injector injector = null; - - @BeforeMethod - void setUpInjector() { - injector = Guice.createInjector(new LiveS3ConnectionModule(), new S3ContextModule() { - @Override - protected void configure() { - bindConstant().annotatedWith( - Names.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to( - "localhost"); - bindConstant().annotatedWith( - Names.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)) - .to("localhost"); - bindConstant().annotatedWith( - Names.named(S3Constants.PROPERTY_HTTP_ADDRESS)).to( - "localhost"); - bindConstant().annotatedWith( - Names.named(S3Constants.PROPERTY_HTTP_PORT)).to("1000"); - bindConstant().annotatedWith( - Names.named(S3Constants.PROPERTY_HTTP_SECURE)).to( - "false"); - super.configure(); - } - }, new JavaUrlHttpFutureCommandClientModule()); - } - - @AfterMethod - void tearDownInjector() { - injector = null; - } - - private static class ClientErrorHandlerTest { - @Inject - @ClientErrorHandler - HttpResponseHandler errorHandler; - } - - @Test - void testClientErrorHandler() { - ClientErrorHandlerTest error = injector - .getInstance(ClientErrorHandlerTest.class); - assertEquals(error.errorHandler.getClass(), - ParseS3ErrorFromXmlContent.class); - } - - private static class ServerErrorHandlerTest { - @Inject - @ServerErrorHandler - HttpResponseHandler errorHandler; - } - - @Test - void testServerErrorHandler() { - ServerErrorHandlerTest error = injector - .getInstance(ServerErrorHandlerTest.class); - assertEquals(error.errorHandler.getClass(), - ParseS3ErrorFromXmlContent.class); - } - - private static class RedirectHandlerTest { - @Inject - @RedirectHandler - HttpResponseHandler errorHandler; - } - - @Test - void testRedirectHandler() { - RedirectHandlerTest error = injector - .getInstance(RedirectHandlerTest.class); - assertEquals(error.errorHandler.getClass(), - CloseContentAndSetExceptionHandler.class); - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/config/StubS3ConnectionModule.java b/s3/src/test/java/org/jclouds/aws/s3/config/StubS3ConnectionModule.java deleted file mode 100644 index f26095ff9f..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/config/StubS3ConnectionModule.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.jclouds.aws.s3.config; - -import com.google.inject.AbstractModule; -import org.jclouds.aws.s3.S3Connection; -import org.jclouds.aws.s3.StubS3Connection; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -@S3ConnectionModule -public class StubS3ConnectionModule extends AbstractModule { - protected void configure() { - bind(S3Connection.class).to(StubS3Connection.class); - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java b/s3/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java deleted file mode 100644 index 9cfc69254b..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.domain; - -import org.jclouds.http.ContentTypes; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -import java.io.File; - -@Test(groups = "unit", testName = "s3.S3ObjectTest") -public class S3ObjectTest { - - @Test - void testSetNoContentType() { - S3Object object = new S3Object("test"); - File file = new File("hello.txt"); - object.setData(file); - assertEquals(object.getMetadata().getContentType(), - ContentTypes.BINARY); - } -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java b/s3/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java deleted file mode 100644 index f0b49c1515..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/filters/RequestAuthorizeSignatureTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.filters; - -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.name.Names; -import org.jclouds.aws.s3.reference.S3Constants; -import org.jclouds.aws.s3.util.DateService; -import org.testng.annotations.Test; - - -@Test(groups = "unit", testName = "s3.RequestAuthorizeSignatureTest") -public class RequestAuthorizeSignatureTest { - - RequestAuthorizeSignature filter = null; - - @Test - void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException { - filter = Guice.createInjector(new AbstractModule() { - - protected void configure() { - bindConstant().annotatedWith(Names.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to("foo"); - bindConstant().annotatedWith(Names.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY)).to("bar"); - bind(DateService.class); - - } - }).getInstance(RequestAuthorizeSignature.class); -// filter.createNewStamp(); - String timeStamp = filter.timestampAsHeaderString(); -// replay(filter); - for (int i = 0; i < 10; i++) - filter.updateIfTimeOut(); - assert timeStamp.equals(filter.timestampAsHeaderString()); - Thread.sleep(1000); - assert !timeStamp.equals(filter.timestampAsHeaderString()); -// verify(filter); - } - - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/xml/BaseHandlerTest.java b/s3/src/test/java/org/jclouds/aws/s3/xml/BaseHandlerTest.java deleted file mode 100644 index 6bf6bc5cbc..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/xml/BaseHandlerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import org.jclouds.aws.s3.xml.config.S3ParserModule; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; - -public class BaseHandlerTest { - - protected S3ParserFactory parserFactory = null; - private Injector injector; - - public BaseHandlerTest() { - super(); - } - - @BeforeMethod - protected void setUpInjector() { - injector = Guice.createInjector(new S3ParserModule()); - parserFactory = injector.getInstance(S3ParserFactory.class); - assert parserFactory != null; - } - - @AfterMethod - protected void tearDownInjector() { - parserFactory = null; - injector = null; - } - -} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/xml/ErrorHandlerTest.java b/s3/src/test/java/org/jclouds/aws/s3/xml/ErrorHandlerTest.java deleted file mode 100644 index 3c9e7e9b67..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/xml/ErrorHandlerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.domain.S3Error; -import org.jclouds.http.HttpException; -import org.jclouds.http.commands.callables.xml.ParseSax; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "s3.ErrorHandlerTest") -public class ErrorHandlerTest extends BaseHandlerTest { - public static final String errorFromAmazonIfYouDontRemoveTransferEncodingHeader = "NotImplementedA header you provided implies functionality that is not implemented

Transfer-Encoding
7C59925D75D15561fbskVU51OZJg2yZS/wNIxoE2PmCf0ZqFd0iH6Vrzw0uKG3KmokswBytL/Bfp/GWb

- * This allows you to acces the underlying {@link S3Object} so that you can - * manually set metadata such as length, content-type, or md5 hash. - * - * @author Adrian Cole - * - */ -public interface S3ObjectMap extends S3Map { - -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3ResponseException.java b/s3/src/main/java/org/jclouds/aws/s3/S3ResponseException.java deleted file mode 100644 index 1746cff4e2..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/S3ResponseException.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3; - -import org.jclouds.aws.s3.domain.S3Error; -import org.jclouds.http.HttpFutureCommand; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; - -/** - * Encapsulates an S3 Error from Amazon. - * - * @see - * @see S3Error - * @see org.jclouds.aws.s3.handlers.ParseS3ErrorFromXmlContent - * @author Adrian Cole - * - */ -public class S3ResponseException extends HttpResponseException { - - private static final long serialVersionUID = 1L; - - private S3Error error = new S3Error(); - - public S3ResponseException(HttpFutureCommand command, - HttpResponse response, S3Error error) { - super(error.toString(), command, response); - this.setError(error); - - } - - public S3ResponseException(HttpFutureCommand command, - HttpResponse response, S3Error error, Throwable cause) { - super(error.toString(), command, response, cause); - this.setError(error); - - } - - public S3ResponseException(String message, HttpFutureCommand command, - HttpResponse response, S3Error error) { - super(message, command, response); - this.setError(error); - - } - - public S3ResponseException(String message, HttpFutureCommand command, - HttpResponse response, S3Error error, Throwable cause) { - super(message, command, response, cause); - this.setError(error); - - } - - public void setError(S3Error error) { - this.error = error; - } - - public S3Error getError() { - return error; - } - -} diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/BucketExists.java b/s3/src/main/java/org/jclouds/aws/s3/commands/BucketExists.java deleted file mode 100644 index ae77b641b2..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/BucketExists.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import static org.jclouds.aws.s3.commands.options.ListBucketOptions.Builder.maxResults; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.http.HttpResponseException; -import org.jclouds.http.commands.callables.ReturnTrueIf2xx; - -import com.google.common.annotations.VisibleForTesting; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * Issues a HEAD command to determine if the bucket exists or not. - * - * @author Adrian Cole - * - */ -public class BucketExists extends S3FutureCommand { - - @Inject - public BucketExists(@Named("jclouds.http.address") String amazonHost, - ReturnTrueIf2xx callable, @Assisted String s3Bucket) { - super("HEAD", "/" + maxResults(0).buildQueryString(), callable, - amazonHost, s3Bucket); - } - - @Override - public Boolean get() throws InterruptedException, ExecutionException { - try { - return super.get(); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } - - @VisibleForTesting - Boolean attemptNotFound(ExecutionException e) throws ExecutionException { - if (e.getCause() != null - && e.getCause() instanceof HttpResponseException) { - HttpResponseException responseException = (HttpResponseException) e - .getCause(); - if (responseException.getResponse().getStatusCode() == 404) { - return false; - } - } - throw e; - } - - @Override - public Boolean get(long l, TimeUnit timeUnit) throws InterruptedException, - ExecutionException, TimeoutException { - try { - return super.get(l, timeUnit); - } catch (ExecutionException e) { - return attemptNotFound(e); - } - } -} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/CopyObject.java b/s3/src/main/java/org/jclouds/aws/s3/commands/CopyObject.java deleted file mode 100644 index f2eb938570..0000000000 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/CopyObject.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.commands; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.aws.s3.commands.options.CopyObjectOptions; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.xml.CopyObjectHandler; -import org.jclouds.http.commands.callables.xml.ParseSax; - -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; - -/** - * The copy operation creates a copy of an object that is already storedin - * Amazon S3. - *

"; - - @Test - public void testErrorFromAmazonIfYouDontRemoveTransferEncodingHeader() - throws HttpException { - ParseSax parser = parserFactory.createErrorParser(); - S3Error error = parser - .parse(IOUtils - .toInputStream(errorFromAmazonIfYouDontRemoveTransferEncodingHeader)); - assertEquals(error.getCode(), "NotImplemented"); - assertEquals(error.getMessage(), - "A header you provided implies functionality that is not implemented"); - assertEquals(error.getDetails().get("Header"), "Transfer-Encoding"); - assertEquals(error.getRequestId(), "7C59925D75D15561"); - assertEquals(error.getDetails().get("HostId"), - "fbskVU51OZJg2yZS/wNIxoE2PmCf0ZqFd0iH6Vrzw0uKG3KmokswBytL/Bfp/GWb"); - } - - public static final String badRequestWhenSourceIsDestBucketOnCopy400 = "InvalidRequestThe Source and Destination may not be the same when the MetadataDirective is Copy.54C77CAF4D42474BSJecknEUUUx88/65VAKbCdKSOCkpuVTeu7ZG9in9x9NTNglGnoxdbALCfS4k/DUZ"; - public static final String noSuchSourceKeyOrBucketOnCopy404 = "NoSuchKeyThe specified key does not exist.null9CCDF1DACA78B36F63cqk9YsTFBVfBfks840JVGsepPEdQM42mU+r7HN35sF4Nk5xAcWDEUPaQpK2eFU"; - public static final String noSuchDestinationBucketOnCopy404 = "NoSuchBucketThe specified bucketName does not existcopydestination4F0CF319C5535975hdZyHOm7VK+JI2UCdye3d6TVkKhRBIoWflldXVDTKbgipYlamy8HgPBzHrUAVQNJ"; - public static final String badSign403 = "\n" - + "SignatureDoesNotMatchThe operation signature we calculated does not match the signature you provided. Check your key and signing method.47 45 54 0a 0a 0a 54 68 75 2c 20 31 39 20 4d 61 72 20 32 30 30 39 20 31 37 3a 34 38 3a 30 31 20 47 4d 54 0a 2f 61 64 72 69 61 6e 63 6f 6c 65 2e 73 33 2e 61 6d 61 7a 6f 6e 73 33 74 65 73 74 2e 66 69 6c 65 74 65 73 74 73 66 6f 72 61 64 72 69 61 6e 2f 66 69 6c 65514AA22EB75A6E42H5nqnZkGjuKvB+seutvx5hnp1P+WAuC9c3Y7MdQCcYDr1TGwNX/mt+FHstK0pVldQm6Wss7e5e/eNXV50AxChH+xkLI=GET\n" - + "\n" - + "\n" - + "Thu, 19 Mar 2009 17:48:01 GMT\n" - + "/adriancole.s3.amazons3test.filetestsforadrian/file0101100101001001"; - public static final String amazonHadAnError500 = "InternalErrorWe encountered an internal error. Please try again.EF6FA7A639CAFF15tBkX23mIeq2riHsNw2YShupMlZ9+iy3V/uN+lRhqCR4qHTE07ujFeyAUPTowvuH/"; - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java b/s3/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java deleted file mode 100644 index a83f96ae30..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.HttpException; -import org.jclouds.http.commands.callables.xml.ParseSax; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "s3.ListBucketHandlerTest") -public class ListBucketHandlerTest extends BaseHandlerTest { - public static final String listBucketWithPrefixAppsSlash = "adriancole.org.jclouds.aws.s3.amazons3testdelimiterapps/1000falseapps/02009-05-07T18:27:08.000Z"c82e6a0025c31c5de5947fda62ac51ab"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/12009-05-07T18:27:09.000Z"944fab2c5a9a6bacf07db5e688310d7a"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/22009-05-07T18:27:09.000Z"a227b8888045c8fd159fb495214000f0"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/32009-05-07T18:27:09.000Z"c9caa76c3dec53e2a192608ce73eef03"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/42009-05-07T18:27:09.000Z"1ce5d0dcc6154a647ea90c7bdf82a224"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/52009-05-07T18:27:09.000Z"79433524d87462ee05708a8ef894ed55"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/62009-05-07T18:27:10.000Z"dd00a060b28ddca8bc5a21a49e306f67"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/72009-05-07T18:27:10.000Z"8cd06eca6e819a927b07a285d750b100"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/82009-05-07T18:27:10.000Z"174495094d0633b92cbe46603eee6bad"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/92009-05-07T18:27:10.000Z"cd8a19b26fea8a827276df0ad11c580d"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; - public static final String listBucketWithSlashDelimiterAndCommonPrefixApps = " / apps/"; - ParseSax parser; - - @BeforeMethod - void setUpParser() { - parser = parserFactory.createListBucketParser(); - ((ListBucketHandler) parser.getHandler()).setBucketName("test"); - } - - @Test - public void testListMyBucketsWithDelimiterSlashAndCommonPrefixesAppsSlash() - throws HttpException { - - S3Bucket bucket = parser.parse(IOUtils - .toInputStream(listBucketWithSlashDelimiterAndCommonPrefixApps)); - assertEquals(bucket.getCommonPrefixes().iterator().next(), "apps/"); - assertEquals(bucket.getDelimiter(), "/"); - assert bucket.getMarker() == null; - } - - @Test - public void testListMyBucketsWithPrefixAppsSlash() throws HttpException { - - S3Bucket bucket = parser.parse(IOUtils - .toInputStream(listBucketWithPrefixAppsSlash)); - assertEquals(bucket.getPrefix(), "apps/"); - assertEquals(bucket.getMaxKeys(), 1000); - assert bucket.getMarker() == null; - - } - -} diff --git a/s3/src/test/java/org/jclouds/aws/s3/xml/S3ParserFactoryTest.java b/s3/src/test/java/org/jclouds/aws/s3/xml/S3ParserFactoryTest.java deleted file mode 100644 index 0e2cdf37dc..0000000000 --- a/s3/src/test/java/org/jclouds/aws/s3/xml/S3ParserFactoryTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.aws.s3.xml; - -import com.google.inject.Guice; -import com.google.inject.Injector; -import org.jclouds.aws.s3.xml.config.S3ParserModule; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "s3.S3ParserFactoryTest") -public class S3ParserFactoryTest { - - Injector injector = null; - S3ParserFactory parserFactory = null; - - @BeforeMethod - void setUpInjector() { - injector = Guice.createInjector(new S3ParserModule()); - parserFactory = injector.getInstance(S3ParserFactory.class); - } - - @AfterMethod - void tearDownInjector() { - parserFactory = null; - injector = null; - } - - @Test - void testCreateListBucketsParser() { - assert parserFactory.createListBucketsParser() != null; - } - - @Test - void testCreateListBucketParser() { - assert parserFactory.createListBucketParser() != null; - } - - @Test - void testCreateCopyObjectParser() { - assert parserFactory.createCopyObjectParser() != null; - } - - @Test - void testCreateErrorParser() { - assert parserFactory.createErrorParser() != null; - } - -} \ No newline at end of file