Sunday 4 October 2015

Mule Connector

Mule Connector

This tutorial explains about the Dropbox Connector functionality in Mule.
Operations performed in this flow:
  1. Authorize
  2. Get Account Details
  3. Create a Folder in Dropbox
  4. Unauthorized

Pre-requisites:
  1. Anypoint Studio  5.1 with Dropbox plugin
  2. Dropbox developer account
  3. Jdk 1.7

Create an app in Dropbox developer site https://www.dropbox.com/developers/. Copy the App Secret and App key and provide the oauth2 redirect URL. These details are required for Dropbox connector configuration.


Dropbox Connector Configuration:



Dropbox Flow:
This flow will connect to Dropbox and fetches the account details and then creates a folder with name “MuleFolder” and then unauthorize.
Source code :
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"xmlns:dropbox="http://www.mulesoft.org/schema/mule/dropbox" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"xmlns:http="http://www.mulesoft.org/schema/mule/http"xmlns:facebook="http://www.mulesoft.org/schema/mule/facebook"xmlns="http://www.mulesoft.org/schema/mule/core"xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="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
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/facebook http://www.mulesoft.org/schema/mule/facebook/current/mule-facebook.xsd
http://www.mulesoft.org/schema/mule/dropbox http://www.mulesoft.org/schema/mule/dropbox/current/mule-dropbox.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
   <dropbox:config name="Dropbox" appKey="appkey" appSecret="appsecret"doc:name="Dropbox">
       <dropbox:oauth-callback-config domain="localhost" localPort="8080"remotePort="8080" path="dropbox" />
   </dropbox:config>
   <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0"port="8081" doc:name="HTTP Listener Configuration"/>
   <flow name="DropboxConnectorFlow">
       <http:listener config-ref="HTTP_Listener_Configuration" path="/dropbox"doc:name="HTTP"/>
       <dropbox:authorize config-ref="Dropbox" doc:name="Authorize Dropbox"/>
       <logger message="Login Succefull #[message]" level="INFO" doc:name="Logger"/>
       <dropbox:get-account config-ref="Dropbox" doc:name="get Dropbox Account Details"/>
       <json:object-to-json-transformer doc:name="Convert Result Object to JSON"/>
       <logger message="#[payload.toString()]" level="INFO" doc:name="Logger"/>
       <dropbox:create-folder config-ref="Dropbox" path="MuleFolder"doc:name="Create a folder in Dropbox"/>
       <json:object-to-json-transformer doc:name="Conver the Result Object to JSON"/>
       <logger message="Created Folder in DropBox : #[payload]" level="INFO"doc:name="Logger"/>
       <dropbox:unauthorize config-ref="Dropbox" doc:name="Unauthorize Dropbox"/>
   </flow>
</mule>