Question

I am developing a Mule Application that takes json data from some xively feeds and transform them with a Java transformer I made.

Then the results are mailed to my e-mail. The content of the messages are the returned String in the toString() method of my custom transformer's returnClass.

I am not sure how this all is put together, but it works.

However, I want to twit part of the mailed message too. I can't do it so far because the message is loo long. What component could I use to take the Strings transformed and returned for each feed, manipulate them and then return them again so they can be twitted?

I use Mule Studio.

This is my xml:

<?xml version="1.0" encoding="UTF-8"?>

<mule>
    <http:polling-connector name="HTTP_Polling_90" cookieSpec="netscape" validateConnections="true" pollingFrequency="90000" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" proxyHostname="api.xively.com" proxyUsername="****" proxyPassword="****" doc:name="HTTP Polling"/>
    <spring:beans>
        <spring:bean id="Bean" name="Bean" class="events.Transformer"/>
    </spring:beans>
    <twitter:config name="Twitter" accessKey="****" accessSecret="****" consumerKey="****" consumerSecret="****" doc:name="Twitter">
        <twitter:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/>
    </twitter:config>
    <flow name="flow1" doc:name="flow1">
        <composite-source doc:name="Composite Source">
            <http:inbound-endpoint exchange-pattern="one-way" host="api.xively.com" port="8081" path="v2/feeds/****.json" connector-ref="HTTP_Polling_90" user="****" password="****" contentType="application/json" doc:name="Weather Station (Barcelona)"/>
            <http:inbound-endpoint exchange-pattern="one-way" host="api.xively.com" port="8081" path="v2/feeds/****.json" connector-ref="HTTP_Polling_90" user="****" password="****" contentType="application/json" doc:name="Radiation &amp; Airpressure"/>
        </composite-source>
        <json:json-to-object-transformer doc:name="JSON to Object"/>
        <auto-transformer returnClass="events.Event" name="JSONToObject"></auto-transformer>
        <logger level="INFO" doc:name="Logger"/>
        <all doc:name="All">
            <smtps:outbound-endpoint host="****" port="465" user="${mail.username}" password="****" to="****" from="****" subject="blabla" responseTimeout="10000" doc:name="SMTP"/>
            <processor-chain>
                <twitter:update-status config-ref="Twitter" doc:name="Twitter" status="#[payload]"/>
                <echo-component doc:name="Echo"/>
            </processor-chain>
        </all>
    </flow>
</mule>
Was it helpful?

Solution

From your post I assume that you are looking a way to read the String obtained after the Mail message and Cut it and then tweet it.

Try the following.

<processor-chain>
    <set-payload value="#[message.payloadAs(java.lang.String).substring(0,139)]"        
    <twitter:update-status config-ref="Twitter" doc:name="Twitter" status="#[payload]"/>
    <echo-component doc:name="Echo"/>
</processor-chain>

This truncates the message to 140 characters and send its a payload to the Twitter update-status processor.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top