Blogs

Integration with Dropbox using Mule ESB

Written by Coforge-Salesforce BU | May 5, 2015 6:30:00 PM

Overview

Dropbox is a file hosting service operated by Dropbox, Inc. , headquartered in San Francisco, California. It offers cloud storage, file synchronization, personal cloud, and client software for Microsoft Windows, Mac OS X, Linux, Android, iOS, BlackBerry OS, Windows Phone and web browsers. In this blog post, a step by step procedure of connecting to Dropbox cloud using Mule ESB Dropbox Cloud Connector is shown.

Versions and Assumptions

  • For this illustration, we are using
    • Dropbox Cloud Connector 3.3.0
    • Anypoint Studio
    • Mule ESB Server 3.5.2
    • Mule requester Module 1.2.0
  • To integrate Dropbox with Mule ESB, we will need a Dropbox account
  • We need to create a new Dropbox app under Dropbox developer apps in order to communicate with the Dropbox account from Mule ESB application
  • We will be using OAuth2 authentication to connect to Dropbox using Mule ESB Dropbox Cloud Connector

Configuring Dropbox

  • Go to https://www.dropbox.com/developers/apps
  • Click on Create app button
  • Click on Dropbox API app
  • Select “Files and datastores” radio button
  • Select “No - My app needs access to files already on Dropbox” radio button
  • Select “All file types -My app needs access to a user's full Dropbox” radio button
  • Provide an app name and click on Create app button
  • Provide a redirect URI for OAuth2 and click on Add button
  • Make a note of the App key, App secret, Redirect URI as these will be used in our Mule application to connect to Dropbox cloud. A sample screen of a drop box app is given below.

Dropbox App Screen

Configuring Global properties in Mule

  • Create a new Mule Application
  • Click on Global Elements tab in the main flow
  • Click on Create Button
  • Select Property Placeholder component
  • Provide the property file location and click on OK. Our property file should have at least two properties for app key and app secret which will  be used later in the Dropbox connector configuration. A sample screen shot and XML configuration is as follows:

mule-app.properties

DropboxAppkey=**********
DropboxAppSecret=*********

Property Placeholder

<context:property-placeholder location="file:${mule_home}/conf/mule-app.properties"/>

Configuring Dropbox Connector

  • Click on Global Elements tab in the main flow
  • Click on Create Button
  • Select Dropbox under Connector Configuration group
  • Add the Dropbox App Key value to App Key text box
  • Add the Dropbox Secret value to App Secret text box
  • Click on Oauth tab and specify domain, local port, remote port and path values. These values should be same as provided in Redirect URI during Dropbox app configuration. A sample screen shot and XML configuration is as follows.

Dropbox Connector_1

Dropbox Connector_2

<dropbox:config name="DropboxConfig" appKey="${DropboxAppkey}"
appSecret="${DropboxAppSecret}" doc:name="Dropbox">
<dropbox:oauth-callback-config domain="localhost"
localPort="2200" remotePort="2200" path="afterauthorize" />
</dropbox:config>

Mule Flow for Dropbox Authentication

  • Configure a flow as shown in the below picture
<flow name="dropboxflow" doc:name="dropboxflow">
<http:inbound-endpoint exchange-pattern="request-response"
host="localhost" port="2222" path="dropboxcloudconnect" doc:name="HTTP"/>
<dropbox:authorize config-ref="DropboxConfig"
doc:name="AuthorizeDropboxConnection" />
<choice doc:name="IsOAuthAccessTokenIdAvailble">
<when expression="flowVars.OAuthAccessTokenId != null">
<logger message="Authorization is successful" level="INFO"
doc:name="LogAuthSuccessful" />
<set-payload value="Authorization is successful"
doc:name="SetAuthSuccessPayload" />
</when>
<otherwise>
<logger message="Authorization to Dropbox Failed" level="INFO"
doc:name="LogAuthFailed" />
<set-payload value="Authorization to Dropbox Failed"
doc:name="SetAuthFailedPayload" />
</otherwise>
</choice>
</flow>
  • If the app authorizes in to the Dropbox app successfully, the connector returns two flow variables to Mule ESB flow which are “_oauthVerifier” and “OAuthAccessTokenId”
  • Using Choice router, we can check if a flow received is a valid “OAuthAccessTokenId” or not and based on the response, we can determine the success or failure of the Dropbox authorization

Testing and Observation

  • Deploy the Mule application
  • Hit the following URL on the browser
    • http://localhost:2222/dropboxcloudconnect
  • Dropbox will ask us to authorize your new app to connect to Dropbox.
  • Click on Allow button and we should be able to see a message printed on the browser as “Authorization is successful”

If you would like to find out more about how Systems Integration could help you make the most out of your current infrastructure while enabling you to open your digital horizons, do give us a call at +44 (0)203 475 7980 or email us at Salesforce@coforge.com

Other useful links:

Integration with LinkedIn using Mule ESB

Integration of Mule ESB with Microsoft Azure

Integration with Twitter using Mule ESB