Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:pop3s="http://www.mulesoft.org/schema/mule/pop3s" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:script="http://www.mulesoft.org/schema/mule/scripting" xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" xmlns:pivotal-tracker="http://www.mulesoft.org/schema/mule/pivotaltracker"
xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="EE-3.2.2"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd
http://www.mulesoft.org/schema/mule/pop3s http://www.mulesoft.org/schema/mule/pop3s/current/mule-pop3s.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/imaps http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd
http://www.mulesoft.org/schema/mule/pivotaltracker http://www.mulesoft.org/schema/mule/pivotaltracker/1.0/mule-pivotaltracker.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd ">
<spring:bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<spring:property name="locations">
<spring:list>
<spring:value>classpath:/config.properties</spring:value>
</spring:list>
</spring:property>
</spring:bean>
<pivotal-tracker:config name="pivotalTrackerConnector" trackerToken="${connector.token}" storiesUrl="${connector.stories.url}" username="" password=""></pivotal-tracker:config>
<pop3s:connector name="POP3" validateConnections="true" deleteReadMessages="false" doc:name="POP3" />
<jms:activemq-connector name="Active_MQ" brokerURL="${activeMQ.broker.url}" validateConnections="true" doc:name="Active MQ" />
<smtp:gmail-connector name="smtpGmailConnector" contentType="text/plain" fromAddress="${error.email.from}" />
<flow name="main" doc:name="main">
<pop3s:inbound-endpoint host="pop.gmail.com" port="995" user="${email.user}" password="${email.password}" responseTimeout="10000" connector-ref="POP3" doc:name="Pop3" />
<message-properties-transformer scope="session" doc:name="Add Session Header: From">
<add-message-property key="from" value="#[header:from]" />
<add-message-property key="subject" value="#[header:subject]" />
</message-properties-transformer>
<custom-transformer class="com.mulesoft.se.EmailBodyToXmlTransformer" doc:name="Email Body to Xml" />
<choice doc:name="Choice">
<when expression="message.getOutboundProperty('References') == null" evaluator="groovy">
<processor-chain>
<flow-ref name="newEmail" doc:name="Invoke newEmail" />
</processor-chain>
</when>
<otherwise>
<processor-chain>
<flow-ref name="replyEmail" doc:name="Invoke replyEmail" />
</processor-chain>
</otherwise>
</choice>
</flow>
<sub-flow name="newEmail" doc:name="New Email">
<logger message="#[string:New email received from #[header:session:from]]" level="INFO" doc:name="New Email received" />
<scripting:transformer doc:name="Add Session Header: Email ID">
<scripting:script engine="groovy">
<scripting:text><![CDATA[def emailId;
if (message.getSessionProperty("emailId") == null) {
emailId = message.getOutboundProperty("Message-ID");
def newEmailId = emailId.substring(1, emailId.indexOf("@"));
message.setSessionProperty("emailId", newEmailId);
}
return payload;]]></scripting:text>
</scripting:script>
</scripting:transformer>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="Create Pivotal Tracker Request">
<mulexml:xslt-text>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="" version="2.0">
<xsl:output method="xml" />
<xsl:param name="name" />
<xsl:param name="requestedBy" />
<xsl:template match="/">
<story>
<story_type>feature</story_type>
<name>
<xsl:value-of select="$name" />
</name>
<description>
<xsl:value-of select="message/text()" />
</description>
<requested_by>API Client</requested_by>
</story>
</xsl:template>
</xsl:stylesheet>
</mulexml:xslt-text>
<mulexml:context-property key="name" value="#[header:session:subject]" />
<mulexml:context-property key="sentBy" value="#[header:session:from]" />
</mulexml:xslt-transformer>
<object-to-string-transformer doc:name="Object to String" />
<vm:outbound-endpoint path="createStory" doc:name="Dispatch to createStory" exchange-pattern="one-way" />
</sub-flow>
<spring:bean id="createStoryObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore" />
<flow name="createStory">
<composite-source>
<vm:inbound-endpoint path="createStory" exchange-pattern="one-way" doc:name="createStory"/>
<jms:inbound-endpoint queue="error.createStory" connector-ref="Active_MQ" doc:name="error.createStory" />
</composite-source>
<until-successful objectStore-ref="createStoryObjectStore" maxRetries="12" secondsBetweenRetries="300">
<processor-chain>
<pivotal-tracker:create-story storyXml="#[payload]" doc:name="Create Story on Pivotal Tracker" />
<logger message="Posted story to Pivotal Tracker" level="INFO" doc:name="Story posted to Pivotal Tracker" />
<message-properties-transformer scope="session" doc:name="Add Session Header: Story ID">
<add-message-property key="storyId" value="#[xpath:/story/id/text()]" />
</message-properties-transformer>
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="Create Pivotal Tracker Request">
<mulexml:xslt-text>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="" version="2.0">
<xsl:output method="xml" />
<xsl:param name="label" />
<xsl:template match="/">
<story>
<labels>
<xsl:value-of select="$label" />
</labels>
</story>
</xsl:template>
</xsl:stylesheet>
</mulexml:xslt-text>
<mulexml:context-property key="label" value="#[header:session:emailId]" />
</mulexml:xslt-transformer>
<object-to-string-transformer doc:name="Object to String" />
<vm:outbound-endpoint path="labelStory" doc:name="Dispatch to labelStory" exchange-pattern="one-way" />
</processor-chain>
</until-successful>
<default-exception-strategy>
<processor-chain>
<logger message="Failed to invoke createStory on PivotalTracker connector. Will retry in 1 hour" level="ERROR" />
<smtp:outbound-endpoint host="smtp.googlemail.com" port="25" subject="Exception in createStory flow" to="nial.darbey@mulesoft.com" connector-ref="smtpGmailConnector" />
<scripting:transformer doc:name="Replace with Original Payload">
<scripting:script engine="groovy">
<scripting:text><![CDATA[return payload.getPayload()]]></scripting:text>
</scripting:script>
</scripting:transformer>
<quartz:outbound-endpoint repeatCount="0" cronExpression="0 * * * * ? *" jobName="createStory" startDelay="3600000">
<quartz:scheduled-dispatch-job>
<quartz:job-endpoint address="jms://error.createStory" />
</quartz:scheduled-dispatch-job>
</quartz:outbound-endpoint>
</processor-chain>
</default-exception-strategy>
</flow>
<spring:bean id="labelStoryObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore" />
<flow name="labelStory">
<composite-source>
<vm:inbound-endpoint path="labelStory" exchange-pattern="one-way" doc:name="labelStory"/>
<jms:inbound-endpoint queue="error.labelStory" connector-ref="Active_MQ" doc:name="error.LabelStory" />
</composite-source>
<until-successful objectStore-ref="labelStoryObjectStore" maxRetries="12" secondsBetweenRetries="300">
<processor-chain>
<pivotal-tracker:label-story labelXml="#[payload]" storyId="#[header:session:storyId]" doc:name="Label Story on Pivotal Tracker" />
<logger message="#[string:Story #[header:session:storyId] labelled on Pivotal Tracker with #[header:session:emailId]]" level="INFO" doc:name="Story labelled on Pivotal Tracker" />
</processor-chain>
</until-successful>
<default-exception-strategy>
<processor-chain>
<logger message="Failed to invoke labelStory on PivotalTracker connector. Will retry in 1 hour" level="ERROR" />
<smtp:outbound-endpoint host="smtp.googlemail.com" port="25" subject="Exception in labelStory flow" to="nial.darbey@mulesoft.com" connector-ref="smtpGmailConnector" />
<scripting:transformer doc:name="Replace with Original Payload">
<scripting:script engine="groovy">
<scripting:text><![CDATA[return payload.getPayload()]]></scripting:text>
</scripting:script>
</scripting:transformer>
<quartz:outbound-endpoint repeatCount="0" cronExpression="0 * * * * ? *" jobName="labelStory" startDelay="3600000">
<quartz:scheduled-dispatch-job>
<quartz:job-endpoint address="jms://error.labelStory" />
</quartz:scheduled-dispatch-job>
</quartz:outbound-endpoint>
</processor-chain>
</default-exception-strategy>
</flow>
<sub-flow name="replyEmail" doc:name="Reply Email">
<logger message="Reply email received from #[header:session:from]]" level="INFO" doc:name="Reply email received" />
<scripting:transformer doc:name="Add Session Header: Email ID">
<scripting:script engine="groovy">
<scripting:text><![CDATA[def emailId;
if (message.getSessionProperty("emailId") == null) {
emailId = message.getOutboundProperty("References");
def newEmailId = emailId.substring(1, emailId.indexOf("@"));
message.setSessionProperty("emailId", newEmailId);
}
return payload;]]></scripting:text>
</scripting:script>
</scripting:transformer>
<vm:outbound-endpoint path="commentStory" doc:name="Dispatch to commentStory" exchange-pattern="one-way" />
</sub-flow>
<spring:bean id="commentStoryObjectStore" class="org.mule.util.store.SimpleMemoryObjectStore" />
<flow name="commentStory">
<composite-source>
<vm:inbound-endpoint path="commentStory" exchange-pattern="one-way" doc:name="commentStory"/>
<jms:inbound-endpoint queue="error.commentStory" connector-ref="Active_MQ" doc:name="error.commentStory" />
</composite-source>
<until-successful objectStore-ref="commentStoryObjectStore" maxRetries="12" secondsBetweenRetries="300">
<processor-chain>
<enricher source="#[xpath:/stories/story/id/text()]" target="#[header:session:storyId]">
<pivotal-tracker:find-story-by-filter filter="label:#[header:session:emailId] type:feature" doc:name="Find Story on Pivotal Tracker by Filter" />
</enricher>
<choice doc:name="Choice">
<when expression="message.getSessionProperty('storyId') != null" evaluator="groovy">
<processor-chain>
<logger message="Story matching #[header:session:emailId] found on Pivotal Tracker" level="INFO" doc:name="Matching story found" />
<mulexml:xslt-transformer maxIdleTransformers="2" maxActiveTransformers="5" doc:name="Create Comment Xml">
<mulexml:xslt-text>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="" version="2.0">
<xsl:output method="xml" />
<xsl:param name="emailBody" />
<xsl:param name="sentBy" />
<xsl:template match="/">
<note>
<text>
(Sent by
<xsl:value-of select="$sentBy" />
)
<xsl:value-of select="$emailBody" />
</text>
</note>
</xsl:template>
</xsl:stylesheet>
</mulexml:xslt-text>
<mulexml:context-property key="emailBody" value="#[xpath:/message/text()]" />
<mulexml:context-property key="sentBy" value="#[header:session:from]" />
</mulexml:xslt-transformer>
<byte-array-to-string-transformer doc:name="Byte Array to String" />
<pivotal-tracker:comment-story commentsXml="#[payload]" storyId="#[header:session:storyId]" doc:name="Comment Story on Pivotal Tracker" />
<logger message="Commented story with body of email" level="INFO" doc:name="Story commented on Pivotal Tracker" />
</processor-chain>
</when>
<otherwise>
<processor-chain>
<logger message="No matching story with ID #[header:session:emailId] found on Pivotal Tracker" level="INFO" doc:name="No matching story found" />
<flow-ref name="newEmail" doc:name="Invoke newEmail" />
</processor-chain>
</otherwise>
</choice>
</processor-chain>
</until-successful>
<default-exception-strategy>
<processor-chain>
<logger message="Failed to invoke commentStory on PivotalTracker connector. Will retry in 1 hour" level="ERROR" />
<smtp:outbound-endpoint host="smtp.googlemail.com" port="25" subject="Exception in comment-story flow" to="nial.darbey@mulesoft.com" connector-ref="smtpGmailConnector" />
<scripting:transformer doc:name="Replace with Original Payload">
<scripting:script engine="groovy">
<scripting:text><![CDATA[return payload.getPayload()]]></scripting:text>
</scripting:script>
</scripting:transformer>
<quartz:outbound-endpoint repeatCount="0" cronExpression="0 * * * * ? *" jobName="commentStory" startDelay="3600000">
<quartz:scheduled-dispatch-job>
<quartz:job-endpoint address="jms://error.commentStory" />
</quartz:scheduled-dispatch-job>
</quartz:outbound-endpoint>
</processor-chain>
</default-exception-strategy>
</flow>
</mule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.