Skip to content

Commit

Permalink
INTSAMPLES-10 added Twitter samples
Browse files Browse the repository at this point in the history
  • Loading branch information
olegz committed Nov 18, 2010
1 parent c5fabc2 commit f4e019d
Show file tree
Hide file tree
Showing 17 changed files with 384 additions and 0 deletions.
8 changes: 8 additions & 0 deletions basic/twitter/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions basic/twitter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
29 changes: 29 additions & 0 deletions basic/twitter/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>twitter</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Thu Nov 18 13:53:30 EST 2010
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/twitter/src/test/resources/META-INF/spring/integration/TwitterSearch-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="TransformerModelElement" type\="transformer">\n<structure end\="1667" endstart\="1667" start\="1558" startend\="1667"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="LoggingChannelAdapterModelElement" type\="logging-channel-adapter">\n<structure end\="1717" endstart\="1717" start\="1671" startend\="1717"/>\n<bounds height\="112" width\="116" x\="291" y\="17"/>\n</element>\n<element clazz\="ImplicitChannelModelElement" type\="channel">\n<structure end\="1667" endstart\="1667" start\="1558" startend\="1667"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/twitter/src/test/resources/META-INF/spring/integration/TwitterSendUpdates-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="ChannelModelElement" type\="channel">\n<structure end\="1357" endstart\="1357" start\="1327" startend\="1357"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n</graph>
//com.springsource.sts.config.flow.coordinates\:http\://www.springframework.org/schema/integration\:/twitter/src/test/resources/META-INF/spring/integration/TwitterTimelineUpdates-context.xml=<?xml version\="1.0" encoding\="UTF-8"?>\n<graph>\n<element clazz\="TransformerModelElement" type\="transformer">\n<structure end\="1656" endstart\="1656" start\="1547" startend\="1656"/>\n<bounds height\="112" width\="116" x\="155" y\="17"/>\n</element>\n<element clazz\="LoggingChannelAdapterModelElement" type\="logging-channel-adapter">\n<structure end\="1706" endstart\="1706" start\="1660" startend\="1706"/>\n<bounds height\="112" width\="116" x\="291" y\="17"/>\n</element>\n<element clazz\="ImplicitChannelModelElement" type\="channel">\n<structure end\="1656" endstart\="1656" start\="1547" startend\="1656"/>\n<bounds height\="112" width\="116" x\="19" y\="17"/>\n</element>\n</graph>
eclipse.preferences.version=1
13 changes: 13 additions & 0 deletions basic/twitter/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Thu Nov 18 11:41:09 EST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
9 changes: 9 additions & 0 deletions basic/twitter/.settings/org.maven.ide.eclipse.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Thu Nov 18 11:39:52 EST 2010
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
includeModules=false
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1
14 changes: 14 additions & 0 deletions basic/twitter/.springBeans
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.5.0.201010221000-RELEASE]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[false]]></enableImports>
<configs>
<config>src/test/resources/META-INF/spring/integration/TwitterTimelineUpdates-context.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>
63 changes: 63 additions & 0 deletions basic/twitter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>twitter</artifactId>
<version>2.0.0</version>
<name>Twitter Demo</name>
<packaging>jar</packaging>
<properties>
<spring.integration.version>2.0.0.BUILD-SNAPSHOT</spring.integration.version>
<log4j.version>1.2.16</log4j.version>
<junit.version>4.7</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-twitter</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<!-- test-scoped dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>repository.springframework.maven.release</id>
<name>Spring Framework Maven Release Repository</name>
<url>http://maven.springframework.org/release</url>
</repository>
<repository>
<id>repository.springframework.maven.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>http://maven.springframework.org/milestone</url>
</repository>
<repository>
<id>repository.springframework.maven.snapshot</id>
<name>Spring Framework Maven Snapshot Repository</name>
<url>http://maven.springframework.org/snapshot</url>
</repository>
</repositories>
</project>
36 changes: 36 additions & 0 deletions basic/twitter/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This example demonstrates the following aspects of the Twitter support available with Spring Integration:
1. Twitter Inbound Channel Adapter - allows you to receive HOME status updates
2. Twitter Inbound Search Channel Adapter - allows you to receive HOME status updates
3. Twitter Outboud Channel Adapter - allows send status updates

In order to run this sample you need to configure OAuth and set the values in the OAuth properties.
================
To use OAuth authentication/authorization with Twitter you must create new Application on Twitter Developers site.
Follow the directions below to create a new application and obtain consumer keys and access token:

- Go to http://dev.twitter.com/
- Click on 'Register an app' link and fill out all required fields on the form provided;
- Set 'Application Type' to 'Client' and depending on the nature of your application select
'Default Access Type' as 'Read & Write' or 'Read-only' and Submit the form.
- If everything is successful you'll be presented with the 'Consumer Key' and 'Consumer Secret'.
- Copy both values in the safe place.

On the same page you should see 'My Access Token' button on the side bar (right).
- Click on it and you'll be presented with two more values: 'Access Token' and 'Access Token Secret'.
Copy these values in a safe place as well.

