INT-1471 went back to direct dependency on twitter4j API. ntroducing our interfaces is meaningless sionce we are not going to be depending on it once SpringSocial GA is out

This commit is contained in:
Oleg Zhurakousky
2010-10-26 13:18:49 -04:00
parent 2e800eb1ba
commit cebc9892b9
30 changed files with 62 additions and 757 deletions

View File

@@ -1,33 +0,0 @@
/*
* Copyright 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;
/**
* Describes a direct-message in twitter. (Also known as a "DM").
* <p/>
* these are messages sent privately to a user.
*
* @author Josh Long
* @since 2.0
*/
public interface DirectMessage extends TwitterMessage{
User getSender() ;
User getRecipient();
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright 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;
/**
* interface for geo location records
*
* @author Josh Long
* @since 2.0
*
*/
public interface GeoLocation {
double getLongitude() ;
double getLatitude() ;
}

View File

@@ -1,50 +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;
/**
* describes a simple status message on twitter. this could be a message that
* updates a timeline on behalf of a user, or it could be a message that
* contains a reply.
*
*
* @author Josh Long
* @since 2.0
*/
public interface Status extends TwitterMessage{
String getSource();
boolean isTruncated();
long getInReplyToStatusId();
int getInReplyToUserId();
java.lang.String getInReplyToScreenName();
boolean isFavorited();
User getUser();
boolean isRetweet();
Status getRetweetedStatus();
String[] getContributors();
}

View File

@@ -1,71 +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.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import twitter4j.DirectMessage;
import twitter4j.GeoLocation;
import twitter4j.Status;
import twitter4j.User;
/**
* Sine our Twitter domain model is modeled after Twitter4j API
* this interceptor will delegate method calls that are made on SI Twitter interfaces
* to the corresponding Twitter4j objects.
*
* @author Oleg Zhurakousky
* @since 2.0
*/
class Twitter4jDecorator implements MethodInterceptor {
private final Object twitterObject;
public Twitter4jDecorator(Object twitterObject){
this.validateTwitter4JObject(twitterObject);
this.twitterObject = twitterObject;
}
/* (non-Javadoc)
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
*/
public Object invoke(MethodInvocation invocation) throws Throwable {
Class<?> twitter4jClass = twitterObject.getClass();
Object[] args = invocation.getArguments();
Class<?>[] argsType = new Class[args.length];
for (int i = 0; i < args.length; i++) {
Object object = args[i];
argsType[i] = object.getClass();
}
String invokedmethodName = invocation.getMethod().getName();
Method targetMethod = ReflectionUtils.findMethod(twitter4jClass, invokedmethodName, argsType);
return targetMethod.invoke(twitterObject, args);
}
private void validateTwitter4JObject(Object twitterObject){
Assert.notNull(twitterObject, "'twitterObject' must not be null");
Assert.isTrue(twitterObject instanceof Status ||
twitterObject instanceof DirectMessage ||
twitterObject instanceof User ||
twitterObject instanceof GeoLocation,
"Only twitter4j.DirectMessage, twitter4j.Status, twitter4j.User, twitter4j.GeoLocation is supported");
}
}

View File

@@ -1,75 +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.aop.framework.ProxyFactory;
import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.util.Assert;
import twitter4j.DirectMessage;
import twitter4j.Status;
/**
* Factory class with several static factory methods for constructing
* Twitter objects that are independent from the underlying API (e.g., twitter4j)
*
* @author Oleg Zhurakousky
* @since 2.0
*/
public class TwitterFactory {
private TwitterFactory(){}
/**
* Will construct either {@link org.springframework.integration.twitter.core.Status} or
* {@link org.springframework.integration.twitter.core.DirectMessage} from the instances of
* {@link Status} pr {@link DirectMessage}
*
* @param twitterMessage
* @return
*/
public static TwitterMessage formTwitter4jMessage(Object twitterMessage){
Assert.isTrue(twitterMessage instanceof Status || twitterMessage instanceof DirectMessage,
"'twitterMessage' must be an instance of either twitter4j.DirectMessage or twitter4j.Status");
Class<?> interfaze = twitterMessage instanceof DirectMessage
? org.springframework.integration.twitter.core.DirectMessage.class
: org.springframework.integration.twitter.core.Status.class;
ProxyFactory factory = new ProxyFactory(interfaze, EmptyTargetSource.INSTANCE);
factory.addAdvice(new Twitter4jDecorator(twitterMessage));
return (TwitterMessage) factory.getProxy();
}
/**
* Will constuct {@link GeoLocation} from 'latitude' and 'longitude'
*
* @param latitude
* @param longitude
* @return
*/
public static GeoLocation fromLatitudeLongitude(double latitude, double longitude){
twitter4j.GeoLocation geolocation = new twitter4j.GeoLocation(latitude, longitude);
return fromTwitter4jGeoLocation(geolocation);
}
/**
* Will constuct {@link GeoLocation} from {@link twitter4j.GeoLocation}
* @param geolocation
* @return
*/
public static GeoLocation fromTwitter4jGeoLocation(twitter4j.GeoLocation geolocation){
ProxyFactory factory = new ProxyFactory(GeoLocation.class, EmptyTargetSource.INSTANCE);
factory.addAdvice(new Twitter4jDecorator(geolocation));
return (GeoLocation) factory.getProxy();
}
}

View File

@@ -1,30 +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;
/**
* @author Oleg Zhurakousky
* @since 2.0
*/
public interface TwitterMessage {
int getId();
String getText();
Date getCreatedAt();
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 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;
/**
* describes the user producing or receiving messages
*
* @author Josh Long
* @since 2.0
*/
public interface User {
int getId();
java.lang.String getName();
java.lang.String getScreenName();
java.lang.String getLocation();
java.lang.String getDescription();
boolean isContributorsEnabled();
java.net.URL getProfileImageURL();
java.net.URL getURL();
boolean isProtected();
int getFollowersCount();
}

View File

@@ -19,8 +19,8 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.springframework.integration.twitter.core.Status;
import org.springframework.integration.twitter.core.TwitterFactory;
import twitter4j.Status;
import twitter4j.TwitterFactory;
/**
* Simple base class for the reply and timeline cases (as well as any other {@link twitter4j.Status} implementations of
@@ -37,13 +37,13 @@ abstract public class AbstractInboundTwitterStatusEndpointSupport extends Abstra
}
};
protected List<Status> fromTwitter4jStatuses(List<twitter4j.Status> stats) {
List<Status> fwd = new ArrayList<Status>();
for (twitter4j.Status s : stats) {
fwd.add((Status) TwitterFactory.formTwitter4jMessage(s));
}
return fwd;
}
// protected List<Status> fromTwitter4jStatuses(List<twitter4j.Status> stats) {
// List<Status> fwd = new ArrayList<Status>();
// for (twitter4j.Status s : stats) {
// fwd.add((Status) TwitterFactory.formTwitter4jMessage(s));
// }
// return fwd;
// }
@Override
protected void markLastStatusId(Status statusId) {

View File

@@ -21,9 +21,8 @@ import java.util.Comparator;
import java.util.List;
import org.springframework.integration.MessagingException;
import org.springframework.integration.twitter.core.DirectMessage;
import org.springframework.integration.twitter.core.TwitterFactory;
import twitter4j.DirectMessage;
import twitter4j.Paging;
/**
@@ -73,13 +72,13 @@ public class InboundDirectMessageEndpoint extends AbstractInboundTwitterEndpoint
List<twitter4j.DirectMessage> dms = !hasMarkedStatus()
? twitter.getDirectMessages()
: twitter.getDirectMessages(new Paging(sinceId));
List<DirectMessage> dmsToFwd = new ArrayList<DirectMessage>();
for( twitter4j.DirectMessage dm : dms) {
dmsToFwd.add((DirectMessage) TwitterFactory.formTwitter4jMessage(dm));
}
forwardAll(dmsToFwd);
// List<DirectMessage> dmsToFwd = new ArrayList<DirectMessage>();
//
// for( twitter4j.DirectMessage dm : dms) {
// dmsToFwd.add((DirectMessage) TwitterFactory.formTwitter4jMessage(dm));
// }
forwardAll(dms);
} catch (Exception e) {
e.printStackTrace();
if (e instanceof RuntimeException){

View File

@@ -40,9 +40,9 @@ public class InboundMentionEndpoint extends AbstractInboundTwitterStatusEndpoint
try {
long sinceId = getMarkerId();
List<twitter4j.Status> stats = (!hasMarkedStatus())
? twitter.getMentions()
: twitter.getMentions(new Paging(sinceId));
forwardAll( fromTwitter4jStatuses( stats));
? twitter.getMentions()
: twitter.getMentions(new Paging(sinceId));
forwardAll(stats);
} catch (Exception e) {
if (e instanceof RuntimeException){
throw (RuntimeException)e;

View File

@@ -41,9 +41,9 @@ public class InboundTimelineUpdateEndpoint extends AbstractInboundTwitterStatusE
public void run() {
try {
long sinceId = getMarkerId();
forwardAll( fromTwitter4jStatuses(!hasMarkedStatus()
? twitter.getFriendsTimeline() :
twitter.getFriendsTimeline(new Paging(sinceId))));
forwardAll(!hasMarkedStatus()
? twitter.getFriendsTimeline()
: twitter.getFriendsTimeline(new Paging(sinceId)));
} catch (Exception e) {
if (e instanceof RuntimeException){
throw (RuntimeException)e;

View File

@@ -18,10 +18,10 @@ package org.springframework.integration.twitter.outbound;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.mapping.OutboundMessageMapper;
import org.springframework.integration.twitter.core.GeoLocation;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.util.StringUtils;
import twitter4j.GeoLocation;
import twitter4j.StatusUpdate;
@@ -69,15 +69,9 @@ public class OutboundStatusUpdateMessageMapper implements OutboundMessageMapper<
if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_GEOLOCATION)) {
org.springframework.integration.twitter.core.GeoLocation geoLocation = (org.springframework.integration.twitter.core.GeoLocation) message.getHeaders()
.get(TwitterHeaders.TWITTER_GEOLOCATION);
twitter4j.GeoLocation gl = null;
if (geoLocation instanceof GeoLocation) {
gl = new twitter4j.GeoLocation(geoLocation.getLatitude(), geoLocation.getLongitude());
if (null != gl) {
statusUpdate.location(gl);
}
GeoLocation geoLocation = (GeoLocation) message.getHeaders().get(TwitterHeaders.TWITTER_GEOLOCATION);
if (null != geoLocation) {
statusUpdate.location(geoLocation);
}
}

View File

@@ -0,0 +1,11 @@
log4j.rootCategory=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n
log4j.category.org.springframework=WARN
# log4j.category.org.springframework.integration=DEBUG
# log4j.category.org.springframework.integration.jdbc=DEBUG
log4j.category.org.springframework.twitter=DEBUG

View File

@@ -1,121 +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;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.twitter.inbound.InboundDirectMessageEndpoint;
import org.springframework.integration.twitter.oauth.OAuthConfiguration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import twitter4j.DirectMessage;
import twitter4j.Paging;
import twitter4j.RateLimitStatus;
import twitter4j.ResponseList;
import twitter4j.Twitter;
/**
* @author Oleg Zhurakousky
*
*/
public class InboundDirectMessageStatusEndpointTests {
private DirectMessage firstMessage;
private DirectMessage secondMessage;
private Twitter twitter;
@Test
@Ignore
/*
* In order to run this test you need to provide values to the twitter.properties file
*/
public void testUpdatesWithRealTwitter() throws Exception{
CountDownLatch latch = new CountDownLatch(1);
new ClassPathXmlApplicationContext("TestReceivingUsingNamespace-context.xml", this.getClass());
latch.await(10000, TimeUnit.SECONDS);
}
@Test
public void testTwitterMockedUpdates() throws Exception{
QueueChannel channel = new QueueChannel();
InboundDirectMessageEndpoint endpoint = new InboundDirectMessageEndpoint();
endpoint.setOutputChannel(channel);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
endpoint.setTaskScheduler(scheduler);
endpoint.setConfiguration(this.getTestConfigurationForDirectMessages());
endpoint.afterPropertiesSet();
endpoint.start();
Message message1 = channel.receive(3000);
assertNotNull(message1);
System.out.println();
assertEquals(secondMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message1.getPayload()).getId());
Message message2 = channel.receive(3000);
assertNotNull(message2);
assertEquals(firstMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message2.getPayload()).getId());
}
@Before
public void prepare(){
twitter = mock(Twitter.class);
firstMessage = mock(DirectMessage.class);
when(firstMessage.getCreatedAt()).thenReturn(new Date(5555555555L));
when(firstMessage.getId()).thenReturn(200);
secondMessage = mock(DirectMessage.class);
when(secondMessage.getCreatedAt()).thenReturn(new Date(2222222222L));
when(secondMessage.getId()).thenReturn(2000);
}
@SuppressWarnings("unchecked")
private OAuthConfiguration getTestConfigurationForDirectMessages() throws Exception{
OAuthConfiguration configuration = mock(OAuthConfiguration.class);
RateLimitStatus rateLimitStatus = mock(RateLimitStatus.class);
when(twitter.getRateLimitStatus()).thenReturn(rateLimitStatus);
when(configuration.getTwitter()).thenReturn(twitter);
when(rateLimitStatus.getSecondsUntilReset()).thenReturn(2464);
when(rateLimitStatus.getRemainingHits()).thenReturn(250);
ResponseList<DirectMessage> responses = mock(ResponseList.class);
List<DirectMessage> testMessages = new ArrayList<DirectMessage>();
testMessages.add(firstMessage);
testMessages.add(secondMessage);
when(responses.iterator()).thenReturn(testMessages.iterator());
when(twitter.getDirectMessages()).thenReturn(responses);
when(twitter.getDirectMessages(Mockito.any(Paging.class))).thenReturn(responses);
return configuration;
}
}

