Integration with dropbox using mule esb

14
Integration with Dropbox using Mule ESB

Transcript of Integration with dropbox using mule esb

Page 1: Integration with dropbox using mule esb

Integration with Dropbox using Mule ESB

Page 2: Integration with dropbox using mule esb

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.

Overview

Page 3: Integration with dropbox using mule esb

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

Versions and Assumptions

Page 4: Integration with dropbox using mule esb

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.

Configuring Dropbox

Page 6: Integration with dropbox using mule esb

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:

Configuring Global properties in Mule

Page 7: Integration with dropbox using mule esb

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

mule-app.propertiesDropboxAppkey=**********DropboxAppSecret=*********

Page 8: Integration with dropbox using mule esb

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.

Configuring Dropbox Connector

Page 10: Integration with dropbox using mule esb

<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>

Page 12: Integration with dropbox using mule esb

<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>

Page 13: Integration with dropbox using mule esb

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

Page 14: Integration with dropbox using mule esb

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”

Testing and Observation