camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-7067: Use message headers instead of exchange properties.
Date Tue, 24 Dec 2013 11:18:59 GMT
Updated Branches:
  refs/heads/master 39abbbf1a -> 431daf45d


CAMEL-7067: Use message headers instead of exchange properties.

Signed-off-by: Gregor Zurowski <gregor@zurowski.org>

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

Branch: refs/heads/master
Commit: 431daf45dd929b48c41cf7662e9971dac60dfa92
Parents: 39abbbf
Author: Gregor Zurowski <gregor@zurowski.org>
Authored: Tue Dec 24 00:25:30 2013 -0500
Committer: Gregor Zurowski <gregor@zurowski.org>
Committed: Tue Dec 24 00:25:30 2013 -0500

----------------------------------------------------------------------
 .../apache/camel/component/jcr/JcrProducer.java | 39 ++++++++++++++------
 .../jcr/AuthTokenLoginFailureTest.java          |  4 +-
 .../jcr/JcrAuthTokenWithLoginTest.java          |  4 +-
 .../camel/component/jcr/JcrGetNodeByIdTest.java |  4 +-
 .../component/jcr/JcrNodePathCreationTest.java  |  4 +-
 .../component/jcr/JcrProducerSubNodeTest.java   |  4 +-
 .../camel/component/jcr/JcrProducerTest.java    |  4 +-
 7 files changed, 39 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/431daf45/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
b/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
index fd7c950..de4b8f3 100644
--- a/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
+++ b/components/camel-jcr/src/main/java/org/apache/camel/component/jcr/JcrProducer.java
@@ -19,6 +19,9 @@ package org.apache.camel.component.jcr;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
@@ -28,6 +31,7 @@ import javax.jcr.Session;
 import javax.jcr.Value;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.jackrabbit.util.Text;
@@ -41,13 +45,15 @@ public class JcrProducer extends DefaultProducer {
     public void process(Exchange exchange) throws Exception {
         TypeConverter converter = exchange.getContext().getTypeConverter();
         Session session = openSession();
-        String operation = determineOperation(exchange);
+        Message message = exchange.getIn();
+        String operation = determineOperation(message);
         try {
             if (JcrConstants.JCR_INSERT.equals(operation)) {
                 Node base = findOrCreateNode(session.getRootNode(), getJcrEndpoint().getBase());
-                Node node = findOrCreateNode(base, getNodeName(exchange));
-                for (String key : exchange.getProperties().keySet()) {
-                    Value value = converter.convertTo(Value.class, exchange, exchange.getProperty(key));
+                Node node = findOrCreateNode(base, getNodeName(message));
+                Map<String, Object> headers = filterComponentHeaders(message.getHeaders());
+                for (String key : headers.keySet()) {
+                    Value value = converter.convertTo(Value.class, exchange, message.getHeader(key));
                     node.setProperty(key, value);
                 }
                 node.addMixin("mix:referenceable");
@@ -60,7 +66,7 @@ public class JcrProducer extends DefaultProducer {
                     Property property = properties.nextProperty();
                     Class<?> aClass = classForJCRType(property);
                     Object value = converter.convertTo(aClass, exchange, property.getValue());
-                    exchange.setProperty(property.getName(), value);
+                    message.setHeader(property.getName(), value);
                 }
             } else {
                 throw new RuntimeException("Unsupported operation: " + operation);
@@ -74,6 +80,17 @@ public class JcrProducer extends DefaultProducer {
         }
     }
 
+    private Map<String, Object> filterComponentHeaders(Map<String, Object> properties)
{
+        Map<String, Object> result = new HashMap<String, Object>(properties.size());
+        for (Map.Entry<String, Object> entry : properties.entrySet()) {
+            String key = entry.getKey();
+            if (!key.equals(JcrConstants.JCR_NODE_NAME) && !key.equals(JcrConstants.JCR_OPERATION))
{
+                result.put(entry.getKey(), entry.getValue());
+            }
+        }
+        return result;
+    }
+    
     private Class<?> classForJCRType(Property property) throws RepositoryException
{
         switch (property.getType()) {
         case PropertyType.STRING:
@@ -107,16 +124,14 @@ public class JcrProducer extends DefaultProducer {
         }
     }
 
-    private String determineOperation(Exchange exchange) {
-        String operation = exchange.getIn().getHeader(JcrConstants.JCR_OPERATION, String.class);
+    private String determineOperation(Message message) {
+        String operation = message.getHeader(JcrConstants.JCR_OPERATION, String.class);
         return operation != null ? operation : JcrConstants.JCR_INSERT;
     }
 
-    private String getNodeName(Exchange exchange) {
-        if (exchange.getProperty(JcrConstants.JCR_NODE_NAME) != null) {
-            return exchange.getProperty(JcrConstants.JCR_NODE_NAME, String.class);
-        }
-        return exchange.getExchangeId();
+    private String getNodeName(Message message) {
+        String nodeName = message.getHeader(JcrConstants.JCR_NODE_NAME, String.class);
+        return nodeName != null ? nodeName : message.getExchange().getExchangeId();
     }
 
     private Node findOrCreateNode(Node parent, String path) throws RepositoryException {

http://git-wip-us.apache.org/repos/asf/camel/blob/431daf45/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/AuthTokenLoginFailureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/AuthTokenLoginFailureTest.java
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/AuthTokenLoginFailureTest.java
index 5cf762e..406bf2c 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/AuthTokenLoginFailureTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/AuthTokenLoginFailureTest.java
@@ -54,8 +54,8 @@ public class AuthTokenLoginFailureTest extends JcrAuthTestBase {
             @Override
             public void configure() throws Exception {
                 // START SNIPPET: jcr
-                from("direct:a").setProperty(JcrConstants.JCR_NODE_NAME,
-                        constant("node")).setProperty("my.contents.property",
+                from("direct:a").setHeader(JcrConstants.JCR_NODE_NAME,
+                        constant("node")).setHeader("my.contents.property",
                         body()).to(
                         "jcr://test:quatloos@repository" + BASE_REPO_PATH);
                 // END SNIPPET: jcr

http://git-wip-us.apache.org/repos/asf/camel/blob/431daf45/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrAuthTokenWithLoginTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrAuthTokenWithLoginTest.java
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrAuthTokenWithLoginTest.java
index c79c456..e1dee1a 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrAuthTokenWithLoginTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrAuthTokenWithLoginTest.java
@@ -39,8 +39,8 @@ public class JcrAuthTokenWithLoginTest extends JcrAuthTestBase {
             @Override
             public void configure() throws Exception {
                 // START SNIPPET: jcr
-                from("direct:a").setProperty(JcrConstants.JCR_NODE_NAME,
-                        constant("node")).setProperty("my.contents.property",
+                from("direct:a").setHeader(JcrConstants.JCR_NODE_NAME,
+                        constant("node")).setHeader("my.contents.property",
                         body()).to(
                         "jcr://not-a-user:nonexisting-password@repository" + BASE_REPO_PATH);
                 // END SNIPPET: jcr

http://git-wip-us.apache.org/repos/asf/camel/blob/431daf45/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
index 99621d0..d0ea37a 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrGetNodeByIdTest.java
@@ -53,8 +53,8 @@ public class JcrGetNodeByIdTest extends JcrRouteTestSupport {
     @Test
     public void testJcrProducer() throws Exception {
         result.expectedMessageCount(1);
-        result.expectedPropertyReceived("my.contents.property", CONTENT);
-        result.expectedPropertyReceived("content.approved", APPROVED);
+        result.expectedHeaderReceived("my.contents.property", CONTENT);
+        result.expectedHeaderReceived("content.approved", APPROVED);
 
         Exchange exchange = createExchangeWithBody(identifier);
         template.send("direct:a", exchange);

http://git-wip-us.apache.org/repos/asf/camel/blob/431daf45/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
index f688faf..4c004b2 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrNodePathCreationTest.java
@@ -65,8 +65,8 @@ public class JcrNodePathCreationTest extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 // START SNIPPET: jcr
-                from("direct:a").setProperty(JcrConstants.JCR_NODE_NAME, constant("node/with/path"))
-                    .setProperty("my.contents.property", body()).to("jcr://user:pass@repository/home/test");
+                from("direct:a").setHeader(JcrConstants.JCR_NODE_NAME, constant("node/with/path"))
+                    .setHeader("my.contents.property", body()).to("jcr://user:pass@repository/home/test");
                 // END SNIPPET: jcr
             }
         };

http://git-wip-us.apache.org/repos/asf/camel/blob/431daf45/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerSubNodeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerSubNodeTest.java
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerSubNodeTest.java
index 951b1dd..42d4a55 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerSubNodeTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerSubNodeTest.java
@@ -41,7 +41,7 @@ public class JcrProducerSubNodeTest extends JcrRouteTestSupport {
         try {
             // create node
             Exchange exchange1 = ExchangeBuilder.anExchange(context)
-                .withProperty(JcrConstants.JCR_NODE_NAME, "node")
+                .withHeader(JcrConstants.JCR_NODE_NAME, "node")
                 .build();
             Exchange out1 = template.send("direct:a", exchange1);
             assertNotNull(out1);
@@ -53,7 +53,7 @@ public class JcrProducerSubNodeTest extends JcrRouteTestSupport {
             
             // create sub node
             Exchange exchange2 = ExchangeBuilder.anExchange(context)
-                .withProperty(JcrConstants.JCR_NODE_NAME, "node/subnode")
+                .withHeader(JcrConstants.JCR_NODE_NAME, "node/subnode")
                 .build();
             Exchange out2 = template.send("direct:a", exchange2);
             assertNotNull(out2);

http://git-wip-us.apache.org/repos/asf/camel/blob/431daf45/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
index 8c66863..231fefa 100644
--- a/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
+++ b/components/camel-jcr/src/test/java/org/apache/camel/component/jcr/JcrProducerTest.java
@@ -58,8 +58,8 @@ public class JcrProducerTest extends JcrRouteTestSupport {
             @Override
             public void configure() throws Exception {
                 // START SNIPPET: jcr-create-node
-                from("direct:a").setProperty(JcrConstants.JCR_NODE_NAME, constant("node"))
-                        .setProperty("my.contents.property", body())
+                from("direct:a").setHeader(JcrConstants.JCR_NODE_NAME, constant("node"))
+                        .setHeader("my.contents.property", body())
                         .to("jcr://user:pass@repository/home/test");
                 // END SNIPPET: jcr-create-node
             }


Mime
View raw message