View File

@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:twitter="http://www.springframework.org/schema/integration/twitter"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter.xsd">
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="file://${user.home}/Desktop/twitter.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection
id="tc"
access-token="${twitter.oauth.accessToken}"
access-token-secret="${twitter.oauth.accessTokenSecret}"
consumer-key="${twitter.oauth.consumerKey}"
consumer-secret="${twitter.oauth.consumerSecret}"
/>
<beans:bean class="org.springframework.integration.twitter.SimpleTwitterTestClient"/>
</beans:beans>

View File

@@ -1,49 +0,0 @@
/*
* Copyright 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;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* provides a simple example of a command-line client to receive DMs, messages, timeline updates.
*
* @author Josh Long
*/
@ContextConfiguration
public class TestReceivingUsingNamespace
extends AbstractJUnit4SpringContextTests {
@Autowired
private TwitterAnnouncer twitterAnnouncer;
@Test
@Ignore
public void testIt() throws Throwable {
long ctr = 0;
long s = 1000;
while (ctr < (s * 60 * 3)) {
Thread.sleep(s);
ctr += s;
}
}
}

View File

@@ -18,11 +18,8 @@
<message-history/>
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="classpath:twitter.properties"
location="classpath:twitter.receiver.properties"
ignore-unresolvable="true"/>
<channel id="inbound_dm"/>
@@ -45,7 +42,7 @@
<twitter:inbound-update-channel-adapter twitter-connection="tc" channel="inbound_updates"/>
<service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>
<beans:bean id="twitterAnnouncer" class="org.springframework.integration.twitter.config.TwitterAnnouncer"/>
</beans:beans>

