Created
July 23, 2012 06:19
-
-
Save rossmason/3162247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snip:mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:snip="http://www.mulesoft.org/schema/mule/snippet" xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" xmlns:boxnet="http://www.mulesoft.org/schema/mule/boxnet" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:cloudhub="http://www.mulesoft.org/schema/mule/cloudhub" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation=" | |
http://www.mulesoft.org/schema/mule/imaps http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd | |
http://www.mulesoft.org/schema/mule/boxnet http://www.mulesoft.org/schema/mule/boxnet/1.0/mule-boxnet.xsd | |
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/cloudhub http://www.mulesoft.org/schema/mule/cloudhub/1.0/mule-cloudhub.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd | |
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> | |
<flow name="Boxnet-init-getAuthToken-callback" doc:name="Boxnet-init-getAuthToken-callback"> | |
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="${http.port}" path="authtoken" doc:name="HTTP"/> | |
<boxnet:auth-token config-ref="Boxnet" doc:name="Get Auth Token"/> | |
<set-payload value="Authenitcation complete: #[message.payload]" doc:name="Success Message"/> | |
<http:response-builder status="200" contentType="text/plain" doc:name="HTTP Response Builder"/> | |
</flow> | |
</snip:mule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snip:mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:snip="http://www.mulesoft.org/schema/mule/snippet" xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" xmlns:boxnet="http://www.mulesoft.org/schema/mule/boxnet" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:cloudhub="http://www.mulesoft.org/schema/mule/cloudhub" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation=" | |
http://www.mulesoft.org/schema/mule/imaps http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd | |
http://www.mulesoft.org/schema/mule/boxnet http://www.mulesoft.org/schema/mule/boxnet/1.0/mule-boxnet.xsd | |
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/cloudhub http://www.mulesoft.org/schema/mule/cloudhub/1.0/mule-cloudhub.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd | |
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> | |
<flow name="Boxnet-init-Authenticate" doc:name="Boxnet-init-Authenticate"> | |
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="${http.port}" path="boxauth" doc:name="HTTP"/> | |
<boxnet:get-ticket config-ref="Boxnet" doc:name="Get Ticket"/> | |
<scripting:component doc:name="Open Browser and Auth"> | |
<scripting:script engine="Groovy"> | |
<scripting:text><![CDATA[url = "https://www.box.net/api/1.0/auth/" + payload; | |
if( !java.awt.Desktop.isDesktopSupported() ) { | |
result = "Desktop is not supported on this platform, you'll need to go to the following URL in a browser before you can use this app: " + url + "\n\n"; | |
} else { | |
java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); | |
if( !desktop.isSupported( java.awt.Desktop.Action.BROWSE ) ) { | |
result = "This desktop does not support the browse action, you'll need to go to the following URL in a browser manually before you can use this app: " + url + "\n\n"; | |
} else { | |
desktop.browse( new java.net.URI( url ) ); | |
} | |
}]]></scripting:text> | |
</scripting:script> | |
</scripting:component> | |
</flow> | |
</snip:mule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snip:mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:snip="http://www.mulesoft.org/schema/mule/snippet" xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" xmlns:boxnet="http://www.mulesoft.org/schema/mule/boxnet" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:cloudhub="http://www.mulesoft.org/schema/mule/cloudhub" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation=" | |
http://www.mulesoft.org/schema/mule/imaps http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd | |
http://www.mulesoft.org/schema/mule/boxnet http://www.mulesoft.org/schema/mule/boxnet/1.0/mule-boxnet.xsd | |
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/cloudhub http://www.mulesoft.org/schema/mule/cloudhub/1.0/mule-cloudhub.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd | |
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> | |
<boxnet:config name="Boxnet" apiKey="${boxnet.api.key}" doc:name="Boxnet"/> | |
<sub-flow name="Write-files-to-Box" doc:name="Write-files-to-Box"> | |
<expression-filter expression="#[sessionVars['files'].size() > 0]" doc:name="Files to upload?"/> | |
<boxnet:upload-files config-ref="Boxnet" doc:name="Write Files to Box.net"> | |
<boxnet:paths ref="#[sessionVars['files']]"/> | |
</boxnet:upload-files> | |
</sub-flow> | |
</snip:mule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snip:mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:snip="http://www.mulesoft.org/schema/mule/snippet" xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" xmlns:boxnet="http://www.mulesoft.org/schema/mule/boxnet" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:cloudhub="http://www.mulesoft.org/schema/mule/cloudhub" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation=" | |
http://www.mulesoft.org/schema/mule/imaps http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd | |
http://www.mulesoft.org/schema/mule/boxnet http://www.mulesoft.org/schema/mule/boxnet/1.0/mule-boxnet.xsd | |
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/cloudhub http://www.mulesoft.org/schema/mule/cloudhub/1.0/mule-cloudhub.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd | |
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> | |
<imaps:connector name="IMAP" mailboxFolder="INBOX" validateConnections="true" deleteReadMessages="${gmail.archive.messages}" doc:name="IMAP"/> | |
<imaps:inbound-endpoint host="imap.gmail.com" port="993" user="${gmail.username}" password="${gmail.password}" responseTimeout="10000" connector-ref="IMAP" doc:name="From Gmail"/> | |
</snip:mule> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snip:mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:snip="http://www.mulesoft.org/schema/mule/snippet" xmlns:imaps="http://www.mulesoft.org/schema/mule/imaps" xmlns:boxnet="http://www.mulesoft.org/schema/mule/boxnet" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:cloudhub="http://www.mulesoft.org/schema/mule/cloudhub" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.3.0" xsi:schemaLocation=" | |
http://www.mulesoft.org/schema/mule/imaps http://www.mulesoft.org/schema/mule/imaps/current/mule-imaps.xsd | |
http://www.mulesoft.org/schema/mule/boxnet http://www.mulesoft.org/schema/mule/boxnet/1.0/mule-boxnet.xsd | |
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/cloudhub http://www.mulesoft.org/schema/mule/cloudhub/1.0/mule-cloudhub.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd | |
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd "> | |
<sub-flow name="Extract-Attachments" doc:name="Extract-Attachments"> | |
<expression-transformer doc:name="Extract attachments"> | |
<return-argument evaluator="attachments-list" expression="*"/> | |
</expression-transformer> | |
<scripting:component doc:name="Save Attachments"> | |
<scripting:script engine="Groovy"> | |
<property key="attachmentFilter" value="image*"/> | |
<scripting:text><![CDATA[def files = []; | |
log.info("extracting attachments...") | |
if(attachmentFilter==null) { | |
attachmentFilter = "*"; | |
} | |
log.info("filtering attachment content type using: " + attachmentFilter); | |
org.mule.routing.filters.WildcardFilter filter = new org.mule.routing.filters.WildcardFilter(attachmentFilter); | |
((java.util.ArrayList)payload).each { | |
name = it.name; | |
ct = it.contentType; | |
if(filter.accept(ct)) | |
{ | |
if(name==null) { | |
name = org.mule.util.UUID.getUUID() + "." + ct.substring(ct.lastIndexOf("/")+1); | |
} | |
java.io.File f = new java.io.File(muleContext.configuration.workingDirectory, name); | |
org.mule.util.FileUtils.copyStreamToFile(it.inputStream, f); | |
files.add(f.getAbsolutePath()); | |
log.info("Added file: " + f.getAbsolutePath()); | |
} | |
else { | |
log.warn("Attachment rejected: " + ct); | |
} | |
} | |
message.setSessionProperty("files", files); | |
result = payload;]]></scripting:text> | |
</scripting:script> | |
</scripting:component> | |
<logger message="Files to upload: #[sessionVars['files']]" level="INFO" doc:name="Logger"/> | |
</sub-flow> | |
</snip:mule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment