camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1228606 - in /camel/branches/camel-2.9.x/components: camel-freemarker/src/main/java/org/apache/camel/component/freemarker/ camel-freemarker/src/test/java/org/apache/camel/component/freemarker/ camel-freemarker/src/test/resources/org/apache...
Date Sat, 07 Jan 2012 12:37:19 GMT
Author: cmueller
Date: Sat Jan  7 12:37:18 2012
New Revision: 1228606

URL: http://svn.apache.org/viewvc?rev=1228606&view=rev
Log:
CAMEL-4870: Attachments is not propagated in the template components such as camel-stringtemplate

Removed:
    camel/branches/camel-2.9.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerHeaderSetTemplateTest.java
    camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateOutHeaderTest.java
Modified:
    camel/branches/camel-2.9.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
    camel/branches/camel-2.9.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTest.java
    camel/branches/camel-2.9.x/components/camel-freemarker/src/test/resources/org/apache/camel/component/freemarker/example.ftl
    camel/branches/camel-2.9.x/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
    camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java
    camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/template.tm
    camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
    camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
    camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm

Modified: camel/branches/camel-2.9.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerEndpoint.java
Sat Jan  7 12:37:18 2012
@@ -20,7 +20,6 @@ import java.io.Reader;
 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;
@@ -96,7 +95,6 @@ public class FreemarkerEndpoint extends 
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     protected void onExchange(Exchange exchange) throws Exception {
         String path = getResourceUri();
         ObjectHelper.notNull(configuration, "configuration");
@@ -121,7 +119,7 @@ public class FreemarkerEndpoint extends 
             exchange.getIn().removeHeader(FreemarkerConstants.FREEMARKER_TEMPLATE);
         }
 
-        Map variableMap = ExchangeHelper.createVariableMap(exchange);
+        Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);
         // let freemarker parse and generate the result in buffer
         Template template;
 
@@ -143,9 +141,7 @@ public class FreemarkerEndpoint extends 
         // now lets output the results to the exchange
         Message out = exchange.getOut();
         out.setBody(buffer.toString());
-        Map<String, Object> headers = (Map<String, Object>) variableMap.get("headers");
-        for (Entry<String, Object> entry : headers.entrySet()) {
-            out.setHeader(entry.getKey(), entry.getValue());
-        }
+        out.setHeaders(exchange.getIn().getHeaders());
+        out.setAttachments(exchange.getIn().getAttachments());
     }
 }
\ No newline at end of file

Modified: camel/branches/camel-2.9.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTest.java?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-freemarker/src/test/java/org/apache/camel/component/freemarker/FreemarkerTest.java
Sat Jan  7 12:37:18 2012
@@ -16,8 +16,9 @@
  */
 package org.apache.camel.component.freemarker;
 
+import javax.activation.DataHandler;
+
 import org.apache.camel.Exchange;
