camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [3/9] camel git commit: [CAMEL-9659] Add more headers to resulting exchange
Date Tue, 01 Mar 2016 20:02:00 GMT
[CAMEL-9659] Add more headers to resulting exchange


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f80654f4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f80654f4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f80654f4

Branch: refs/heads/master
Commit: f80654f493481535ca297e240ee03468ab0cd2f7
Parents: bfaec78
Author: Daniel Kulp <dkulp@apache.org>
Authored: Mon Feb 29 13:14:31 2016 -0500
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Tue Mar 1 14:23:00 2016 -0500

----------------------------------------------------------------------
 .../camel/component/gridfs/GridFsConsumer.java      |  2 +-
 .../camel/component/gridfs/GridFsProducer.java      | 16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f80654f4/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java b/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java
index dce195a..4f2ce66 100644
--- a/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java
+++ b/src/main/java/org/apache/camel/component/gridfs/GridFsConsumer.java
@@ -26,7 +26,7 @@ import org.apache.camel.impl.DefaultConsumer;
  * 
  */
 public class GridFsConsumer extends DefaultConsumer {
-    GridFsEndpoint ep;
+    final GridFsEndpoint ep;
     
     /**
      * @param endpoint

http://git-wip-us.apache.org/repos/asf/camel/blob/f80654f4/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java b/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java
index 5178220..7954644 100644
--- a/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java
+++ b/src/main/java/org/apache/camel/component/gridfs/GridFsProducer.java
@@ -32,6 +32,10 @@ import org.apache.camel.impl.DefaultProducer;
 
 
 public class GridFsProducer extends DefaultProducer {
+    public static final String GRIDFS_OPERATION = "gridfs.operation";
+    public static final String GRIDFS_METADATA = "gridfs.metadata";
+    public static final String GRIDFS_CHUNKSIZE = "gridfs.chunksize";
+    
     private GridFsEndpoint endpoint;
 
     public GridFsProducer(GridFsEndpoint endpoint) {
@@ -42,11 +46,11 @@ public class GridFsProducer extends DefaultProducer {
     public void process(Exchange exchange) throws Exception {
         String operation = endpoint.getOperation();
         if (operation == null) {
-            operation = exchange.getIn().getHeader("gridfs.operation", String.class);
+            operation = exchange.getIn().getHeader(GRIDFS_OPERATION, String.class);
         }
         if (operation == null || "create".equals(operation)) {
             final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
-            Long chunkSize = exchange.getIn().getHeader("gridfs.chunksize", Long.class);
+            Long chunkSize = exchange.getIn().getHeader(GRIDFS_CHUNKSIZE, Long.class);
 
             InputStream ins = exchange.getIn().getMandatoryBody(InputStream.class);
             GridFSInputFile gfsFile = endpoint.getGridFs().createFile(ins, filename, true);
@@ -57,7 +61,7 @@ public class GridFsProducer extends DefaultProducer {
             if (ct != null) {
                 gfsFile.setContentType(ct);
             }
-            String metaData = exchange.getIn().getHeader("gridfs.metadata", String.class);
+            String metaData = exchange.getIn().getHeader(GRIDFS_METADATA, String.class);
             DBObject dbObject = (DBObject) JSON.parse(metaData);
             gfsFile.setMetaData(dbObject);
             gfsFile.save();
@@ -69,7 +73,11 @@ public class GridFsProducer extends DefaultProducer {
             final String filename = exchange.getIn().getHeader(Exchange.FILE_NAME, String.class);
             GridFSDBFile file = endpoint.getGridFs().findOne(filename);
             if (file != null) {
-                exchange.getIn().setBody(file.getInputStream(), InputStream.class);
+                exchange.getIn().setHeader(GRIDFS_METADATA, JSON.serialize(file.getMetaData()));
+                exchange.getIn().setHeader(Exchange.FILE_CONTENT_TYPE, file.getContentType());
+                exchange.getIn().setHeader(Exchange.FILE_LENGTH, file.getLength());
+                exchange.getIn().setHeader(Exchange.FILE_LAST_MODIFIED, file.getUploadDate());
+                exchange.getIn().setBody(file.getInputStream(), InputStream.class);     
          
             } else {
                 throw new FileNotFoundException("No GridFS file for " + filename);
             }


Mime
View raw message