INTSAMPLES-10 added Twitter samples

This commit is contained in:
Oleg Zhurakousky
2010-11-18 14:10:17 -05:00
parent c5fabc21ca
commit f4e019da3f
17 changed files with 384 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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

View File

@@ -0,0 +1,4 @@
twitter.oauth.consumerKey=
twitter.oauth.consumerSecret=
twitter.oauth.accessToken=
twitter.oauth.accessTokenSecret=