cleanup for Twitter module INT-1471
This commit is contained in:
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
public class InboundDMStatusEndpoint extends AbstractInboundTwitterEndpointSupport<DirectMessage> {
|
||||
public class InboundDirectMessageStatusEndpoint extends AbstractInboundTwitterEndpointSupport<DirectMessage> {
|
||||
private Comparator<DirectMessage> dmComparator = new Comparator<DirectMessage>() {
|
||||
public int compare(DirectMessage directMessage, DirectMessage directMessage1) {
|
||||
return directMessage.getCreatedAt().compareTo(directMessage1.getCreatedAt());
|
||||
@@ -53,8 +53,8 @@ public class InboundDMStatusEndpoint extends AbstractInboundTwitterEndpointSuppo
|
||||
|
||||
@Override
|
||||
protected void refresh() throws Exception {
|
||||
this.runAsAPIRateLimitsPermit(new ApiCallback<InboundDMStatusEndpoint>() {
|
||||
public void run(InboundDMStatusEndpoint t, Twitter twitter)
|
||||
this.runAsAPIRateLimitsPermit(new ApiCallback<InboundDirectMessageStatusEndpoint>() {
|
||||
public void run(InboundDirectMessageStatusEndpoint t, Twitter twitter)
|
||||
throws Exception {
|
||||
forwardAll((!hasMarkedStatus()) ? t.twitter.getDirectMessages() : t.twitter.getDirectMessages(new Paging(t.getMarkerId())));
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import twitter4j.TwitterException;
|
||||
* @see org.springframework.integration.twitter.TwitterHeaders
|
||||
* @see twitter4j.Twitter
|
||||
*/
|
||||
public class OutboundDMStatusMessageHandler extends AbstractOutboundTwitterEndpointSupport {
|
||||
public class OutboundDirectMessageStatusMessageHandler extends AbstractOutboundTwitterEndpointSupport {
|
||||
public void handleMessage(Message<?> message) throws MessageRejectedException, MessageHandlingException, MessageDeliveryException {
|
||||
try {
|
||||
String txt = (String) message.getPayload();
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.twitter.oauth.OAuthConfigurationFactoryBean;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class ConnectionParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return OAuthConfigurationFactoryBean.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
TwitterNamespaceHandler.configureTwitterConnection(element, parserContext, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.twitter.InboundDirectMessageStatusEndpoint;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class DirectMessageInboundEndpointParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return InboundDirectMessageStatusEndpoint.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel", "requestChannel");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
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.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.twitter.OutboundDirectMessageStatusMessageHandler;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class DirectMessageOutboundEndpointParser extends AbstractOutboundChannelAdapterParser {
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(OutboundDirectMessageStatusMessageHandler.class.getName());
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.twitter.InboundMentionStatusEndpoint;
|
||||
import org.springframework.integration.twitter.config.TwitterNamespaceHandler;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class MentionInboundEndpointParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return InboundMentionStatusEndpoint.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel", "requestChannel");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,8 @@
|
||||
*/
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
@@ -30,26 +27,24 @@ import org.w3c.dom.Element;
|
||||
* @since 2.0
|
||||
*/
|
||||
public class TwitterNamespaceHandler extends org.springframework.beans.factory.xml.NamespaceHandlerSupport {
|
||||
public static final String DIRECT_MESSAGES = "direct-messages";
|
||||
public static final String MENTIONS = "mentions";
|
||||
public static final String FRIENDS = "friends";
|
||||
private static final String BASE_PACKAGE = "org.springframework.integration.twitter";
|
||||
|
||||
|
||||
|
||||
public void init() {
|
||||
// twitter connections
|
||||
registerBeanDefinitionParser("twitter-connection", new TwitterConnectionParser());
|
||||
registerBeanDefinitionParser("twitter-connection", new ConnectionParser());
|
||||
|
||||
// inbound
|
||||
registerBeanDefinitionParser("inbound-update-channel-adapter", new TwitterUpdatedStatusInboundEndpointParser());
|
||||
registerBeanDefinitionParser("inbound-dm-channel-adapter", new TwitterDMInboundEndpointParser());
|
||||
registerBeanDefinitionParser("inbound-mention-channel-adapter", new TwitterMentionInboundEndpointParser());
|
||||
registerBeanDefinitionParser("inbound-update-channel-adapter", new UpdatedStatusInboundEndpointParser());
|
||||
registerBeanDefinitionParser("inbound-dm-channel-adapter", new DirectMessageInboundEndpointParser());
|
||||
registerBeanDefinitionParser("inbound-mention-channel-adapter", new MentionInboundEndpointParser());
|
||||
|
||||
// outbound
|
||||
registerBeanDefinitionParser("outbound-update-channel-adapter", new TwitterUpdatedStatusOutboundEndpointParser());
|
||||
registerBeanDefinitionParser("outbound-dm-channel-adapter", new TwitterDMOutboundEndpointParser());
|
||||
registerBeanDefinitionParser("outbound-update-channel-adapter", new UpdatedStatusOutboundEndpointParser());
|
||||
registerBeanDefinitionParser("outbound-dm-channel-adapter", new DirectMessageOutboundEndpointParser());
|
||||
}
|
||||
|
||||
private static void configureTwitterConnection(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
public static void configureTwitterConnection(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String ref = element.getAttribute("twitter-connection");
|
||||
|
||||
if (org.springframework.util.StringUtils.hasText(ref)) {
|
||||
@@ -61,104 +56,7 @@ public class TwitterNamespaceHandler extends org.springframework.beans.factory.x
|
||||
}
|
||||
}
|
||||
|
||||
// twitter:twitter-connection
|
||||
|
||||
private static class TwitterConnectionParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return BASE_PACKAGE + "oauth.OAuthConfigurationFactoryBean";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
configureTwitterConnection(element, parserContext, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// twitter:inbound-mention-channel-adapter
|
||||
|
||||
private static class TwitterMentionInboundEndpointParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return BASE_PACKAGE + ".InboundMentionStatusEndpoint";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel", "requestChannel");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
}
|
||||
}
|
||||
|
||||
// twitter:inbound-dm-channel-adapter
|
||||
|
||||
private static class TwitterDMInboundEndpointParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return BASE_PACKAGE + ".InboundDMStatusEndpoint";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel", "requestChannel");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
}
|
||||
}
|
||||
|
||||
// twitter:inbound-update-channel-adapter
|
||||
|
||||
private static class TwitterUpdatedStatusInboundEndpointParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return BASE_PACKAGE + ".InboundUpdatedStatusEndpoint";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "channel", "requestChannel");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
}
|
||||
}
|
||||
|
||||
// twitter:outbound-update-channel-adapter
|
||||
|
||||
private static class TwitterUpdatedStatusOutboundEndpointParser extends AbstractOutboundChannelAdapterParser {
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BASE_PACKAGE + ".OutboundUpdatedStatusMessageHandler");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
}
|
||||
|
||||
// twitter:outbound-dm-channel-adapter
|
||||
|
||||
private static class TwitterDMOutboundEndpointParser extends AbstractOutboundChannelAdapterParser {
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BASE_PACKAGE + ".OutboundDMStatusMessageHandler");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "twitter-connection", "configuration");
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.twitter.InboundUpdatedStatusEndpoint;
|
||||
import org.springframework.integration.twitter.config.TwitterNamespaceHandler;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class UpdatedStatusInboundEndpointParser extends AbstractSingleBeanDefinitionParser {
|
||||
@Override
|
||||
protected String getBeanClassName(Element element) {
|
||||
return InboundUpdatedStatusEndpoint.class.getName() ;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
|
||||
"channel", "requestChannel");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
|
||||
"twitter-connection", "configuration");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
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.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.twitter.OutboundUpdatedStatusMessageHandler;
|
||||
import org.springframework.integration.twitter.config.TwitterNamespaceHandler;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class UpdatedStatusOutboundEndpointParser extends AbstractOutboundChannelAdapterParser {
|
||||
@Override
|
||||
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
OutboundUpdatedStatusMessageHandler.class.getName() );
|
||||
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element,
|
||||
"twitter-connection", "configuration");
|
||||
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import java.util.Collection;
|
||||
*
|
||||
* @author Josh Long
|
||||
*/
|
||||
@ContextConfiguration(locations = "twitter_connection_using_ns.xml")
|
||||
@ContextConfiguration(locations = "org/springframework/integration/twitter/twitter_connection_using_ns.xml")
|
||||
public class SimpleTwitterTestClient {
|
||||
private Twitter twitter;
|
||||
@Autowired
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
* @author Josh Long
|
||||
*/
|
||||
@ContextConfiguration(locations = {
|
||||
"/receiving_dms_using_ns.xml"}
|
||||
"/org/springframework/integration/twitter/receiving_dms_using_ns.xml"}
|
||||
)
|
||||
public class TestRecievingUsingNamespace extends AbstractJUnit4SpringContextTests {
|
||||
@Autowired
|
||||
|
||||
@@ -34,7 +34,7 @@ import twitter4j.GeoLocation;
|
||||
* @author Josh Long
|
||||
*/
|
||||
@ContextConfiguration(locations = {
|
||||
"/sending_dms_using_ns.xml"}
|
||||
"/org/springframework/integration/twitter/sending_dms_using_ns.xml"}
|
||||
)
|
||||
public class TestSendingDMsUsingNamespace extends AbstractJUnit4SpringContextTests {
|
||||
private volatile MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
|
||||
@@ -33,7 +33,7 @@ import twitter4j.GeoLocation;
|
||||
* @author Josh Long
|
||||
*/
|
||||
@ContextConfiguration(locations = {
|
||||
"/sending_updates_using_ns.xml"}
|
||||
"/org/springframework/integration/twitter/sending_updates_using_ns.xml"}
|
||||
)
|
||||
public class TestSendingUpdatesUsingNamespace extends AbstractJUnit4SpringContextTests {
|
||||
private MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
|
||||
Reference in New Issue
Block a user