INT-1636 rolling back the DM target user expression support
This commit is contained in:
@@ -18,15 +18,12 @@ package org.springframework.integration.twitter.config;
|
||||
|
||||
import static org.springframework.integration.twitter.config.TwitterNamespaceHandler.BASE_PACKAGE;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for all outbound Twitter adapters
|
||||
@@ -42,12 +39,6 @@ public class TwitterOutboundChannelAdapterParser extends AbstractOutboundChannel
|
||||
String className = determineClassName(element, parserContext);
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(className);
|
||||
builder.addConstructorArgReference(element.getAttribute("twitter-template"));
|
||||
String targetUserExpression = element.getAttribute("target-user-expression");
|
||||
if (StringUtils.hasText(targetUserExpression)){
|
||||
BeanDefinition expressionDef = new RootBeanDefinition("org.springframework.integration.config.ExpressionFactoryBean");
|
||||
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(targetUserExpression);
|
||||
builder.addPropertyValue("targetUserExpression", expressionDef);
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
@@ -64,7 +55,6 @@ public class TwitterOutboundChannelAdapterParser extends AbstractOutboundChannel
|
||||
else {
|
||||
parserContext.getReaderContext().error("element '" + elementName + "' is not supported by this parser.", element);
|
||||
}
|
||||
|
||||
return className;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,6 @@
|
||||
|
||||
package org.springframework.integration.twitter.outbound;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.handler.AbstractMessageHandler;
|
||||
import org.springframework.integration.twitter.core.TwitterHeaders;
|
||||
@@ -40,18 +32,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class DirectMessageSendingMessageHandler extends AbstractMessageHandler {
|
||||
|
||||
private static final ExpressionParser PARSER = new SpelExpressionParser();
|
||||
|
||||
private static final Expression DEFAULT_TARGET_USER_EXPRESSION = PARSER.parseExpression(
|
||||
"headers[T(org.springframework.integration.twitter.core.TwitterHeaders).DM_TARGET_USER_ID]");
|
||||
|
||||
|
||||
private final TwitterOperations twitterOperations;
|
||||
|
||||
private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
|
||||
|
||||
private volatile Expression targetUserExpression = DEFAULT_TARGET_USER_EXPRESSION;
|
||||
|
||||
|
||||
public DirectMessageSendingMessageHandler(TwitterOperations twitterOperations) {
|
||||
Assert.notNull(twitterOperations, "twitterOperations must not be null");
|
||||
@@ -59,31 +41,14 @@ public class DirectMessageSendingMessageHandler extends AbstractMessageHandler {
|
||||
}
|
||||
|
||||
|
||||
public void setTargetUserExpression(Expression targetUserExpression) {
|
||||
this.targetUserExpression = (targetUserExpression != null) ? targetUserExpression : DEFAULT_TARGET_USER_EXPRESSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInit() throws Exception {
|
||||
super.onInit();
|
||||
BeanFactory beanFactory = this.getBeanFactory();
|
||||
if (beanFactory != null) {
|
||||
this.evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
|
||||
}
|
||||
ConversionService conversionService = this.getConversionService();
|
||||
if (conversionService != null) {
|
||||
this.evaluationContext.setTypeConverter(new StandardTypeConverter(conversionService));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMessageInternal(Message<?> message) throws Exception {
|
||||
Assert.isTrue(message.getPayload() instanceof String, "Only payload of type String is supported. " +
|
||||
"Consider adding a transformer to the message flow in front of this adapter.");
|
||||
Object toUser = this.targetUserExpression.getValue(this.evaluationContext, message);
|
||||
Object toUser = message.getHeaders().get(TwitterHeaders.DM_TARGET_USER_ID);
|
||||
Assert.isTrue(toUser instanceof String || toUser instanceof Integer,
|
||||
"the header '" + TwitterHeaders.DM_TARGET_USER_ID +
|
||||
"' must be either a String (a screenname) or an int (a user ID)");
|
||||
"' must contain either a String (a screenname) or an int (a user ID)");
|
||||
String payload = (String) message.getPayload();
|
||||
if (toUser instanceof Integer) {
|
||||
this.twitterOperations.sendDirectMessage((Integer) toUser, payload);
|
||||
|
||||
@@ -94,15 +94,7 @@
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="outbound-twitter-type">
|
||||
<xsd:attribute name="target-user-expression" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Allows you to provide a valid SpEL Expression which will compute the target userid.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
<xsd:extension base="outbound-twitter-type"/>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
Reference in New Issue
Block a user