mirror of https://github.com/apache/jclouds.git
Issue 318: updated to gae 1.3.5
This commit is contained in:
parent
318e9b9071
commit
9bffee1135
|
@ -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
|
|||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.5</appengine.home>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.3.5</appengine.home>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@
|
|||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
|
|
|
@ -54,7 +54,7 @@ public class GoogleDevServer {
|
|||
|
||||
});
|
||||
server.start();
|
||||
Thread.sleep(15 * 1000);
|
||||
Thread.sleep(30 * 1000);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
@ -36,7 +36,7 @@ attempting to run 'mvn -Plive install'
|
|||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.5</appengine.home>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.3.5</appengine.home>
|
||||
<appengine.applicationid>yourappid</appengine.applicationid>
|
||||
</properties>
|
||||
</profile>
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<appengine.applicationid>jclouds-tweetstore-spring</appengine.applicationid>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.tweetstore.blobstores>googlestorage,s3,azureblob</jclouds.tweetstore.blobstores>
|
||||
<jclouds.tweetstore.container>jclouds-tweetstore-spring</jclouds.tweetstore.container>
|
||||
</properties>
|
||||
|
||||
|
@ -168,12 +169,12 @@
|
|||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-labs</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
|
@ -305,6 +306,10 @@
|
|||
<name>devappserver.port</name>
|
||||
<value>${devappserver.port}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.blobstores</name>
|
||||
<value>${jclouds.tweetstore.blobstores}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.container</name>
|
||||
<value>${jclouds.tweetstore.container}</value>
|
||||
|
|
|
@ -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<String, BlobStoreContext> 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<Status> 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");
|
||||
|
|
|
@ -54,7 +54,7 @@ public class GoogleDevServer {
|
|||
|
||||
});
|
||||
server.start();
|
||||
Thread.sleep(10 * 1000);
|
||||
Thread.sleep(30 * 1000);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
@ -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<String, BlobStoreContext> contexts;
|
||||
private String container;
|
||||
|
||||
private static final Iterable<String> 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<String> 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<TwitterClient, TwitterAsyncClient> twitterContext = new RestContextFactory().createContext("twitter",
|
||||
wiring, props);
|
||||
wiring, props);
|
||||
StoreTweetsController controller = new StoreTweetsController(contexts, container, twitterContext.getApi());
|
||||
|
||||
Set<Status> 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");
|
||||
|
|
|
@ -28,7 +28,7 @@ attempting to run 'mvn -Plive install'
|
|||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.5</appengine.home>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.3.5</appengine.home>
|
||||
<appengine.applicationid>yourappid</appengine.applicationid>
|
||||
</properties>
|
||||
</profile>
|
||||
|
|
|
@ -1,309 +1,313 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Cloud Conscious, LLC.
|
||||
<info@cloudconscious.com>
|
||||
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
|
||||
====================================================================
|
||||
Licensed 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
|
||||
====================================================================
|
||||
Licensed 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.
|
||||
====================================================================
|
||||
-->
|
||||
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.
|
||||
====================================================================
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-demos-project</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>jclouds-demo-gae-tweetstore</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>JClouds TweetStore for Google App Engine</name>
|
||||
<description>JClouds TweetStore for Google App Engine</description>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-demos-project</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>jclouds-demo-gae-tweetstore</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>JClouds TweetStore for Google App Engine</name>
|
||||
<description>JClouds TweetStore for Google App Engine</description>
|
||||
|
||||
<properties>
|
||||
<!--
|
||||
note you must set the property ${appengine.home} to a valid
|
||||
extraction of appengine-java-sdk
|
||||
-->
|
||||
<appengine.home>YOUR_APPENGINE_HOME</appengine.home>
|
||||
<appengine.applicationid>jclouds-tweetstore</appengine.applicationid>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.tweetstore.container>jclouds-tweetstore</jclouds.tweetstore.container>
|
||||
</properties>
|
||||
<properties>
|
||||
<!--
|
||||
note you must set the property ${appengine.home} to a valid
|
||||
extraction of appengine-java-sdk
|
||||
-->
|
||||
<appengine.home>YOUR_APPENGINE_HOME</appengine.home>
|
||||
<appengine.applicationid>jclouds-tweetstore</appengine.applicationid>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.tweetstore.blobstores>googlestorage,s3,azureblob</jclouds.tweetstore.blobstores>
|
||||
<jclouds.tweetstore.container>jclouds-tweetstore</jclouds.tweetstore.container>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-blobstore</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-blobstore</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-log4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.14</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-twitter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-aws</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-azure</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-rackspace</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-gae</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.guice</groupId>
|
||||
<artifactId>guice-servlet</artifactId>
|
||||
<version>2.1-r1172</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>displaytag</groupId>
|
||||
<artifactId>displaytag</artifactId>
|
||||
<version>1.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<version>1.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>standard</artifactId>
|
||||
<groupId>taglibs</groupId>
|
||||
<version>1.1.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jstl</artifactId>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-el_1.0_spec</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-jsp_2.1_spec</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-servlet_2.5_spec</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-labs</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<webResources>
|
||||
<resource>
|
||||
<directory>src/main/appengine</directory>
|
||||
<targetPath>WEB-INF/</targetPath>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>appengine.home</name>
|
||||
<value>${appengine.home}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.address</name>
|
||||
<value>${devappserver.address}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.port</name>
|
||||
<value>${devappserver.port}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>warfile</name>
|
||||
<value>${project.build.directory}/${project.artifactId}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<additionalClasspathElements>
|
||||
<additionalClasspathElement>${appengine.home}/lib/appengine-tools-api.jar</additionalClasspathElement>
|
||||
</additionalClasspathElements>
|
||||
<environmentVariables>
|
||||
<DEBUG>true</DEBUG>
|
||||
<SDK_BIN>${appengine.home}/bin</SDK_BIN>
|
||||
<SDK_LIB>${appengine.home}/lib</SDK_LIB>
|
||||
<SDK_CONFIG>${appengine.home}/config/sdk</SDK_CONFIG>
|
||||
</environmentVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-blobstore</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-blobstore</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-log4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.14</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-twitter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-aws</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-azure</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-rackspace</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-gae</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.guice</groupId>
|
||||
<artifactId>guice-servlet</artifactId>
|
||||
<version>2.1-r1172</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>displaytag</groupId>
|
||||
<artifactId>displaytag</artifactId>
|
||||
<version>1.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-jdk14</artifactId>
|
||||
<version>1.5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>standard</artifactId>
|
||||
<groupId>taglibs</groupId>
|
||||
<version>1.1.2</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>jstl</artifactId>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-el_1.0_spec</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-jsp_2.1_spec</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-servlet_2.5_spec</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-labs</artifactId>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.5</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<webResources>
|
||||
<resource>
|
||||
<directory>src/main/appengine</directory>
|
||||
<targetPath>WEB-INF/</targetPath>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>appengine.home</name>
|
||||
<value>${appengine.home}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.address</name>
|
||||
<value>${devappserver.address}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.port</name>
|
||||
<value>${devappserver.port}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>warfile</name>
|
||||
<value>${project.build.directory}/${project.artifactId}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<additionalClasspathElements>
|
||||
<additionalClasspathElement>${appengine.home}/lib/appengine-tools-api.jar</additionalClasspathElement>
|
||||
</additionalClasspathElements>
|
||||
<environmentVariables>
|
||||
<DEBUG>true</DEBUG>
|
||||
<SDK_BIN>${appengine.home}/bin</SDK_BIN>
|
||||
<SDK_LIB>${appengine.home}/lib</SDK_LIB>
|
||||
<SDK_CONFIG>${appengine.home}/config/sdk</SDK_CONFIG>
|
||||
</environmentVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>live</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>twitter.identity</name>
|
||||
<value>${jclouds.twitter.user}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>twitter.credential</name>
|
||||
<value>${jclouds.twitter.password}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>azureblob.identity</name>
|
||||
<value>${jclouds.azure.storage.account}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>azureblob.credential</name>
|
||||
<value>${jclouds.azure.storage.key}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>cloudfiles.identity</name>
|
||||
<value>${jclouds.rackspace.user}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>cloudfiles.credential</name>
|
||||
<value>${jclouds.rackspace.key}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>s3.identity</name>
|
||||
<value>${jclouds.aws.accesskeyid}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>s3.credential</name>
|
||||
<value>${jclouds.aws.secretaccesskey}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>googlestorage.identity</name>
|
||||
<value>${jclouds.googlestorage.accesskeyid}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>googlestorage.credential</name>
|
||||
<value>${jclouds.googlestorage.secretaccesskey}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>appengine.home</name>
|
||||
<value>${appengine.home}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.address</name>
|
||||
<value>${devappserver.address}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.port</name>
|
||||
<value>${devappserver.port}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.container</name>
|
||||
<value>${jclouds.tweetstore.container}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>warfile</name>
|
||||
<value>${project.build.directory}/${project.artifactId}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>live</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>twitter.identity</name>
|
||||
<value>${jclouds.twitter.user}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>twitter.credential</name>
|
||||
<value>${jclouds.twitter.password}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>azureblob.identity</name>
|
||||
<value>${jclouds.azure.storage.account}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>azureblob.credential</name>
|
||||
<value>${jclouds.azure.storage.key}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>cloudfiles.identity</name>
|
||||
<value>${jclouds.rackspace.user}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>cloudfiles.credential</name>
|
||||
<value>${jclouds.rackspace.key}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>s3.identity</name>
|
||||
<value>${jclouds.aws.accesskeyid}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>s3.credential</name>
|
||||
<value>${jclouds.aws.secretaccesskey}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>googlestorage.identity</name>
|
||||
<value>${jclouds.googlestorage.accesskeyid}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>googlestorage.credential</name>
|
||||
<value>${jclouds.googlestorage.secretaccesskey}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>appengine.home</name>
|
||||
<value>${appengine.home}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.address</name>
|
||||
<value>${devappserver.address}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.port</name>
|
||||
<value>${devappserver.port}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.blobstores</name>
|
||||
<value>${jclouds.tweetstore.blobstores}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.tweetstore.container</name>
|
||||
<value>${jclouds.tweetstore.container}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>warfile</name>
|
||||
<value>${project.build.directory}/${project.artifactId}</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
|
|
@ -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<String, BlobStoreContext> 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<Status> 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");
|
||||
|
|
|
@ -54,7 +54,7 @@ public class GoogleDevServer {
|
|||
|
||||
});
|
||||
server.start();
|
||||
Thread.sleep(10 * 1000);
|
||||
Thread.sleep(30 * 1000);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
@ -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<String, BlobStoreContext> contexts;
|
||||
private String container;
|
||||
|
||||
private static final Iterable<String> 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<String> 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<TwitterClient, TwitterAsyncClient> twitterContext = new RestContextFactory().createContext("twitter",
|
||||
wiring, props);
|
||||
wiring, props);
|
||||
StoreTweetsController controller = new StoreTweetsController(contexts, container, twitterContext.getApi());
|
||||
|
||||
Set<Status> 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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -19,4 +19,4 @@
|
|||
#
|
||||
# An extension to run jclouds on Google App Engine (http://code.google.com/appengine/).
|
||||
#
|
||||
# TODO: Usage example.
|
||||
# TODO: Usage example.
|
||||
|
|
|
@ -47,24 +47,24 @@
|
|||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-stubs</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-testing</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-local-runtime</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -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<HttpRequest, HTTPRequest> {
|
||||
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<HttpRequest, HTTPRequest> {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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<HttpRequest, HTTPRequest> {
|
|||
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<HttpRequest, HTTPRequest> {
|
|||
}
|
||||
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<HttpRequest, HTTPRequest> {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue