From 9bffee11357922daf9af5bd779a1d860c13b22ce Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 21 Jul 2010 11:51:08 -0700 Subject: [PATCH] Issue 318: updated to gae 1.3.5 --- aws/demos/googleappengine/README.txt | 4 +- aws/demos/googleappengine/pom.xml | 2 +- .../functest/GoogleDevServer.java | 2 +- demos/gae-tweetstore-spring/README.txt | 2 +- demos/gae-tweetstore-spring/pom.xml | 9 +- .../controller/StoreTweetsController.java | 23 +- .../integration/GoogleDevServer.java | 2 +- .../integration/TweetStoreLiveTest.java | 25 +- demos/gae-tweetstore/README.txt | 2 +- demos/gae-tweetstore/pom.xml | 602 +++++++++--------- .../controller/StoreTweetsController.java | 8 +- .../integration/GoogleDevServer.java | 2 +- .../integration/TweetStoreLiveTest.java | 35 +- .../jclouds/http/apachehc/ApacheHCUtils.java | 11 +- extensions/gae/README.txt | 2 +- extensions/gae/pom.xml | 8 +- .../org/jclouds/gae/ConvertToGaeRequest.java | 37 +- .../jclouds/gae/ConvertToGaeRequestTest.java | 21 +- 18 files changed, 408 insertions(+), 389 deletions(-) diff --git a/aws/demos/googleappengine/README.txt b/aws/demos/googleappengine/README.txt index 1621b44f86..0e4ef37197 100755 --- a/aws/demos/googleappengine/README.txt +++ b/aws/demos/googleappengine/README.txt @@ -16,7 +16,7 @@ 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.5.zip +This samples uses the Google App Engine for Java SDK located at http://googleappengine.googlecode.com/files/appengine-java-sdk-1.3.5.zip Please unzip the above file and modify your maven settings.xml like below before attempting to run 'mvn -Plive install' @@ -26,7 +26,7 @@ Please unzip the above file and modify your maven settings.xml like below before true - /path/to/appengine-java-sdk-1.2.5 + /path/to/appengine-java-sdk-1.3.5 diff --git a/aws/demos/googleappengine/pom.xml b/aws/demos/googleappengine/pom.xml index d1c7f71b2c..a9da52fb57 100644 --- a/aws/demos/googleappengine/pom.xml +++ b/aws/demos/googleappengine/pom.xml @@ -101,7 +101,7 @@ com.google.appengine appengine-tools-api - 1.3.2 + 1.3.5 system ${appengine.home}/lib/appengine-tools-api.jar diff --git a/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleDevServer.java b/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleDevServer.java index 6f06ea8c54..bbc4342eb3 100755 --- a/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleDevServer.java +++ b/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleDevServer.java @@ -54,7 +54,7 @@ public class GoogleDevServer { }); server.start(); - Thread.sleep(15 * 1000); + Thread.sleep(30 * 1000); } @SuppressWarnings("deprecation") diff --git a/demos/gae-tweetstore-spring/README.txt b/demos/gae-tweetstore-spring/README.txt index 5ea882839c..0531f59583 100644 --- a/demos/gae-tweetstore-spring/README.txt +++ b/demos/gae-tweetstore-spring/README.txt @@ -36,7 +36,7 @@ attempting to run 'mvn -Plive install' true - /path/to/appengine-java-sdk-1.2.5 + /path/to/appengine-java-sdk-1.3.5 yourappid diff --git a/demos/gae-tweetstore-spring/pom.xml b/demos/gae-tweetstore-spring/pom.xml index 1c62a3f573..896093ca57 100644 --- a/demos/gae-tweetstore-spring/pom.xml +++ b/demos/gae-tweetstore-spring/pom.xml @@ -41,6 +41,7 @@ jclouds-tweetstore-spring localhost 8088 + googlestorage,s3,azureblob jclouds-tweetstore-spring @@ -168,12 +169,12 @@ com.google.appengine appengine-api-labs - 1.3.2 + 1.3.5 com.google.appengine appengine-tools-api - 1.3.2 + 1.3.5 system ${appengine.home}/lib/appengine-tools-api.jar @@ -305,6 +306,10 @@ devappserver.port ${devappserver.port} + + jclouds.tweetstore.blobstores + ${jclouds.tweetstore.blobstores} + jclouds.tweetstore.container ${jclouds.tweetstore.container} diff --git a/demos/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java index 2346fa74e6..bd408987d6 100644 --- a/demos/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ b/demos/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java @@ -63,10 +63,9 @@ public class StoreTweetsController extends HttpServlet { public Blob apply(Status from) { Blob to = map.newBlob(from.getId() + ""); - to.getMetadata().setContentType(MediaType.TEXT_PLAIN); to.setPayload(from.getText()); - to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, - from.getUser().getScreenName()); + to.getPayload().setContentType(MediaType.TEXT_PLAIN); + to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); return to; } } @@ -84,8 +83,7 @@ public class StoreTweetsController extends HttpServlet { @Inject @VisibleForTesting public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, - TwitterClient client) { + @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, TwitterClient client) { this.container = container; this.contexts = contexts; this.client = client; @@ -93,8 +91,8 @@ public class StoreTweetsController extends HttpServlet { @VisibleForTesting public void addMyTweets(String contextName, Set allAboutMe) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " - + contextName + " in " + contexts.keySet()); + BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " + + contexts.keySet()); BlobMap map = context.createBlobMap(container); for (Status status : allAboutMe) { Blob blob = null; @@ -104,20 +102,17 @@ public class StoreTweetsController extends HttpServlet { } catch (AuthorizationException e) { throw e; } catch (Exception e) { - logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, - context, container); + logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container); } } } @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getHeader("X-AppEngine-QueueName") != null - && request.getHeader("X-AppEngine-QueueName").equals("twitter")) { + && request.getHeader("X-AppEngine-QueueName").equals("twitter")) { try { - String contextName = checkNotNull(request.getHeader("context"), - "missing header context"); + String contextName = checkNotNull(request.getHeader("context"), "missing header context"); logger.info("retrieving tweets"); addMyTweets(contextName, client.getMyMentions()); logger.debug("done storing tweets"); diff --git a/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java b/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java index 271dcd67fa..585872cbb0 100644 --- a/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java +++ b/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java @@ -54,7 +54,7 @@ public class GoogleDevServer { }); server.start(); - Thread.sleep(10 * 1000); + Thread.sleep(30 * 1000); } @SuppressWarnings("deprecation") diff --git a/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java index 376ea5b15b..2ee32afec7 100644 --- a/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ b/demos/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java @@ -49,13 +49,14 @@ import org.testng.annotations.Parameters; import org.testng.annotations.Test; import com.google.common.base.Joiner; +import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.inject.Module; /** - * Starts up the Google App Engine for Java Development environment and deploys an application which - * tests accesses twitter and blobstores. + * Starts up the Google App Engine for Java Development environment and deploys + * an application which tests accesses twitter and blobstores. * * @author Adrian Cole */ @@ -67,7 +68,9 @@ public class TweetStoreLiveTest { private Map contexts; private String container; - private static final Iterable blobstores = ImmutableSet.of("cloudfiles", "googlestorage", "s3", "azureblob"); + private static final String blobs = System.getProperty("jclouds.tweetstore.blobstores", + "cloudfiles,googlestorage,s3,azureblob"); + private static final Iterable blobstores = Splitter.on(',').split(blobs); private static final Properties props = new Properties(); @BeforeTest @@ -75,7 +78,7 @@ public class TweetStoreLiveTest { container = checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER)); props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER), - PROPERTY_TWEETSTORE_CONTAINER)); + PROPERTY_TWEETSTORE_CONTAINER)); props.setProperty(SpringServletConfig.PROPERTY_BLOBSTORE_CONTEXTS, Joiner.on(',').join(blobstores)); @@ -95,7 +98,7 @@ public class TweetStoreLiveTest { } RestContext twitterContext = new RestContextFactory().createContext("twitter", - wiring, props); + wiring, props); StoreTweetsController controller = new StoreTweetsController(contexts, container, twitterContext.getApi()); Set statuses = twitterContext.getApi().getMyMentions(); @@ -104,7 +107,7 @@ public class TweetStoreLiveTest { for (BlobStoreContext context : contexts.values()) { if (context.getBlobStore().containerExists(container)) { System.err.printf("deleting container %s at %s%n", container, context.getProviderSpecificContext() - .getEndpoint()); + .getEndpoint()); context.getBlobStore().deleteContainer(container); deleted = true; } @@ -115,7 +118,7 @@ public class TweetStoreLiveTest { } for (BlobStoreContext context : contexts.values()) { System.err.printf("creating container %s at %s%n", container, context.getProviderSpecificContext() - .getEndpoint()); + .getEndpoint()); context.getBlobStore().createContainerInLocation(null, container); } if (deleted) { @@ -134,15 +137,15 @@ public class TweetStoreLiveTest { String twitterCredential = checkNotNull(System.getProperty("twitter.credential"), "twitter.credential"); props.putAll(RestContextFactory.toProperties(contextSpec("twitter", "http://twitter.com", "1", twitterIdentity, - twitterCredential, TwitterClient.class, TwitterAsyncClient.class))); + twitterCredential, TwitterClient.class, TwitterAsyncClient.class))); } private void addCredentialsForBlobStores(Properties props) { for (String provider : blobstores) { props.setProperty(provider + ".identity", checkNotNull(System.getProperty(provider + ".identity"), provider - + ".identity")); + + ".identity")); props.setProperty(provider + ".credential", checkNotNull(System.getProperty(provider + ".credential"), - provider + ".credential")); + provider + ".credential")); } } @@ -170,7 +173,7 @@ public class TweetStoreLiveTest { public void testPrimeContainers() throws IOException, InterruptedException { URL gurl = new URL(url, "/store/do"); // WATCH THIS, you need to add a context each time - for (String context : new String[] { "cloudfiles", "s3", "azureblob" }) { + for (String context : blobstores) { System.out.println("storing at context: " + context); HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); connection.addRequestProperty("X-AppEngine-QueueName", "twitter"); diff --git a/demos/gae-tweetstore/README.txt b/demos/gae-tweetstore/README.txt index e74ce55897..a50d18d4b0 100755 --- a/demos/gae-tweetstore/README.txt +++ b/demos/gae-tweetstore/README.txt @@ -28,7 +28,7 @@ attempting to run 'mvn -Plive install' true - /path/to/appengine-java-sdk-1.2.5 + /path/to/appengine-java-sdk-1.3.5 yourappid diff --git a/demos/gae-tweetstore/pom.xml b/demos/gae-tweetstore/pom.xml index 3758077b6d..10f83c34c8 100644 --- a/demos/gae-tweetstore/pom.xml +++ b/demos/gae-tweetstore/pom.xml @@ -1,309 +1,313 @@ - + 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. + ==================================================================== + --> - 4.0.0 - - org.jclouds - jclouds-demos-project - 1.0-SNAPSHOT - - jclouds-demo-gae-tweetstore - war - JClouds TweetStore for Google App Engine - JClouds TweetStore for Google App Engine + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + + org.jclouds + jclouds-demos-project + 1.0-SNAPSHOT + + jclouds-demo-gae-tweetstore + war + JClouds TweetStore for Google App Engine + JClouds TweetStore for Google App Engine - - - YOUR_APPENGINE_HOME - jclouds-tweetstore - localhost - 8088 - jclouds-tweetstore - + + + YOUR_APPENGINE_HOME + jclouds-tweetstore + localhost + 8088 + googlestorage,s3,azureblob + jclouds-tweetstore + - - - ${project.groupId} - jclouds-blobstore - ${project.version} - - - ${project.groupId} - jclouds-blobstore - ${project.version} - test-jar - test - - - ${project.groupId} - jclouds-core - ${project.version} - test-jar - test - - - ${project.groupId} - jclouds-log4j - ${project.version} - test - - - log4j - log4j - 1.2.14 - test - - - ${project.groupId} - jclouds-twitter - ${project.version} - - - ${project.groupId} - jclouds-aws - ${project.version} - - - ${project.groupId} - jclouds-azure - ${project.version} - - - ${project.groupId} - jclouds-rackspace - ${project.version} - - - ${project.groupId} - jclouds-gae - ${project.version} - - - com.google.code.guice - guice-servlet - 2.1-r1172 - - - displaytag - displaytag - 1.2 - - - org.slf4j - slf4j-log4j12 - - - - - org.slf4j - slf4j-jdk14 - 1.5.6 - - - standard - taglibs - 1.1.2 - runtime - - - jstl - javax.servlet - 1.1.2 - - - org.apache.geronimo.specs - geronimo-el_1.0_spec - 1.0.1 - - - 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-api-labs - 1.3.2 - - - com.google.appengine - appengine-tools-api - 1.3.2 - system - ${appengine.home}/lib/appengine-tools-api.jar - - - - ${project.artifactId} - - - maven-war-plugin - - - - src/main/appengine - WEB-INF/ - true - - - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - - 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 - - - - - - - + + + ${project.groupId} + jclouds-blobstore + ${project.version} + + + ${project.groupId} + jclouds-blobstore + ${project.version} + test-jar + test + + + ${project.groupId} + jclouds-core + ${project.version} + test-jar + test + + + ${project.groupId} + jclouds-log4j + ${project.version} + test + + + log4j + log4j + 1.2.14 + test + + + ${project.groupId} + jclouds-twitter + ${project.version} + + + ${project.groupId} + jclouds-aws + ${project.version} + + + ${project.groupId} + jclouds-azure + ${project.version} + + + ${project.groupId} + jclouds-rackspace + ${project.version} + + + ${project.groupId} + jclouds-gae + ${project.version} + + + com.google.code.guice + guice-servlet + 2.1-r1172 + + + displaytag + displaytag + 1.2 + + + org.slf4j + slf4j-log4j12 + + + + + org.slf4j + slf4j-jdk14 + 1.5.6 + + + standard + taglibs + 1.1.2 + runtime + + + jstl + javax.servlet + 1.1.2 + + + org.apache.geronimo.specs + geronimo-el_1.0_spec + 1.0.1 + + + 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-api-labs + 1.3.5 + + + com.google.appengine + appengine-tools-api + 1.3.5 + system + ${appengine.home}/lib/appengine-tools-api.jar + + + + ${project.artifactId} + + + maven-war-plugin + + + + src/main/appengine + WEB-INF/ + true + + + + + + maven-surefire-plugin + + + integration + integration-test + + test + + + + + 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 + + + + + + + - - - live - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - - twitter.identity - ${jclouds.twitter.user} - - - twitter.credential - ${jclouds.twitter.password} - - - azureblob.identity - ${jclouds.azure.storage.account} - - - azureblob.credential - ${jclouds.azure.storage.key} - - - cloudfiles.identity - ${jclouds.rackspace.user} - - - cloudfiles.credential - ${jclouds.rackspace.key} - - - s3.identity - ${jclouds.aws.accesskeyid} - - - s3.credential - ${jclouds.aws.secretaccesskey} - - - googlestorage.identity - ${jclouds.googlestorage.accesskeyid} - - - googlestorage.credential - ${jclouds.googlestorage.secretaccesskey} - - - appengine.home - ${appengine.home} - - - devappserver.address - ${devappserver.address} - - - devappserver.port - ${devappserver.port} - - - jclouds.tweetstore.container - ${jclouds.tweetstore.container} - - - warfile - ${project.build.directory}/${project.artifactId} - - - - - - - - - - + + + live + + + + maven-surefire-plugin + + + integration + integration-test + + test + + + + + twitter.identity + ${jclouds.twitter.user} + + + twitter.credential + ${jclouds.twitter.password} + + + azureblob.identity + ${jclouds.azure.storage.account} + + + azureblob.credential + ${jclouds.azure.storage.key} + + + cloudfiles.identity + ${jclouds.rackspace.user} + + + cloudfiles.credential + ${jclouds.rackspace.key} + + + s3.identity + ${jclouds.aws.accesskeyid} + + + s3.credential + ${jclouds.aws.secretaccesskey} + + + googlestorage.identity + ${jclouds.googlestorage.accesskeyid} + + + googlestorage.credential + ${jclouds.googlestorage.secretaccesskey} + + + appengine.home + ${appengine.home} + + + devappserver.address + ${devappserver.address} + + + devappserver.port + ${devappserver.port} + + + jclouds.tweetstore.blobstores + ${jclouds.tweetstore.blobstores} + + + jclouds.tweetstore.container + ${jclouds.tweetstore.container} + + + warfile + ${project.build.directory}/${project.artifactId} + + + + + + + + + + diff --git a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java index ad3d560b7c..bd408987d6 100644 --- a/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ b/demos/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java @@ -63,8 +63,8 @@ public class StoreTweetsController extends HttpServlet { public Blob apply(Status from) { Blob to = map.newBlob(from.getId() + ""); - to.getMetadata().setContentType(MediaType.TEXT_PLAIN); to.setPayload(from.getText()); + to.getPayload().setContentType(MediaType.TEXT_PLAIN); to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); return to; } @@ -83,7 +83,7 @@ public class StoreTweetsController extends HttpServlet { @Inject @VisibleForTesting public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, TwitterClient client) { + @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, TwitterClient client) { this.container = container; this.contexts = contexts; this.client = client; @@ -92,7 +92,7 @@ public class StoreTweetsController extends HttpServlet { @VisibleForTesting public void addMyTweets(String contextName, Set allAboutMe) { BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " - + contexts.keySet()); + + contexts.keySet()); BlobMap map = context.createBlobMap(container); for (Status status : allAboutMe) { Blob blob = null; @@ -110,7 +110,7 @@ public class StoreTweetsController extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getHeader("X-AppEngine-QueueName") != null - && request.getHeader("X-AppEngine-QueueName").equals("twitter")) { + && request.getHeader("X-AppEngine-QueueName").equals("twitter")) { try { String contextName = checkNotNull(request.getHeader("context"), "missing header context"); logger.info("retrieving tweets"); diff --git a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java index 271dcd67fa..585872cbb0 100755 --- a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java +++ b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java @@ -54,7 +54,7 @@ public class GoogleDevServer { }); server.start(); - Thread.sleep(10 * 1000); + Thread.sleep(30 * 1000); } @SuppressWarnings("deprecation") diff --git a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java index b65eeeaaac..a05ac32e9b 100755 --- a/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ b/demos/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java @@ -38,6 +38,7 @@ import org.jclouds.blobstore.BlobStoreContextFactory; import org.jclouds.demo.tweetstore.config.GuiceServletConfig; import org.jclouds.demo.tweetstore.controller.StoreTweetsController; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextFactory; import org.jclouds.twitter.TwitterAsyncClient; @@ -49,13 +50,14 @@ import org.testng.annotations.Parameters; import org.testng.annotations.Test; import com.google.common.base.Joiner; +import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.inject.Module; /** - * Starts up the Google App Engine for Java Development environment and deploys an application which - * tests accesses twitter and blobstores. + * Starts up the Google App Engine for Java Development environment and deploys + * an application which tests accesses twitter and blobstores. * * @author Adrian Cole */ @@ -66,8 +68,9 @@ public class TweetStoreLiveTest { private URL url; private Map contexts; private String container; - - private static final Iterable blobstores = ImmutableSet.of("cloudfiles", "googlestorage", "s3", "azureblob"); + private static final String blobs = System.getProperty("jclouds.tweetstore.blobstores", + "cloudfiles,googlestorage,s3,azureblob"); + private static final Iterable blobstores = Splitter.on(',').split(blobs); private static final Properties props = new Properties(); @BeforeTest @@ -75,7 +78,7 @@ public class TweetStoreLiveTest { container = checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER)); props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, checkNotNull(System.getProperty(PROPERTY_TWEETSTORE_CONTAINER), - PROPERTY_TWEETSTORE_CONTAINER)); + PROPERTY_TWEETSTORE_CONTAINER)); props.setProperty(GuiceServletConfig.PROPERTY_BLOBSTORE_CONTEXTS, Joiner.on(',').join(blobstores)); @@ -95,18 +98,22 @@ public class TweetStoreLiveTest { } RestContext twitterContext = new RestContextFactory().createContext("twitter", - wiring, props); + wiring, props); StoreTweetsController controller = new StoreTweetsController(contexts, container, twitterContext.getApi()); Set statuses = twitterContext.getApi().getMyMentions(); boolean deleted = false; for (BlobStoreContext context : contexts.values()) { - if (context.getBlobStore().containerExists(container)) { - System.err.printf("deleting container %s at %s%n", container, context.getProviderSpecificContext() + try { + if (context.getBlobStore().containerExists(container)) { + System.err.printf("deleting container %s at %s%n", container, context.getProviderSpecificContext() .getEndpoint()); - context.getBlobStore().deleteContainer(container); - deleted = true; + context.getBlobStore().deleteContainer(container); + deleted = true; + } + } catch (AuthorizationException e) { + throw new AuthorizationException("for context: " + context, e); } } if (deleted) { @@ -115,7 +122,7 @@ public class TweetStoreLiveTest { } for (BlobStoreContext context : contexts.values()) { System.err.printf("creating container %s at %s%n", container, context.getProviderSpecificContext() - .getEndpoint()); + .getEndpoint()); context.getBlobStore().createContainerInLocation(null, container); } @@ -144,15 +151,15 @@ public class TweetStoreLiveTest { String twitterCredential = checkNotNull(System.getProperty("twitter.credential"), "twitter.credential"); props.putAll(RestContextFactory.toProperties(contextSpec("twitter", "http://twitter.com", "1", twitterIdentity, - twitterCredential, TwitterClient.class, TwitterAsyncClient.class))); + twitterCredential, TwitterClient.class, TwitterAsyncClient.class))); } private void addCredentialsForBlobStores(Properties props) { for (String provider : blobstores) { props.setProperty(provider + ".identity", checkNotNull(System.getProperty(provider + ".identity"), provider - + ".identity")); + + ".identity")); props.setProperty(provider + ".credential", checkNotNull(System.getProperty(provider + ".credential"), - provider + ".credential")); + provider + ".credential")); } } diff --git a/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java b/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java index 44b35f4a04..142c4599f8 100644 --- a/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java +++ b/extensions/apachehc/src/main/java/org/jclouds/http/apachehc/ApacheHCUtils.java @@ -97,8 +97,7 @@ public class ApacheHCUtils { } public static void addEntityForContent(HttpEntityEnclosingRequest apacheRequest, Payload payload) { - payload = payload instanceof DelegatingPayload ? DelegatingPayload.class.cast(payload) - .getDelegate() : payload; + payload = payload instanceof DelegatingPayload ? DelegatingPayload.class.cast(payload).getDelegate() : payload; if (payload instanceof StringPayload) { StringEntity nStringEntity = null; try { @@ -109,17 +108,15 @@ public class ApacheHCUtils { nStringEntity.setContentType(payload.getContentType()); apacheRequest.setEntity(nStringEntity); } else if (payload instanceof FilePayload) { - apacheRequest.setEntity(new FileEntity((File) payload.getRawContent(), payload - .getContentType())); + apacheRequest.setEntity(new FileEntity((File) payload.getRawContent(), payload.getContentType())); } else if (payload instanceof ByteArrayPayload) { ByteArrayEntity Entity = new ByteArrayEntity((byte[]) payload.getRawContent()); Entity.setContentType(payload.getContentType()); apacheRequest.setEntity(Entity); } else { InputStream inputStream = payload.getInput(); - if (!new Long(1).equals(payload.getContentLength())) - throw new IllegalArgumentException( - "you must specify size when content is an InputStream"); + if (payload.getContentLength() == null) + throw new IllegalArgumentException("you must specify size when content is an InputStream"); InputStreamEntity Entity = new InputStreamEntity(inputStream, payload.getContentLength()); Entity.setContentType(payload.getContentType()); apacheRequest.setEntity(Entity); diff --git a/extensions/gae/README.txt b/extensions/gae/README.txt index 0c8fe250cc..792e59c0b8 100644 --- a/extensions/gae/README.txt +++ b/extensions/gae/README.txt @@ -19,4 +19,4 @@ # # An extension to run jclouds on Google App Engine (http://code.google.com/appengine/). # -# TODO: Usage example. \ No newline at end of file +# TODO: Usage example. diff --git a/extensions/gae/pom.xml b/extensions/gae/pom.xml index 5108126cd6..ea2d1fc29b 100644 --- a/extensions/gae/pom.xml +++ b/extensions/gae/pom.xml @@ -47,24 +47,24 @@ com.google.appengine appengine-api - 1.3.2 + 1.3.5 com.google.appengine appengine-api-stubs - 1.3.2 + 1.3.5 test com.google.appengine appengine-testing - 1.3.2 + 1.3.5 test com.google.appengine appengine-local-runtime - 1.3.2 + 1.3.5 test diff --git a/extensions/gae/src/main/java/org/jclouds/gae/ConvertToGaeRequest.java b/extensions/gae/src/main/java/org/jclouds/gae/ConvertToGaeRequest.java index 0bd0be8dac..c436ec5a10 100644 --- a/extensions/gae/src/main/java/org/jclouds/gae/ConvertToGaeRequest.java +++ b/extensions/gae/src/main/java/org/jclouds/gae/ConvertToGaeRequest.java @@ -34,6 +34,7 @@ import javax.ws.rs.core.HttpHeaders; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.HttpRequest; +import org.jclouds.io.Payload; import com.google.appengine.api.urlfetch.FetchOptions; import com.google.appengine.api.urlfetch.HTTPHeader; @@ -48,7 +49,7 @@ import com.google.common.base.Function; */ @Singleton public class ConvertToGaeRequest implements Function { - public static final String USER_AGENT = "jclouds/1.0 urlfetch/1.3.2"; + public static final String USER_AGENT = "jclouds/1.0 urlfetch/1.3.5"; private final EncryptionService encryptionService; @@ -58,8 +59,8 @@ public class ConvertToGaeRequest implements Function { } /** - * byte [] content is replayable and the only content type supportable by GAE. As such, we - * convert the original request content to a byte array. + * byte [] content is replayable and the only content type supportable by + * GAE. As such, we convert the original request content to a byte array. */ @Override public HTTPRequest apply(HttpRequest request) { @@ -73,8 +74,7 @@ public class ConvertToGaeRequest implements Function { FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); - HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod() - .toString()), options); + HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options); for (String header : request.getHeaders().keySet()) { for (String value : request.getHeaders().get(header)) { @@ -84,15 +84,21 @@ public class ConvertToGaeRequest implements Function { } gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT)); /** - * byte [] content is replayable and the only content type supportable by GAE. As such, we - * convert the original request content to a byte array. + * byte [] content is replayable and the only content type supportable by + * GAE. As such, we convert the original request content to a byte array. */ if (request.getPayload() != null) { InputStream input = request.getPayload().getInput(); try { byte[] array = toByteArray(input); - if (!request.getPayload().isRepeatable()) + if (!request.getPayload().isRepeatable()) { + Payload oldPayload = request.getPayload(); request.setPayload(array); + if (oldPayload.getContentMD5() != null) + request.getPayload().setContentMD5(oldPayload.getContentMD5()); + if (oldPayload.getContentType() != null) + request.getPayload().setContentType(oldPayload.getContentType()); + } gaeRequest.setPayload(array); } catch (IOException e) { Throwables.propagate(e); @@ -100,16 +106,15 @@ public class ConvertToGaeRequest implements Function { closeQuietly(input); } if (request.getPayload().getContentMD5() != null) - gaeRequest.addHeader(new HTTPHeader("Content-MD5", encryptionService.base64(request - .getPayload().getContentMD5()))); - - Long length = checkNotNull(request.getPayload().getContentLength(), - "payload.getContentLength"); - gaeRequest.addHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, length.toString())); + gaeRequest.setHeader(new HTTPHeader("Content-MD5", encryptionService.base64(request.getPayload() + .getContentMD5()))); + if (request.getPayload().getContentType() != null) + gaeRequest.setHeader(new HTTPHeader(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentType())); + Long length = checkNotNull(request.getPayload().getContentLength(), "payload.getContentLength"); + gaeRequest.setHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, length.toString())); } else { - gaeRequest.addHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, "0")); + gaeRequest.setHeader(new HTTPHeader(HttpHeaders.CONTENT_LENGTH, "0")); } return gaeRequest; } - } \ No newline at end of file diff --git a/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java b/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java index a2aae241ad..1b91e70412 100644 --- a/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java +++ b/extensions/gae/src/test/java/org/jclouds/gae/ConvertToGaeRequestTest.java @@ -37,6 +37,7 @@ import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test; +import com.google.appengine.api.urlfetch.HTTPHeader; import com.google.appengine.api.urlfetch.HTTPRequest; import com.google.appengine.repackaged.com.google.common.base.Charsets; import com.google.common.io.Files; @@ -84,9 +85,10 @@ public class ConvertToGaeRequestTest { HttpRequest request = new HttpRequest(HttpMethod.GET, endPoint); HTTPRequest gaeRequest = req.apply(request); assert gaeRequest.getPayload() == null; - assertEquals(gaeRequest.getHeaders().size(), 2);// content length, user agent + assertEquals(gaeRequest.getHeaders().size(), 2);// content length, user + // agent assertEquals(gaeRequest.getHeaders().get(0).getName(), HttpHeaders.USER_AGENT); - assertEquals(gaeRequest.getHeaders().get(0).getValue(), "jclouds/1.0 urlfetch/1.3.2"); + assertEquals(gaeRequest.getHeaders().get(0).getValue(), "jclouds/1.0 urlfetch/1.3.5"); } @Test @@ -129,15 +131,16 @@ public class ConvertToGaeRequestTest { } private void testHoot(HttpRequest request) throws IOException { - request.getHeaders().put(HttpHeaders.CONTENT_TYPE, "text/plain"); + request.getPayload().setContentType("text/plain"); + request.getPayload().setContentMD5(new byte[] { 1, 2, 3, 4 }); HTTPRequest gaeRequest = req.apply(request); - try { - assertEquals(gaeRequest.getHeaders().get(0).getName(), HttpHeaders.CONTENT_TYPE); - assertEquals(gaeRequest.getHeaders().get(0).getValue(), "text/plain"); - } catch (AssertionError e) { - assertEquals(gaeRequest.getHeaders().get(1).getName(), HttpHeaders.CONTENT_TYPE); - assertEquals(gaeRequest.getHeaders().get(1).getValue(), "text/plain"); + + StringBuilder builder = new StringBuilder(); + for (HTTPHeader header : gaeRequest.getHeaders()) { + builder.append(header.getName()).append(": ").append(header.getValue()).append("\n"); } + assertEquals(builder.toString(), + "User-Agent: jclouds/1.0 urlfetch/1.3.5\nContent-MD5: AQIDBA==\nContent-Type: text/plain\nContent-Length: 5\n"); assertEquals(new String(gaeRequest.getPayload()), "hoot!"); } }