View File

@@ -36,6 +36,8 @@ public class TestReceivingUsingNamespace {
public void testUpdatesWithRealTwitter() throws Exception{
CountDownLatch latch = new CountDownLatch(1);
new ClassPathXmlApplicationContext("TestReceivingUsingNamespace-context.xml", this.getClass());
System.out.println("done");
latch.await(10000, TimeUnit.SECONDS);
}
}

View File

@@ -18,7 +18,7 @@
<context:property-placeholder
location="classpath:twitter.properties"
location="classpath:twitter.sender.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection

View File

@@ -21,12 +21,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.core.TwitterFactory;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.util.StringUtils;
import twitter4j.GeoLocation;
/**
* @author Josh Long
* @author Oleg Zhurakouksy
@@ -44,7 +45,7 @@ public class TestSendingDMsUsingNamespace extends AbstractJUnit4SpringContextTes
String dmUsr = "z_oleg";
MessageBuilder<String> mb = MessageBuilder.withPayload("'Hello world!', from the Spring Integration outbound Twitter adapter " + System.currentTimeMillis())
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
if (StringUtils.hasText(dmUsr)) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.twitter;
package org.springframework.integration.twitter.config;
import org.junit.Ignore;
import org.junit.Test;

View File

@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.twitter;
package org.springframework.integration.twitter.config;
import org.springframework.integration.twitter.core.DirectMessage;
import org.springframework.integration.twitter.core.Status;
import org.springframework.stereotype.Component;
import twitter4j.DirectMessage;
import twitter4j.Status;
@Component
public class TwitterAnnouncer {

View File

@@ -1,34 +0,0 @@
/**
*
*/
package org.springframework.integration.twitter.core;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.integration.twitter.core.Twitter4jDecorator;
import twitter4j.Status;
/**
* @author ozhurakousky
*
*/
public class Twitter4jDecoratorTests {
@Test
public void testTwitter4JDecorator(){
Status status = mock(Status.class);
when(status.getSource()).thenReturn("Hello World");
ProxyFactory factory = new ProxyFactory(org.springframework.integration.twitter.core.Status.class, EmptyTargetSource.INSTANCE);
factory.addAdvice(new Twitter4jDecorator(status));
Object decoratedStatus = factory.getProxy();
assertTrue(decoratedStatus instanceof org.springframework.integration.twitter.core.Status);
String source = ((org.springframework.integration.twitter.core.Status)decoratedStatus).getSource();
System.out.println("source: " + source);
}
}

