You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2014/04/11 11:00:11 UTC
[2/2] git commit: DropBox component initial commit. Great thanks to
Giovanni for the contribution.
DropBox component initial commit. Great thanks to Giovanni for the contribution.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/037f3f09
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/037f3f09
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/037f3f09
Branch: refs/heads/master
Commit: 037f3f091f8de0f043e02a19f0131032821fe3c1
Parents: 82c7edc
Author: Henryk Konsek <he...@gmail.com>
Authored: Fri Apr 11 10:59:36 2014 +0200
Committer: Henryk Konsek <he...@gmail.com>
Committed: Fri Apr 11 10:59:36 2014 +0200
----------------------------------------------------------------------
components/camel-dropbox/pom.xml | 118 +++++++
.../component/dropbox/DropboxComponent.java | 73 +++++
.../component/dropbox/DropboxConfiguration.java | 140 +++++++++
.../component/dropbox/DropboxEndpoint.java | 105 +++++++
.../dropbox/core/DropboxAPIFacade.java | 314 +++++++++++++++++++
.../component/dropbox/dto/DropboxDelResult.java | 39 +++
.../dropbox/dto/DropboxFileDownloadResult.java | 59 ++++
.../dropbox/dto/DropboxFileUploadResult.java | 59 ++++
.../dropbox/dto/DropboxMoveResult.java | 40 +++
.../component/dropbox/dto/DropboxResult.java | 40 +++
.../dropbox/dto/DropboxSearchResult.java | 51 +++
.../consumer/DropboxScheduledPollConsumer.java | 72 +++++
.../DropboxScheduledPollGetConsumer.java | 56 ++++
.../DropboxScheduledPollSearchConsumer.java | 56 ++++
.../producer/DropboxDelProducer.java | 43 +++
.../producer/DropboxGetProducer.java | 43 +++
.../producer/DropboxMoveProducer.java | 42 +++
.../integration/producer/DropboxProducer.java | 59 ++++
.../producer/DropboxPutProducer.java | 43 +++
.../producer/DropboxSearchProducer.java | 41 +++
.../dropbox/util/DropboxConstants.java | 26 ++
.../dropbox/util/DropboxException.java | 23 ++
.../dropbox/util/DropboxOperation.java | 38 +++
.../dropbox/util/DropboxPropertyManager.java | 62 ++++
.../dropbox/util/DropboxResultCode.java | 22 ++
.../dropbox/util/DropboxResultHeader.java | 22 ++
.../dropbox/util/DropboxUploadMode.java | 35 +++
.../DropboxConfigurationValidator.java | 126 ++++++++
.../Dropbox_API_Terms_and_Conditions.txt | 2 +
.../src/main/resources/META-INF/LICENSE.txt | 203 ++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../services/org/apache/camel/component/dropbox | 18 ++
.../src/main/resources/dropbox.properties | 19 ++
.../src/main/resources/features.xml | 27 ++
.../src/main/resources/log4j.properties | 16 +
.../dropbox/integration/DropboxTestSupport.java | 55 ++++
.../consumer/DropboxConsumerGetSingleTest.java | 58 ++++
.../DropboxConsumerSearchQueryTest.java | 57 ++++
.../consumer/DropboxConsumerSearchTest.java | 57 ++++
.../producer/DropboxProducerDelTest.java | 66 ++++
.../producer/DropboxProducerGetFolderTest.java | 68 ++++
.../producer/DropboxProducerGetSingleTest.java | 67 ++++
.../producer/DropboxProducerMoveTest.java | 66 ++++
.../DropboxProducerPutSingleFileTest.java | 66 ++++
...ProducerPutSingleFileWithRemotePathTest.java | 66 ++++
.../DropboxProducerPutWithRemotePathTest.java | 67 ++++
.../DropboxProducerSearchQueryTest.java | 67 ++++
.../producer/DropboxProducerSearchTest.java | 67 ++++
.../src/test/resources/test-options.properties | 19 ++
components/pom.xml | 1 +
50 files changed, 2990 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/pom.xml b/components/camel-dropbox/pom.xml
new file mode 100755
index 0000000..7a75966
--- /dev/null
+++ b/components/camel-dropbox/pom.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.13-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-dropbox</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Dropbox</name>
+ <description>Camel Dropbox support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.dropbox.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=dropbox</camel.osgi.export.service>
+ </properties>
+
+ <profiles>
+ <profile>
+ <id>no-integration-test</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>
+ **/integration/**
+ </exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
+ <!-- dropbox -->
+ <dependency>
+ <groupId>com.dropbox.core</groupId>
+ <artifactId>dropbox-core-sdk</artifactId>
+ <version>[1.7,1.8)</version>
+ </dependency>
+
+ <!-- apache commons-io -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>${mockito-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <!-- Allows the routes to be run via 'mvn camel:run' -->
+ <plugin>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxComponent.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxComponent.java
new file mode 100755
index 0000000..d445f76
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxComponent.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.dropbox.util.DropboxOperation;
+import org.apache.camel.component.dropbox.util.DropboxPropertyManager;
+import org.apache.camel.component.dropbox.util.DropboxUploadMode;
+import org.apache.camel.component.dropbox.validator.DropboxConfigurationValidator;
+import org.apache.camel.impl.DefaultComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropboxComponent extends DefaultComponent {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxComponent.class);
+
+ /**
+ * Create a camel endpoint after passing validation on the incoming url.
+ * @param uri the full URI of the endpoint
+ * @param remaining the remaining part of the URI without the query
+ * parameters or component prefix
+ * @param parameters the optional parameters passed in
+ * @return the camel endpoint
+ * @throws Exception
+ */
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ DropboxConfiguration configuration = new DropboxConfiguration();
+
+ // set options from component
+ configuration.setAccessToken((String)parameters.get("accessToken"));
+ configuration.setLocalPath((String)parameters.get("localPath"));
+ configuration.setRemotePath((String)parameters.get("remotePath"));
+ configuration.setNewRemotePath((String)parameters.get("newRemotePath"));
+ configuration.setQuery((String)parameters.get("query"));
+ configuration.setOperation(DropboxOperation.valueOf(remaining));
+ configuration.setClientIdentifier(
+ parameters.get("clientIdentifier") == null
+ ? DropboxPropertyManager.getInstance().getProperty("clientIdentifier")
+ : (String) parameters.get("clientIdentifier"));
+ if (parameters.get("uploadMode") != null) {
+ configuration.setUploadMode(DropboxUploadMode.valueOf((String)parameters.get("uploadMode")));
+ }
+
+ //pass validation test
+ DropboxConfigurationValidator.validate(configuration);
+
+ // and then override from parameters
+ setProperties(configuration, parameters);
+
+ LOG.info("dropbox configuration set!");
+
+ Endpoint endpoint = new DropboxEndpoint(uri, this, configuration);
+ return endpoint;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxConfiguration.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxConfiguration.java
new file mode 100755
index 0000000..be6fe8b
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxConfiguration.java
@@ -0,0 +1,140 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox;
+
+import java.util.Locale;
+
+import com.dropbox.core.DbxClient;
+import com.dropbox.core.DbxRequestConfig;
+import org.apache.camel.component.dropbox.util.DropboxException;
+import org.apache.camel.component.dropbox.util.DropboxOperation;
+import org.apache.camel.component.dropbox.util.DropboxUploadMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DropboxConfiguration {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxConfiguration.class);
+
+ //dropbox auth options
+ private String accessToken;
+ //local path to put files
+ private String localPath;
+ //where to put files on dropbox
+ private String remotePath;
+ //new path on dropbox when moving files
+ private String newRemotePath;
+ //search query on dropbox
+ private String query;
+ //in case of uploading if force or add existing file
+ private DropboxUploadMode uploadMode;
+ //id of the app
+ private String clientIdentifier;
+ //specific dropbox operation for the component
+ private DropboxOperation operation;
+ //reference to dropboxclient
+ private DbxClient client;
+
+ public void setClient(DbxClient client) {
+ this.client = client;
+ }
+
+ public DbxClient getClient() {
+ return client;
+ }
+
+ /**
+ * Obtain a new instance of DbxClient and store it in configuration.
+ * @throws DropboxException
+ */
+ public void createClient() throws DropboxException {
+ DbxRequestConfig config =
+ new DbxRequestConfig(clientIdentifier, Locale.getDefault().toString());
+ DbxClient client = new DbxClient(config, accessToken);
+ if (client == null) {
+ throw new DropboxException("can't establish a Dropbox conenction!");
+ }
+ this.client = client;
+
+ }
+
+ public String getAccessToken() {
+ return accessToken;
+ }
+
+ public void setAccessToken(String accessToken) {
+ this.accessToken = accessToken;
+ }
+
+ public String getLocalPath() {
+ return localPath;
+ }
+
+ public void setLocalPath(String localPath) {
+ this.localPath = localPath;
+ }
+
+ public String getRemotePath() {
+ return remotePath;
+ }
+
+ public void setRemotePath(String remotePath) {
+ this.remotePath = remotePath;
+ }
+
+ public String getNewRemotePath() {
+ return newRemotePath;
+ }
+
+ public void setNewRemotePath(String newRemotePath) {
+ this.newRemotePath = newRemotePath;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public void setQuery(String query) {
+ this.query = query;
+ }
+
+ public String getClientIdentifier() {
+ return clientIdentifier;
+ }
+
+ public void setClientIdentifier(String clientIdentifier) {
+ this.clientIdentifier = clientIdentifier;
+ }
+
+ public DropboxOperation getOperation() {
+ return operation;
+ }
+
+ public void setOperation(DropboxOperation operation) {
+ this.operation = operation;
+ }
+
+ public DropboxUploadMode getUploadMode() {
+ return uploadMode;
+ }
+
+ public void setUploadMode(DropboxUploadMode uploadMode) {
+ this.uploadMode = uploadMode;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java
new file mode 100755
index 0000000..5cbb0ed
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.dropbox.integration.consumer.DropboxScheduledPollConsumer;
+import org.apache.camel.component.dropbox.integration.consumer.DropboxScheduledPollGetConsumer;
+import org.apache.camel.component.dropbox.integration.consumer.DropboxScheduledPollSearchConsumer;
+import org.apache.camel.component.dropbox.integration.producer.DropboxDelProducer;
+import org.apache.camel.component.dropbox.integration.producer.DropboxGetProducer;
+import org.apache.camel.component.dropbox.integration.producer.DropboxMoveProducer;
+import org.apache.camel.component.dropbox.integration.producer.DropboxPutProducer;
+import org.apache.camel.component.dropbox.integration.producer.DropboxSearchProducer;
+import org.apache.camel.component.dropbox.util.DropboxException;
+import org.apache.camel.component.dropbox.util.DropboxOperation;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.camel.component.dropbox.util.DropboxConstants.POLL_CONSUMER_DELAY;
+
+public class DropboxEndpoint extends DefaultEndpoint {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxEndpoint.class);
+
+ private DropboxConfiguration configuration;
+
+ public DropboxEndpoint() {
+ }
+
+ public DropboxEndpoint(String uri, DropboxComponent component, DropboxConfiguration configuration) {
+ super(uri, component);
+ this.configuration = configuration;
+ }
+
+ public DropboxEndpoint(String endpointUri) {
+ super(endpointUri);
+ }
+
+ /**
+ * Create one of the camel producer available based on the configuration
+ * @return the camel producer
+ * @throws Exception
+ */
+ public Producer createProducer() throws Exception {
+ LOG.info("resolve producer dropbox endpoint {" + configuration.getOperation().toString() + "}");
+ LOG.info("resolve producer dropbox attached client: " + configuration.getClient());
+ if (configuration.getOperation() == DropboxOperation.put) {
+ return new DropboxPutProducer(this, configuration);
+ } else if (this.configuration.getOperation() == DropboxOperation.search) {
+ return new DropboxSearchProducer(this, configuration);
+ } else if (this.configuration.getOperation() == DropboxOperation.del) {
+ return new DropboxDelProducer(this, configuration);
+ } else if (this.configuration.getOperation() == DropboxOperation.get) {
+ return new DropboxGetProducer(this, configuration);
+ } else if (this.configuration.getOperation() == DropboxOperation.move) {
+ return new DropboxMoveProducer(this, configuration);
+ } else {
+ throw new DropboxException("operation specified is not valid for producer!");
+ }
+ }
+
+ /**
+ * Create one of the camel consumer available based on the configuration
+ * @param processor the given processor
+ * @return the camel consumer
+ * @throws Exception
+ */
+ public Consumer createConsumer(Processor processor) throws Exception {
+ LOG.debug("resolve consumer dropbox endpoint {" + configuration.getOperation().toString() + "}");
+ LOG.debug("resolve consumer dropbox attached client:" + configuration.getClient());
+ DropboxScheduledPollConsumer consumer = null;
+ if (this.configuration.getOperation() == DropboxOperation.search) {
+ consumer = new DropboxScheduledPollSearchConsumer(this, processor, configuration);
+ consumer.setDelay(POLL_CONSUMER_DELAY);
+ return consumer;
+ } else if (this.configuration.getOperation() == DropboxOperation.get) {
+ consumer = new DropboxScheduledPollGetConsumer(this, processor, configuration);
+ consumer.setDelay(POLL_CONSUMER_DELAY);
+ return consumer;
+ } else {
+ throw new DropboxException("operation specified is not valid for consumer!");
+ }
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java
new file mode 100755
index 0000000..aba52f6
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/core/DropboxAPIFacade.java
@@ -0,0 +1,314 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.core;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.dropbox.core.DbxClient;
+import com.dropbox.core.DbxEntry;
+import com.dropbox.core.DbxException;
+import com.dropbox.core.DbxWriteMode;
+import org.apache.camel.component.dropbox.dto.DropboxDelResult;
+import org.apache.camel.component.dropbox.dto.DropboxFileDownloadResult;
+import org.apache.camel.component.dropbox.dto.DropboxFileUploadResult;
+import org.apache.camel.component.dropbox.dto.DropboxMoveResult;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+import org.apache.camel.component.dropbox.dto.DropboxSearchResult;
+import org.apache.camel.component.dropbox.util.DropboxException;
+import org.apache.camel.component.dropbox.util.DropboxResultCode;
+import org.apache.camel.component.dropbox.util.DropboxUploadMode;
+import org.apache.commons.io.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import static org.apache.camel.component.dropbox.util.DropboxConstants.DROPBOX_FILE_SEPARATOR;
+
+
+public final class DropboxAPIFacade {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxAPIFacade.class);
+
+ private static DropboxAPIFacade instance;
+ private static DbxClient client;
+
+ private DropboxAPIFacade() { }
+
+ /**
+ * Return a singleton instance of this class
+ * @param client the DbxClient performing dropbox low level operations
+ * @return the singleton instance of this class
+ */
+ public static DropboxAPIFacade getInstance(DbxClient client) {
+ if (instance == null) {
+ instance = new DropboxAPIFacade();
+ instance.client = client;
+ }
+ return instance;
+ }
+
+ /**
+ * Put or upload a new file or an entire directory to dropbox
+ * @param localPath the file path or the dir path on the local filesystem
+ * @param remotePath the remote path destination on dropbox
+ * @param mode how a file should be saved on dropbox;
+ * in case of "add" the new file will be renamed in case
+ * a file with the same name already exists on dropbox.
+ * in case of "force" the file already existing with the same name will be overridden.
+ * @return a DropboxResult object reporting for each remote path the result of the operation.
+ * @throws DropboxException
+ */
+ public DropboxResult put(String localPath, String remotePath, DropboxUploadMode mode) throws DropboxException {
+ DropboxResult result = new DropboxFileUploadResult();
+ //a map representing for each path the result of the put operation
+ Map<String, DropboxResultCode> resultEntries = null;
+ //in case the remote path is not specified, the remotePath = localPath
+ String dropboxPath = remotePath == null ? localPath : remotePath;
+ DbxEntry entry = null;
+ try {
+ entry = instance.client.getMetadata(dropboxPath);
+ } catch (DbxException e) {
+ throw new DropboxException(dropboxPath + " does not exist or can't obtain metadata");
+ }
+ File fileLocalPath = new File(localPath);
+ //verify uploading of a single file
+ if (fileLocalPath.isFile()) {
+ //check if dropbox file exists
+ if (entry != null && !entry.isFile()) {
+ throw new DropboxException(dropboxPath + " exists on dropbox and is not a file!");
+ }
+ //in case the entry not exists on dropbox check if the filename should be appended
+ if (entry == null) {
+ if (dropboxPath.endsWith(DROPBOX_FILE_SEPARATOR)) {
+ dropboxPath = dropboxPath + fileLocalPath.getName();
+ }
+ }
+ resultEntries = new HashMap<String, DropboxResultCode>(1);
+ try {
+ DbxEntry.File uploadedFile = putSingleFile(fileLocalPath, dropboxPath, mode);
+ if (uploadedFile == null) {
+ resultEntries.put(dropboxPath, DropboxResultCode.KO);
+ } else {
+ resultEntries.put(dropboxPath, DropboxResultCode.OK);
+ }
+
+ } catch (Exception ex) {
+ resultEntries.put(dropboxPath, DropboxResultCode.KO);
+ } finally {
+ result.setResultEntries(resultEntries);
+ }
+ return result;
+ } else { //verify uploading of a list of files inside a dir
+ LOG.info("uploading a dir...");
+ //check if dropbox folder exists
+ if (entry != null && !entry.isFolder()) {
+ throw new DropboxException(dropboxPath + " exists on dropbox and is not a folder!");
+ }
+ if (!dropboxPath.endsWith(DROPBOX_FILE_SEPARATOR)) {
+ dropboxPath = dropboxPath + DROPBOX_FILE_SEPARATOR;
+ }
+ //revert to old path
+ String oldDropboxPath = dropboxPath;
+ //list all files in a dir
+ Collection<File> listFiles = FileUtils.listFiles(fileLocalPath, null, true);
+ if (listFiles == null || listFiles.isEmpty()) {
+ throw new DropboxException(localPath + " doesn't contain any files");
+ }
+ resultEntries = new HashMap<String, DropboxResultCode>(listFiles.size());
+ for (File file : listFiles) {
+ String absPath = file.getAbsolutePath();
+ int indexRemainingPath = localPath.length();
+ if (!localPath.endsWith("/")) {
+ indexRemainingPath += 1;
+ }
+ String remainingPath = absPath.substring(indexRemainingPath);
+ dropboxPath = dropboxPath + remainingPath;
+ try {
+ LOG.info("uploading:" + fileLocalPath + "," + dropboxPath);
+ DbxEntry.File uploadedFile = putSingleFile(file, dropboxPath, mode);
+ if (uploadedFile == null) {
+ resultEntries.put(dropboxPath, DropboxResultCode.KO);
+ } else {
+ resultEntries.put(dropboxPath, DropboxResultCode.OK);
+ }
+ } catch (Exception ex) {
+ resultEntries.put(dropboxPath, DropboxResultCode.KO);
+ }
+ dropboxPath = oldDropboxPath;
+ }
+ result.setResultEntries(resultEntries);
+ return result;
+ }
+ }
+
+ private DbxEntry.File putSingleFile(File inputFile, String dropboxPath, DropboxUploadMode mode) throws Exception {
+ FileInputStream inputStream = new FileInputStream(inputFile);
+ DbxEntry.File uploadedFile = null;
+ try {
+ DbxWriteMode uploadMode = null;
+ if (mode == DropboxUploadMode.force) {
+ uploadMode = DbxWriteMode.force();
+ } else {
+ uploadMode = DbxWriteMode.add();
+ }
+ uploadedFile =
+ instance.client.uploadFile(dropboxPath,
+ uploadMode, inputFile.length(), inputStream);
+ return uploadedFile;
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ /**
+ * Search inside a remote path including its sub directories.
+ * The query param can be null.
+ * @param remotePath the remote path where starting the search from
+ * @param query a space-separated list of substrings to search for. A file matches only if it contains all the substrings
+ * @return a DropboxResult object containing all the files found.
+ * @throws DropboxException
+ */
+ public DropboxResult search(String remotePath, String query) throws DropboxException {
+ DropboxResult result = new DropboxSearchResult();
+ DbxEntry.WithChildren listing = null;
+ if (query == null) {
+ LOG.info("search no query");
+ try {
+ listing = instance.client.getMetadataWithChildren(remotePath);
+ } catch (DbxException e) {
+ throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
+ }
+ result.setResultEntries(listing.children);
+ } else {
+ LOG.info("search by query:" + query);
+ List<DbxEntry> entries = null;
+ try {
+ entries = instance.client.searchFileAndFolderNames(remotePath, query);
+ } catch (DbxException e) {
+ throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
+ }
+ result.setResultEntries(entries);
+ }
+ return result;
+ }
+
+ /**
+ * Delete every files and subdirectories inside the remote directory.
+ * In case the remotePath is a file, delete the file.
+ * @param remotePath the remote location to delete
+ * @return a DropboxResult object with the result of the delete operation.
+ * @throws DropboxException
+ */
+ public DropboxResult del(String remotePath) throws DropboxException {
+ DropboxResult result = null;
+ try {
+ instance.client.delete(remotePath);
+ } catch (DbxException e) {
+ throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
+ }
+ result = new DropboxDelResult();
+ result.setResultEntries(remotePath);
+ return result;
+ }
+
+ /**
+ * Rename a remote path with the new path location.
+ * @param remotePath the existing remote path to be renamed
+ * @param newRemotePath the new remote path substituting the old one
+ * @return a DropboxResult object with the result of the move operation.
+ * @throws DropboxException
+ */
+ public DropboxResult move(String remotePath, String newRemotePath) throws DropboxException {
+ DropboxResult result = null;
+ try {
+ instance.client.move(remotePath, newRemotePath);
+ } catch (DbxException e) {
+ throw new DropboxException(remotePath + " does not exist or can't obtain metadata");
+ }
+ result = new DropboxMoveResult();
+ result.setResultEntries(remotePath + "-" + newRemotePath);
+ return result;
+ }
+
+ /**
+ * Get the content of every file inside the remote path.
+ * @param remotePath the remote path where to download from
+ * @return a DropboxResult object with the content (ByteArrayOutputStream) of every files inside the remote path.
+ * @throws DropboxException
+ */
+ public DropboxResult get(String remotePath) throws DropboxException {
+ DropboxResult result = new DropboxFileDownloadResult();
+ //a map representing for each path the result of the baos
+ Map<String, ByteArrayOutputStream> resultEntries = new HashMap<String, ByteArrayOutputStream>();
+ //iterate from the remotePath
+ downloadFilesInFolder(remotePath, resultEntries);
+ //put the map of baos as result
+ result.setResultEntries(resultEntries);
+ return result;
+ }
+
+ private void downloadFilesInFolder(String path, Map<String, ByteArrayOutputStream> resultEntries) throws DropboxException {
+ DbxEntry.WithChildren listing = null;
+ try {
+ listing = instance.client.getMetadataWithChildren(path);
+ } catch (DbxException e) {
+ throw new DropboxException(path + " does not exist or can't obtain metadata");
+ }
+ if (listing.children == null) {
+ LOG.info("downloading a single file...");
+ downloadSingleFile(path, resultEntries);
+ return;
+ }
+ for (DbxEntry entry : listing.children) {
+ if (entry.isFile()) {
+ try {
+ //get the baos of the file
+ downloadSingleFile(entry.path, resultEntries);
+ } catch (DropboxException e) {
+ LOG.warn("can't download from " + entry.path);
+ }
+ } else {
+ //iterate on folder
+ downloadFilesInFolder(entry.path, resultEntries);
+ }
+ }
+ }
+
+ private void downloadSingleFile(String path, Map<String, ByteArrayOutputStream> resultEntries) throws DropboxException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DbxEntry.File downloadedFile;
+ try {
+ downloadedFile = instance.client.getFile(path, null, baos);
+ } catch (DbxException e) {
+ throw new DropboxException(path + " does not exist or can't obtain metadata");
+ } catch (IOException e) {
+ throw new DropboxException(path + " can't obtain a stream");
+ }
+ if (downloadedFile != null) {
+ resultEntries.put(path, baos);
+ LOG.info("downloaded path:" + path + " - baos size:" + baos.size());
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxDelResult.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxDelResult.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxDelResult.java
new file mode 100755
index 0000000..50ed909
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxDelResult.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.dto;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.util.DropboxResultHeader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropboxDelResult extends DropboxResult {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxDelResult.class);
+
+ /**
+ * Object payload contained in Exchange
+ * Exchange Body is populated with the remote path deleted on dropbox.
+ * @param exchange
+ */
+ @Override
+ public void populateExchange(Exchange exchange) {
+ String remotePath = (String)resultEntries;
+ exchange.getIn().setHeader(DropboxResultHeader.DELETED_PATH.name(), remotePath);
+ exchange.getIn().setBody(remotePath);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileDownloadResult.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileDownloadResult.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileDownloadResult.java
new file mode 100755
index 0000000..394b05d
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileDownloadResult.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.dto;
+
+import java.io.ByteArrayOutputStream;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.util.DropboxResultHeader;
+
+public class DropboxFileDownloadResult extends DropboxResult {
+
+ /**
+ * Object payload contained in Exchange
+ * In case of a single file Exchange Header is populated with the name of the remote path downloaded
+ * In case of a multiple files Exchange Header is populated with the name of the remote paths downloaded
+ * In case of a single file Exchange Body is populated with the ByteArrayOutputStream downloaded from dropbox.
+ * In case of multiple files Exchange Body is populated with a map containing as key the remote path
+ * and as value the linked ByteArrayOutputStream
+ * @param exchange
+ */
+ @Override
+ public void populateExchange(Exchange exchange) {
+ //in case we have only one baos put it directly in body
+ Map<String, ByteArrayOutputStream> map = (Map<String, ByteArrayOutputStream>)resultEntries;
+ if (map.size() == 1) {
+ //set info in exchange
+ String pathExtracted = null;
+ ByteArrayOutputStream baosExtracted = null;
+ for (Map.Entry<String, ByteArrayOutputStream> entry : map.entrySet()) {
+ pathExtracted = entry.getKey();
+ baosExtracted = entry.getValue();
+ }
+ exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILE.name(), pathExtracted);
+ exchange.getIn().setBody(baosExtracted);
+ } else {
+ StringBuffer pathsExtracted = new StringBuffer();
+ for (Map.Entry<String, ByteArrayOutputStream> entry : map.entrySet()) {
+ pathsExtracted.append(entry.getKey() + "\n");
+ }
+ exchange.getIn().setHeader(DropboxResultHeader.DOWNLOADED_FILES.name(), pathsExtracted.toString());
+ exchange.getIn().setBody(map);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileUploadResult.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileUploadResult.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileUploadResult.java
new file mode 100755
index 0000000..5774558
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxFileUploadResult.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.dto;
+
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.util.DropboxResultCode;
+import org.apache.camel.component.dropbox.util.DropboxResultHeader;
+
+
+public class DropboxFileUploadResult extends DropboxResult {
+
+ /**
+ * Object payload contained in Exchange
+ * In case of a single file Exchange Header is populated with the name of the remote path uploaded
+ * In case of a multiple files Exchange Header is populated with the name of the remote paths uploaded
+ * In case of a single file Exchange Body is populated with the result code of the upload operation for the remote path.
+ * In case of multiple files Exchange Body is populated with a map containing as key the remote path uploaded
+ * and as value the result code of the upload operation
+ * @param exchange
+ */
+ @Override
+ public void populateExchange(Exchange exchange) {
+ Map<String, DropboxResultCode> map = (Map<String, DropboxResultCode>)resultEntries;
+ if (map.size() == 1) {
+ //set info in exchange
+ String pathExtracted = null;
+ DropboxResultCode codeExtracted = null;
+ for (Map.Entry<String, DropboxResultCode> entry : map.entrySet()) {
+ pathExtracted = entry.getKey();
+ codeExtracted = entry.getValue();
+ }
+ exchange.getIn().setHeader(DropboxResultHeader.UPLOADED_FILE.name(), pathExtracted);
+ exchange.getIn().setBody(codeExtracted.name());
+ } else {
+ StringBuffer pathsExtracted = new StringBuffer();
+ for (Map.Entry<String, DropboxResultCode> entry : map.entrySet()) {
+ pathsExtracted.append(entry.getKey() + "\n");
+ }
+ exchange.getIn().setHeader(DropboxResultHeader.UPLOADED_FILES.name(), pathsExtracted.toString());
+ exchange.getIn().setBody(map);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxMoveResult.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxMoveResult.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxMoveResult.java
new file mode 100755
index 0000000..8337f62
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxMoveResult.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.dto;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.util.DropboxResultHeader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DropboxMoveResult extends DropboxResult {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxMoveResult.class);
+
+ /**
+ * Object payload contained in Exchange
+ * Exchange Header and Body contains the mode path
+ * @param exchange
+ */
+ @Override
+ public void populateExchange(Exchange exchange) {
+ String movedPath = (String)resultEntries;
+ exchange.getIn().setHeader(DropboxResultHeader.MOVED_PATH.name(), movedPath);
+ exchange.getIn().setBody(movedPath);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxResult.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxResult.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxResult.java
new file mode 100755
index 0000000..09bb40c
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxResult.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.dto;
+
+import org.apache.camel.Exchange;
+
+
+public abstract class DropboxResult {
+
+ protected Object resultEntries;
+
+ /**
+ * Populate the camel exchange with the results from dropbox method invocations.
+ * @param exchange
+ */
+ public abstract void populateExchange(Exchange exchange);
+
+ public Object getResultEntries() {
+ return resultEntries;
+ }
+
+ public void setResultEntries(Object resultEntries) {
+ this.resultEntries = resultEntries;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxSearchResult.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxSearchResult.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxSearchResult.java
new file mode 100755
index 0000000..97a5972
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/dto/DropboxSearchResult.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.dto;
+
+import java.util.List;
+
+import com.dropbox.core.DbxEntry;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.util.DropboxResultHeader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class DropboxSearchResult extends DropboxResult {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxSearchResult.class);
+
+ /**
+ * Object payload contained in Exchange
+ * Exchange Header is populated with the remote paths found.
+ * Exchange Body is populated with the list of DbxEntry found.
+ * @param exchange
+ */
+ @Override
+ public void populateExchange(Exchange exchange) {
+ StringBuffer fileExtracted = new StringBuffer();
+ List<DbxEntry> entries = null;
+ if (resultEntries != null) {
+ entries = (List<DbxEntry>) resultEntries;
+ for (DbxEntry entry : entries) {
+ fileExtracted.append(entry.name + "-" + entry.path + "\n");
+ }
+ }
+ exchange.getIn().setHeader(DropboxResultHeader.FOUNDED_FILES.name(), fileExtracted.toString());
+ exchange.getIn().setBody(entries);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollConsumer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollConsumer.java
new file mode 100755
index 0000000..7efc934
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollConsumer.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.consumer;
+
+import org.apache.camel.Processor;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.impl.ScheduledPollConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public abstract class DropboxScheduledPollConsumer extends ScheduledPollConsumer {
+ protected static final transient Logger LOG = LoggerFactory.getLogger(DropboxScheduledPollConsumer.class);
+ protected DropboxEndpoint endpoint;
+ protected DropboxConfiguration configuration;
+
+ public DropboxScheduledPollConsumer(DropboxEndpoint endpoint, Processor processor, DropboxConfiguration configuration) {
+ super(endpoint, processor);
+ this.endpoint = endpoint;
+ this.configuration = configuration;
+ }
+
+ @Override
+ protected abstract int poll() throws Exception;
+
+ /**
+ * Lifecycle method invoked when the consumer has created.
+ * Internally create or reuse a connection to the low level dropbox client
+ * @throws Exception
+ */
+ @Override
+ protected void doStart() throws Exception {
+ if (configuration.getClient() == null) {
+ //create dropbox client
+ configuration.createClient();
+
+ LOG.info("consumer dropbox client created");
+ }
+
+ super.doStart();
+ }
+
+ /**
+ * Lifecycle method invoked when the consumer has destroyed.
+ * Erase the reference to the dropbox low level client
+ * @throws Exception
+ */
+ @Override
+ protected void doStop() throws Exception {
+ if (configuration.getClient() == null) {
+ configuration.setClient(null);
+
+ LOG.info("consumer dropbox client deleted");
+ }
+ super.doStop();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollGetConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollGetConsumer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollGetConsumer.java
new file mode 100755
index 0000000..de42292
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollGetConsumer.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.consumer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.component.dropbox.core.DropboxAPIFacade;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+
+public class DropboxScheduledPollGetConsumer extends DropboxScheduledPollConsumer {
+
+ public DropboxScheduledPollGetConsumer(DropboxEndpoint endpoint, Processor processor, DropboxConfiguration configuration) {
+ super(endpoint, processor, configuration);
+ }
+
+ /**
+ * Poll from a dropbox remote path and put the result in the message exchange
+ * @return number of messages polled
+ * @throws Exception
+ */
+ @Override
+ protected int poll() throws Exception {
+ Exchange exchange = endpoint.createExchange();
+ DropboxResult result = DropboxAPIFacade.getInstance(configuration.getClient())
+ .get(configuration.getRemotePath());
+ result.populateExchange(exchange);
+ LOG.info("consumer --> downloaded: " + result.toString());
+
+ try {
+ // send message to next processor in the route
+ getProcessor().process(exchange);
+ return 1; // number of messages polled
+ } finally {
+ // log exception if an exception occurred and was not handled
+ if (exchange.getException() != null) {
+ getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollSearchConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollSearchConsumer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollSearchConsumer.java
new file mode 100755
index 0000000..a8c125f
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/consumer/DropboxScheduledPollSearchConsumer.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.consumer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.component.dropbox.core.DropboxAPIFacade;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+
+public class DropboxScheduledPollSearchConsumer extends DropboxScheduledPollConsumer {
+
+ public DropboxScheduledPollSearchConsumer(DropboxEndpoint endpoint, Processor processor, DropboxConfiguration configuration) {
+ super(endpoint, processor, configuration);
+ }
+
+ /**
+ * Poll from a dropbox remote path and put the result in the message exchange
+ * @return number of messages polled
+ * @throws Exception
+ */
+ @Override
+ protected int poll() throws Exception {
+ Exchange exchange = endpoint.createExchange();
+ DropboxResult result = DropboxAPIFacade.getInstance(configuration.getClient())
+ .search(configuration.getRemotePath(), configuration.getQuery());
+ result.populateExchange(exchange);
+ LOG.info("consumer --> downloaded: " + result.toString());
+
+ try {
+ // send message to next processor in the route
+ getProcessor().process(exchange);
+ return 1; // number of messages polled
+ } finally {
+ // log exception if an exception occurred and was not handled
+ if (exchange.getException() != null) {
+ getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxDelProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxDelProducer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxDelProducer.java
new file mode 100755
index 0000000..f81ed34
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxDelProducer.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.component.dropbox.core.DropboxAPIFacade;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropboxDelProducer extends DropboxProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxDelProducer.class);
+
+ public DropboxDelProducer(DropboxEndpoint endpoint, DropboxConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ DropboxResult result = DropboxAPIFacade.getInstance(configuration.getClient())
+ .del(configuration.getRemotePath());
+ result.populateExchange(exchange);
+ log.info("Deleted: " + configuration.getRemotePath());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxGetProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxGetProducer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxGetProducer.java
new file mode 100755
index 0000000..9eaca52
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxGetProducer.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.component.dropbox.core.DropboxAPIFacade;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropboxGetProducer extends DropboxProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxGetProducer.class);
+
+ public DropboxGetProducer(DropboxEndpoint endpoint, DropboxConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ DropboxResult result = DropboxAPIFacade.getInstance(configuration.getClient())
+ .get(configuration.getRemotePath());
+ result.populateExchange(exchange);
+ LOG.info("producer --> downloaded: " + result.toString());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxMoveProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxMoveProducer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxMoveProducer.java
new file mode 100755
index 0000000..7ab6142
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxMoveProducer.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.component.dropbox.core.DropboxAPIFacade;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropboxMoveProducer extends DropboxProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxMoveProducer.class);
+
+ public DropboxMoveProducer(DropboxEndpoint endpoint, DropboxConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ DropboxResult result = DropboxAPIFacade.getInstance(configuration.getClient())
+ .move(configuration.getRemotePath(), configuration.getNewRemotePath());
+ result.populateExchange(exchange);
+ log.info("Moved from " + configuration.getRemotePath() + " to " + configuration.getNewRemotePath());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxProducer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxProducer.java
new file mode 100755
index 0000000..7faaa84
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxProducer.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.producer;
+
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class DropboxProducer extends DefaultProducer {
+
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxProducer.class);
+
+ protected DropboxEndpoint endpoint;
+ protected DropboxConfiguration configuration;
+
+ public DropboxProducer(DropboxEndpoint endpoint, DropboxConfiguration configuration) {
+ super(endpoint);
+ this.endpoint = endpoint;
+ this.configuration = configuration;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ if (configuration.getClient() == null) {
+ //create dropbox client
+ configuration.createClient();
+
+ LOG.info("producer dropbox client created");
+ }
+
+ super.doStart();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (configuration.getClient() == null) {
+ configuration.setClient(null);
+
+ LOG.info("producer dropbox client deleted");
+ }
+ super.doStop();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxPutProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxPutProducer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxPutProducer.java
new file mode 100755
index 0000000..1def466
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxPutProducer.java
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.component.dropbox.core.DropboxAPIFacade;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropboxPutProducer extends DropboxProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxPutProducer.class);
+
+ public DropboxPutProducer(DropboxEndpoint endpoint, DropboxConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ DropboxResult result = DropboxAPIFacade.getInstance(configuration.getClient())
+ .put(configuration.getLocalPath(), configuration.getRemotePath(), configuration.getUploadMode());
+ result.populateExchange(exchange);
+ LOG.info("Uploaded: " + result.toString());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxSearchProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxSearchProducer.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxSearchProducer.java
new file mode 100755
index 0000000..d15e91e
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/integration/producer/DropboxSearchProducer.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.integration.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.dropbox.DropboxConfiguration;
+import org.apache.camel.component.dropbox.DropboxEndpoint;
+import org.apache.camel.component.dropbox.core.DropboxAPIFacade;
+import org.apache.camel.component.dropbox.dto.DropboxResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DropboxSearchProducer extends DropboxProducer {
+ private static final transient Logger LOG = LoggerFactory.getLogger(DropboxSearchProducer.class);
+
+ public DropboxSearchProducer(DropboxEndpoint endpoint, DropboxConfiguration configuration) {
+ super(endpoint, configuration);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ DropboxResult result = DropboxAPIFacade.getInstance(configuration.getClient())
+ .search(configuration.getRemotePath(), configuration.getQuery());
+ result.populateExchange(exchange);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxConstants.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxConstants.java
new file mode 100755
index 0000000..30cdfe4
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxConstants.java
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.util;
+
+public final class DropboxConstants {
+
+ public static final String DROPBOX_FILE_SEPARATOR = "/";
+ public static final long POLL_CONSUMER_DELAY = 60 * 60 * 1000L;
+
+ private DropboxConstants() { }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxException.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxException.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxException.java
new file mode 100755
index 0000000..387d239
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxException.java
@@ -0,0 +1,23 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.util;
+
+public class DropboxException extends Exception {
+ public DropboxException(String message) {
+ super(message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxOperation.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxOperation.java
new file mode 100755
index 0000000..ab25b75
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxOperation.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.util;
+
+public enum DropboxOperation {
+ put("put"),
+ del("del"),
+ search("search"),
+ get("get"),
+ move("move");
+
+ private final String text;
+
+ private DropboxOperation(final String text) {
+ this.text = text;
+ }
+
+ @Override
+ public String toString() {
+ return text;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxPropertyManager.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxPropertyManager.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxPropertyManager.java
new file mode 100755
index 0000000..f9778fe
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxPropertyManager.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+public final class DropboxPropertyManager {
+
+ private static Properties properties;
+ private static DropboxPropertyManager instance;
+
+ private DropboxPropertyManager() { }
+
+ public static synchronized DropboxPropertyManager getInstance() throws Exception {
+ if (instance == null) {
+ instance = new DropboxPropertyManager();
+ properties = loadProperties();
+ }
+ return instance;
+ }
+
+ public String getProperty(String key) {
+ return (String)properties.getProperty(key);
+ }
+
+
+ private static Properties loadProperties() throws Exception {
+ URL url = DropboxPropertyManager.class.getResource("/dropbox.properties");
+ InputStream inStream;
+ try {
+ inStream = url.openStream();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new DropboxException("dropbox.properties could not be found");
+ }
+ properties = new Properties();
+ try {
+ properties.load(inStream);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new DropboxException("dropbox.properties can't be read");
+ }
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/037f3f09/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxResultCode.java
----------------------------------------------------------------------
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxResultCode.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxResultCode.java
new file mode 100755
index 0000000..d22acef
--- /dev/null
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/util/DropboxResultCode.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.dropbox.util;
+
+public enum DropboxResultCode {
+ OK, KO;
+}
+