diff --git a/core/src/main/java/org/jclouds/command/FutureCommand.java b/core/src/main/java/org/jclouds/command/FutureCommand.java index dc00295cc3..883c9dfb30 100644 --- a/core/src/main/java/org/jclouds/command/FutureCommand.java +++ b/core/src/main/java/org/jclouds/command/FutureCommand.java @@ -24,113 +24,118 @@ package org.jclouds.command; import java.util.concurrent.*; +import static com.google.common.base.Preconditions.checkNotNull; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ public class FutureCommand implements Future { - private Q request; - private ResponseRunnableFuture responseRunnableFuture; + private final Q request; + private final ResponseRunnableFuture responseRunnableFuture; private volatile int failureCount; public int incrementFailureCount() { - return ++failureCount; + return ++failureCount; } public int getFailureCount() { - return failureCount; + return failureCount; } public FutureCommand(Q request, ResponseCallable responseCallable) { - this.request = request; - this.responseRunnableFuture = new ResponseRunnableFutureTask(responseCallable); + this.request = checkNotNull(request, "request"); + this.responseRunnableFuture = new ResponseRunnableFutureTask( + checkNotNull(responseCallable, "responseCallable")); } public Q getRequest() { - return request; + return request; } public ResponseRunnableFuture getResponseFuture() { - return responseRunnableFuture; + return responseRunnableFuture; } public void setException(Exception e) { - responseRunnableFuture.setException(e); + responseRunnableFuture.setException(e); } public boolean cancel(boolean b) { - return responseRunnableFuture.cancel(b); + return responseRunnableFuture.cancel(b); } public boolean isCancelled() { - return responseRunnableFuture.isCancelled(); + return responseRunnableFuture.isCancelled(); } public boolean isDone() { - return responseRunnableFuture.isDone(); + return responseRunnableFuture.isDone(); } public T get() throws InterruptedException, ExecutionException { - return responseRunnableFuture.get(); + return responseRunnableFuture.get(); } - public T get(long l, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { - return responseRunnableFuture.get(l, timeUnit); + public T get(long l, TimeUnit timeUnit) throws InterruptedException, + ExecutionException, TimeoutException { + return responseRunnableFuture.get(l, timeUnit); } /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ - public static class ResponseRunnableFutureTask extends FutureTask implements ResponseRunnableFuture { - private final ResponseCallable tCallable; + public static class ResponseRunnableFutureTask extends FutureTask + implements ResponseRunnableFuture { + private final ResponseCallable tCallable; - public ResponseRunnableFutureTask(ResponseCallable tCallable) { - super(tCallable); - this.tCallable = tCallable; - } + public ResponseRunnableFutureTask(ResponseCallable tCallable) { + super(tCallable); + this.tCallable = tCallable; + } - @Override - public String toString() { - return "ApacheHttpResponseFuture{" + - "tCallable=" + tCallable + - '}'; - } + @Override + public String toString() { + return "ResponseRunnableFutureTask{" + "tCallable=" + tCallable + + '}'; + } - public R getResponse() { - return tCallable.getResponse(); - } + public R getResponse() { + return tCallable.getResponse(); + } - public void setResponse(R response) { - tCallable.setResponse(response); - } + public void setResponse(R response) { + tCallable.setResponse(response); + } - /** - * opening this to public so that other errors can be associated with the request, for example i/o errors. - * - * @param throwable - */ - @Override - public void setException(Throwable throwable) { - super.setException(throwable); - } + /** + * opening this to public so that other errors can be associated with + * the request, for example i/o errors. + * + * @param throwable + */ + @Override + public void setException(Throwable throwable) { + super.setException(throwable); + } } - public interface ResponseRunnableFuture extends Response, Runnable, Future { - public void setException(Throwable throwable); + public interface ResponseRunnableFuture extends Response, + Runnable, Future { + public void setException(Throwable throwable); } public interface ResponseCallable extends Response, Callable { } public interface Response { - public R getResponse(); + public R getResponse(); - public void setResponse(R response); + public void setResponse(R response); } } diff --git a/core/src/main/java/org/jclouds/http/HttpFutureCommand.java b/core/src/main/java/org/jclouds/http/HttpFutureCommand.java index cae0427515..ee5130b424 100644 --- a/core/src/main/java/org/jclouds/http/HttpFutureCommand.java +++ b/core/src/main/java/org/jclouds/http/HttpFutureCommand.java @@ -23,38 +23,54 @@ */ package org.jclouds.http; +import static com.google.common.base.Preconditions.checkNotNull; + import org.jclouds.command.FutureCommand; import org.jclouds.Logger; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ -public class HttpFutureCommand extends FutureCommand { - public HttpFutureCommand(String method, String uri, ResponseCallable responseCallable) { - super(new HttpRequest(method, uri), responseCallable); +public class HttpFutureCommand extends + FutureCommand { + public HttpFutureCommand(String method, String uri, + ResponseCallable responseCallable) { + super(new HttpRequest(checkNotNull(method, "method"), checkNotNull(uri, + "uri")), responseCallable); + } + + protected void addHostHeader(String host) { + getRequest().getHeaders().put("Host", host); + } + + @Override + public String toString() { + return this.getClass().getName() + "{" + "request=" + this.getRequest() + + "," + "responseFuture=" + this.getResponseFuture() + '}'; } /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ - public abstract static class ResponseCallable implements FutureCommand.ResponseCallable { - protected final Logger logger; - private HttpResponse response; + public abstract static class ResponseCallable implements + FutureCommand.ResponseCallable { + protected final Logger logger; + private HttpResponse response; - public ResponseCallable(Logger logger) { - this.logger = logger; - } + public ResponseCallable(Logger logger) { + this.logger = logger; + } - public HttpResponse getResponse() { - return response; - } + public HttpResponse getResponse() { + return response; + } - public void setResponse(HttpResponse response) { - this.response = response; - } + public void setResponse(HttpResponse response) { + this.response = response; + } } } diff --git a/core/src/main/java/org/jclouds/http/commands/callables/xml/ParseSax.java b/core/src/main/java/org/jclouds/http/commands/callables/xml/ParseSax.java index 7819931eaf..cc908c2be6 100644 --- a/core/src/main/java/org/jclouds/http/commands/callables/xml/ParseSax.java +++ b/core/src/main/java/org/jclouds/http/commands/callables/xml/ParseSax.java @@ -25,6 +25,8 @@ package org.jclouds.http.commands.callables.xml; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; +import com.google.inject.name.Named; + import org.apache.commons.io.IOUtils; import org.jclouds.Logger; import org.jclouds.Utils; @@ -34,78 +36,89 @@ import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; +import static com.google.common.base.Preconditions.checkNotNull; import java.io.InputStream; /** - * // TODO: Adrian: Document this! - * + * This object will parse the body of an HttpResponse and return the result of + * type back to the caller. + * * @author Adrian Cole */ public class ParseSax extends HttpFutureCommand.ResponseCallable { - private XMLReader parser; - private HandlerWithResult handler; + private final XMLReader parser; + private final HandlerWithResult handler; + @Inject(optional = true) + @Named("jclouds.http.sax.debug") private boolean suckFirst = false; @Inject - public ParseSax(java.util.logging.Logger logger, XMLReader parser, @Assisted HandlerWithResult handler) { - super(new Logger(logger)); - this.parser = parser; - this.handler = handler; + public ParseSax(java.util.logging.Logger logger, XMLReader parser, + @Assisted HandlerWithResult handler) { + super(new Logger(checkNotNull(logger, "logger"))); + this.parser = checkNotNull(parser, "parser"); + this.handler = checkNotNull(handler, "handler"); } public T call() throws HttpException { - InputStream input = null; - try { - input = getResponse().getContent(); - if (input != null) { - return parse(input); - } else { - throw new HttpException("No input to parse"); - } - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new HttpException("Error parsing input for " + getResponse(), e); - } + InputStream input = null; + try { + input = getResponse().getContent(); + if (input != null) { + return parse(input); + } else { + throw new HttpException("No input to parse"); + } + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new HttpException("Error parsing input for " + getResponse(), + e); + } } public T parse(InputStream xml) throws HttpException { - parseAndCloseStream(xml, handler); - return handler.getResult(); + parseAndCloseStream(xml, getHandler()); + return getHandler().getResult(); } - private void parseAndCloseStream(InputStream xml, ContentHandler handler) throws HttpException { - parser.setContentHandler(handler); - String response = null; - try { - if (suckFirst) { - response = IOUtils.toString(xml); - logger.trace("received content %n%s", response); - IOUtils.closeQuietly(xml); - xml = IOUtils.toInputStream(response); - } - parser.parse(new InputSource(xml)); - } catch (Exception e) { - StringBuilder message = new StringBuilder(); - message.append("Error parsing input for ").append(handler); - if (response != null) { - message.append("\n").append(response); - } - logger.error(e, message.toString()); - Utils.rethrowIfRuntimeOrSameType(e); - throw new HttpException(message.toString(), e); - } finally { - IOUtils.closeQuietly(xml); - } + private void parseAndCloseStream(InputStream xml, ContentHandler handler) + throws HttpException { + parser.setContentHandler(handler); + String response = null; + try { + if (suckFirst) { + response = IOUtils.toString(xml); + logger.trace("received content %n%s", response); + IOUtils.closeQuietly(xml); + xml = IOUtils.toInputStream(response); + } + parser.parse(new InputSource(xml)); + } catch (Exception e) { + StringBuilder message = new StringBuilder(); + message.append("Error parsing input for ").append(handler); + if (response != null) { + message.append("\n").append(response); + } + logger.error(e, message.toString()); + Utils. rethrowIfRuntimeOrSameType(e); + throw new HttpException(message.toString(), e); + } finally { + IOUtils.closeQuietly(xml); + } + } + + public HandlerWithResult getHandler() { + return handler; } /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ public abstract static class HandlerWithResult extends DefaultHandler { - public abstract T getResult(); + public abstract T getResult(); } } diff --git a/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java b/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java index ab006cd589..572685c202 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpFutureCommandClientTest.java @@ -139,7 +139,7 @@ public abstract class BaseHttpFutureCommandClientTest { server.stop(); } - @Test(invocationCount = 500, timeOut = 1000) + @Test(invocationCount = 500, timeOut = 1500) void testRequestFilter() throws MalformedURLException, ExecutionException, InterruptedException { GetString get = factory.createGetString("/"); @@ -149,7 +149,7 @@ public abstract class BaseHttpFutureCommandClientTest { "expected: [%1s], but got [%2s]", "test", get.get()); } - @Test(invocationCount = 500, timeOut = 1000) + @Test(invocationCount = 500, timeOut = 1500) void testGetStringWithHeader() throws MalformedURLException, ExecutionException, InterruptedException { GetString get = factory.createGetString("/"); @@ -159,7 +159,7 @@ public abstract class BaseHttpFutureCommandClientTest { "expected: [%1s], but got [%2s]", "test", get.get()); } - @Test(invocationCount = 500, timeOut = 1000) + @Test(invocationCount = 500, timeOut = 1500) void testGetString() throws MalformedURLException, ExecutionException, InterruptedException { GetString get = factory.createGetString("/"); @@ -169,7 +169,7 @@ public abstract class BaseHttpFutureCommandClientTest { "expected: [%1s], but got [%2s]", XML, get.get()); } - @Test(invocationCount = 500, timeOut = 1000) + @Test(invocationCount = 500, timeOut = 1500) void testHead() throws MalformedURLException, ExecutionException, InterruptedException { Head head = factory.createHead("/"); @@ -178,7 +178,7 @@ public abstract class BaseHttpFutureCommandClientTest { assert head.get(); } - @Test(invocationCount = 500, timeOut = 1000) + @Test(invocationCount = 500, timeOut = 1500) void testGetAndParseSax() throws MalformedURLException, ExecutionException, InterruptedException { GetAndParseSax getAndParseSax = factory.createGetAndParseSax("/", diff --git a/gae/src/test/java/org/jclouds/gae/URLFetchServiceClientTest.java b/gae/src/test/java/org/jclouds/gae/URLFetchServiceClientTest.java index 3d24cf07fa..7ba3bbbbf7 100644 --- a/gae/src/test/java/org/jclouds/gae/URLFetchServiceClientTest.java +++ b/gae/src/test/java/org/jclouds/gae/URLFetchServiceClientTest.java @@ -23,7 +23,7 @@ */ package org.jclouds.gae; -import static junit.framework.Assert.assertEquals; +import static org.testng.Assert.*; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createNiceMock; diff --git a/project/pom.xml b/project/pom.xml index 48058ab249..f9928fd123 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -143,7 +143,7 @@ org.testng testng - 5.8 + 5.9 test jdk15 diff --git a/repo/com/google/appengine/appengine-api/maven-metadata-local.xml b/repo/com/google/appengine/appengine-api/maven-metadata-local.xml index 37a0e80543..a73c89f739 100644 --- a/repo/com/google/appengine/appengine-api/maven-metadata-local.xml +++ b/repo/com/google/appengine/appengine-api/maven-metadata-local.xml @@ -1,4 +1,29 @@ + com.google.appengine diff --git a/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml index 98dbf02bb2..8a8333786d 100644 --- a/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-core/maven-metadata.xml b/repo/org/jclouds/jclouds-core/maven-metadata.xml index 057fdb57cd..7011c3e757 100644 --- a/repo/org/jclouds/jclouds-core/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-core/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml index 7d2a74f154..352263f0ea 100644 --- a/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml b/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml index 8017a06b06..071da08260 100644 --- a/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-project/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-project/1.0-SNAPSHOT/maven-metadata.xml index daf7a8a73b..4410e11202 100644 --- a/repo/org/jclouds/jclouds-project/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-project/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-project/maven-metadata.xml b/repo/org/jclouds/jclouds-project/maven-metadata.xml index c63441a093..7101cd9d2d 100644 --- a/repo/org/jclouds/jclouds-project/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-project/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml index ed606214fd..692e03939a 100644 --- a/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3/maven-metadata.xml b/repo/org/jclouds/jclouds-s3/maven-metadata.xml index b42a9b66da..1b9a01cadf 100644 --- a/repo/org/jclouds/jclouds-s3/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml index eedb18d7d5..e618fd594e 100644 --- a/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml b/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml index 5241b88178..6c7f0d9b1b 100644 --- a/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/testng/testng/maven-metadata-local.xml b/repo/org/testng/testng/maven-metadata-local.xml index b5171603c1..765375268e 100644 --- a/repo/org/testng/testng/maven-metadata-local.xml +++ b/repo/org/testng/testng/maven-metadata-local.xml @@ -1,4 +1,29 @@ + org.testng diff --git a/s3/perftest/pom.xml b/s3/perftest/pom.xml index 68d81a542a..c9dec649b9 100644 --- a/s3/perftest/pom.xml +++ b/s3/perftest/pom.xml @@ -53,6 +53,12 @@ jar Performance test verses Amazon samples implementation + + + + + + ${project.groupId} @@ -94,4 +100,25 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + jclouds.aws.accesskeyid + ${jclouds.aws.accesskeyid} + + + jclouds.aws.secretaccesskey + ${jclouds.aws.secretaccesskey} + + + + + + + diff --git a/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java b/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java index f42a30a165..da33e8a1db 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java +++ b/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java @@ -54,10 +54,9 @@ public abstract class BaseJCloudsPerformance extends BasePerformance { @Override protected boolean putByteArray(String bucket, String key, byte[] data, String contentType) throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucket); - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(); - object.setKey(key); + S3Bucket s3Bucket = new S3Bucket(bucket); + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( + key); object.setContentType(contentType); object.setContent(data); return client.addObject(s3Bucket, object).get() != null; @@ -66,10 +65,9 @@ public abstract class BaseJCloudsPerformance extends BasePerformance { @Override protected boolean putFile(String bucket, String key, File data, String contentType) throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucket); - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(); - object.setKey(key); + S3Bucket s3Bucket = new S3Bucket(bucket); + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( + key); object.setContentType(contentType); object.setContent(data); return client.addObject(s3Bucket, object).get() != null; @@ -78,10 +76,9 @@ public abstract class BaseJCloudsPerformance extends BasePerformance { @Override protected boolean putInputStream(String bucket, String key, InputStream data, String contentType) throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucket); - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(); - object.setKey(key); + S3Bucket s3Bucket = new S3Bucket(bucket); + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( + key); object.setContentType(contentType); object.setContent(data); object.setSize(data.available()); @@ -91,10 +88,9 @@ public abstract class BaseJCloudsPerformance extends BasePerformance { @Override protected boolean putString(String bucket, String key, String data, String contentType) throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucket); - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(); - object.setKey(key); + S3Bucket s3Bucket = new S3Bucket(bucket); + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( + key); object.setContentType(contentType); object.setContent(data); return client.addObject(s3Bucket, object).get() != 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 index c57d9914fb..84e5e18d08 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java +++ b/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java @@ -50,7 +50,6 @@ import com.google.inject.Provider; * * @author Adrian Cole */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, groups = "performance") public abstract class BasePerformance extends S3IntegrationTest { protected static int LOOP_COUNT = 100; @@ -80,14 +79,13 @@ public abstract class BasePerformance extends S3IntegrationTest { @Override @BeforeTest - @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) + @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, + S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) protected void setUpClient(@Optional String AWSAccessKeyId, @Optional String AWSSecretAccessKey) throws Exception { super.setUpClient(AWSAccessKeyId, AWSSecretAccessKey); - S3Bucket s3Bucket = new S3Bucket(); for (String bucket : BUCKETS) { - s3Bucket.setName(bucket); - client.createBucketIfNotExists(s3Bucket).get(); + client.createBucketIfNotExists(new S3Bucket(bucket)).get(); } } diff --git a/s3/pom.xml b/s3/pom.xml index 49731d6b75..a1f697ad97 100644 --- a/s3/pom.xml +++ b/s3/pom.xml @@ -67,11 +67,6 @@ bcprov-jdk15 140 - - eu.medsea.mimeutil - mime-util - 1.3 - diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3Context.java b/s3/src/main/java/org/jclouds/aws/s3/S3Context.java index 5b3b338cc0..7c6bf19e7a 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/S3Context.java +++ b/s3/src/main/java/org/jclouds/aws/s3/S3Context.java @@ -33,13 +33,21 @@ public interface S3Context { S3Connection getConnection(); /** - * Creates a Map view of the specified + * Creates a Map view of the specified * bucket. * * @param bucket * @return */ - S3ObjectMap createMapView(S3Bucket bucket); + S3InputStreamMap createS3InputStreamMap(S3Bucket bucket); + + /** + * Creates a Map view of the specified bucket. + * + * @param bucket + * @return + */ + S3ObjectMap createS3ObjectMap(S3Bucket bucket); /** * Closes all connections to S3. diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3Utils.java b/s3/src/main/java/org/jclouds/aws/s3/S3Utils.java index d7159ccc74..52111dbb4e 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/S3Utils.java +++ b/s3/src/main/java/org/jclouds/aws/s3/S3Utils.java @@ -45,7 +45,7 @@ public class S3Utils extends Utils { (byte) '8', (byte) '9', (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd', (byte) 'e', (byte) 'f' }; - public static String getHexString(byte[] raw) + public static String toHexString(byte[] raw) throws UnsupportedEncodingException { byte[] hex = new byte[2 * raw.length]; int index = 0; @@ -58,6 +58,15 @@ public class S3Utils extends Utils { return new String(hex, "ASCII"); } + 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 { @@ -71,14 +80,14 @@ public class S3Utils extends Utils { return new String(Base64.encode(resBuf)); } - public static String md5Hex(byte [] toEncode) + public static String md5Hex(byte[] toEncode) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, UnsupportedEncodingException { byte[] resBuf = md5(toEncode); - return getHexString(resBuf); + return toHexString(resBuf); } - public static String md5Base64(byte [] toEncode) + public static String md5Base64(byte[] toEncode) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException { byte[] resBuf = md5(toEncode); 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 index a56aae399d..caa8eb1581 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/CopyObject.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/CopyObject.java @@ -23,23 +23,31 @@ */ package org.jclouds.aws.s3.commands; +import static com.google.common.base.Preconditions.checkNotNull; + import org.jclouds.aws.s3.commands.callables.CopyObjectCallable; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; -public class CopyObject extends HttpFutureCommand { +public class CopyObject extends S3FutureCommand { @Inject - public CopyObject(@Named("jclouds.http.address") String amazonHost, CopyObjectCallable callable, @Assisted("sourceBucket") S3Bucket sourceBucket, @Assisted("sourceObject") S3Object sourceObject, @Assisted("destinationBucket") S3Bucket destinationBucket, @Assisted("destinationObject") S3Object destinationObject) { - super("PUT", "/" + destinationObject.getKey(), callable); - getRequest().getHeaders().put("Host", - destinationBucket.getName() + "." + amazonHost); - getRequest().getHeaders().put("x-amz-copy-source", String.format("/%1s/%2s", sourceBucket.getName(), sourceObject.getKey())); + public CopyObject(@Named("jclouds.http.address") String amazonHost, + CopyObjectCallable callable, + @Assisted("sourceBucket") S3Bucket sourceBucket, + @Assisted("sourceObject") S3Object sourceObject, + @Assisted("destinationBucket") S3Bucket destinationBucket, + @Assisted("destinationObject") S3Object destinationObject) { + super("PUT", "/" + checkNotNull(destinationObject.getKey(),"destinationObject.getKey()"), callable, + amazonHost, destinationBucket); + getRequest().getHeaders().put( + "x-amz-copy-source", + String.format("/%1s/%2s", checkNotNull(sourceBucket.getName(), + "sourceBucket.getName()"), checkNotNull(sourceObject + .getKey(), "sourceObject.getKey()"))); } - } \ 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 index 55fcb11489..7c03a55502 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteBucket.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteBucket.java @@ -25,19 +25,16 @@ package org.jclouds.aws.s3.commands; import org.jclouds.aws.s3.commands.callables.DeleteBucketCallable; import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; -public class DeleteBucket extends HttpFutureCommand { +public class DeleteBucket extends S3FutureCommand { @Inject public DeleteBucket(@Named("jclouds.http.address") String amazonHost, DeleteBucketCallable callable, @Assisted S3Bucket s3Bucket) { - super("DELETE", "/", callable); - getRequest().getHeaders().put("Host", - s3Bucket.getName() + "." + amazonHost); + super("DELETE", "/", callable, amazonHost, s3Bucket); } } \ 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 index b3d7c18312..afd64dd553 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteObject.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/DeleteObject.java @@ -23,22 +23,21 @@ */ package org.jclouds.aws.s3.commands; +import static com.google.common.base.Preconditions.checkNotNull; + import org.jclouds.aws.s3.commands.callables.DeleteCallable; import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; -public class DeleteObject extends HttpFutureCommand { +public class DeleteObject extends S3FutureCommand { @Inject public DeleteObject(@Named("jclouds.http.address") String amazonHost, DeleteCallable callable, @Assisted S3Bucket s3Bucket, @Assisted String key) { - super("DELETE", "/" + key, callable); - getRequest().getHeaders().put("Host", - s3Bucket.getName() + "." + amazonHost); + super("DELETE", "/" + checkNotNull(key), callable, amazonHost, s3Bucket); } } \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/HeadBucket.java b/s3/src/main/java/org/jclouds/aws/s3/commands/HeadBucket.java index 2ae0084f87..1501431eb5 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/HeadBucket.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/HeadBucket.java @@ -24,20 +24,17 @@ package org.jclouds.aws.s3.commands; import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.commands.callables.ReturnTrueIf200; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; -public class HeadBucket extends HttpFutureCommand { +public class HeadBucket extends S3FutureCommand { @Inject public HeadBucket(@Named("jclouds.http.address") String amazonHost, ReturnTrueIf200 callable, @Assisted S3Bucket s3Bucket) { - super("HEAD", "/", callable); - getRequest().getHeaders().put("Host", - s3Bucket.getName() + "." + amazonHost); + super("HEAD", "/", callable, amazonHost, s3Bucket); } } \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/ListAllMyBuckets.java b/s3/src/main/java/org/jclouds/aws/s3/commands/ListAllMyBuckets.java index 18dca627c2..442dbd0a06 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/ListAllMyBuckets.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/ListAllMyBuckets.java @@ -26,19 +26,17 @@ package org.jclouds.aws.s3.commands; import java.util.List; import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.commands.callables.xml.ParseSax; import com.google.inject.Inject; import com.google.inject.name.Named; -public class ListAllMyBuckets extends HttpFutureCommand> { +public class ListAllMyBuckets extends S3FutureCommand> { @Inject public ListAllMyBuckets(@Named("jclouds.http.address") String amazonHost, ParseSax> callable) { - super("GET", "/", callable); - getRequest().getHeaders().put("Host", amazonHost); + super("GET", "/", callable, amazonHost); } } \ 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 index afab200ade..286598e51d 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/ListBucket.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/ListBucket.java @@ -23,22 +23,22 @@ */ package org.jclouds.aws.s3.commands; +import org.jclouds.aws.s3.commands.callables.xml.ListBucketHandler; import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.HttpFutureCommand; 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; -public class ListBucket extends HttpFutureCommand { +public class ListBucket extends S3FutureCommand { @Inject public ListBucket(@Named("jclouds.http.address") String amazonHost, ParseSax callable, @Assisted S3Bucket s3Bucket) { - super("GET", "/", callable); - getRequest().getHeaders().put("Host", - s3Bucket.getName() + "." + amazonHost); + super("GET", "/", callable, amazonHost, s3Bucket); + ListBucketHandler handler = (ListBucketHandler) callable.getHandler(); + handler.setBucket(s3Bucket); } - } \ 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 index 9a759c6765..23816eab40 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/PutBucket.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/PutBucket.java @@ -25,20 +25,17 @@ package org.jclouds.aws.s3.commands; import org.jclouds.aws.s3.commands.callables.PutBucketCallable; import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; -public class PutBucket extends HttpFutureCommand { +public class PutBucket extends S3FutureCommand { @Inject public PutBucket(@Named("jclouds.http.address") String amazonHost, PutBucketCallable callable, @Assisted S3Bucket s3Bucket) { - super("PUT", "/", callable); - getRequest().getHeaders().put("Host", - s3Bucket.getName() + "." + amazonHost); + super("PUT", "/", callable, amazonHost, s3Bucket); } } \ 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 index 1804badff9..9be3fbadc2 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/PutObject.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/PutObject.java @@ -23,34 +23,30 @@ */ package org.jclouds.aws.s3.commands; +import static com.google.common.base.Preconditions.checkNotNull; + import org.jclouds.aws.s3.commands.callables.PutObjectCallable; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; -public class PutObject extends HttpFutureCommand { +public class PutObject extends S3FutureCommand { @Inject public PutObject(@Named("jclouds.http.address") String amazonHost, PutObjectCallable callable, @Assisted S3Bucket s3Bucket, @Assisted S3Object object) { - super("PUT", "/" + object.getKey(), callable); - getRequest().getHeaders().put("Host", - s3Bucket.getName() + "." + amazonHost); - if (object.getContentType() == null) { - throw new IllegalArgumentException( - "PUT requests need content type set"); - } - Object o = object.getContent(); - if (o == null) { - throw new IllegalArgumentException("PUT requests need object"); - } - getRequest().setContent(o); - getRequest().setContentType(object.getContentType()); + super("PUT", "/" + checkNotNull(object.getKey()), callable, amazonHost, + s3Bucket); + getRequest().setContent( + checkNotNull(object.getContent(), "object.getContent()")); + getRequest() + .setContentType( + checkNotNull(object.getContentType(), + "object.getContentType()")); getRequest().setContentLength(object.getSize()); } diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/RetrieveObject.java b/s3/src/main/java/org/jclouds/aws/s3/commands/RetrieveObject.java index 5dc9671a41..2eaa292aa0 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/RetrieveObject.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/RetrieveObject.java @@ -23,44 +23,24 @@ */ package org.jclouds.aws.s3.commands; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.aws.s3.commands.callables.RetrieveObjectCallable; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.http.HttpFutureCommand; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; -public class RetrieveObject extends HttpFutureCommand { - private String key; +public class RetrieveObject extends S3FutureCommand { @Inject public RetrieveObject(@Named("jclouds.http.address") String amazonHost, RetrieveObjectCallable callable, @Assisted S3Bucket s3Bucket, @Assisted String key, @Assisted boolean getContent) { - super(getContent ? "GET" : "HEAD", "/" + key, callable); - this.key = key; - getRequest().getHeaders().put("Host", - s3Bucket.getName() + "." + amazonHost); - } - - @Override - public S3Object get() throws InterruptedException, ExecutionException { - S3Object object = super.get(); - object.setKey(key); - return object; - } - - @Override - public S3Object get(long l, TimeUnit timeUnit) throws InterruptedException, - ExecutionException, TimeoutException { - S3Object object = super.get(l, timeUnit); - object.setKey(key); - return object; + super(getContent ? "GET" : "HEAD", "/" + checkNotNull(key), callable, + amazonHost, s3Bucket); + callable.setKey(key); } } \ 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 new file mode 100644 index 0000000000..189868725c --- /dev/null +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/S3FutureCommand.java @@ -0,0 +1,53 @@ +/** + * + * 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.domain.S3Bucket; +import org.jclouds.http.HttpFutureCommand; + +public class S3FutureCommand extends HttpFutureCommand { + + public S3FutureCommand(String method, String uri, + ResponseCallable responseCallable, String amazonHost, + S3Bucket s3Bucket) { + super(method, uri, responseCallable); + addHostHeader(checkNotNull(amazonHost, "amazonHost"), checkNotNull( + s3Bucket, "s3Bucket")); + } + + public S3FutureCommand(String method, String uri, + ResponseCallable responseCallable, String amazonHost) { + super(method, uri, responseCallable); + addHostHeader(checkNotNull(amazonHost, "amazonHost")); + } + + protected void addHostHeader(String amazonHost, S3Bucket s3Bucket) { + String host = checkNotNull(s3Bucket.getName(), "s3Bucket.getName()") + + "." + amazonHost; + addHostHeader(host); + } + +} \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/RetrieveObjectCallable.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/RetrieveObjectCallable.java index e0674da727..7f4db4cce5 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/RetrieveObjectCallable.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/RetrieveObjectCallable.java @@ -28,7 +28,6 @@ import java.io.IOException; import org.jclouds.Logger; import org.jclouds.Utils; import org.jclouds.aws.s3.DateService; -import org.jclouds.aws.s3.S3Utils; import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.http.HttpException; import org.jclouds.http.HttpFutureCommand; @@ -43,13 +42,12 @@ import com.google.inject.Inject; public class RetrieveObjectCallable extends HttpFutureCommand.ResponseCallable { private final DateService dateParser; - private final S3Utils utils; + private String key; @Inject public RetrieveObjectCallable(java.util.logging.Logger logger, - DateService dateParser, S3Utils utils) { + DateService dateParser) { super(new Logger(logger)); - this.utils = utils; this.dateParser = dateParser; } @@ -59,7 +57,7 @@ public class RetrieveObjectCallable extends */ public S3Object call() throws HttpException { if (getResponse().getStatusCode() == 200) { - S3Object object = new S3Object(); + S3Object object = new S3Object(key); String md5Header = getResponse().getFirstHeaderOrNull( "x-amz-meta-object-md5"); if (md5Header != null) @@ -93,4 +91,12 @@ public class RetrieveObjectCallable extends + " reason: " + reason); } } + + public void setKey(String key) { + this.key = key; + } + + public String getKey() { + return key; + } } \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListAllMyBucketsHandler.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListAllMyBucketsHandler.java index 17e7dc90e6..0ab95a40a3 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListAllMyBucketsHandler.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListAllMyBucketsHandler.java @@ -35,10 +35,11 @@ import java.util.List; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ -public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult> { +public class ListAllMyBucketsHandler extends + ParseSax.HandlerWithResult> { private List buckets = new ArrayList(); private S3Bucket currentS3Bucket; @@ -49,40 +50,41 @@ public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult getResult() { - return buckets; + return buckets; } - public void startElement(String uri, String name, String qName, Attributes attrs) { - if (qName.equals("Bucket")) { - currentS3Bucket = new S3Bucket(); - currentS3Bucket.setHasData(false); - currentS3Bucket.setComplete(false); - } else if (qName.equals("Owner")) { - currentOwner = new S3Owner(); - } + public void startElement(String uri, String name, String qName, + Attributes attrs) { + if (qName.equals("Bucket")) { + } else if (qName.equals("Owner")) { + currentOwner = new S3Owner(); + } } public void endElement(String uri, String name, String qName) { - if (qName.equals("ID")) { //owner stuff - currentOwner.setId(currentText.toString()); - } else if (qName.equals("DisplayName")) { - currentOwner.setDisplayName(currentText.toString()); - } else if (qName.equals("Bucket")) { - currentS3Bucket.setCanonicalUser(currentOwner); - buckets.add(currentS3Bucket); - } else if (qName.equals("Name")) { - currentS3Bucket.setName(currentText.toString()); - } else if (qName.equals("CreationDate")) { - currentS3Bucket.setCreationDate(dateParser.dateTimeFromXMLFormat(currentText.toString())); - } - currentText = new StringBuilder(); + if (qName.equals("ID")) { // owner stuff + currentOwner.setId(currentText.toString()); + } else if (qName.equals("DisplayName")) { + currentOwner.setDisplayName(currentText.toString()); + } else if (qName.equals("Bucket")) { + currentS3Bucket.setCanonicalUser(currentOwner); + buckets.add(currentS3Bucket); + } else if (qName.equals("Name")) { + currentS3Bucket = new S3Bucket(currentText.toString()); + currentS3Bucket.setHasData(false); + currentS3Bucket.setComplete(false); + } 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); + currentText.append(ch, start, length); } } diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListBucketHandler.java b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListBucketHandler.java index 4b8a676926..dd4267a4b7 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListBucketHandler.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/callables/xml/ListBucketHandler.java @@ -23,76 +23,91 @@ */ package org.jclouds.aws.s3.commands.callables.xml; +import static com.google.common.base.Preconditions.checkNotNull; + import org.jclouds.aws.s3.DateService; -import com.google.inject.Inject; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Owner; import org.jclouds.http.commands.callables.xml.ParseSax; import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.inject.Inject; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ public class ListBucketHandler extends ParseSax.HandlerWithResult { public S3Bucket getResult() { - return s3Bucket; + return s3Bucket; } - private S3Bucket s3Bucket = new S3Bucket(); + public void setBucket(S3Bucket s3Bucket) { + this.s3Bucket = s3Bucket; + } + + private S3Bucket s3Bucket; private S3Object currentObject; private S3Owner currentOwner; private StringBuilder currentText = new StringBuilder(); @Inject private DateService dateParser; - public void startElement(String uri, String name, String qName, Attributes attrs) { - if (qName.equals("Contents")) { - currentObject = new S3Object(); - } else if (qName.equals("Owner")) { - currentOwner = new S3Owner(); - } + @Override + public void startDocument() throws SAXException { + checkNotNull(s3Bucket, "s3Bucket"); + s3Bucket.getContents().clear(); + super.startDocument(); + } + + public void startElement(String uri, String name, String qName, + Attributes attrs) { + if (qName.equals("Contents")) { + } else if (qName.equals("Owner")) { + currentOwner = new S3Owner(); + } } public void endElement(String uri, String name, String qName) { - if (qName.equals("ID")) { //owner stuff - currentOwner.setId(currentText.toString()); - } else if (qName.equals("DisplayName")) { - currentOwner.setDisplayName(currentText.toString()); - } else if (qName.equals("Key")) { //content stuff - currentObject.setKey(currentText.toString()); - } else if (qName.equals("LastModified")) { - currentObject.setLastModified(dateParser.dateTimeFromXMLFormat(currentText.toString())); - } else if (qName.equals("ETag")) { - currentObject.setETag(currentText.toString().replaceAll("\"", "")); - } else if (qName.equals("Size")) { - currentObject.setSize(Long.parseLong(currentText.toString())); - } else if (qName.equals("Owner")) { - currentObject.setOwner(currentOwner); - } else if (qName.equals("StorageClass")) { - currentObject.setStorageClass(currentText.toString()); - } else if (qName.equals("Contents")) { - s3Bucket.getContents().add(currentObject); - } else if (qName.equals("Name")) {//bucket stuff last, as least likely - s3Bucket.setName(currentText.toString()); -// } else if (qName.equals("Prefix")) { -// // no-op -// } else if (qName.equals("Marker")) { -// // no-op -// } else if (qName.equals("MaxKeys")) { -// // no-op - } else if (qName.equals("IsTruncated")) { - boolean isTruncated = Boolean.parseBoolean(currentText.toString()); - s3Bucket.setComplete(!isTruncated); - } - currentText = new StringBuilder(); + if (qName.equals("ID")) { // owner stuff + currentOwner.setId(currentText.toString()); + } else if (qName.equals("DisplayName")) { + currentOwner.setDisplayName(currentText.toString()); + } else if (qName.equals("Key")) { // content stuff + currentObject = new S3Object(currentText.toString()); + } else if (qName.equals("LastModified")) { + currentObject.setLastModified(dateParser + .dateTimeFromXMLFormat(currentText.toString())); + } else if (qName.equals("ETag")) { + currentObject.setETag(currentText.toString().replaceAll("\"", "")); + } else if (qName.equals("Size")) { + currentObject.setSize(Long.parseLong(currentText.toString())); + } else if (qName.equals("Owner")) { + currentObject.setOwner(currentOwner); + } else if (qName.equals("StorageClass")) { + currentObject.setStorageClass(currentText.toString()); + } else if (qName.equals("Contents")) { + s3Bucket.getContents().add(currentObject); + } else if (qName.equals("Name")) {// bucket stuff last, as least likely + // } else if (qName.equals("Prefix")) { + // // no-op + // } else if (qName.equals("Marker")) { + // // no-op + // } else if (qName.equals("MaxKeys")) { + // // no-op + } else if (qName.equals("IsTruncated")) { + boolean isTruncated = Boolean.parseBoolean(currentText.toString()); + s3Bucket.setComplete(!isTruncated); + } + currentText = new StringBuilder(); } public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); + currentText.append(ch, start, length); } } 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 index 135d69fccb..bbb65e661c 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java +++ b/s3/src/main/java/org/jclouds/aws/s3/config/S3ContextModule.java @@ -33,6 +33,7 @@ import org.jclouds.aws.s3.filters.RemoveTransferEncodingHeader; import org.jclouds.aws.s3.filters.RequestAuthorizeSignature; 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.aws.s3.internal.GuiceS3Context.S3ObjectMapFactory; import org.jclouds.http.HttpRequestFilter; @@ -59,6 +60,10 @@ public class S3ContextModule extends AbstractModule { 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/domain/S3Bucket.java b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java index f085c810b6..c6befd73b7 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java +++ b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java @@ -26,101 +26,113 @@ package org.jclouds.aws.s3.domain; import org.joda.time.DateTime; import org.jclouds.aws.s3.domain.S3Owner; import org.jclouds.aws.s3.domain.S3Object; +import static com.google.common.base.Preconditions.checkNotNull; import java.util.HashSet; import java.util.Set; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ public class S3Bucket { - public static final S3Bucket NOT_FOUND = new S3Bucket(); + public static final S3Bucket NOT_FOUND = new S3Bucket("NOT_FOUND"); - private String name; + private final String name; private DateTime creationDate; private S3Owner canonicalUser; private Set objects = new HashSet(); boolean isComplete; boolean hasData; - public String getName() { - return name; + public S3Bucket(String name) { + this.name = checkNotNull(name).toLowerCase(); } - public void setName(String name) { - this.name = name.toLowerCase(); + public String getName() { + return name; } public DateTime getCreationDate() { - return creationDate; + return creationDate; } public void setCreationDate(DateTime creationDate) { - this.creationDate = creationDate; + this.creationDate = creationDate; } public S3Owner getCanonicalUser() { - return canonicalUser; + return canonicalUser; } public void setCanonicalUser(S3Owner canonicalUser) { - this.canonicalUser = canonicalUser; + this.canonicalUser = canonicalUser; } public Set getContents() { - return objects; + return objects; } public void setContents(Set objects) { - this.objects = objects; + this.objects = objects; } - public boolean isComplete() { - return isComplete; + return isComplete; } public void setComplete(boolean complete) { - isComplete = complete; + isComplete = complete; } public boolean isHasData() { - return hasData; + return hasData; } public void setHasData(boolean hasData) { - this.hasData = hasData; + this.hasData = hasData; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof S3Bucket)) return false; + if (this == o) + return true; + if (!(o instanceof S3Bucket)) + return false; - S3Bucket s3Bucket = (S3Bucket) o; + S3Bucket s3Bucket = (S3Bucket) o; - if (hasData != s3Bucket.hasData) return false; - if (isComplete != s3Bucket.isComplete) return false; - if (canonicalUser != null ? !canonicalUser.equals(s3Bucket.canonicalUser) : s3Bucket.canonicalUser != null) - return false; - if (objects != null ? !objects.equals(s3Bucket.objects) : s3Bucket.objects != null) return false; - if (creationDate != null ? !creationDate.equals(s3Bucket.creationDate) : s3Bucket.creationDate != null) - return false; - if (!name.equals(s3Bucket.name)) return false; + if (hasData != s3Bucket.hasData) + return false; + if (isComplete != s3Bucket.isComplete) + return false; + if (canonicalUser != null ? !canonicalUser + .equals(s3Bucket.canonicalUser) + : s3Bucket.canonicalUser != null) + return false; + if (objects != null ? !objects.equals(s3Bucket.objects) + : s3Bucket.objects != null) + return false; + if (creationDate != null ? !creationDate.equals(s3Bucket.creationDate) + : s3Bucket.creationDate != null) + return false; + if (!name.equals(s3Bucket.name)) + return false; - return true; + return true; } @Override public int hashCode() { - int result = name.hashCode(); - result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0); - result = 31 * result + (canonicalUser != null ? canonicalUser.hashCode() : 0); - result = 31 * result + (objects != null ? objects.hashCode() : 0); - result = 31 * result + (isComplete ? 1 : 0); - result = 31 * result + (hasData ? 1 : 0); - return result; + int result = name.hashCode(); + result = 31 * result + + (creationDate != null ? creationDate.hashCode() : 0); + result = 31 * result + + (canonicalUser != null ? canonicalUser.hashCode() : 0); + result = 31 * result + (objects != null ? objects.hashCode() : 0); + result = 31 * result + (isComplete ? 1 : 0); + result = 31 * result + (hasData ? 1 : 0); + return result; } } 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 index f397b53b3f..ae4dfafeb7 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java +++ b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java @@ -24,6 +24,7 @@ package org.jclouds.aws.s3.domain; import org.joda.time.DateTime; +import static com.google.common.base.Preconditions.checkNotNull; /** * // TODO: Adrian: Document this! @@ -31,11 +32,11 @@ import org.joda.time.DateTime; * @author Adrian Cole */ public class S3Object { - public static final S3Object NOT_FOUND = new S3Object(); + public static final S3Object NOT_FOUND = new S3Object("NOT_FOUND"); public static final String UNKNOWN_MIME_TYPE = "application/x-unknown-mime-type"; - private String key; + private final String key; private DateTime lastModified; private String eTag; private long size = -1; @@ -47,12 +48,12 @@ public class S3Object { private String server; private Object content; - public String getKey() { - return key; + public S3Object(String key) { + this.key = checkNotNull(key); } - public void setKey(String key) { - this.key = key; + public String getKey() { + return key; } public DateTime getLastModified() { 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 index 3fef28739c..c018e78d4c 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/GuiceS3Context.java +++ b/s3/src/main/java/org/jclouds/aws/s3/internal/GuiceS3Context.java @@ -28,6 +28,7 @@ import java.io.IOException; import org.jclouds.Logger; 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.aws.s3.domain.S3Bucket; import org.jclouds.lifecycle.Closer; @@ -45,16 +46,23 @@ public class GuiceS3Context implements S3Context { S3ObjectMap createMapView(S3Bucket bucket); } + public interface S3InputStreamMapFactory { + S3InputStreamMap createMapView(S3Bucket bucket); + } + private final Logger logger; private final Injector injector; + private final S3InputStreamMapFactory s3InputStreamMapFactory; private final S3ObjectMapFactory s3ObjectMapFactory; private final Closer closer; @Inject private GuiceS3Context(java.util.logging.Logger logger, Injector injector, - Closer closer, S3ObjectMapFactory s3ObjectMapFactory) { + Closer closer, S3ObjectMapFactory s3ObjectMapFactory, + S3InputStreamMapFactory s3InputStreamMapFactory) { this.logger = new Logger(logger); this.injector = injector; + this.s3InputStreamMapFactory = s3InputStreamMapFactory; this.s3ObjectMapFactory = s3ObjectMapFactory; this.closer = closer; } @@ -69,7 +77,15 @@ public class GuiceS3Context implements S3Context { /** * {@inheritDoc} */ - public S3ObjectMap createMapView(S3Bucket bucket) { + public S3InputStreamMap createS3InputStreamMap(S3Bucket bucket) { + getConnection().createBucketIfNotExists(bucket); + return s3InputStreamMapFactory.createMapView(bucket); + } + + /** + * {@inheritDoc} + */ + public S3ObjectMap createS3ObjectMap(S3Bucket bucket) { getConnection().createBucketIfNotExists(bucket); return s3ObjectMapFactory.createMapView(bucket); } diff --git a/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java b/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java index 1af76e25e3..6e8c00a34d 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java +++ b/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java @@ -47,16 +47,13 @@ public class AmazonS3Test extends S3IntegrationTest { } S3Object getObject() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); return client.getObject(s3Bucket, "3366").get(); } String putFileObject() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); - S3Object object = new S3Object(); - object.setKey("meat"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); + S3Object object = new S3Object("meat"); object.setContentType("text/xml"); object.setContent(new File("pom.xml")); return client.addObject(s3Bucket, object).get(); @@ -77,49 +74,55 @@ public class AmazonS3Test extends S3IntegrationTest { @Test(dataProvider = "putTests") void testPutObject(String key, String type, Object content, Object realObject) throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "filetestsforadrian"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "filetestsforadrian"); client.createBucketIfNotExists(s3Bucket).get(); - S3Object object = new S3Object(); - - object.setKey(key); + context.createS3ObjectMap(s3Bucket).clear(); + assertEquals(client.getBucket(s3Bucket).get().getContents().size(), 0); + S3Object object = new S3Object(key); object.setContentType(type); object.setContent(content); assertNotNull(client.addObject(s3Bucket, object).get()); object = client.getObject(s3Bucket, object.getKey()).get(); returnedString = S3Utils.getContentAsStringAndClose(object); assertEquals(returnedString, realObject); - + assertEquals(client.getBucket(s3Bucket).get().getContents().size(), 1); } @Test void testCopyObject() throws Exception { String realObject = IOUtils.toString(new FileInputStream("pom.xml")); - S3Bucket sourceBucket = new S3Bucket(); - sourceBucket.setName(bucketPrefix + "copysource"); + S3Bucket sourceBucket = new S3Bucket(bucketPrefix + "copysource"); client.createBucketIfNotExists(sourceBucket).get(); + assertEquals(client.getBucket(sourceBucket).get().getContents().size(), + 0); - S3Object sourceObject = new S3Object(); - sourceObject.setKey("file"); + S3Object sourceObject = new S3Object("file"); sourceObject.setContentType("text/xml"); sourceObject.setContent(new File("pom.xml")); client.addObject(sourceBucket, sourceObject).get(); + assertEquals(client.getBucket(sourceBucket).get().getContents().size(), + 1); + sourceObject = client.getObject(sourceBucket, sourceObject.getKey()) .get(); assertEquals(S3Utils.getContentAsStringAndClose(sourceObject), realObject); - S3Bucket destinationBucket = new S3Bucket(); - destinationBucket.setName(bucketPrefix + "copydestination"); + S3Bucket destinationBucket = new S3Bucket(bucketPrefix + + "copydestination"); client.createBucketIfNotExists(destinationBucket).get(); + assertEquals(client.getBucket(destinationBucket).get().getContents() + .size(), 0); - S3Object destinationObject = new S3Object(); - destinationObject.setKey(sourceObject.getKey()); + S3Object destinationObject = new S3Object(sourceObject.getKey()); client.copyObject(sourceBucket, sourceObject, destinationBucket, destinationObject).get(); + assertEquals(client.getBucket(destinationBucket).get().getContents() + .size(), 1); + destinationObject = client.getObject(destinationBucket, destinationObject.getKey()).get(); @@ -129,38 +132,32 @@ public class AmazonS3Test extends S3IntegrationTest { } S3Object headObject() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); return client.headObject(s3Bucket, "3366").get(); } Boolean bucketExists() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); return client.bucketExists(s3Bucket).get(); } Boolean deleteBucket() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); return client.deleteBucket(s3Bucket).get(); } Boolean deleteObject() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); return client.deleteObject(s3Bucket, "3366").get(); } Boolean createBucketIfNotExists() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); return client.createBucketIfNotExists(s3Bucket).get(); } S3Bucket getBucket() throws Exception { - S3Bucket s3Bucket = new S3Bucket(); - s3Bucket.setName(bucketPrefix + "adrianjbosstest"); + S3Bucket s3Bucket = new S3Bucket(bucketPrefix + "adrianjbosstest"); return client.getBucket(s3Bucket).get(); } diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java index 154fc10781..233b4636b7 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java @@ -129,6 +129,7 @@ public class S3IntegrationTest { checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey")); properties.setProperty(HttpConstants.PROPERTY_HTTP_SECURE, "false"); properties.setProperty(HttpConstants.PROPERTY_HTTP_PORT, "80"); +// properties.setProperty("jclouds.http.sax.debug", "true"); return properties; } @@ -163,7 +164,7 @@ public class S3IntegrationTest { @AfterTest protected void tearDownClient() throws Exception { - deleteEverything(); +// deleteEverything(); context.close(); context = null; } diff --git a/s3/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java b/s3/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java index d5aac89da6..7059adafd0 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java @@ -37,7 +37,7 @@ import java.util.concurrent.CompletionService; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorCompletionService; -import static junit.framework.Assert.*; +import static org.testng.Assert.*; /** * This tests the performance of Digest commands. diff --git a/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java b/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java index a55483a8e9..b8c71bfff7 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java +++ b/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java @@ -55,8 +55,7 @@ public class StubS3Connection implements S3Connection { .get(s3Bucket); if (!realContents.containsKey(key)) return S3Object.NOT_FOUND; - S3Object object = new S3Object(); - object.setKey(key); + S3Object object = new S3Object(key); object.setContent(realContents.get(key)); return object; } @@ -158,8 +157,7 @@ public class StubS3Connection implements S3Connection { .get(s3Bucket); if (realContents != null) { for (String key : realContents.keySet()) { - S3Object object = new S3Object(); - object.setKey(key); + S3Object object = new S3Object(key); object.setContent(realContents.get(key)); contents.add(object); } 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 index f2a8267d28..0222880e46 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java @@ -72,30 +72,30 @@ public class S3CommandFactoryTest { @Test void testCreateCopyObject() { - assert commandFactory.createCopyObject(createMock(S3Bucket.class), - createMock(S3Object.class), createMock(S3Bucket.class), - createMock(S3Object.class)) != null; + assert commandFactory.createCopyObject(new S3Bucket("sourceBucket"), + new S3Object("sourceObject"), new S3Bucket("destBucket"), + new S3Object("destObject")) != null; } @Test void testCreateDeleteBucket() { - assert commandFactory.createDeleteBucket(createMock(S3Bucket.class)) != null; + assert commandFactory.createDeleteBucket(new S3Bucket("test")) != null; } @Test void testCreateDeleteObject() { - assert commandFactory.createDeleteObject(createMock(S3Bucket.class), + assert commandFactory.createDeleteObject(new S3Bucket("test"), "blah") != null; } @Test void testCreateHeadBucket() { - assert commandFactory.createHeadBucket(createMock(S3Bucket.class)) != null; + assert commandFactory.createHeadBucket(new S3Bucket("test")) != null; } @Test void testCreatePutBucket() { - assert commandFactory.createPutBucket(createMock(S3Bucket.class)) != null; + assert commandFactory.createPutBucket(new S3Bucket("test")) != null; } @Test @@ -108,13 +108,13 @@ public class S3CommandFactoryTest { replay(object); - assert commandFactory.createPutObject(createMock(S3Bucket.class), + assert commandFactory.createPutObject(new S3Bucket("test"), object) != null; } @Test void testCreateRetrieveObject() { - assert commandFactory.createRetrieveObject(createMock(S3Bucket.class), + assert commandFactory.createRetrieveObject(new S3Bucket("test"), "blah", false) != null; } @@ -135,7 +135,7 @@ public class S3CommandFactoryTest { @Test void testCreateListBucket() { - assert commandFactory.createListBucket(createMock(S3Bucket.class)) != null; + assert commandFactory.createListBucket(new S3Bucket("test")) != 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 index 1d2ec8f0dc..6142196856 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java @@ -34,11 +34,13 @@ import java.util.concurrent.ExecutorCompletionService; import org.apache.commons.io.IOUtils; import org.jclouds.aws.PerformanceTest; +import org.jclouds.aws.s3.commands.callables.xml.ListBucketHandler; import org.jclouds.aws.s3.commands.config.S3CommandsModule; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Owner; import org.jclouds.http.HttpException; +import org.jclouds.http.commands.callables.xml.ParseSax; import org.joda.time.DateTime; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; @@ -68,6 +70,8 @@ public class S3ParserTest extends PerformanceTest { protected void configure() { bindConstant().annotatedWith( Names.named("jclouds.http.address")).to("localhost"); + // bindConstant().annotatedWith( + // Names.named("jclouds.http.sax.debug")).to(true); super.configure(); } }); @@ -161,8 +165,10 @@ public class S3ParserTest extends PerformanceTest { } private S3Bucket runParseListBucketResult() throws HttpException { - return commandFactory.createListBucketParser().parse( - IOUtils.toInputStream(listBucketResult)); + ParseSax parser = commandFactory.createListBucketParser(); + ListBucketHandler handler = (ListBucketHandler) parser.getHandler(); + handler.setBucket(new S3Bucket("adrianjbosstest")); + return parser.parse(IOUtils.toInputStream(listBucketResult)); } @Test 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 index 44a688a3b9..6b93cd0d26 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java @@ -25,7 +25,7 @@ package org.jclouds.aws.s3.domain; import java.io.File; -import junit.framework.Assert; +import static org.testng.Assert.*; import org.jclouds.aws.s3.domain.S3Object; import org.testng.annotations.Test; @@ -34,10 +34,11 @@ import org.testng.annotations.Test; public class S3ObjectTest { @Test - void testSetNoContentType(){ - S3Object object = new S3Object(); + void testSetNoContentType() { + S3Object object = new S3Object("test"); File file = new File("hello.txt"); object.setContent(file); - Assert.assertEquals(object.getContentType(), S3Object.UNKNOWN_MIME_TYPE); + assertEquals(object.getContentType(), + S3Object.UNKNOWN_MIME_TYPE); } } diff --git a/samples/googleappengine/pom.xml b/samples/googleappengine/pom.xml index a33784e9d8..7fc785c661 100644 --- a/samples/googleappengine/pom.xml +++ b/samples/googleappengine/pom.xml @@ -85,18 +85,6 @@ guice-servlet 2.0-r936 - - org.testng - testng - 5.8 - test - jdk15 - - - commons-io - commons-io - 1.4 - standard taglibs diff --git a/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java b/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java index 451a757ae5..d68166c526 100644 --- a/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java +++ b/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java @@ -24,10 +24,8 @@ package org.jclouds.samples.googleappengine; import java.io.IOException; -import java.io.InputStream; import java.io.Writer; import java.util.List; -import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; @@ -48,6 +46,8 @@ import com.google.inject.Singleton; */ @Singleton public class JCloudsServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + @Inject S3Context context; @@ -62,7 +62,8 @@ public class JCloudsServlet extends HttpServlet { writer.write("List:\n"); for (S3Bucket bucket : myBuckets) { writer.write(String.format(" %1s: %2s entries%n", bucket - .getName(), context.createMapView(bucket).size())); + .getName(), context.createS3InputStreamMap(bucket) + .size())); } } catch (Exception e) { throw new ServletException(e); diff --git a/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java b/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java index 122329d402..1ee54011e4 100644 --- a/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java +++ b/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java @@ -34,7 +34,6 @@ import org.jclouds.aws.s3.S3Constants; import org.jclouds.aws.s3.S3Context; import org.jclouds.aws.s3.S3ContextFactory; import org.jclouds.gae.config.URLFetchServiceClientModule; -import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; import org.jclouds.samples.googleappengine.JCloudsServlet; import com.google.inject.Inject; @@ -76,6 +75,7 @@ public class GuiceServletConfig extends GuiceServletContextListener { } finally { IOUtils.closeQuietly(input); } + props.setProperty("jclouds.http.sax.debug", "true"); return props; }