Author: ningjiang
Date: Tue Jun 17 19:42:17 2008
New Revision: 669059
URL: http://svn.apache.org/viewvc?rev=669059&view=rev
Log:
CAMEL-615 patch applied with thanks to Stephen
Added:
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/FruitFilter.java
(with props)
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySetHeaderTest.java
(with props)
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/AppleTemplate.vm
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/OrangeTemplate.vm
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml
(with props)
Modified:
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
Modified:
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java?rev=669059&r1=669058&r2=669059&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
(original)
+++
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
Tue Jun 17 19:42:17 2008
@@ -84,6 +84,7 @@
this.loaderCache = loaderCache;
}
+ @SuppressWarnings("unchecked")
@Override
protected void onExchange(Exchange exchange) throws Exception {
Resource resource = getResource();
@@ -106,6 +107,10 @@
Message out = exchange.getOut(true);
out.setBody(buffer.toString());
out.setHeader("org.apache.camel.velocity.resource", resource);
+ Map<String, Object> headers = (Map<String,
Object>)velocityContext.get("headers");
+ for (String key : headers.keySet()) {
+ out.setHeader(key, headers.get(key));
+ }
}
-
+
}
Added:
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/FruitFilter.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/FruitFilter.java?rev=669059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/FruitFilter.java
(added)
+++
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/FruitFilter.java
Tue Jun 17 19:42:17 2008
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.velocity;
+
+public class FruitFilter {
+
+ public boolean isApple(String body) {
+ return "apple".equalsIgnoreCase(body);
+ }
+
+ public boolean isOrange(String body) {
+ return "orange".equalsIgnoreCase(body);
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/FruitFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/FruitFilter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySetHeaderTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySetHeaderTest.java?rev=669059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySetHeaderTest.java
(added)
+++
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySetHeaderTest.java
Tue Jun 17 19:42:17 2008
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.velocity;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class VelocitySetHeaderTest extends SpringTestSupport {
+ public void testSendingApple() throws Exception {
+ assertRespondsWith("apple", "I am an apple");
+ }
+
+ public void testSendingOrgane() throws Exception {
+ assertRespondsWith("orange", "I am an orange");
+ }
+
+ protected void assertRespondsWith(final String value, String expectedBody)
throws InvalidPayloadException, InterruptedException {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.expectedHeaderReceived("fruit", value);
+ mock.expectedBodiesReceived(expectedBody);
+ template.request("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ in.setBody(value);
+
+ }
+ });
+ mock.assertIsSatisfied();
+ }
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/component/velocity/camel-context.xml");
+ }
+
+
+}
\ No newline at end of file
Propchange:
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySetHeaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySetHeaderTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/AppleTemplate.vm
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/AppleTemplate.vm?rev=669059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/AppleTemplate.vm
(added)
+++
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/AppleTemplate.vm
Tue Jun 17 19:42:17 2008
@@ -0,0 +1,17 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ------------------------------------------------------------------------
+$in.setHeader('fruit', 'apple')I am an $body
\ No newline at end of file
Added:
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/OrangeTemplate.vm
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/OrangeTemplate.vm?rev=669059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/OrangeTemplate.vm
(added)
+++
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/OrangeTemplate.vm
Tue Jun 17 19:42:17 2008
@@ -0,0 +1,17 @@
+## ------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ------------------------------------------------------------------------
+$in.setHeader('fruit', 'orange')I am an $body
\ No newline at end of file
Added:
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml?rev=669059&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml
(added)
+++
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml
Tue Jun 17 19:42:17 2008
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
+
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <filter>
+ <methodCall bean="fruitFilter" method="isApple"/>
+ <to
uri="velocity:org/apache/camel/component/velocity/AppleTemplate.vm" />
+ <to uri="mock:result" />
+ </filter>
+ <filter>
+ <methodCall bean="fruitFilter" method="isOrange"/>
+ <to
uri="velocity:org/apache/camel/component/velocity/OrangeTemplate.vm" />
+ <to uri="mock:result" />
+ </filter>
+ </route>
+ </camelContext>
+
+ <bean id="fruitFilter"
class="org.apache.camel.component.velocity.FruitFilter"/>
+
+</beans>
\ No newline at end of file
Propchange:
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/camel-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml