You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ch...@apache.org on 2014/07/02 01:41:14 UTC
git commit: Added a GenericFile to Box upload converter to more
easily move data from file components to the Box component.
Repository: camel
Updated Branches:
refs/heads/master 6ad1db766 -> 929bb33ff
Added a GenericFile to Box upload converter to more easily move data from file components to the Box component.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/929bb33f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/929bb33f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/929bb33f
Branch: refs/heads/master
Commit: 929bb33ff11fbffd47c973db02988335ceede1bb
Parents: 6ad1db7
Author: Hiram Chirino <hi...@hiramchirino.com>
Authored: Tue Jul 1 19:40:41 2014 -0400
Committer: Hiram Chirino <hi...@hiramchirino.com>
Committed: Tue Jul 1 19:41:05 2014 -0400
----------------------------------------------------------------------
components/camel-box/pom.xml | 2 +-
.../camel/component/box/BoxConverter.java | 57 ++++++++++++++++++++
.../services/org/apache/camel/TypeConverter | 17 ++++++
3 files changed, 75 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/929bb33f/components/camel-box/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-box/pom.xml b/components/camel-box/pom.xml
index f01a53b..aee2b38 100644
--- a/components/camel-box/pom.xml
+++ b/components/camel-box/pom.xml
@@ -12,7 +12,7 @@
<artifactId>camel-box</artifactId>
<packaging>bundle</packaging>
- <name>Camel Box.com Component</name>
+ <name>Camel :: Box.com</name>
<description>Camel Component for Box.com</description>
<properties>
http://git-wip-us.apache.org/repos/asf/camel/blob/929bb33f/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java
new file mode 100644
index 0000000..e5daf5c
--- /dev/null
+++ b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java
@@ -0,0 +1,57 @@
+/**
+ * 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.box;
+
+import com.box.boxjavalibv2.exceptions.BoxJSONException;
+import com.box.restclientv2.exceptions.BoxRestException;
+import com.box.restclientv2.requestsbase.BoxFileUploadRequestObject;
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.component.file.GenericFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+@Converter
+public final class BoxConverter {
+
+ private BoxConverter() {
+ //Utility Class
+ }
+
+ @Converter
+ public static BoxFileUploadRequestObject genericFileToBoxFileUploadRequestObject(GenericFile<?> file, Exchange exchange) throws IOException, NoTypeConversionAvailableException, BoxRestException, BoxJSONException {
+ String parentId = "0";
+ if (exchange != null) {
+ parentId = exchange.getProperty("box.parentId", "0", String.class);
+ }
+ if (file.getFile() instanceof File) {
+ // prefer to use a file input stream if its a java.io.File
+ File f = (File) file.getFile();
+ return BoxFileUploadRequestObject.uploadFileRequestObject(parentId, file.getFileName(), f);
+ }
+ if (exchange != null) {
+ // otherwise ensure the body is loaded as we want the input stream of the body
+ file.getBinding().loadContent(exchange, file);
+ InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, file.getBody());
+ return BoxFileUploadRequestObject.uploadFileRequestObject(parentId, file.getFileName(), is);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/929bb33f/components/camel-box/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
----------------------------------------------------------------------
diff --git a/components/camel-box/src/main/resources/META-INF/services/org/apache/camel/TypeConverter b/components/camel-box/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
new file mode 100644
index 0000000..3172b44
--- /dev/null
+++ b/components/camel-box/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+org.apache.camel.component.box.BoxConverter