-import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
@@ -29,24 +30,21 @@ import org.junit.Test;
 public class FreemarkerTest extends CamelTestSupport {
 
     @Test
-    public void testReceivesFooResponse() throws Exception {
-        assertRespondsWith("foo", "<hello>foo</hello>");
-    }
-
-    @Test
-    public void testReceivesBarResponse() throws Exception {
-        assertRespondsWith("bar", "<hello>bar</hello>");
-    }
-
-    protected void assertRespondsWith(final String value, String expectedBody) throws Exception
{
-        Exchange response = template.request("direct:a", new Processor() {
+    public void testVelocityLetter() throws Exception {
+        final DataHandler dataHandler = new DataHandler("my attachment", "text/plain");
+        Exchange exchange = template.request("direct:a", new Processor() {
+            @Override
             public void process(Exchange exchange) throws Exception {
-                Message in = exchange.getIn();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
+                exchange.getIn().addAttachment("item", dataHandler);
+                exchange.getIn().setBody("Monday");
+                exchange.getIn().setHeader("name", "Christian");
+                exchange.setProperty("item", "7");
             }
         });
-        assertOutMessageBodyEquals(response, expectedBody);
+
+        assertEquals("Dear Christian. You ordered item 7 on Monday.", exchange.getOut().getBody());
+        assertEquals("Christian", exchange.getOut().getHeader("name"));
+        assertSame(dataHandler, exchange.getOut().getAttachment("item"));
     }
 
     protected RouteBuilder createRouteBuilder() {

Modified: camel/branches/camel-2.9.x/components/camel-freemarker/src/test/resources/org/apache/camel/component/freemarker/example.ftl
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-freemarker/src/test/resources/org/apache/camel/component/freemarker/example.ftl?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-freemarker/src/test/resources/org/apache/camel/component/freemarker/example.ftl
(original)
+++ camel/branches/camel-2.9.x/components/camel-freemarker/src/test/resources/org/apache/camel/component/freemarker/example.ftl
Sat Jan  7 12:37:18 2012
@@ -16,4 +16,4 @@
 ## limitations under the License.
 ## ------------------------------------------------------------------------
 -->
-<hello>${headers.cheese}</hello>
\ No newline at end of file
+Dear ${headers.name}. You ordered item ${exchange.properties.item} on ${body}.
\ No newline at end of file

Modified: camel/branches/camel-2.9.x/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateEndpoint.java
Sat Jan  7 12:37:18 2012
@@ -18,7 +18,6 @@ package org.apache.camel.component.strin
 
 import java.io.StringWriter;
 import java.util.Map;
-import java.util.Map.Entry;
 
 import org.antlr.stringtemplate.AutoIndentWriter;
 import org.antlr.stringtemplate.StringTemplate;
@@ -52,7 +51,6 @@ public class StringTemplateEndpoint exte
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     protected void onExchange(Exchange exchange) throws Exception {
         StringWriter buffer = new StringWriter();
         Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);
@@ -67,10 +65,8 @@ public class StringTemplateEndpoint exte
         // now lets output the results to the exchange
         Message out = exchange.getOut();
         out.setBody(buffer.toString());
+        out.setHeaders(exchange.getIn().getHeaders());
         out.setHeader(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI, getResourceUri());
-        Map<String, Object> headers = (Map<String, Object>) variableMap.get("headers");
-        for (Entry<String, Object> entry : headers.entrySet()) {
-            out.setHeader(entry.getKey(), entry.getValue());
-        }
+        out.setAttachments(exchange.getIn().getAttachments());
     }
 }
\ No newline at end of file

Modified: camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/java/org/apache/camel/component/stringtemplate/StringTemplateTest.java
Sat Jan  7 12:37:18 2012
@@ -16,38 +16,33 @@
  */
 package org.apache.camel.component.stringtemplate;
 
+import javax.activation.DataHandler;
+
 import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-/**
- * @version 
- */
 public class StringTemplateTest extends CamelTestSupport {
-
-    @Test
-    public void testReceivesFooResponse() throws Exception {
-        assertRespondsWith("foo", "<hello>foo</hello>");
-    }
-
+    
     @Test
-    public void testReceivesBarResponse() throws Exception {
-        assertRespondsWith("bar", "<hello>bar</hello>");
-    }
-
-    protected void assertRespondsWith(final String value, String expectedBody) throws InvalidPayloadException
{
+    public void test() throws Exception {
+        final DataHandler dataHandler = new DataHandler("my attachment", "text/plain");
+        
         Exchange response = template.request("direct:a", new Processor() {
             public void process(Exchange exchange) throws Exception {
-                Message in = exchange.getIn();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
+                exchange.getIn().addAttachment("item", dataHandler);
+                exchange.getIn().setBody("Monday");
+                exchange.getIn().setHeader("name", "Christian");
+                exchange.setProperty("item", "7");
             }
         });
-        assertOutMessageBodyEquals(response, expectedBody);
+        
+        assertEquals("Dear Christian. You ordered item 7 on Monday.", response.getOut().getBody());
+        assertEquals("org/apache/camel/component/stringtemplate/template.tm", response.getOut().getHeader(StringTemplateConstants.STRINGTEMPLATE_RESOURCE_URI));
+        assertEquals("Christian", response.getOut().getHeader("name"));
+        assertSame(dataHandler, response.getOut().getAttachment("item"));
     }
 
     protected RouteBuilder createRouteBuilder() {

Modified: camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/template.tm
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/template.tm?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/template.tm
(original)
+++ camel/branches/camel-2.9.x/components/camel-stringtemplate/src/test/resources/org/apache/camel/component/stringtemplate/template.tm
Sat Jan  7 12:37:18 2012
@@ -14,4 +14,4 @@ $!--------------------------------------
  See the License for the specific language governing permissions and
  limitations under the License.
  ------------------------------------------------------------------------
-!$<hello>$headers.cheese$</hello>
\ No newline at end of file
+!$Dear $headers.name$. You ordered item $exchange.properties.item$ on $body$.
\ No newline at end of file

Modified: camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
Sat Jan  7 12:37:18 2012
@@ -22,7 +22,6 @@ import java.io.Reader;
 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;
@@ -39,10 +38,8 @@ import org.apache.velocity.app.VelocityE
 import org.apache.velocity.context.Context;
 import org.apache.velocity.runtime.log.CommonsLogLogChute;
 
-/**
- * @version 
- */
 public class VelocityEndpoint extends ResourceEndpoint {
+    
     private VelocityEngine velocityEngine;
     private boolean loaderCache = true;
     private String encoding;
@@ -150,7 +147,6 @@ public class VelocityEndpoint extends Re
         return getCamelContext().getEndpoint(newUri, VelocityEndpoint.class);
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     protected void onExchange(Exchange exchange) throws Exception {
         String path = getResourceUri();
@@ -186,7 +182,7 @@ public class VelocityEndpoint extends Re
         // getResourceAsInputStream also considers the content cache
         StringWriter buffer = new StringWriter();
         String logTag = getClass().getName();
-        Map variableMap = ExchangeHelper.createVariableMap(exchange);
+        Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange);
         Context velocityContext = new VelocityContext(variableMap);
 
         // let velocity parse and generate the result in buffer
@@ -197,11 +193,7 @@ public class VelocityEndpoint extends Re
         // 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 (Entry<String, Object> entry : headers.entrySet()) {
-            out.setHeader(entry.getKey(), entry.getValue());
-        }
+        out.setHeaders(exchange.getIn().getHeaders());
+        out.setAttachments(exchange.getIn().getAttachments());
     }
-
 }
\ No newline at end of file

Modified: camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
Sat Jan  7 12:37:18 2012
@@ -16,37 +16,32 @@
  */
 package org.apache.camel.component.velocity;
 
+import javax.activation.DataHandler;
+
 import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
-import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-/**
- * @version 
- */
 public class VelocityTest extends CamelTestSupport {
+    
     @Test
-    public void testReceivesFooResponse() throws Exception {
-        assertRespondsWith("foo", "<hello>foo</hello>");
-    }
-
-    @Test
-    public void testReceivesBarResponse() throws Exception {
-        assertRespondsWith("bar", "<hello>bar</hello>");
-    }
-
-    protected void assertRespondsWith(final String value, String expectedBody) throws InvalidPayloadException
{
-        Exchange response = template.request("direct:a", new Processor() {
+    public void testVelocityLetter() throws Exception {
+        final DataHandler dataHandler = new DataHandler("my attachment", "text/plain");
+        Exchange exchange = template.request("direct:a", new Processor() {
+            @Override
             public void process(Exchange exchange) throws Exception {
-                Message in = exchange.getIn();
-                in.setBody("answer");
-                in.setHeader("cheese", value);
+                exchange.getIn().addAttachment("item", dataHandler);
+                exchange.getIn().setBody("Monday");
+                exchange.getIn().setHeader("name", "Christian");
+                exchange.setProperty("item", "7");
             }
         });
-        assertOutMessageBodyEquals(response, expectedBody);
+
+        assertEquals("Dear Christian. You ordered item 7 on Monday.", exchange.getOut().getBody());
+        assertEquals("Christian", exchange.getOut().getHeader("name"));
+        assertSame(dataHandler, exchange.getOut().getAttachment("item"));
     }
 
     protected RouteBuilder createRouteBuilder() {

Modified: camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm?rev=1228606&r1=1228605&r2=1228606&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm
(original)
+++ camel/branches/camel-2.9.x/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm
Sat Jan  7 12:37:18 2012
@@ -14,4 +14,4 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ------------------------------------------------------------------------
-<hello>${headers.cheese}</hello>
\ No newline at end of file
+Dear ${headers.name}. You ordered item ${exchange.properties.item} on ${body}.
\ No newline at end of file



Mime
View raw message