camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject git commit: CAMEL-6878. Include Content-Type in the cxf header map.
Date Tue, 19 Nov 2013 18:19:15 GMT
Updated Branches:
  refs/heads/camel-2.12.x d89e76f81 -> cffe20373


CAMEL-6878. Include Content-Type in the cxf header map.


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

Branch: refs/heads/camel-2.12.x
Commit: cffe20373b6de0038c5d9dcf1902b424e6407b29
Parents: d89e76f
Author: Hadrian Zbarcea <hzbarcea@gmail.com>
Authored: Tue Nov 19 12:13:10 2013 -0500
Committer: Hadrian Zbarcea <hzbarcea@gmail.com>
Committed: Tue Nov 19 13:19:04 2013 -0500

----------------------------------------------------------------------
 .../cxf/common/header/CxfHeaderHelper.java      |  7 ++--
 .../cxf/common/header/CxfHeaderHelperTest.java  | 36 ++++++++++++++++++--
 2 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cffe2037/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
index 7e1672d..e7a2154 100644
--- a/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
+++ b/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelper.java
@@ -68,9 +68,10 @@ public final class CxfHeaderHelper {
 
                 if (Exchange.CONTENT_TYPE.equals(entry.getKey())) {
                     message.put(Message.CONTENT_TYPE, entry.getValue());
-                } else if (Client.REQUEST_CONTEXT.equals(entry.getKey())
-                            || Client.RESPONSE_CONTEXT.equals(entry.getKey())
-                            || Message.RESPONSE_CODE.equals(entry.getKey())) {
+                }
+                if (Client.REQUEST_CONTEXT.equals(entry.getKey())
+                    || Client.RESPONSE_CONTEXT.equals(entry.getKey())
+                    || Message.RESPONSE_CODE.equals(entry.getKey())) {
                     message.put(entry.getKey(), entry.getValue());
                 } else {
                     Object values = entry.getValue();

http://git-wip-us.apache.org/repos/asf/camel/blob/cffe2037/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
index 25fd240..9698f26 100755
--- a/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
+++ b/components/camel-cxf-transport/src/test/java/org/apache/camel/component/cxf/common/header/CxfHeaderHelperTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.cxf.common.header;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -26,11 +27,15 @@ import org.apache.camel.component.cxf.common.message.CxfConstants;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.impl.DefaultHeaderFilterStrategy;
-
+import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
 
+
 /**
  * 
  */
@@ -104,7 +109,24 @@ public class CxfHeaderHelperTest extends Assert {
         assertEquals("peach", camelHeaders.get("MyFruitHeader"));
         assertEquals("cappuccino, espresso", camelHeaders.get("MyBrewHeader"));
     } 
-    
+
+    @Test
+    public void testContentType() {
+
+        Exchange camelExchange = EasyMock.createMock(Exchange.class);
+        HeaderFilterStrategy strategy = setupHeaderStrategy(camelExchange);
+        Message cxfMessage = new MessageImpl();
+        CxfHeaderHelper.propagateCamelToCxf(strategy, 
+            Collections.<String, Object>singletonMap("Content-Type", "text/xml"), cxfMessage,
camelExchange);
+
+        Map<String, List<String>> cxfHeaders = CastUtils.cast((Map<?, ?>)cxfMessage.get(Message.PROTOCOL_HEADERS));

+        assertEquals(1, cxfHeaders.size());
+        assertEquals(1, cxfHeaders.get("Content-Type").size());
+        assertEquals("text/xml", cxfHeaders.get("Content-Type").get(0)); 
+      
+        assertEquals("text/xml", cxfMessage.get(Message.CONTENT_TYPE));   
+    }
+
     private void verifyHeader(Map<String, List<String>> headers, String name,
List<String> value) {
         List<String> values = headers.get(name);
         assertTrue("The entry must be available", values != null && values.size()
== ((List<?>)value).size());
@@ -116,4 +138,14 @@ public class CxfHeaderHelperTest extends Assert {
         assertTrue("The entry must be available", values != null && values.size()
== 1);
         assertEquals("The value must match", value, values.get(0));
     }
+
+    private HeaderFilterStrategy setupHeaderStrategy(Exchange exchange) {
+
+        HeaderFilterStrategy strategy = EasyMock.createMock(HeaderFilterStrategy.class);
+        strategy.applyFilterToCamelHeaders("Content-Type", "text/xml", exchange);
+        EasyMock.expectLastCall().andReturn(false);
+        EasyMock.replay(strategy);
+        return strategy;
+    }
+
 }


Mime
View raw message