You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/02/17 16:55:51 UTC

svn commit: r911028 - in /camel/trunk/components/camel-velocity/src: main/java/org/apache/camel/component/velocity/VelocityEndpoint.java test/java/org/apache/camel/component/velocity/VelocityTemplateInHeaderTest.java

Author: davsclaus
Date: Wed Feb 17 15:55:51 2010
New Revision: 911028

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

Modified:
    camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
    camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTemplateInHeaderTest.java

Modified: camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java?rev=911028&r1=911027&r2=911028&view=diff
==============================================================================
--- camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java (original)
+++ camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java Wed Feb 17 15:55:51 2010
@@ -22,6 +22,7 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 
 import org.apache.camel.Exchange;
@@ -75,11 +76,11 @@
             // load the velocity properties from property file
             if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
                 Resource resource = getResourceLoader().getResource(getPropertiesFile());
-                InputStream reader = resource.getInputStream();               
+                InputStream reader = resource.getInputStream();
                 properties.load(reader);
                 log.info("Loaded the velocity configuration file " + getPropertiesFile());
             }
-            
+
             properties.setProperty(Velocity.FILE_RESOURCE_LOADER_CACHE, isLoaderCache() ? "true" : "false");
             properties.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, CommonsLogLogChute.class.getName());
             properties.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME, VelocityEndpoint.class.getName());
@@ -114,11 +115,11 @@
     public String getEncoding() {
         return encoding;
     }
-    
+
     public void setPropertiesFile(String file) {
         propertiesFile = file;
     }
-    
+
     public String getPropertiesFile() {
         return propertiesFile;
     }
@@ -186,11 +187,10 @@
         // now lets output the results to the exchange
         Message out = exchange.getOut();
         out.setBody(buffer.toString());
-       
+
         Map<String, Object> headers = (Map<String, Object>) velocityContext.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-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTemplateInHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTemplateInHeaderTest.java?rev=911028&r1=911027&r2=911028&view=diff
==============================================================================
--- camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTemplateInHeaderTest.java (original)
+++ camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTemplateInHeaderTest.java Wed Feb 17 15:55:51 2010
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.component.velocity;
 
+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,45 @@
 
     @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>");
     }
 
-    protected void assertRespondsWith(final String value, String expectedBody) throws InvalidPayloadException {
+    @Test
+    public void testRespectHeaderNamesUpperCase() throws Exception {
+        assertRespondsWith("Cheese", "bar", "<hello>bar</hello>");
+    }
+
+    @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(VelocityConstants.VELOCITY_TEMPLATE, "<hello>${headers.cheese}</hello>");
-                in.setHeader("cheese", value);
+                in.setHeader(VelocityConstants.VELOCITY_TEMPLATE, "<hello>${headers." + headerName + "}</hello>");
+                in.setHeader(headerName, headerValue);
             }
         });
         assertOutMessageBodyEquals(response, expectedBody);
 
         Object template = response.getOut().getHeader(VelocityConstants.VELOCITY_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() {