diff --git a/docs/src/reference/docbook/twitter.xml b/docs/src/reference/docbook/twitter.xml
index 1443d7007a..88086ab00f 100644
--- a/docs/src/reference/docbook/twitter.xml
+++ b/docs/src/reference/docbook/twitter.xml
@@ -106,11 +106,12 @@ and configuring a property-placeholder pointing to he above propert
Twitter Inbound Adapters
- Twitter inbound adapters allow you to receive Twitter Messages. There are several types of twitter messages:
- Types of Tweets
+ Twitter inbound adapters allow you to receive Twitter Messages. There are several types of
+ twitter messages - tweets
- Current release of Spring Integration provides support for Public Messages, Direct Messages as well as Mention Messages
+ Current release of Spring Integration provides support for receiving Public Messages,
+ Direct Messages as well as Mention Messages
Every Inbound Twitter Channel Adapter is a Polling consumer which means you have to provide a poller
@@ -175,4 +176,43 @@ The Poller that is configured as part of the any Inbound Twitter Adapter (see be
simply invoke getText() method. For more information please refer to Twitter4J API
+
+
+ Twitter Outbound Adapter
+
+ Twitter outbound channels adapters allow you to send Twitter Messages - tweets
+
+
+ Current release of Spring Integration supports sending Status Update Messages and Direct Messages.
+ Twitter outbound channels adapters as any other outbound adapter will take the Message payload and send it as
+ Twitter message. Currently the only supported payload type is String, so consider adding a transformer
+ if the payload of the incoming message is not a String.
+
+
+
+ Twitter Outbound Update Channel Adapter
+
+ This adapter allows you to send regular status updates by simply sending a Message to a channel
+ identified via channel attribute.
+ ]]>
+ The only extra configuration that is required for this adapter is twitter-connection
+
+
+
+
+ Twitter Outbound Direct Message Channel Adapter
+
+ This adapter allows you to send Direct Twitter Messages (i.e., @user) by simply sending a Message to a channel
+ identified via channel attribute.
+ ]]>
+ The only extra configuration that is required for this adapter is twitter-connection
+
+
+
+ Twitter does not allow you to post duplicate Messages. This is a common problem during testing when
+ the same code works the first time but doesn't work the second time,so make sure to change the content of the Message.
+ One thing that works good for testing is appent timestamp to the end of the message.
+
+
+
diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/MarshallingTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/MarshallingTransformer.java
index 0c4e2e497e..c5a24f461c 100644
--- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/MarshallingTransformer.java
+++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/MarshallingTransformer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * 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.
@@ -46,8 +46,7 @@ public class MarshallingTransformer extends AbstractTransformer {
private volatile boolean extractPayload = true;
- public MarshallingTransformer(Marshaller marshaller, ResultTransformer resultTransformer)
- throws ParserConfigurationException {
+ public MarshallingTransformer(Marshaller marshaller, ResultTransformer resultTransformer) throws ParserConfigurationException {
Assert.notNull(marshaller, "a marshaller is required");
this.marshaller = marshaller;
this.resultTransformer = resultTransformer;
@@ -89,9 +88,6 @@ public class MarshallingTransformer extends AbstractTransformer {
catch (IOException e) {
throw new MessagingException("Failed to marshal payload", e);
}
- if (transformedPayload == null) {
- throw new MessagingException("Failed to transform payload");
- }
if (this.resultTransformer != null) {
transformedPayload = this.resultTransformer.transformResult(result);
}
diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToDocumentTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToDocumentTransformer.java
index 1267116a07..5e13461a5a 100644
--- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToDocumentTransformer.java
+++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToDocumentTransformer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * 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.
@@ -24,11 +24,12 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.dom.DOMResult;
-import org.springframework.integration.MessagingException;
-import org.springframework.xml.transform.StringResult;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
+import org.springframework.integration.MessagingException;
+import org.springframework.xml.transform.StringResult;
+
/**
* Creates a {@link Document} from a {@link Result} payload. Supports
* {@link DOMResult} and {@link StringResult} implementations.
@@ -40,6 +41,7 @@ public class ResultToDocumentTransformer implements ResultTransformer {
// Not guaranteed to be thread safe
private final DocumentBuilderFactory documentBuilderFactory;
+
public ResultToDocumentTransformer(DocumentBuilderFactory documentBuilderFactory) {
this.documentBuilderFactory = documentBuilderFactory;
}
@@ -49,40 +51,41 @@ public class ResultToDocumentTransformer implements ResultTransformer {
this.documentBuilderFactory.setNamespaceAware(true);
}
- public Object transformResult(Result res) {
- Document doc = null;
- if (DOMResult.class.isAssignableFrom(res.getClass())) {
- doc = createDocumentFromDomResult((DOMResult) res);
+
+ public Object transformResult(Result result) {
+ Document document = null;
+ if (DOMResult.class.isAssignableFrom(result.getClass())) {
+ document = createDocumentFromDomResult((DOMResult) result);
}
- else if (StringResult.class.isAssignableFrom(res.getClass())) {
- doc = createDocumentFromStringResult((StringResult) res);
+ else if (StringResult.class.isAssignableFrom(result.getClass())) {
+ document = createDocumentFromStringResult((StringResult) result);
}
else {
- throw new MessagingException("Failed to create document from payload type [" + res.getClass().getName()
- + "]");
+ throw new MessagingException("failed to create document from payload type [" +
+ result.getClass().getName() + "]");
}
- return doc;
+ return document;
}
- protected Document createDocumentFromDomResult(DOMResult domResult) {
+ private Document createDocumentFromDomResult(DOMResult domResult) {
return (Document) domResult.getNode();
}
- protected Document createDocumentFromStringResult(StringResult stringResult) {
+ private Document createDocumentFromStringResult(StringResult stringResult) {
try {
return getDocumentBuilder().parse(new InputSource(new StringReader(stringResult.toString())));
}
catch (Exception e) {
- throw new MessagingException("Failed to create Document from StringResult payload", e);
+ throw new MessagingException("failed to create Document from StringResult payload", e);
}
}
- protected synchronized DocumentBuilder getDocumentBuilder() {
+ private synchronized DocumentBuilder getDocumentBuilder() {
try {
return this.documentBuilderFactory.newDocumentBuilder();
}
catch (ParserConfigurationException e) {
- throw new MessagingException("Failed to create a new DocumentBuilder", e);
+ throw new MessagingException("failed to create a new DocumentBuilder", e);
}
}
diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToStringTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToStringTransformer.java
index 33d9249115..3382864806 100644
--- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToStringTransformer.java
+++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultToStringTransformer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * 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.
@@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.integration.xml.transformer;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
@@ -30,62 +28,49 @@ import org.springframework.integration.MessagingException;
import org.springframework.xml.transform.StringResult;
/**
- * Converts the passed {@link Result} to an instance of {@link String}
- *
+ * Converts the passed {@link Result} to an instance of {@link String}.
* Supports {@link StringResult} and {@link DOMResult}
*
* @author Jonas Partner
- *
+ * @author Mark Fisher
*/
public class ResultToStringTransformer implements ResultTransformer {
- private DocumentBuilderFactory docBuilderFactory;
+ private final TransformerFactory transformerFactory;
- private TransformerFactory transformerFactory;
public ResultToStringTransformer() {
- this.docBuilderFactory = DocumentBuilderFactory.newInstance();
- this.docBuilderFactory.setNamespaceAware(true);
this.transformerFactory = TransformerFactory.newInstance();
}
- protected Transformer getNewTransformer()
- throws TransformerConfigurationException {
- synchronized (transformerFactory) {
- return transformerFactory.newTransformer();
- }
- }
- public Object transformResult(Result res) {
+ public Object transformResult(Result result) {
String returnString = null;
- if (res instanceof StringResult) {
- returnString = ((StringResult) res).toString();
- } else if (res instanceof DOMResult) {
+ if (result instanceof StringResult) {
+ returnString = ((StringResult) result).toString();
+ }
+ else if (result instanceof DOMResult) {
try {
- StringResult strRes = new StringResult();
- getNewTransformer().transform(
- new DOMSource(((DOMResult) res).getNode()), strRes);
- returnString = strRes.toString();
- } catch (TransformerException transE) {
- throw new MessagingException(
- "Transformation from DOMSOurce failed", transE);
+ StringResult stringResult = new StringResult();
+ this.getNewTransformer().transform(
+ new DOMSource(((DOMResult) result).getNode()), stringResult);
+ returnString = stringResult.toString();
+ }
+ catch (TransformerException e) {
+ throw new MessagingException("failed to transform from DOMSource failed", e);
}
}
-
if (returnString == null) {
- throw new MessagingException("Could not convert Result type "
- + res.getClass().getName() + " to string");
+ throw new MessagingException("failed to convert Result type ["
+ + result.getClass().getName() + "] to string");
}
-
return returnString;
}
- protected DocumentBuilder getNewDocumentBuilder()
- throws ParserConfigurationException {
- synchronized (docBuilderFactory) {
- return docBuilderFactory.newDocumentBuilder();
+ private Transformer getNewTransformer() throws TransformerConfigurationException {
+ synchronized (this.transformerFactory) {
+ return this.transformerFactory.newTransformer();
}
-
}
}
diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultTransformer.java
index c2769349e8..62c73b0a6b 100644
--- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultTransformer.java
+++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/ResultTransformer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * 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.
@@ -13,10 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.integration.xml.transformer;
+import javax.xml.transform.Result;
+
+/**
+ * @author Jonas Partner
+ */
public interface ResultTransformer {
- Object transformResult(javax.xml.transform.Result res);
+ Object transformResult(Result result);
}
diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/SourceCreatingTransformer.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/SourceCreatingTransformer.java
index b2fd320f7c..539cad4293 100644
--- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/SourceCreatingTransformer.java
+++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/transformer/SourceCreatingTransformer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2008 the original author or authors.
+ * 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.
@@ -41,6 +41,7 @@ public class SourceCreatingTransformer extends AbstractPayloadTransformer