camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r911036 - in /camel/trunk/components/camel-freemarker/src: main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java test/java/org/apache/camel/component/freemarker/FreemarkerTemplateInHeaderTest.java
Date Wed, 17 Feb 2010 16:06:08 GMT
Author: davsclaus
Date: Wed Feb 17 16:06:08 2010
New Revision: 911036

URL: http://svn.apache.org/viewvc?rev=911036&view=rev
Log:
CAMEL-2477: Applied patch with thanks to Christian Mueller.

Modified:
    camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
    camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTemplateInHeaderTest.java

Modified: camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java?rev=911036&r1=911035&r2=911036&view=diff
==============================================================================
--- camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
(original)
+++ camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
Wed Feb 17 16:06:08 2010
@@ -20,6 +20,7 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import freemarker.template.Configuration;
 import freemarker.template.Template;
@@ -146,10 +147,8 @@
         Message out = exchange.getOut();
         out.setBody(buffer.toString());
         Map<String, Object> headers = (Map<String, Object>) variableMap.get("headers");
-        for (String key : headers.keySet()) {
-            out.setHeader(key, headers.get(key));
+        for (Entry<String, Object> entry : headers.entrySet()) {
+            out.setHeader(entry.getKey(), entry.getValue());
         }
     }
-
-}
-
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTemplateInHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTemplateInHeaderTest.java?rev=911036&r1=911035&r2=911036&view=diff
==============================================================================
--- camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTemplateInHeaderTest.java
(original)
+++ camel/trunk/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTemplateInHeaderTest.java
Wed Feb 17 16:06:08 2010
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.freemarker;
 
+import java.util.Map.Entry;
+import java.util.Set;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
@@ -31,26 +34,46 @@
 
     @Test
     public void testReceivesFooResponse() throws Exception {
-        assertRespondsWith("foo", "<hello>foo</hello>");
+        assertRespondsWith("cheese", "foo", "<hello>foo</hello>");
     }
 
     @Test
     public void testReceivesBarResponse() throws Exception {
-        assertRespondsWith("bar", "<hello>bar</hello>");
+        assertRespondsWith("cheese", "bar", "<hello>bar</hello>");
+    }
+
+    @Test
+    public void testRespectHeaderNamesUpperCase() throws Exception {
+        assertRespondsWith("Cheese", "bar", "<hello>bar</hello>");
     }
 
-    protected void assertRespondsWith(final String value, String expectedBody) throws InvalidPayloadException
{
+    @Test
+    public void testRespectHeaderNamesCamelCase() throws Exception {
+        assertRespondsWith("CorrelationID", "bar", "<hello>bar</hello>");
+    }
+
+    protected void assertRespondsWith(final String headerName, final String headerValue,
String expectedBody) throws InvalidPayloadException {
         Exchange response = template.request("direct:a", new Processor() {
             public void process(Exchange exchange) throws Exception {
                 Message in = exchange.getIn();
-                in.setHeader(FreemarkerConstants.FREEMARKER_TEMPLATE, "<hello>${headers.cheese}</hello>");
-                in.setHeader("cheese", value);
+                in.setHeader(FreemarkerConstants.FREEMARKER_TEMPLATE, "<hello>${headers."
+ headerName + "}</hello>");
+                in.setHeader(headerName, headerValue);
             }
         });
         assertOutMessageBodyEquals(response, expectedBody);
 
         Object template = response.getOut().getHeader(FreemarkerConstants.FREEMARKER_TEMPLATE);
         assertNull("Template header should have been removed", template);
+
+        Set<Entry<String, Object>> entrySet = response.getOut().getHeaders().entrySet();
+        boolean keyFound = false;
+        for (Entry<String, Object> entry : entrySet) {
+            if (entry.getKey().equals(headerName)) {
+                keyFound = true;
+            }
+        }
+        assertTrue("Header should been found", keyFound);
+
     }
 
     protected RouteBuilder createRouteBuilder() {
@@ -60,5 +83,4 @@
             }
         };
     }
-
-}
+}
\ No newline at end of file



Mime
View raw message