mirror of https://github.com/apache/jclouds.git
Converted the TweetStore *app* (not just the tests ;-)) to use OAuth for Twitter
This commit is contained in:
parent
5b10d5d0f8
commit
5ef3778468
|
@ -21,6 +21,10 @@ package org.jclouds.demo.tweetstore.config;
|
||||||
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -90,8 +94,11 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
// shared across all blobstores and used to retrieve tweets
|
// shared across all blobstores and used to retrieve tweets
|
||||||
try {
|
try {
|
||||||
twitter4j.conf.Configuration twitterConf = new ConfigurationBuilder()
|
twitter4j.conf.Configuration twitterConf = new ConfigurationBuilder()
|
||||||
.setUser(props.getProperty("twitter.identity"))
|
.setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY))
|
||||||
.setPassword(props.getProperty("twitter.credential")).build();
|
.setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET))
|
||||||
|
.setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN))
|
||||||
|
.setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
||||||
|
.build();
|
||||||
twitterClient = new TwitterFactory(twitterConf).getInstance();
|
twitterClient = new TwitterFactory(twitterConf).getInstance();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e);
|
throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.demo.tweetstore.reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties and constants used in Twitter connections.
|
||||||
|
*
|
||||||
|
* @author Andrew Phillips
|
||||||
|
*/
|
||||||
|
public interface TwitterConstants {
|
||||||
|
static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity";
|
||||||
|
static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential";
|
||||||
|
static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity";
|
||||||
|
static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential";
|
||||||
|
}
|
|
@ -21,6 +21,10 @@ package org.jclouds.demo.tweetstore.integration;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -100,10 +104,10 @@ public class TweetStoreLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration conf = new ConfigurationBuilder()
|
Configuration conf = new ConfigurationBuilder()
|
||||||
.setOAuthConsumerKey(props.getProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY))
|
.setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY))
|
||||||
.setOAuthConsumerSecret(props.getProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET))
|
.setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET))
|
||||||
.setOAuthAccessToken(props.getProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN))
|
.setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN))
|
||||||
.setOAuthAccessTokenSecret(props.getProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
.setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
||||||
.build();
|
.build();
|
||||||
Twitter client = new TwitterFactory(conf).getInstance();
|
Twitter client = new TwitterFactory(conf).getInstance();
|
||||||
StoreTweetsController controller = new StoreTweetsController(contexts, container, client);
|
StoreTweetsController controller = new StoreTweetsController(contexts, container, client);
|
||||||
|
@ -144,14 +148,14 @@ public class TweetStoreLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConfigurationForTwitter(Properties props) {
|
private void addConfigurationForTwitter(Properties props) {
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY,
|
props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET,
|
props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN,
|
props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET,
|
props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCredentialsForBlobStores(Properties props) {
|
private void addCredentialsForBlobStores(Properties props) {
|
||||||
|
@ -220,11 +224,4 @@ public class TweetStoreLiveTest {
|
||||||
String string = Strings2.toStringAndClose(i);
|
String string = Strings2.toStringAndClose(i);
|
||||||
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface TwitterConstants {
|
|
||||||
static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity";
|
|
||||||
static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential";
|
|
||||||
static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity";
|
|
||||||
static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ package org.jclouds.demo.tweetstore.config;
|
||||||
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -80,8 +84,11 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
// shared across all blobstores and used to retrieve tweets
|
// shared across all blobstores and used to retrieve tweets
|
||||||
try {
|
try {
|
||||||
Configuration twitterConf = new ConfigurationBuilder()
|
Configuration twitterConf = new ConfigurationBuilder()
|
||||||
.setUser(props.getProperty("twitter.identity"))
|
.setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY))
|
||||||
.setPassword(props.getProperty("twitter.credential")).build();
|
.setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET))
|
||||||
|
.setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN))
|
||||||
|
.setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
||||||
|
.build();
|
||||||
twitterClient = new TwitterFactory(twitterConf).getInstance();
|
twitterClient = new TwitterFactory(twitterConf).getInstance();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e);
|
throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.demo.tweetstore.reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties and constants used in Twitter connections.
|
||||||
|
*
|
||||||
|
* @author Andrew Phillips
|
||||||
|
*/
|
||||||
|
public interface TwitterConstants {
|
||||||
|
static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity";
|
||||||
|
static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential";
|
||||||
|
static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity";
|
||||||
|
static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential";
|
||||||
|
}
|
|
@ -21,6 +21,10 @@ package org.jclouds.demo.tweetstore.integration;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -99,10 +103,10 @@ public class TweetStoreLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration conf = new ConfigurationBuilder()
|
Configuration conf = new ConfigurationBuilder()
|
||||||
.setOAuthConsumerKey(props.getProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY))
|
.setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY))
|
||||||
.setOAuthConsumerSecret(props.getProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET))
|
.setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET))
|
||||||
.setOAuthAccessToken(props.getProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN))
|
.setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN))
|
||||||
.setOAuthAccessTokenSecret(props.getProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
.setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
||||||
.build();
|
.build();
|
||||||
Twitter client = new TwitterFactory(conf).getInstance();
|
Twitter client = new TwitterFactory(conf).getInstance();
|
||||||
StoreTweetsController controller = new StoreTweetsController(contexts, container, client);
|
StoreTweetsController controller = new StoreTweetsController(contexts, container, client);
|
||||||
|
@ -148,14 +152,14 @@ public class TweetStoreLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConfigurationForTwitter(Properties props) {
|
private void addConfigurationForTwitter(Properties props) {
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY,
|
props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET,
|
props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN,
|
props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET,
|
props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCredentialsForBlobStores(Properties props) {
|
private void addCredentialsForBlobStores(Properties props) {
|
||||||
|
@ -225,11 +229,4 @@ public class TweetStoreLiveTest {
|
||||||
String string = Strings2.toStringAndClose(i);
|
String string = Strings2.toStringAndClose(i);
|
||||||
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface TwitterConstants {
|
|
||||||
static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity";
|
|
||||||
static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential";
|
|
||||||
static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity";
|
|
||||||
static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,10 @@ package org.jclouds.demo.tweetstore.config;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -81,12 +85,14 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
// shared across all blobstores and used to retrieve tweets
|
// shared across all blobstores and used to retrieve tweets
|
||||||
try {
|
try {
|
||||||
Configuration twitterConf = new ConfigurationBuilder()
|
Configuration twitterConf = new ConfigurationBuilder()
|
||||||
.setUser(props.getProperty("twitter.identity"))
|
.setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY))
|
||||||
.setPassword(props.getProperty("twitter.credential")).build();
|
.setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET))
|
||||||
|
.setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN))
|
||||||
|
.setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
||||||
|
.build();
|
||||||
twitterClient = new TwitterFactory(twitterConf).getInstance();
|
twitterClient = new TwitterFactory(twitterConf).getInstance();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException("properties for twitter not configured properly in "
|
throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e);
|
||||||
+ props.toString(), e);
|
|
||||||
}
|
}
|
||||||
// common namespace for storing tweets
|
// common namespace for storing tweets
|
||||||
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER);
|
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
package org.jclouds.demo.tweetstore.reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration properties and constants used in Twitter connections.
|
||||||
|
*
|
||||||
|
* @author Andrew Phillips
|
||||||
|
*/
|
||||||
|
public interface TwitterConstants {
|
||||||
|
static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity";
|
||||||
|
static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential";
|
||||||
|
static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity";
|
||||||
|
static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential";
|
||||||
|
}
|
|
@ -21,6 +21,10 @@ package org.jclouds.demo.tweetstore.integration;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES;
|
||||||
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY;
|
||||||
|
import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -100,10 +104,10 @@ public class TweetStoreLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration conf = new ConfigurationBuilder()
|
Configuration conf = new ConfigurationBuilder()
|
||||||
.setOAuthConsumerKey(props.getProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY))
|
.setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY))
|
||||||
.setOAuthConsumerSecret(props.getProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET))
|
.setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET))
|
||||||
.setOAuthAccessToken(props.getProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN))
|
.setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN))
|
||||||
.setOAuthAccessTokenSecret(props.getProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
.setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET))
|
||||||
.build();
|
.build();
|
||||||
Twitter client = new TwitterFactory(conf).getInstance();
|
Twitter client = new TwitterFactory(conf).getInstance();
|
||||||
StoreTweetsController controller = new StoreTweetsController(contexts, container, client);
|
StoreTweetsController controller = new StoreTweetsController(contexts, container, client);
|
||||||
|
@ -149,14 +153,14 @@ public class TweetStoreLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConfigurationForTwitter(Properties props) {
|
private void addConfigurationForTwitter(Properties props) {
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY,
|
props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET,
|
props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN,
|
props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN));
|
||||||
props.setProperty(TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET,
|
props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET,
|
||||||
getRequiredSystemProperty("test." + TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET));
|
getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCredentialsForBlobStores(Properties props) {
|
private void addCredentialsForBlobStores(Properties props) {
|
||||||
|
@ -228,11 +232,4 @@ public class TweetStoreLiveTest {
|
||||||
String string = Strings2.toStringAndClose(i);
|
String string = Strings2.toStringAndClose(i);
|
||||||
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
assert string.indexOf("Tweets in Clouds") >= 0 : string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static interface TwitterConstants {
|
|
||||||
static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity";
|
|
||||||
static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential";
|
|
||||||
static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity";
|
|
||||||
static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue