camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-8628: camel-dozer component fails with multiple expression mappings
Date Tue, 14 Apr 2015 05:42:21 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 8e4485292 -> 7f052361f


CAMEL-8628: camel-dozer component fails with multiple expression mappings


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

Branch: refs/heads/camel-2.15.x
Commit: 7f052361f169153ba940177712b02845e3e7d7ff
Parents: 8e44852
Author: Keith Babo <kbabo@redhat.com>
Authored: Mon Apr 13 15:15:24 2015 -0400
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Apr 14 07:45:18 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/component/dozer/DozerProducer.java  |  9 +++++++--
 .../camel/component/dozer/ExpressionMapper.java      |  6 ------
 .../camel/component/dozer/ExpressionMappingTest.java | 15 +++++++++++----
 .../camel/component/dozer/expressionMapping.xml      |  4 ++++
 4 files changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7f052361/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
index 4cd1159..b7b12c8 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/DozerProducer.java
@@ -80,8 +80,13 @@ public class DozerProducer extends DefaultProducer {
         // Second pass to process literal mappings
         endpoint.getMapper().map(endpoint.getVariableMapper(), targetObject);
         // Third pass to process expression mappings
-        endpoint.getExpressionMapper().setCurrentExchange(exchange);
-        endpoint.getMapper().map(endpoint.getExpressionMapper(), targetObject);
+        try {
+            endpoint.getExpressionMapper().setCurrentExchange(exchange);
+            endpoint.getMapper().map(endpoint.getExpressionMapper(), targetObject);
+        } finally {
+            // Clear out the exchange reference on the expression mapper
+            endpoint.getExpressionMapper().setCurrentExchange(null);
+        }
         msg.setBody(targetObject);
         exchange.setIn(msg);
         

http://git-wip-us.apache.org/repos/asf/camel/blob/7f052361/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/ExpressionMapper.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/ExpressionMapper.java
b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/ExpressionMapper.java
index cf9664d..afee452 100644
--- a/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/ExpressionMapper.java
+++ b/components/camel-dozer/src/main/java/org/apache/camel/component/dozer/ExpressionMapper.java
@@ -81,10 +81,4 @@ public class ExpressionMapper extends BaseConverter {
     public void setCurrentExchange(Exchange exchange) {
         currentExchange.set(exchange);
     }
-    
-    @Override
-    public void done() {
-        super.done();
-        currentExchange.set(null);
-    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7f052361/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/ExpressionMappingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/ExpressionMappingTest.java
b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/ExpressionMappingTest.java
index 97d6bf7..423f2a9 100644
--- a/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/ExpressionMappingTest.java
+++ b/components/camel-dozer/src/test/java/org/apache/camel/component/dozer/ExpressionMappingTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.dozer;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
@@ -52,14 +55,18 @@ public class ExpressionMappingTest {
     @Test
     public void testExpressionMapping() throws Exception {
         resultEndpoint.expectedMessageCount(1);
-        final String headerName = "customerNumber";
-        final String headerVal = "CAFE-123";
+        Map<String, Object> headers = new HashMap<String, Object>();
+        final String customerNumber = "CAFE-123";
+        final String orderNumber = "ABC-000";
+        headers.put("customerNumber", customerNumber);
+        headers.put("orderNumber", orderNumber);
         ABCOrder abcOrder = new ABCOrder();
         // Header value should be mapped to custId in target model
-        startEndpoint.sendBodyAndHeader(abcOrder, headerName, headerVal);
+        startEndpoint.sendBodyAndHeaders(abcOrder, headers);
         // check results
         resultEndpoint.assertIsSatisfied();
         XYZOrder result = resultEndpoint.getExchanges().get(0).getIn().getBody(XYZOrder.class);
-        Assert.assertEquals(headerVal, result.getCustId());
+        Assert.assertEquals(customerNumber, result.getCustId());
+        Assert.assertEquals(orderNumber, result.getOrderId());
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7f052361/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/expressionMapping.xml
----------------------------------------------------------------------
diff --git a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/expressionMapping.xml
b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/expressionMapping.xml
index c4aa084..6e9ae3a 100644
--- a/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/expressionMapping.xml
+++ b/components/camel-dozer/src/test/resources/org/apache/camel/component/dozer/expressionMapping.xml
@@ -35,5 +35,9 @@
             <a>expression</a>
             <b>custId</b>
         </field>
+        <field custom-converter-id="_expressionMapping" custom-converter-param="header:orderNumber">
+            <a>expression</a>
+            <b>orderId</b>
+        </field>
     </mapping>
 </mappings>


Mime
View raw message