diff --git a/build.gradle b/build.gradle
index 90789114df..ee3ca7cccd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -457,7 +457,8 @@ project('spring-integration-twitter') {
dependencies {
compile project(":spring-integration-core")
compile "org.springframework:spring-context-support:$springVersion"
- compile "org.twitter4j:twitter4j-core:2.1.12"
+ compile "org.springframework.social:spring-social-twitter:1.0.0.RELEASE"
+ compile "org.springframework.security:spring-security-crypto:3.1.0.RC3"
compile("javax.activation:activation:$javaxActivationVersion") { optional = true }
testCompile project(":spring-integration-test")
}
diff --git a/docs/src/reference/docbook/twitter.xml b/docs/src/reference/docbook/twitter.xml
index e0ee7fb3dc..c7ae623def 100644
--- a/docs/src/reference/docbook/twitter.xml
+++ b/docs/src/reference/docbook/twitter.xml
@@ -18,9 +18,9 @@
- Current Twitter support is based on the Twitter4J API.
- However, future versions will be changed to use the Spring Social
- project as it is nearing its first release at the time of writing.
+ Previous versions of Spring Integration were dependent on Twitter4J API,
+ but after the release of Spring Social 1.0 GA
+ Spring Integration 2.1 and all future releases are now depending on Spring Social framework's Twitter support.
@@ -29,7 +29,7 @@
the following within your XML header.
+ http://www.springframework.org/schema/integration/twitter/spring-integration-twitter-2.1.xsd"]]>
@@ -72,15 +72,14 @@ xsi:schemaLocation="http://www.springframework.org/schema/integration/twitter
Twitter Template
- Spring Integration uses the same familiar template pattern to interact with Twitter. Since current Twitter support
- is based on the Twitter4J API we provide a simple Twiter4JTemplate.
- For anonymous operations (e.g., search), you don't have to define Twitter4JTemplate explicitly, since a default
+ Spring Integration uses the same familiar template pattern to interact with Twitter and Spring Social provides org.springframework.social.twitter.api.impl.TwitterTemplate
+ For anonymous operations (e.g., search), you don't have to define TwitterTemplate explicitly, since a default
instance will be created and injected into the endpoint. However, for authenticated operation
- (update status, send direct message, etc.), you must configure Twitter4JTemplate as a bean and
+ (update status, send direct message, etc.), you must configure TwitterTemplate as a bean and
inject it explicitly into the endpoint, because the authentication configuration is required.
- Below is a sample configuration of Twitter4JTemplate:
+ Below is a sample configuration of TwitterTemplate:
-
+
@@ -108,7 +107,7 @@ twitter.oauth.accessTokenSecret=AbRxUAvyNCtqQtxFK8w5ZMtMj20KFhB6o]]>
-
+
@@ -219,7 +218,7 @@ received.
of Spring Social.
- To get the text from the org.springframework.integration.twitter.core.Tweet
+ To get the text from the org.springframework.social.twitter.api.Tweet
simply invoke the getText() method.
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterInboundChannelAdapterParser.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterInboundChannelAdapterParser.java
index 10b8e49b69..675c52fe9f 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterInboundChannelAdapterParser.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterInboundChannelAdapterParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors
+ * Copyright 2002-2011 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,11 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
+import org.springframework.integration.twitter.inbound.DirectMessageReceivingMessageSource;
+import org.springframework.integration.twitter.inbound.MentionsReceivingMessageSource;
+import org.springframework.integration.twitter.inbound.SearchReceivingMessageSource;
+import org.springframework.integration.twitter.inbound.TimelineReceivingMessageSource;
+import org.springframework.social.twitter.api.impl.TwitterTemplate;
import org.springframework.util.StringUtils;
/**
@@ -33,20 +38,16 @@ import org.springframework.util.StringUtils;
*/
public class TwitterInboundChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser {
- private static final String BASE_PACKAGE = "org.springframework.integration.twitter";
-
-
@Override
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
- String className = determineClassName(element, parserContext);
- BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(className);
+ Class> clazz = determineClass(element, parserContext);
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(clazz);
String templateBeanName = element.getAttribute("twitter-template");
if (StringUtils.hasText(templateBeanName)) {
builder.addConstructorArgReference(templateBeanName);
}
else {
- BeanDefinitionBuilder templateBuilder = BeanDefinitionBuilder.genericBeanDefinition(
- BASE_PACKAGE + ".core.Twitter4jTemplate");
+ BeanDefinitionBuilder templateBuilder = BeanDefinitionBuilder.genericBeanDefinition(TwitterTemplate.class);
builder.addConstructorArgValue(templateBuilder.getBeanDefinition());
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "query");
@@ -54,25 +55,25 @@ public class TwitterInboundChannelAdapterParser extends AbstractPollingInboundCh
}
- private static String determineClassName(Element element, ParserContext parserContext) {
- String className = null;
+ private static Class> determineClass(Element element, ParserContext parserContext) {
+ Class> clazz = null;
String elementName = element.getLocalName().trim();
if ("inbound-channel-adapter".equals(elementName)) {
- className = BASE_PACKAGE + ".inbound.TimelineReceivingMessageSource";
+ clazz = TimelineReceivingMessageSource.class;
}
else if ("dm-inbound-channel-adapter".equals(elementName)) {
- className = BASE_PACKAGE + ".inbound.DirectMessageReceivingMessageSource";
+ clazz = DirectMessageReceivingMessageSource.class;
}
else if ("mentions-inbound-channel-adapter".equals(elementName)) {
- className = BASE_PACKAGE + ".inbound.MentionsReceivingMessageSource";
+ clazz = MentionsReceivingMessageSource.class;
}
else if ("search-inbound-channel-adapter".equals(elementName)){
- className = BASE_PACKAGE + ".inbound.SearchReceivingMessageSource";
+ clazz = SearchReceivingMessageSource.class;
}
else {
parserContext.getReaderContext().error("element '" + elementName + "' is not supported by this parser.", element);
}
- return className;
+ return clazz;
}
}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterNamespaceHandler.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterNamespaceHandler.java
index ea8938578c..b0dcb6698b 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterNamespaceHandler.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterNamespaceHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors
+ * Copyright 2002-2011 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterOutboundChannelAdapterParser.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterOutboundChannelAdapterParser.java
index 2aab23a2f5..ee53cc95b4 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterOutboundChannelAdapterParser.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/config/TwitterOutboundChannelAdapterParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors
+ * Copyright 2002-2011 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,13 @@
package org.springframework.integration.twitter.config;
-import org.w3c.dom.Element;
-
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
+import org.springframework.integration.twitter.outbound.DirectMessageSendingMessageHandler;
+import org.springframework.integration.twitter.outbound.StatusUpdatingMessageHandler;
+import org.w3c.dom.Element;
/**
* Parser for all outbound Twitter adapters
@@ -32,31 +33,28 @@ import org.springframework.integration.config.xml.AbstractOutboundChannelAdapter
*/
public class TwitterOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser {
- private static final String BASE_PACKAGE = "org.springframework.integration.twitter";
-
-
@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
- String className = determineClassName(element, parserContext);
- BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(className);
+ Class> clazz = determineClass(element, parserContext);
+ BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(clazz);
builder.addConstructorArgReference(element.getAttribute("twitter-template"));
return builder.getBeanDefinition();
}
- private static String determineClassName(Element element, ParserContext parserContext) {
- String className = null;
+ private static Class> determineClass(Element element, ParserContext parserContext) {
+ Class> clazz = null;
String elementName = element.getLocalName().trim();
if ("outbound-channel-adapter".equals(elementName)) {
- className = BASE_PACKAGE + ".outbound.StatusUpdatingMessageHandler";
+ clazz = StatusUpdatingMessageHandler.class;
}
else if ("dm-outbound-channel-adapter".equals(elementName)) {
- className = BASE_PACKAGE + ".outbound.DirectMessageSendingMessageHandler";
+ clazz = DirectMessageSendingMessageHandler.class;
}
else {
parserContext.getReaderContext().error("element '" + elementName + "' is not supported by this parser.", element);
}
- return className;
+ return clazz;
}
}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/SearchResults.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/SearchResults.java
deleted file mode 100644
index 337c982ae7..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/SearchResults.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2002-2010 the original author or authors.
- *
- * 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.springframework.integration.twitter.core;
-
-import java.util.List;
-
-/**
- * Represents the results of a Twitter search, including matching {@link Tweet}s
- * and any metadata associated with that search.
- *
- * @author Craig Walls
- */
-public class SearchResults {
-
- private List tweets;
-
- private long maxId;
-
- private long sinceId;
-
-
- public SearchResults(List tweets, long maxId, long sinceId) {
- this.tweets = tweets;
- this.maxId = maxId;
- this.sinceId = sinceId;
- }
-
-
- /**
- * Returns the list of matching {@link Tweet}s
- */
- public List getTweets() {
- return tweets;
- }
-
- /**
- * Returns the maximum {@link Tweet} ID in the search results
- */
- public long getMaxId() {
- return maxId;
- }
-
- /**
- * Returns the {@link Tweet} ID after which all of the matching {@link Tweet}s were created
- */
- public long getSinceId() {
- return sinceId;
- }
-
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Tweet.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Tweet.java
deleted file mode 100644
index 6ee1671380..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Tweet.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2002-2010 the original author or authors
- *
- * 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.springframework.integration.twitter.core;
-
-import java.util.Date;
-
-/**
- * Represents a Twitter status update (e.g., a "tweet").
- *
- * @author Craig Walls
- * @author Oleg Zhurakousky
- */
-public class Tweet {
-
- private long id;
-
- private String text;
-
- private Date createdAt;
-
- private String fromUser;
-
- private String profileImageUrl;
-
- private Long toUserId;
-
- private long fromUserId;
-
- private String languageCode;
-
- private String source;
-
-
- public String getText() {
- return text;
- }
-
- public void setText(String text) {
- this.text = text;
- }
-
- public Date getCreatedAt() {
- return createdAt;
- }
-
- public void setCreatedAt(Date createdAt) {
- this.createdAt = createdAt;
- }
-
- public String getFromUser() {
- return fromUser;
- }
-
- public void setFromUser(String fromUser) {
- this.fromUser = fromUser;
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public String getProfileImageUrl() {
- return profileImageUrl;
- }
-
- public void setProfileImageUrl(String profileImageUrl) {
- this.profileImageUrl = profileImageUrl;
- }
-
- public Long getToUserId() {
- return toUserId;
- }
-
- public void setToUserId(Long toUserId) {
- this.toUserId = toUserId;
- }
-
- public long getFromUserId() {
- return fromUserId;
- }
-
- public void setFromUserId(long fromUserId) {
- this.fromUserId = fromUserId;
- }
-
- public String getLanguageCode() {
- return languageCode;
- }
-
- public void setLanguageCode(String languageCode) {
- this.languageCode = languageCode;
- }
-
- public String getSource() {
- return source;
- }
-
- public void setSource(String source) {
- this.source = source;
- }
-
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Twitter4jTemplate.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Twitter4jTemplate.java
deleted file mode 100644
index e6cc2ea07d..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Twitter4jTemplate.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright 2002-2011 the original author or authors
- *
- * 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.springframework.integration.twitter.core;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.springframework.util.Assert;
-
-import twitter4j.DirectMessage;
-import twitter4j.Paging;
-import twitter4j.Query;
-import twitter4j.QueryResult;
-import twitter4j.ResponseList;
-import twitter4j.Status;
-import twitter4j.StatusUpdate;
-import twitter4j.Twitter;
-import twitter4j.TwitterFactory;
-import twitter4j.http.AccessToken;
-
-/**
- * Implementation of {@link TwitterOperations} that delegates to Twitter4J.
- *
- * @author Oleg Zhurakousky
- * @since 2.0
- */
-public class Twitter4jTemplate implements TwitterOperations {
-
- private final Twitter twitter;
-
-
- /**
- * Used to construct this template to perform Twitter API calls that do not require authorization.
- * (e.g., search)
- */
- public Twitter4jTemplate() {
- this.twitter = new TwitterFactory().getInstance();
- }
-
- /**
- * Used to construct this template with OAuth authentication/authorization to perform Twitter API calls
- * that do require authorization (e.g., send/receive DirectMessage)
- *
- * @param consumerKey
- * @param consumerSecret
- * @param accessToken
- * @param accessTokenSecret
- */
- @SuppressWarnings("deprecation")
- public Twitter4jTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) {
- Assert.hasText(consumerKey, "'consumerKey' must be provided");
- Assert.hasText(consumerSecret, "'consumerSecret' must be provided");
- Assert.hasText(accessToken, "'accessToken' must be provided");
- Assert.hasText(accessTokenSecret, "'accessTokenSecret' must be provided");
-
- AccessToken token = new AccessToken(accessToken, accessTokenSecret);
- this.twitter = new TwitterFactory().getOAuthAuthorizedInstance(consumerKey, consumerSecret, token);
- /*
- * We are aware of the fact that the above method is deprecated and the code should really look
- * like the one below, but we are keeping the deprecated call to address backwards compatibility.
- * In future versions we won't be relying on Twitter4J in favor of SpringSocial API.
- */
-// Properties properties = new Properties();
-// properties.put("oauth.consumerKey", consumerKey);
-// properties.put("oauth.consumerSecret", consumerSecret);
-// Configuration configuration = new PropertyConfiguration(properties);
-// this.twitter = new TwitterFactory(configuration).getInstance(token);
- }
-
-
- public String getProfileId() {
- try {
- if (twitter.isOAuthEnabled()) {
- return twitter.getScreenName();
- }
- else {
- return "twitter-anonymous";
- }
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to obtain Profile ID. ", e);
- }
- }
-
- public List getDirectMessages() {
- try {
- ResponseList directMessages = twitter.getDirectMessages();
- return this.buildTweetsFromTwitterResponses(directMessages);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to receive Direct Messages. ", e);
- }
- }
-
- public List getDirectMessages(long sinceId) {
- try {
- ResponseList directMessages = twitter.getDirectMessages(new Paging(sinceId));
- return this.buildTweetsFromTwitterResponses(directMessages);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to receive Direct Messages since the last message with ID: "
- + sinceId + ".", e);
- }
- }
-
- public List getMentions() {
- try {
- ResponseList mentions = twitter.getMentions();
- return this.buildTweetsFromTwitterResponses(mentions);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to receive Mention statuses. ", e);
- }
- }
-
- public List getMentions(long sinceId) {
- try {
- ResponseList mentions = twitter.getMentions(new Paging(sinceId));
- return this.buildTweetsFromTwitterResponses(mentions);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to receive Mention statuses since the last status with ID: "
- + sinceId + ".", e);
- }
- }
-
- public List getTimeline() {
- try {
- ResponseList timelines = twitter.getHomeTimeline();
- return this.buildTweetsFromTwitterResponses(timelines);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to receive Timeline statuses. ", e);
- }
- }
-
- public List getTimeline(long sinceId) {
- try {
- ResponseList timelines = twitter.getHomeTimeline(new Paging(sinceId));
- return this.buildTweetsFromTwitterResponses(timelines);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to receive Timeline statuses since the last status with ID: "
- + sinceId + ".", e);
- }
- }
-
- public void sendDirectMessage(String userName, String text) {
- Assert.hasText(userName, "'userName' is required");
- Assert.hasText(text, "'text' is required");
- try {
- twitter.sendDirectMessage(userName, text);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to send Direct Message to user: " + userName + ".", e);
- }
- }
-
- public void sendDirectMessage(int userId, String text) {
- Assert.state(userId > 0, "'userId' is required");
- Assert.hasText(text, "'text' is required");
- try {
- twitter.sendDirectMessage(userId, text);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to send Direct Message to user with id: " + userId + ".", e);
- }
- }
-
- public void updateStatus(String statusTweet) {
- Assert.hasText(statusTweet, "'statusTweet' must not be null");
- try {
- StatusUpdate status = new StatusUpdate(statusTweet);
- twitter.updateStatus(status);
- }
- catch (Exception e) {
- throw new TwitterOperationException("Failed to send Status update. ", e);
- }
- }
-
- public SearchResults search(String query) {
- Assert.hasText(query, "'query' must not be null");
- Query q = new Query(query);
- return this.search(q);
- }
-
- public SearchResults search(String query, long sinceId) {
- Assert.hasText(query, "'query' must not be null");
- Query q = new Query(query);
- q.setSinceId(sinceId);
- return this.search(q);
- }
-
- public Twitter getUnderlyingTwitter() {
- return this.twitter;
- }
-
-
- private SearchResults search(Query query) {
- try {
- QueryResult result = twitter.search(query);
- if (result != null) {
- List t4jTweets = result.getTweets();
- List tweets = this.buildTweetsFromTwitterResponses(t4jTweets);
- SearchResults results = new SearchResults(tweets, result.getMaxId(), result.getSinceId());
- return results;
- }
- }
- catch (Exception e) {
- throw new TwitterOperationException("failed to perform Twitter search", e);
- }
- return null;
- }
-
- private List buildTweetsFromTwitterResponses(List> responses) {
- List tweets = new LinkedList();
- if (responses != null) {
- for (Object response : responses) {
- if (response instanceof Status) {
- tweets.add(this.buildTweetFromStatus((Status) response));
- }
- else if (response instanceof DirectMessage) {
- tweets.add(this.buildTweetFromDm((DirectMessage) response));
- }
- else if (response instanceof twitter4j.Tweet) {
- tweets.add(this.buildTweetFromTwitter4jTweet((twitter4j.Tweet) response));
- }
- else {
- throw new TwitterOperationException("Unsupported response type: " + response.getClass());
- }
- }
- }
- return tweets;
- }
-
- private Tweet buildTweetFromDm(DirectMessage dm) {
- Tweet tweet = new Tweet();
- tweet.setCreatedAt(dm.getCreatedAt());
- tweet.setFromUser(dm.getSenderScreenName());
- tweet.setFromUserId(dm.getSenderId());
- tweet.setId(dm.getId());
- tweet.setText(dm.getText());
- tweet.setToUserId((long)dm.getRecipientId());
- return tweet;
- }
-
- private Tweet buildTweetFromStatus(Status status) {
- Tweet tweet = new Tweet();
- tweet.setCreatedAt(status.getCreatedAt());
- if (status.getUser() != null){
- tweet.setFromUser(status.getUser().getScreenName());
- tweet.setFromUserId(status.getUser().getId());
- }
- tweet.setId(status.getId());
- tweet.setSource(status.getSource());
- tweet.setText(status.getText());
- return tweet;
- }
-
- private Tweet buildTweetFromTwitter4jTweet(twitter4j.Tweet t4jTweet) {
- Tweet tweet = new Tweet();
- tweet.setCreatedAt(t4jTweet.getCreatedAt());
- tweet.setFromUser(t4jTweet.getFromUser());
- tweet.setFromUserId(t4jTweet.getFromUserId());
- tweet.setId(t4jTweet.getId());
- tweet.setLanguageCode(t4jTweet.getIsoLanguageCode());
- tweet.setProfileImageUrl(t4jTweet.getProfileImageUrl());
- tweet.setSource(t4jTweet.getSource());
- tweet.setText(t4jTweet.getText());
- return tweet;
- }
-
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterOperationException.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterOperationException.java
deleted file mode 100644
index ba4e91545e..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterOperationException.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2002-2010 the original author or authors.
- *
- * 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.springframework.integration.twitter.core;
-
-import org.springframework.util.StringUtils;
-
-import twitter4j.TwitterException;
-
-/**
- * @author Oleg Zhurakousky
- * @since 2.0
- */
-@SuppressWarnings("serial")
-public class TwitterOperationException extends RuntimeException {
-
- private int twitterStatusCode = -1;
-
-
- public TwitterOperationException() {
- this(null, null);
- }
-
- /**
- * @param description
- */
- public TwitterOperationException(String description) {
- this(description, null);
- }
-
- /**
- * @param throwable
- */
- public TwitterOperationException(Throwable throwable) {
- this(null, throwable);
- }
-
- /**
- * @param description
- * @param throwable
- */
- public TwitterOperationException(String description, Throwable throwable) {
- super(formatDescription(description, throwable), throwable);
- if (throwable instanceof TwitterException){
- this.twitterStatusCode = ((TwitterException)throwable).getStatusCode();
- }
- }
-
-
- public int getTwitterStatusCode() {
- return twitterStatusCode;
- }
-
-
- private static String formatDescription(String description, Throwable throwable) {
- StringBuffer buffer = new StringBuffer();
- if (StringUtils.hasText(description)){
- buffer.append(description + " ");
- }
- if (throwable != null && throwable instanceof TwitterException){
- TwitterException te = (TwitterException) throwable;
- String message = te.getMessage();
- if (StringUtils.hasText(message)) {
- buffer.append("Detailed Error: ");
- if (message.contains("{")){
- buffer.append(message.substring(0, message.indexOf("{")));
- }
- else {
- buffer.append(message);
- }
- }
- buffer.append("For more information about this exception please visit the following Twitter website: " +
- "http://apiwiki.twitter.com/w/page/22554652/HTTP-Response-Codes-and-Errors");
- }
- return buffer.toString();
- }
-
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterOperations.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterOperations.java
deleted file mode 100644
index 6c384fa2a5..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterOperations.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2002-2010 the original author or authors
- *
- * 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.springframework.integration.twitter.core;
-
-import java.util.List;
-
-import twitter4j.Twitter;
-
-/**
- * @author Craig Walls
- * @author Oleg Zhurakousky
- * @since 2.0
- */
-public interface TwitterOperations {
-
- /**
- * Retrieves the user's Twitter screen name.
- *
- * @return the user's screen name at Twitter
- */
- String getProfileId();
-
- /**
- * Updates the user's status.
- *
- * @param status
- * The status message
- *
- */
- void updateStatus(String status);
-
- /**
- * Searches Twitter, returning the first page of {@link Tweet}s
- *
- * @param query
- * The search query string
- * @return a {@link SearchResults} containing {@link Tweet}s
- *
- */
- SearchResults search(String query);
-
- /**
- * Searches Twitter, returning a specific page out of the complete set of
- * results.
- *
- * @param query
- * The search query string
- * @param sinceId
- * The minimum {@link Tweet} ID to return in the results
- *
- * @return a {@link SearchResults} containing {@link Tweet}s
- *
- */
- SearchResults search(String query, long sinceId);
-
- List getDirectMessages();
-
- List getDirectMessages(long sinceId);
-
- List getMentions();
-
- List getMentions(long sinceId);
-
- List getTimeline();
-
- List getTimeline(long sinceId);
-
- void sendDirectMessage(String userName, String text);
-
- void sendDirectMessage(int userId, String text);
-
- /**
- * Temporary method. Should be removed one migrated to Spring Social
- */
- Twitter getUnderlyingTwitter();
-
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java
index c60be8993a..3f66674e94 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractTwitterMessageSource.java
@@ -1,5 +1,4 @@
-/*
- * Copyright 2002-2010 the original author or authors.
+/* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +17,7 @@ package org.springframework.integration.twitter.inbound;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Date;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -31,8 +31,10 @@ import org.springframework.integration.core.MessageSource;
import org.springframework.integration.store.MetadataStore;
import org.springframework.integration.store.SimpleMetadataStore;
import org.springframework.integration.support.MessageBuilder;
-import org.springframework.integration.twitter.core.Tweet;
-import org.springframework.integration.twitter.core.TwitterOperations;
+import org.springframework.social.twitter.api.DirectMessage;
+import org.springframework.social.twitter.api.Tweet;
+import org.springframework.social.twitter.api.Twitter;
+import org.springframework.social.twitter.api.UserOperations;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -58,7 +60,7 @@ abstract class AbstractTwitterMessageSource extends IntegrationObjectSupport
private volatile String metadataKey;
- private final Queue tweets = new LinkedBlockingQueue();
+ private final Queue