When done fill out oauth.properties file so it looks similar to this.

twitter.oauth.consumerKey=4XzBPabcJQxyBzzzH3TrRQ
twitter.oauth.consumerSecret=ab2piKdMfPu8bVa3ab6DAIvIWEVZyMDL0RSEN2I8
twitter.oauth.accessToken=21691649-4XYZY5iJEOfz2A9qCFd9SjBRGb3HLmIm4HNE6AMv4
twitter.oauth.accessTokenSecret=AbRxUAvyNCtqQtvxFK8w5ZMtMj20KFhB6oEfTA0

NOTE: the above values are not real ;)
=======================

Now you ready to execute samples. Just run each sample and look for the output produced by the
inbound adapters (TwitterSearchSample.java and TwitterTimelineUpdateSample.java)

The outbound adapter sample (TwitterSendUpdatesSample.java) will not produce any output.
Instead within seconds you should see your tweet.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2002-2008 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.samples.twitter;

import org.junit.Test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* @author Oleg Zhurakousky
*
*/
public class TwitterSearchSample {

@Test
public void runDemo() throws Exception{
new ClassPathXmlApplicationContext("META-INF/spring/integration/TwitterSearch-context.xml");

Thread.sleep(20000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2002-2008 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.samples.twitter;

import org.junit.Test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.message.GenericMessage;

/**
* @author Oleg Zhurakousky
*
*/
public class TwitterSendUpdatesSample {

@Test
public void runDemo() throws Exception{
ApplicationContext context =
new ClassPathXmlApplicationContext("META-INF/spring/integration/TwitterSendUpdates-context.xml");

MessageChannel twitterOutChannel = context.getBean("twitterOut", MessageChannel.class);
Message<String> twitterUpdate = new GenericMessage<String>("Testing new Twitter samples for #springintegration");
twitterOutChannel.send(twitterUpdate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2002-2008 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.samples.twitter;

import org.junit.Test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* @author Oleg Zhurakousky
*
*/
public class TwitterTimelineUpdatesSample {

@Test
public void runDemo() throws Exception{
new ClassPathXmlApplicationContext("META-INF/spring/integration/TwitterTimelineUpdates-context.xml");

Thread.sleep(20000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter-2.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-twitter="http://www.springframework.org/schema/integration/twitter">

<context:property-placeholder location="classpath:oauth.properties"/>

<bean id="twitterTemplate"
class="org.springframework.integration.twitter.core.Twitter4jTemplate">
<constructor-arg value="${twitter.oauth.consumerKey}" />
<constructor-arg value="${twitter.oauth.consumerSecret}" />
<constructor-arg value="${twitter.oauth.accessToken}" />
<constructor-arg value="${twitter.oauth.accessTokenSecret}" />
</bean>

<int-twitter:search-inbound-channel-adapter id="searchAdapter" channel="sourceExtractor" query="#springintegration">
<int:poller fixed-rate="3000" max-messages-per-poll="5" />
</int-twitter:search-inbound-channel-adapter>

<int:transformer input-channel="sourceExtractor" output-channel="twitterOut" expression="payload.getText()"/>

<int:logging-channel-adapter id="twitterOut"/>
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter-2.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-twitter="http://www.springframework.org/schema/integration/twitter">

<context:property-placeholder location="classpath:oauth.properties"/>

<bean id="twitterTemplate"
class="org.springframework.integration.twitter.core.Twitter4jTemplate">
<constructor-arg value="${twitter.oauth.consumerKey}" />
<constructor-arg value="${twitter.oauth.consumerSecret}" />
<constructor-arg value="${twitter.oauth.accessToken}" />
<constructor-arg value="${twitter.oauth.accessTokenSecret}" />
</bean>

<int:channel id="twitterOut"/>

<int-twitter:outbound-channel-adapter twitter-template="twitterTemplate" channel="twitterOut"/>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/twitter http://www.springframework.org/schema/integration/twitter/spring-integration-twitter-2.0.xsd"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-twitter="http://www.springframework.org/schema/integration/twitter">

<context:property-placeholder location="classpath:oauth.properties"/>

<bean id="twitterTemplate"
class="org.springframework.integration.twitter.core.Twitter4jTemplate">
<constructor-arg value="${twitter.oauth.consumerKey}" />
<constructor-arg value="${twitter.oauth.consumerSecret}" />
<constructor-arg value="${twitter.oauth.accessToken}" />
<constructor-arg value="${twitter.oauth.accessTokenSecret}" />
</bean>

<int-twitter:inbound-channel-adapter id="twitterInbound"
twitter-template="twitterTemplate" channel="sourceExtractor">
<int:poller fixed-rate="1000" max-messages-per-poll="3" />
</int-twitter:inbound-channel-adapter>

<int:transformer input-channel="sourceExtractor" output-channel="twitterOut" expression="payload.getText()"/>

<int:logging-channel-adapter id="twitterOut"/>
</beans>
8 changes: 8 additions & 0 deletions basic/twitter/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
log4j.rootCategory=INFO, 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=INFO
Loading

0 comments on commit f4e019d

Please sign in to comment.