Camel Dropbox component
Available as of Camel x2.xx14
The dropbox: component allows you to treat Dropbox remote folders as a producer or consumer of messages. Using the Dropbox Java Core API (reference version for this component is 1.7.x), this camel component has the following features:
...
Code Block |
---|
|
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-dropbox</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
|
URI format
...
Code Block |
---|
dropbox://[operation]?[options]
|
Where operation is the specific action (typically is a CRUD action) to perform on Dropbox remote folder.
...
Operations
Div |
---|
class | confluenceTableSmall |
---|
|
Operation | Description |
---|
del
| deletes files or directories on Dropbox | get
| download files from Dropbox | move
| move files from folders on Dropbox | put
| upload files on Dropbox | search
| search files on Dropbox based on string queries |
|
Wiki Markup |
---|
{div:class=confluenceTableSmall}
|| Operation || Description ||
| {{del}} | deletes files or directories on Dropbox|
| {{get}} | download files from Dropbox |
| {{move}} | move files from folders on Dropbox |
| {{put}} | upload files on Dropbox |
| {{search}} | search files on Dropbox based on string queries |
{div} |
Operations require additional options to work, some are mandatory for the specific operation.
...
In order to work with Dropbox API you need to obtain an accessToken and a clientIdentifier.
You can refer to the Dropbox documentation that expalins how to get them them.
Below are listed the mandatory options for all operations:
Wiki Markup |
---|
{div:class=confluenceTableSmall}
|| Property || Mandatory || Description ||
| {{accessToken}} | {{true}} | The access token to make API requests for a specific Dropbox user |
| {{clientIdentifier}} | {{true}} | Name of the app registered to make API requests |
{div} |
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Mandatory | Description |
---|
accessToken
| true
| The access token to make API requests for a specific Dropbox user | clientIdentifier
| true
| Name of the app registered to make API requests |
|
Del operation
Delete files on Dropbox.
Works only as Camel producer.
Below are listed the options for this operation:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Mandatory | Description |
---|
remotePath
| true
| Folder or file to delete on Dropbox |
|
Samples
from("direct:start").to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1").to("mock:result");
from("direct:start").to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1/file1.tar.gz").to("mock:result");
The following headers are set on exchanges during message transport.
Wiki Markup |
---|
{div:class=confluenceTableSmall}
|| Property || Value ||
| {{CouchDbDatabase}} | the database the message came from |
| {{CouchDbSeq}} | the couchdb changeset sequence number of the update / delete message |
| {{CouchDbId}} | the couchdb document id |
| {{CouchDbRev}} | the couchdb document revision |
| {{CouchDbMethod}} | the method (delete / update) |
{div} |
Headers are set by the consumer once the message is received. The producer will also set the headers for downstream processors once the insert/update has taken place. Any headers set prior to the producer are ignored. That means for example, if you set CouchDbId as a header, it will not be used as the id for insertion, the id of the document will still be used.
Message Body
The component will use the message body as the document to be inserted. If the body is an instance of String, then it will be marshalled into a GSON object before insert. This means that the string must be valid JSON or the insert / update will fail. If the body is an instance of a com.google.gson.JsonElement then it will be inserted as is. Otherwise the producer will throw an exception of unsupported body type.
Samples
For example if you wish to consume all inserts, updates and deletes from a CouchDB instance running locally, on port 9999 then you could use the following:
Code Block |
---|
from("couchdb:http://localhost:9999").process(someProcessor);
|
If you were only interested in deletes, then you could use the following
Code Block |
---|
from("couchdb:http://localhost:9999?updates=false").process(someProcessor);
|
If you wanted to insert a message as a document, then the body of the exchange is used
result:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Value |
---|
DELETED_PATH
| name of the path deleted on dropbox |
|
Result Message Body
The following objects are set on message body result:
Div |
---|
class | confluenceTableSmall |
---|
|
Object type | Description |
---|
String
| name of the path deleted on dropbox |
|
Get (download) operation
Download files from Dropbox.
Works as Camel producer or Camel consumer.
Below are listed the options for this operation:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Mandatory | Description |
---|
remotePath
| true
| Folder or file to download from Dropbox |
|
Samples
from("direct:start").to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1/file1.tar.gz").to("file:///home/kermit/?fileName=file1.tar.gz");
from("direct:start").to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1").to("mock:result");
from("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1").to("file:///home/kermit/");
The following headers are set on message result:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Value |
---|
DOWNLOADED_FILE
| in case of single file download, path of the remote file downloaded | DOWNLOADED_FILES
| in case of multiple files download, path of the remote files downloaded |
|
Result Message Body
The following objects are set on message body result:
Div |
---|
class | confluenceTableSmall |
---|
|
Object type | Description |
---|
ByteArrayOutputStream
| in case of single file download, stream representing the file downloaded | Map<String, ByteArrayOutputStream>
| in case of multiple files download, a map with as key the path of the remote file downloaded and as value the stream representing the file downloaded |
|
Move operation
Move files on Dropbox between one folder to another.
Works only as Camel producer.
Below are listed the options for this operation:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Mandatory | Description |
---|
remotePath
| true
| Original file or folder to move | newRemotePath
| true
| Destination file or folder |
|
Samples
from("direct:start").to("dropbox://move?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1&newRemotePath=/root/folder2").to("mock:result");
The following headers are set on message result:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Value |
---|
MOVED_PATH
| name of the path moved on dropbox |
|
Result Message Body
The following objects are set on message body result:
Div |
---|
class | confluenceTableSmall |
---|
|
Object type | Description |
---|
String
| name of the path moved on dropbox |
|
Put (upload) operation
Upload files on Dropbox.
Works as Camel producer.
Below are listed the options for this operation:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Mandatory | Description |
---|
uploadMode
| true
| add or force this option specifies how a file should be saved on dropbox: in case of "add" the new file will be renamed if a file with the same name already exists on dropbox. in case of "force" if a file with the same name already exists on dropbox, this will be overwritten. | localPath
| true
| Folder or file to upload on Dropbox from the local filesystem . | remotePath
| false
| Folder destination on Dropbox. If the property is not set, the component will upload the file on a remote path equal to the local path. Note: You can only omit remotePath if you are under Linux/Unix and only is localPath is absolute. With Windows or without an absolute localPath you may run into an exception like the following: "Caused by: java.lang.IllegalArgumentException: 'path': bad path: must start with "/": "C:/My/File" OR "Caused by: java.lang.IllegalArgumentException: 'path': bad path: must start with "/": "MyFile"" |
|
Samples
from("direct:start").to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&localPath=/root/folder1").to("mock:result");
from("direct:start").to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&localPath=/root/folder1&remotePath=/root/folder2").to("mock:result");
The following headers are set on message result:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Value |
---|
UPLOADED_FILE
| in case of single file upload, path of the remote path uploaded | UPLOADED_FILES
| in case of multiple files upload, string with the remote paths uploaded |
|
Result Message Body
The following objects are set on message body result:
Div |
---|
class | confluenceTableSmall |
---|
|
Object type | Description |
---|
String
| in case of single file upload, result of the upload operation, OK or KO | Map<String, DropboxResultCode>
| in case of multiple files upload, a map with as key the path of the remote file uploaded and as value the result of the upload operation, OK or KO |
|
Search operation
Search inside a remote Dropbox folder including its sub directories.
Works as Camel producer and as Camel consumer.
Below are listed the options for this operation:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Mandatory | Description |
---|
remotePath
| true
| Folder on Dropbox where to search in. | query
| false
| A space-separated list of substrings to search for. A file matches only if it contains all the substrings. If this option is not set, all files will be matched. |
|
Samples
from("dropbox://search?accessToken=XXX&clientIdentifier=XXX&remotePath=/XXX&query=XXX").to("mock:result");
from("direct:start").to("dropbox://search?accessToken=XXX&clientIdentifier=XXX&remotePath=/XXX").to("mock:result");
The following headers are set on message result:
Div |
---|
class | confluenceTableSmall |
---|
|
Property | Value |
---|
FOUNDED_FILES
| list of file path founded |
|
Result Message Body
The following objects are set on message body result:
Div |
---|
class | confluenceTableSmall |
---|
|
|
Code Block |
---|
from("someProducingEndpoint").process(someProcessor).to("couchdb:http://localhost:9999")
|