View File

@@ -63,10 +63,10 @@ public class InboundDirectMessageStatusEndpointTests {
Message message1 = channel.receive(3000);
assertNotNull(message1);
System.out.println();
assertEquals(secondMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message1.getPayload()).getId());
assertEquals(secondMessage.getId(), ((DirectMessage)message1.getPayload()).getId());
Message message2 = channel.receive(3000);
assertNotNull(message2);
assertEquals(firstMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message2.getPayload()).getId());
assertEquals(firstMessage.getId(), ((DirectMessage)message2.getPayload()).getId());
}
@Before

View File

@@ -22,10 +22,10 @@ import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.core.TwitterFactory;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.integration.twitter.oauth.OAuthConfiguration;
import twitter4j.GeoLocation;
import twitter4j.Twitter;
/**
@@ -38,7 +38,7 @@ public class OutboundDirectMessageMessageHandlerTests {
@Test
public void validateSendDirectMessage() throws Exception{
MessageBuilder<String> mb = MessageBuilder.withPayload("hello")
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true)
.setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, "foo");
OutboundDirectMessageMessageHandler handler = new OutboundDirectMessageMessageHandler();
@@ -50,7 +50,7 @@ public class OutboundDirectMessageMessageHandlerTests {
verify(twitter, times(1)).sendDirectMessage("foo", "hello");
mb = MessageBuilder.withPayload("hello")
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new GeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true)
.setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, 123);

View File

@@ -1,61 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 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.
-->
<beans:beans
xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:twitter="http://www.springframework.org/schema/integration/twitter"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter.xsd">
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="file://${user.home}/Desktop/twitter.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection
id="tc"
access-token="${twitter.oauth.accessToken}"
access-token-secret="${twitter.oauth.accessTokenSecret}"
consumer-key="${twitter.oauth.consumerKey}"
consumer-secret="${twitter.oauth.consumerSecret}"
/>
<channel id="inbound_tweets"/>
<twitter:inbound-mention-channel-adapter twitter-connection="tc" channel="inbound_tweets"/>
<service-activator input-channel="inbound_tweets" ref="twitterAnnouncer" method="mention"/>
</beans:beans>

View File

@@ -1,68 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 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.
-->
<beans:beans
xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:twitter="http://www.springframework.org/schema/integration/twitter"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter.xsd">
<context:component-scan
base-package="org.springframework.integration.twitter"/>
<context:property-placeholder
location="file://${user.home}/Desktop/twitter.properties"
ignore-unresolvable="true"/>
<twitter:twitter-connection
id="tc"
access-token="${twitter.oauth.accessToken}"
access-token-secret="${twitter.oauth.accessTokenSecret}"
consumer-key="${twitter.oauth.consumerKey}"
consumer-secret="${twitter.oauth.consumerSecret}"
/>
<channel id="inbound_tweets"/>
<twitter:inbound-update-channel-adapter
twitter-connection="tc"
channel="inbound_tweets"
/>
<service-activator input-channel="inbound_tweets"
ref="twitterAnnouncer"
method="friendsTimelineUpdated"/>
</beans:beans>

View File

@@ -0,0 +1,6 @@
# oauth setup for prosibook twitter account
twitter.oauth.consumerKey=
twitter.oauth.consumerSecret=
twitter.oauth.pin=
twitter.oauth.accessToken=
twitter.oauth.accessTokenSecret=