Ported gae-tweetstore to the 1.4.2 appengine API and to changed in Twitter4j

This commit is contained in:
Andrew Phillips 2011-05-21 06:53:47 -04:00
parent 6c9ca419f6
commit b07ca99372
3 changed files with 314 additions and 297 deletions

View File

@ -20,20 +20,23 @@
<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>
<groupId>org.jclouds.demos</groupId>
<artifactId>gae-replicator</artifactId>
<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 example to replicate the contents of a container</name>
<description>JClouds example to replicate the contents of a container</description>
<name>JClouds TweetStore for Google App Engine</name>
<description>JClouds TweetStore for Google App Engine using Guice for Dependency Injection</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-replicate</appengine.applicationid>
<appengine.sdk.version>1.4.2</appengine.sdk.version>
<devappserver.address>localhost</devappserver.address>
<devappserver.port>8088</devappserver.port>
<jclouds.replicate.source>googlestorage</jclouds.replicate.source>
@ -44,9 +47,14 @@
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-allblobstore</artifactId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[2.1,)</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-blobstore</artifactId>
@ -54,28 +62,29 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>aws-s3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<artifactId>jclouds-atmos</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>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds.driver</groupId>
<artifactId>gae</artifactId>
<artifactId>jclouds-gae</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
@ -99,6 +108,11 @@
<artifactId>slf4j-jdk14</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<artifactId>jstl</artifactId>
<groupId>javax.servlet</groupId>
<version>1.1.2</version>
</dependency>
<dependency>
<artifactId>standard</artifactId>
<groupId>taglibs</groupId>
@ -106,16 +120,22 @@
<scope>runtime</scope>
</dependency>
<dependency>
<artifactId>jstl</artifactId>
<groupId>javax.servlet</groupId>
<version>1.1.2</version>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- Google App Engine API -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.4.2</version>
<version>${appengine.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
<version>${appengine.sdk.version}</version>
</dependency>
<!-- Google App Engine Runtime Dependencies -->
@ -125,47 +145,35 @@
<version>1.1.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_3.0_spec</artifactId>
<version>1.1.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.appengine.orm</groupId>
<artifactId>jdo2-api</artifactId>
<version>2.3-eb</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>com.google.appengine.orm</groupId>
<artifactId>datanucleus-appengine</artifactId>
<version>1.0.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-jpa</artifactId>
<version>1.1.5</version>
<scope>runtime</scope>
</dependency>
<!-- App Engine Runtime Dependencies-->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-tools-sdk</artifactId>
<version>1.4.2</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>

View File

@ -18,7 +18,7 @@
*/
package org.jclouds.demo.tweetstore.config;
import static com.google.appengine.api.labs.taskqueue.TaskOptions.Builder.url;
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
@ -38,10 +38,13 @@ import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
import com.google.appengine.api.labs.taskqueue.Queue;
import com.google.appengine.api.labs.taskqueue.QueueFactory;
import com.google.appengine.api.labs.taskqueue.TaskOptions.Method;
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.QueueFactory;
import com.google.appengine.api.taskqueue.TaskOptions.Builder;
import com.google.appengine.api.taskqueue.TaskOptions.Method;
import com.google.appengine.repackaged.com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
@ -77,8 +80,10 @@ public class GuiceServletConfig extends GuiceServletContextListener {
Set<Module> modules = ImmutableSet.<Module> of(googleModule);
// shared across all blobstores and used to retrieve tweets
try {
twitterClient = new TwitterFactory().getInstance(props.getProperty("twitter.identity"), props
.getProperty("twitter.credential"));
Configuration twitterConf = new ConfigurationBuilder()
.setUser(props.getProperty("twitter.identity"))
.setPassword(props.getProperty("twitter.credential")).build();
twitterClient = new TwitterFactory(twitterConf).getInstance();
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e);
}
@ -96,7 +101,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
Queue queue = QueueFactory.getQueue("twitter");
// submit a job to store tweets for each configured blobstore
for (String name : providerTypeToBlobStoreMap.keySet()) {
queue.add(url("/store/do").header("context", name).method(Method.GET));
queue.add(withUrl("/store/do").header("context", name).method(Method.GET));
}
super.contextInitialized(servletContextEvent);

View File

@ -48,6 +48,8 @@ import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
@ -98,8 +100,10 @@ public class TweetStoreLiveTest {
contexts.put(provider, factory.createContext(provider, wiring, props));
}
Twitter client = new TwitterFactory().getInstance(props.getProperty("twitter.identity"),
props.getProperty("twitter.credential"));
Configuration conf = new ConfigurationBuilder()
.setUser(props.getProperty("twitter.identity"))
.setPassword(props.getProperty("twitter.credential")).build();
Twitter client = new TwitterFactory(conf).getInstance();
StoreTweetsController controller = new StoreTweetsController(contexts, container, client);
ResponseList<Status> statuses = client.getMentions();