| Namespace | http://www.mulesoft.org/schema/mule/dropbox |
|---|---|
| Schema Location | http://www.mulesoft.org/schema/mule/dropbox/current/mule-dropbox.xsd (View Schema) |
| Schema Version | 3.2.2 |
| Minimum Mule Version | 3.2 |
Dropbox Cloud Connector. The Dropbox Connector will allow to use the Dropbox REST API. Almost every operation that can be done via the API can be done thru this connector.
| Configuration | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Configure an instance of this module
| |||||||||||
| Message Processors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Copies a file or folder to a new location.
| |||||||||||
Create new folder on Dropbox
| |||||||||||
Deletes a file or folder.
| |||||||||||
Downloads a file from Dropbox
| |||||||||||
Creates and returns a Dropbox link to files or folders users can use to view a preview of the file in a web browser.
| |||||||||||
Lists the content of the remote directory
| |||||||||||
Moves a file or folder to a new location.
| |||||||||||
Upload file to Dropbox.
| |||||||||||
To use the this module within a flow the namespace to the module must be included. The resulting flow will look similar to the following:
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dropbox="http://www.mulesoft.org/schema/mule/dropbox"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/dropbox
http://www.mulesoft.org/schema/mule/dropbox/current/mule-dropbox.xsd">
<!-- here goes your flows and configuration elements -->
</mule>
This module is configured using the config element. This element must be placed outside of your flows and at the root of your Mule application. You can create as many configurations as you deem necessary as long as each carries its own name.
Each message processor, message source or transformer carries a config-ref attribute that allows the invoker to specify which configuration to use.
| Attributes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Type | Name | Default Value | Description | Java Type | MIME Type | Encoding | Optional. Give a name to this configuration so it can be later referenced. | ||||
| Application key | |||||||||||
| Application secret | |||||||||||
| api-content.dropbox.com | Optional. URL of the Dropbox server content API | ||||||||||
| false | Optional. debug mode | ||||||||||
| 80 | Optional. Dropbox server port | ||||||||||
| api.dropbox.com | Optional. URL of the Dropbox server API | ||||||||||
| https://www.dropbox.com/1/oauth/authorize | Optional. The URL defined by the Service Provider where the resource owner will be redirected to grant authorization to the connector | ||||||||||
| https://api.dropbox.com/1/oauth/access_token | Optional. The URL defined by the Service Provider to obtain an access token | ||||||||||
| https://api.dropbox.com/1/oauth/request_token | Optional. The URL defined by the Service Provider used to obtain an un-authorized request token | ||||||||||
This connector uses OAuth as an authorization and authentication mechanism. All the message processors or sources that require the connector to be authorized by the service provider will throw a NotAuthorizedException until the connector is authorized properly.
Authorizing the connector is a simple process of calling:
<dropbox:authorize/>
The call to authorize message processor must be made from a message coming from an HTTP inbound endpoint as the authorize process will reply with a redirect to the service provider. The following is an example of how to use it in a flow with an HTTP inbound endpoint:
<flow name="authorizationAndAuthenticationFlow">
<http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
<dropbox:authorize/>
</flow>
If you hit that endpoint via a web-browser it will initiate the OAuth dance, redirecting the user to the service provider page and creating a callback endpoint so the service provider can call us back once the user has been authenticated. Once the callback gets called then the connector will switch to an authorized state and any message processor or source that requires authentication can be called.
The authorize message processor supports the following attributes:
| Authorize Attributes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Name | Default Value | Description | |||||||||
| https://www.dropbox.com/1/oauth/authorize | Optional. The URL defined by the Service Provider where the resource owner will be redirected to grant authorization to the connector | ||||||||||
| https://api.dropbox.com/1/oauth/access_token | Optional. The URL defined by the Service Provider to obtain an access token | ||||||||||
| https://api.dropbox.com/1/oauth/request_token | Optional. The URL defined by the Service Provider used to obtain an un-authorized request token | ||||||||||
The authorize message processor is an intercepting one. If the connector is not authorized yet, it will with a redirect to the service provider so the user can authorize the connector. This is the reason as to why the authorize needs to be behind and http:inbound-endpoint. The service provider upon successful authentication and authorization then will call back the connector. The connector will extract information from that call, set its internal state to authorized, and then continue execution. When we say continue execution we mean executing everything that was after the authorize whose execution got interrupted because the connector was not authorized.
<flow name="authorizationAndAuthenticationFlow">
<http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
<dropbox:authorize/>
<http:response-builder status="200">
<set-payload value="You have successfully authorized the connector"/>
</http:response-builder>
</flow>
In the previous example we added the http:response-build (notice that this element is available only in Mule 3.3.0 and later). If the connector is not authorized, the execution of the response builder will be delayed up to the point of the callback execution.
On the other hand if the connector has been authorized and you call authorize again then the flow execution will not stop, it will rather continue and the http:response-builder will get executed right away rather than after the callback.
If for any reason, an errors ocurrs while processing the callback, the exception strategy of the flow containing the authorize will be executed. So, if the callback sent the wrong information you can handle that situation by setting up an exception strategy as follows:
<flow name="authorizationAndAuthenticationFlow">
<http:inbound-endpoint host="localhost" port="8080" path="oauth-authorize"/>
<dropbox:authorize/>
<http:response-builder status="200">
<set-payload value="You have successfully authorized the connector"/>
</http:response-builder>
<catch-exception-strategy>
<http:response-builder status="404">
<set-payload value="An error has occurred authorizing the connector"/>
</http:response-builder>
</catch-exception-strategy>
</flow>
Once this connector has been authorized further calls to the authorize message processor will be no-ops. If you wish to reset the state of the connector back to a non-authorized state you can call:
<dropbox:unauthorize/>
Keep in mind that after the connector is unauthorized all future calls that attempt to access protected resources will fail until the connector is re-authorized.
As mentioned earlier once authorize gets called and before we redirect the user to the service provider we create a callback endpoint. The callback endpoint will get called automatically by the service provider once the user is authenticated and he grants authorization to the connector to access his private information.
The callback can be customized in the config element of the this connector as follows:
<dropbox:config>
<dropbox:oauth-callback-config domain="${fullDomain}" localPort="${http.port}" remotePort="80"/>
</dropbox:config>
The oauth-callback-config element can be used to customize the endpoint that gets created for the callback. It features the following attributes:
| OAuth Callback Config Attributes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Name | Description | ||||||||||
| Optional. Reference to a user-defined HTTP connector. | |||||||||||
| Optional. The domain portion of the callback URL. This is usually something like xxx.cloudhub.io if you are deploying to CloudHub for example. | |||||||||||
| Optional. The local port number that the endpoint will listen on. Normally 80, in the case of CloudHub you can use the environment variable ${http.port}. | |||||||||||
| Optional. This is the port number that we will tell the service provider we are listening on. It is usually the same as localPort but it is separated in case your deployment features port forwarding or a proxy. | |||||||||||
| Optional. Path under which the callback should be exposed. If not specified a random path will be generated. | |||||||||||
The example shown above is what the configuration would look like if your app would be deployed to CloudHub.
Once the service providers hits the callback it will do so in way that state information it is also sent. This state information is later used by the connector on each call made to the service provider to let him know that we have completed the authorization and authentication process.
The state information is currently held in-memory but the connector offers hooks to save/restore this state. The ammount of information that needs to be saved and/or restored varies between version of the OAuth specification. At the bare minimum for OAuth 1.0a that needs to be the OAuth access token and OAuth access token secret.
The following is an example of how to log the access token and access token secret.
<dropbox:config>
<dropbox:oauth-save-access-token>
<logger level="INFO" message="Received access token #[variable:OAuthAccessToken] and #[variable:OAuthAccessTokenSecret]"/>
</dropbox:oauth-save-access-token>
</dropbox:config>
The oauth-save-access-token is a message processor chain and you can add inside of it as many message processors as you want. The chain will be called with special inbound properties in the message which the information that needs saved.
Restoring the information is equally simple:
<dropbox:config>
<dropbox:oauth-restore-access-token>
<message-properties-transformer scope="invocation">
<add-message-property key="OAuthAccessToken" value="123"/>
<add-message-property key="OAuthAccessTokenSecret" value="567"/>
</message-properties-transformer>
</dropbox:oauth-restore-access-token>
</dropbox:config>
The example above does not do anything useful expect hardcode the access token and the token secret to 123 and 567 respectively. Just like oauth-save-access-token, oauth-restore-access-token is another message processor chain. Once the chain is done executing we will extract the OAuth access token property and OAuth access token secret property values.
The following shows a full example on how to save and restore using Mule ObjectStore Module to store the information inside an object store.
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dropbox="http://www.mulesoft.org/schema/mule/dropbox"
xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/objectstore
http://www.mulesoft.org/schema/mule/objectstore/1.0/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/dropbox
http://www.mulesoft.org/schema/mule/dropbox/current/mule-dropbox.xsd">
<dropbox:config>
<dropbox:oauth-save-access-token>
<objectstore:store key="OAuthAccessToken" value-ref="#[variable:OAuthAccessToken]"/>
<objectstore:store key="OAuthAccessTokenSecret" value-ref="#[variable:OAuthAccessTokenSecret]"/>
</dropbox:oauth-save-access-token>
<dropbox:oauth-restore-access-token>
<enricher target="#[header:OAuthAccessToken]">
<objectstore:retrieve key="OAuthAccessToken"/>
</enricher>
<enricher target="#[header:OAuthAccessTokenSecret]">
<objectstore:retrieve key="OAuthAccessTokenSecret"/>
</enricher>
</dropbox:oauth-restore-access-token>
</dropbox:config>
</mule>
Copies a file or folder to a new location.
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| Specifies the file or folder to be copied from, relative to root. | String | */* | UTF-8 | ||
| Specifies the destination path, including the new name for the file or folder, relative to root. | String | */* | UTF-8 |
| Return Type | Description |
|---|---|
| String | http response |
| Payload Class | Description |
|---|---|
| Exception | exception |
Create new folder on Dropbox
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| Full path of the folder to be created | String | */* | UTF-8 |
| Return Type | Description |
|---|---|
| String | http response |
| Payload Class | Description |
|---|---|
| Exception | exception |
Deletes a file or folder.
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| Full path to the file to be deleted | String | */* | UTF-8 |
| Return Type | Description |
|---|---|
| String | http response |
| Payload Class | Description |
|---|---|
| Exception | exception |
Downloads a file from Dropbox
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| Path to the file | String | */* | UTF-8 | ||
| false | Optional. Delete the file on the Dropbox after download (ignored if moveTo is set) | boolean | */* |
| Return Type | Description |
|---|---|
| InputStream | Stream containing the downloaded file data |
| Payload Class | Description |
|---|---|
| Exception | exception |
Creates and returns a Dropbox link to files or folders users can use to view a preview of the file in a web browser.
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| The path to the file or folder you want to link to. | String | */* | UTF-8 | ||
| true | Optional. Boolean indicating if the url returned will be shortened using the Dropbox url shortener (when true) or will link directly to the file's preview page (when false). | Boolean | */* |
| Return Type | Description |
|---|---|
| String | String. A Dropbox link to the given path. |
| Payload Class | Description |
|---|---|
| Exception | exception |
Lists the content of the remote directory
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| Path to the remote directory | String | */* | UTF-8 |
| Return Type | Description |
|---|---|
| List<String> | List of files and/or folders |
| Payload Class | Description |
|---|---|
| Exception | exception |
Moves a file or folder to a new location.
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| Specifies the file or folder to be moved from, relative to root. | String | */* | UTF-8 | ||
| Specifies the destination path, including the new name for the file or folder, relative to root. | String | */* | UTF-8 |
| Return Type | Description |
|---|---|
| String | http response |
| Payload Class | Description |
|---|---|
| Exception | exception |
Upload file to Dropbox. The payload is an InputStream containing bytes of the data to be uploaded.
INCLUDE_ERROR
| Name | Default Value | Description | Java Type | MIME Type | Encoding |
|---|---|---|---|---|---|
| Optional. Specify which configuration to use. | |||||
| File to be uploaded | InputStream | */* | |||
| true | Optional. Overwrite file in case it already exists | Boolean | */* | ||
| The destination path | String | */* | UTF-8 | ||
| The destination file name | String | */* | UTF-8 |
| Return Type | Description |
|---|---|
| String | http response |
| Payload Class | Description |
|---|---|
| Exception | exception |