Dropbox
Since Camel 2.14
Both producer and consumer are supported
The Dropbox component allows you to treat Dropbox remote folders as a producer or consumer of messages. Using the Dropbox Java Core API, this camel component has the following features:
-
As a consumer, download files and search files by queries
-
As a producer, download files, move files between remote directories, delete files/dir, upload files and search files by queries
To work with Dropbox API, you need to obtain an accessToken, expireIn, refreshToken, apiKey, apiSecret and a clientIdentifier.
You can refer to the Dropbox documentation that explains how to get them.
Maven users will need to add the following dependency to their pom.xml for this component:
<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
dropbox://[operation]?[options]
Where operation is the specific action (typically is a CRUD action) to perform on Dropbox remote folder.
Operations
| Operation | Description |
|---|---|
| deletes files or directories on Dropbox |
| download files from Dropbox |
| move files from folders on Dropbox |
| upload files on Dropbox |
| search files on Dropbox based on string queries |
Operations require additional options to work. Some are mandatory for the specific operation.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Dropbox component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The Dropbox endpoint is configured using URI syntax:
dropbox:operation
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The operation to perform: put uploads, get downloads, del deletes, move moves and search searches files and folders on Dropbox. The consumer supports only get and search, and runs it at each poll. Enum values:
| DropboxOperation |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The client identifier that the Dropbox SDK sends as the HTTP User-Agent header of each request (DbxRequestConfig), typically the name and version of the app such as MyApp/1.0. When not set, the value of the clientIdentifier key of the dropbox.properties file on the classpath is used. | String | ||
The text to search for with the search operation, the query of the Dropbox search (files/search_v2), at most 1000 characters. Required by search: without a query the search fails. The CamelDropboxQuery header overrides it for the producer. | String | ||
The path on Dropbox, starting with /. put: where to upload to, by default the localPath; when the path does not exist yet and ends with /, the name of the local file is appended (for the message body the CamelDropboxPutFileName or CamelFileName header, else the message id). get: the file to download, or the folder whose files are downloaded (only the files directly in it: the download fails when the folder has a subfolder). del: the file or folder to delete, a folder with all its content. move: the file or folder to move. search: the folder to search in, with its subfolders. The CamelDropboxRemotePath header overrides it for the producer. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A file or folder on the local file system that the put operation uploads to Dropbox; it must exist. A folder is uploaded with all the files in it and in its subfolders. When neither this option nor the CamelDropboxLocalPath header is set, put uploads the message body instead. When remotePath is not set, this path is the Dropbox path as well, so it must then be an absolute path with / as separator. The component only reads local files, it never writes them. | String | ||
The path on Dropbox, starting with /, that the move operation moves the file or folder of remotePath to. Dropbox does not overwrite an existing file or folder at this path. The CamelDropboxNewRemotePath header overrides it. | String | ||
How the put operation treats a file that already exists on Dropbox: force overwrites it (WriteMode.OVERWRITE); add (WriteMode.ADD, without autorename) never overwrites it: an upload from localPath fails when the remote path exists, and for the message body Dropbox rejects the upload and the result is KO. Required by put; the CamelDropboxUploadMode header overrides it. Enum values:
| DropboxUploadMode | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
An existing Dropbox client (DbxClientV2) to use. The endpoint then does not create its own client from the token, app and clientIdentifier options, although these options must still be set. | DbxClientV2 | ||
Required The OAuth 2 access token of the Dropbox user, which the Dropbox SDK sends with each API request. Dropbox access tokens are short-lived: the SDK gets a new one with refreshToken, apiKey and apiSecret when it expires (see expireIn). | String | ||
Required The app key of the Dropbox app (from the Dropbox App Console), which the Dropbox SDK uses with apiSecret and refreshToken to refresh the access token. | String | ||
Required The app secret of the Dropbox app (from the Dropbox App Console), which the Dropbox SDK uses with apiKey and refreshToken to refresh the access token. | String | ||
Required The time at which accessToken expires, in milliseconds since the epoch (1970-01-01 UTC), not a duration: it is the expiresAt of the Dropbox SDK DbxCredential. Before a request the SDK refreshes the access token when it expires in less than 5 minutes, so a time in the past (such as 1000) makes it refresh the token before the first request. Must be greater than 0. | Long | ||
Required The OAuth 2 refresh token of the Dropbox user, which the Dropbox SDK uses with apiKey and apiSecret to get a new access token when accessToken expires. | String |
Message Headers
The Dropbox component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The path on Dropbox, starting with /, to use instead of the remotePath option. | String | |
CamelDropboxNewRemotePath (move) Constant: | The path on Dropbox to move to, used instead of the newRemotePath option. | String | |
| Constant: | The file or folder on the local file system to upload, used instead of the localPath option. | String | |
| Constant: | The upload mode, add or force, used instead of the uploadMode option. | String | |
| Constant: | The text to search for, used instead of the query option. | String | |
| Constant: | The file name that put appends to a remote path that ends with / and does not exist yet, when it uploads the message body. When not set, the CamelFileName header is used, else the message id. | String | |
| Constant: | The Dropbox path of the downloaded file, when get returns exactly one file (the body is then its content). | String | |
| Constant: | The Dropbox paths of the downloaded files, one per line, when get returns no file or more than one file (the body is then a Map of path to content). | String | |
| Constant: | The Dropbox path of the uploaded file, when put uploads exactly one file (the body is then its result, OK or KO). | String | |
| Constant: | The Dropbox paths of the uploaded files, one per line, when put uploads a folder with more than one file (the body is then a Map of path to result). | String | |
| Constant: | The files and folders found, one per line as the name, a dash and the Dropbox path. | String | |
| Constant: | The Dropbox path that was deleted. | String | |
| Constant: | The Dropbox path that was moved from; the body holds the new path. | String |
Message Body
The message body at each side of the Dropbox component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| One message per poll. get: the content of the file in remotePath as a stream cache (a byte array when stream caching is off), or for a folder a Map of the path to the content of each file. search: a List of SearchMatchV2.
|
Producer input |
| Only put reads the body, unless localPath or the CamelDropboxLocalPath header names a local file or folder to upload: the content to upload, as text, bytes, a stream or a file. A Map or a List is not uploaded, and the result is KO without an error: marshal it first. |
Producer output |
| put: OK or KO, a DropboxResultCode, or for a local folder of several files a Map of each remote path to its result. get: the content of the file as a stream cache (a byte array when stream caching is off), or a Map of the path to the content of each file of a folder. del: the path deleted. move: the new path. search: a List of SearchMatchV2.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Del operation
Delete files on Dropbox.
Works only as a Camel producer.
Below are listed the options for this operation:
| Property | Mandatory | Description |
|---|---|---|
|
| Folder or file to delete on Dropbox |
-
Java
-
XML
-
YAML
from("direct:start")
.to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1")
.to("mock:result"); <route>
<from uri="direct:start"/>
<to uri="dropbox://del?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: dropbox://del
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /root/folder1
- to:
uri: mock:result -
Java
-
XML
-
YAML
from("direct:start")
.to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1/file1.tar.gz")
.to("mock:result"); <route>
<from uri="direct:start"/>
<to uri="dropbox://del?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1/file1.tar.gz"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: dropbox://del
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /root/folder1/file1.tar.gz
- to:
uri: mock:result Get (download) operation
Download files from Dropbox.
Works as a Camel producer or Camel consumer.
Below are listed the options for this operation:
| Property | Mandatory | Description |
|---|---|---|
|
| Folder or file to download from Dropbox |
-
Java
-
XML
-
YAML
from("direct:start")
.to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1/file1.tar.gz")
.to("file:///home/kermit/?fileName=file1.tar.gz"); <route>
<from uri="direct:start"/>
<to uri="dropbox://get?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1/file1.tar.gz"/>
<to uri="file:///home/kermit/?fileName=file1.tar.gz"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: dropbox://get
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /root/folder1/file1.tar.gz
- to:
uri: "file:///home/kermit/?fileName=file1.tar.gz" -
Java
-
XML
-
YAML
from("direct:start")
.to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1")
.to("mock:result"); <route>
<from uri="direct:start"/>
<to uri="dropbox://get?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: dropbox://get
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /root/folder1
- to:
uri: mock:result -
Java
-
XML
-
YAML
from("dropbox://get?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1")
.to("file:///home/kermit/"); <route>
<from uri="dropbox://get?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1"/>
<to uri="file:///home/kermit/"/>
</route> - route:
from:
uri: dropbox://get
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /root/folder1
steps:
- to:
uri: "file:///home/kermit/" Result Message Body
The following objects are set on message body result:
| Object type | Description |
|---|---|
| in case of single file download, stream represents the file downloaded |
| in the case of multiple files downloaded, a map with as a 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 a Camel producer.
Below are listed the options for this operation:
| Property | Mandatory | Description |
|---|---|---|
|
| Original file or folder to move |
|
| Destination file or folder |
-
Java
-
XML
-
YAML
from("direct:start")
.to("dropbox://move?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1&newRemotePath=/root/folder2")
.to("mock:result"); <route>
<from uri="direct:start"/>
<to uri="dropbox://move?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/root/folder1&newRemotePath=/root/folder2"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: dropbox://move
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /root/folder1
newRemotePath: /root/folder2
- to:
uri: mock:result Put (upload) operation
Upload files on Dropbox.
Works as a Camel producer.
Below are listed the options for this operation:
| Property | Mandatory | Description |
|---|---|---|
|
| add or force this option specifies how a file should be saved on dropbox: in the case of |
|
| Folder or file to upload on Dropbox from the local filesystem. If this option has been configured, then it takes precedence over uploading as a single file with content from the Camel message body (the message body is converted into a byte array). |
|
| 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. 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" |
-
Java
-
XML
-
YAML
from("direct:start")
.to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&uploadMode=add&localPath=/root/folder1")
.to("mock:result"); <route>
<from uri="direct:start"/>
<to uri="dropbox://put?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&uploadMode=add&localPath=/root/folder1"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: dropbox://put
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
uploadMode: add
localPath: /root/folder1
- to:
uri: mock:result -
Java
-
XML
-
YAML
from("direct:start")
.to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&uploadMode=add&localPath=/root/folder1&remotePath=/root/folder2")
.to("mock:result"); <route>
<from uri="direct:start"/>
<to uri="dropbox://put?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&uploadMode=add&localPath=/root/folder1&remotePath=/root/folder2"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: dropbox://put
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
uploadMode: add
localPath: /root/folder1
remotePath: /root/folder2
- to:
uri: mock:result And to upload a single file with content from the message body
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelDropboxPutFileName", constant("myfile.txt"))
.to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&uploadMode=add&remotePath=/root/folder2")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelDropboxPutFileName">
<constant>myfile.txt</constant>
</setHeader>
<to uri="dropbox://put?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&uploadMode=add&remotePath=/root/folder2"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelDropboxPutFileName
constant: myfile.txt
- to:
uri: dropbox://put
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
uploadMode: add
remotePath: /root/folder2
- to:
uri: mock:result The name of the file can be provided in the header CamelDropboxPutFileName or CamelFileName in that order of precedence. If no header has been provided then the message id (uuid) is used as the file name.
Result Message Body
The following objects are set on message body result:
| Object type | Description |
|---|---|
| in case of single file upload, result of the upload operation, OK or KO |
| in the case of multiple files upload, a map with as a 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 subdirectories.
Works as Camel producer and as Camel consumer.
Below are listed the options for this operation:
| Property | Mandatory | Description |
|---|---|---|
|
| Folder on Dropbox where to search in. |
|
| The text to search for, as the query of the Dropbox search (at most 1000 characters). The query is required to be provided in either the endpoint configuration or as a header |
-
Java
-
XML
-
YAML
from("dropbox://search?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/XXX&query=XXX")
.to("mock:result"); <route>
<from uri="dropbox://search?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/XXX&query=XXX"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: dropbox://search
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /XXX
query: XXX
steps:
- to:
uri: mock:result -
Java
-
XML
-
YAML
from("direct:start")
.setHeader("CamelDropboxQuery", constant("XXX"))
.to("dropbox://search?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/XXX")
.to("mock:result"); <route>
<from uri="direct:start"/>
<setHeader name="CamelDropboxQuery">
<constant>XXX</constant>
</setHeader>
<to uri="dropbox://search?accessToken=XXX&clientIdentifier=XXX&expireIn=1000&refreshToken=XXXX&apiKey=XXXXX&apiSecret=XXXXXX&remotePath=/XXX"/>
<to uri="mock:result"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelDropboxQuery
constant: XXX
- to:
uri: dropbox://search
parameters:
accessToken: XXX
clientIdentifier: XXX
expireIn: 1000
refreshToken: XXXX
apiKey: XXXXX
apiSecret: XXXXXX
remotePath: /XXX
- to:
uri: mock:result Result Message Body
The following objects are set on message body result:
| Object type | Description |
|---|---|
| list of the file path found. For more information on this object, refer to Dropbox documentation. |