Author: davsclaus
Date: Sun Apr 29 09:28:24 2012
New Revision: 1331887
URL: http://svn.apache.org/viewvc?rev=1331887&view=rev
Log:
CAMEL-5232: Resource based endpoints with http resources now support query
parameters.
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyFreemarkerTest.java
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyVelocityTest.java
- copied, changed from r1331877,
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyXsltTest.java
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.ftl
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.vm
Modified:
camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
camel/trunk/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java
camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java
camel/trunk/tests/camel-itest/pom.xml
Modified:
camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java?rev=1331887&r1=1331886&r2=1331887&view=diff
==============================================================================
---
camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
(original)
+++
camel/trunk/components/camel-freemarker/src/main/java/org/apache/camel/component/freemarker/FreemarkerComponent.java
Sun Apr 29 09:28:24 2012
@@ -36,14 +36,9 @@ public class FreemarkerComponent extends
private Configuration noCacheConfiguration;
protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
- FreemarkerEndpoint endpoint = new FreemarkerEndpoint(uri, this,
remaining);
-
// should we use regular configuration or no cache (content cache is
default true)
Configuration config;
String encoding = getAndRemoveParameter(parameters, "encoding",
String.class);
- if (ObjectHelper.isNotEmpty(encoding)) {
- endpoint.setEncoding(encoding);
- }
boolean cache = getAndRemoveParameter(parameters, "contentCache",
Boolean.class, Boolean.TRUE);
if (cache) {
config = getConfiguration();
@@ -55,7 +50,18 @@ public class FreemarkerComponent extends
config = getNoCacheConfiguration();
}
+ FreemarkerEndpoint endpoint = new FreemarkerEndpoint(uri, this,
remaining);
+ if (ObjectHelper.isNotEmpty(encoding)) {
+ endpoint.setEncoding(encoding);
+ }
endpoint.setConfiguration(config);
+
+ // if its a http resource then append any remaining parameters and
update the resource uri
+ if (ResourceHelper.isHttpUri(remaining)) {
+ remaining = ResourceHelper.appendParameters(remaining, parameters);
+ endpoint.setResourceUri(remaining);
+ }
+
return endpoint;
}
Modified:
camel/trunk/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java?rev=1331887&r1=1331886&r2=1331887&view=diff
==============================================================================
---
camel/trunk/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java
(original)
+++
camel/trunk/components/camel-stringtemplate/src/main/java/org/apache/camel/component/stringtemplate/StringTemplateComponent.java
Sun Apr 29 09:28:24 2012
@@ -20,6 +20,7 @@ import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.ResourceHelper;
/**
* @version
@@ -27,8 +28,15 @@ import org.apache.camel.impl.DefaultComp
public class StringTemplateComponent extends DefaultComponent {
protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
- Endpoint answer = new StringTemplateEndpoint(uri, this, remaining);
+ StringTemplateEndpoint answer = new StringTemplateEndpoint(uri, this,
remaining);
setProperties(answer, parameters);
+
+ // if its a http resource then append any remaining parameters and
update the resource uri
+ if (ResourceHelper.isHttpUri(remaining)) {
+ remaining = ResourceHelper.appendParameters(remaining, parameters);
+ answer.setResourceUri(remaining);
+ }
+
return answer;
}
}
\ No newline at end of file
Modified:
camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java?rev=1331887&r1=1331886&r2=1331887&view=diff
==============================================================================
---
camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java
(original)
+++
camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java
Sun Apr 29 09:28:24 2012
@@ -21,6 +21,7 @@ import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResourceHelper;
import org.apache.velocity.app.VelocityEngine;
/**
@@ -40,7 +41,8 @@ public class VelocityComponent extends D
protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
String propertiesFile = getAndRemoveParameter(parameters,
"propertiesFile", String.class);
String encoding = getAndRemoveParameter(parameters, "encoding",
String.class);
- boolean cache = getAndRemoveParameter(parameters, "contentCache",
Boolean.class, Boolean.TRUE);
+ boolean cache = getAndRemoveParameter(parameters, "contentCache",
Boolean.class, Boolean.TRUE);
+
VelocityEndpoint answer = new VelocityEndpoint(uri, this, remaining);
answer.setContentCache(cache);
answer.setPropertiesFile(propertiesFile);
@@ -48,6 +50,13 @@ public class VelocityComponent extends D
answer.setEncoding(encoding);
}
answer.setVelocityEngine(velocityEngine);
+
+ // if its a http resource then append any remaining parameters and
update the resource uri
+ if (ResourceHelper.isHttpUri(remaining)) {
+ remaining = ResourceHelper.appendParameters(remaining, parameters);
+ answer.setResourceUri(remaining);
+ }
+
return answer;
}
}
Modified: camel/trunk/tests/camel-itest/pom.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/pom.xml?rev=1331887&r1=1331886&r2=1331887&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/pom.xml (original)
+++ camel/trunk/tests/camel-itest/pom.xml Sun Apr 29 09:28:24 2012
@@ -74,6 +74,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-freemarker</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-groovy</artifactId>
<scope>test</scope>
</dependency>
@@ -143,6 +148,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-velocity</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-mail</artifactId>
<scope>test</scope>
</dependency>
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyFreemarkerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyFreemarkerTest.java?rev=1331887&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyFreemarkerTest.java
(added)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyFreemarkerTest.java
Sun Apr 29 09:28:24 2012
@@ -0,0 +1,101 @@
+/**
+ * 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.itest.jetty;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResourceHelper;
+import org.junit.Test;
+
+public class JettyFreemarkerTest extends CamelTestSupport {
+
+ private int port;
+
+ @Test
+ public void testClasspath() throws Exception {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("firstName", "John");
+ map.put("lastName", "Doe");
+
+ String response =
template.requestBodyAndHeaders("freemarker:org/apache/camel/itest/jetty/header.ftl",
"", map, String.class);
+
+ assertEquals("Dear Doe, John", response);
+ }
+
+ @Test
+ public void testClasspathInvalidParameter() throws Exception {
+ try {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("firstName", "John");
+ map.put("lastName", "Doe");
+
+
template.requestBodyAndHeaders("freemarker:org/apache/camel/itest/jetty/?name=header.ftl",
"", map, String.class);
+ fail("Should have thrown exception");
+ } catch (ResolveEndpointFailedException e) {
+ assertTrue(e.getMessage().endsWith("Unknown
parameters=[{name=header.ftl}]"));
+ }
+ }
+
+ @Test
+ public void testHttp() throws Exception {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("firstName", "John");
+ map.put("lastName", "Doe");
+
+ String response =
template.requestBodyAndHeaders("freemarker://http://localhost:" + port +
"/test?name=header.ftl", "", map, String.class);
+
+ assertEquals("Dear Doe, John", response);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ port = AvailablePortFinder.getNextAvailable(8000);
+
+ return new RouteBuilder() {
+ public void configure() {
+ from("jetty:http://localhost:" + port + "/test")
+ .process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws
Exception {
+ String name = exchange.getIn().getHeader("name",
String.class);
+ ObjectHelper.notNull(name, "name");
+
+ // strip off the locale
+ name = ObjectHelper.before(name, "_");
+
+ name = "org/apache/camel/itest/jetty/" + name +
".ftl";
+ InputStream is =
ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(),
name);
+ String xml =
exchange.getContext().getTypeConverter().convertTo(String.class, is);
+
+ exchange.getOut().setBody(xml);
+ exchange.getOut().setHeader(Exchange.CONTENT_TYPE,
"text/plain");
+ }
+ });
+ }
+ };
+ }
+
+}
Copied:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyVelocityTest.java
(from r1331877,
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyXsltTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyVelocityTest.java?p2=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyVelocityTest.java&p1=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyXsltTest.java&r1=1331877&r2=1331887&rev=1331887&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyXsltTest.java
(original)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyVelocityTest.java
Sun Apr 29 09:28:24 2012
@@ -17,6 +17,8 @@
package org.apache.camel.itest.jetty;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
@@ -28,32 +30,44 @@ import org.apache.camel.util.ObjectHelpe
import org.apache.camel.util.ResourceHelper;
import org.junit.Test;
-public class JettyXsltTest extends CamelTestSupport {
+public class JettyVelocityTest extends CamelTestSupport {
private int port;
@Test
public void testClasspath() throws Exception {
- String response =
template.requestBody("xslt:org/apache/camel/itest/jetty/greeting.xsl",
"<hello>Camel</hello>", String.class);
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("firstName", "John");
+ map.put("lastName", "Doe");
- assertEquals("<?xml version=\"1.0\"
encoding=\"UTF-8\"?><goodbye>Camel</goodbye>", response);
+ String response =
template.requestBodyAndHeaders("velocity:org/apache/camel/itest/jetty/header.vm",
"", map, String.class);
+
+ assertEquals("Dear Doe, John", response);
}
@Test
public void testClasspathInvalidParameter() throws Exception {
try {
-
template.requestBody("xslt:org/apache/camel/itest/jetty/greeting.xsl?name=greeting.xsl",
"<hello>Camel</hello>", String.class);
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("firstName", "John");
+ map.put("lastName", "Doe");
+
+
template.requestBodyAndHeaders("velocity:org/apache/camel/itest/jetty/?name=header.vm",
"", map, String.class);
fail("Should have thrown exception");
} catch (ResolveEndpointFailedException e) {
- assertTrue(e.getMessage().endsWith("Unknown
parameters=[{name=greeting.xsl}]"));
+ assertTrue(e.getMessage().endsWith("Unknown
parameters=[{name=header.vm}]"));
}
}
@Test
public void testHttp() throws Exception {
- String response = template.requestBody("xslt://http://localhost:" +
port + "/test?name=greeting.xsl", "<hello>Camel</hello>", String.class);
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("firstName", "John");
+ map.put("lastName", "Doe");
+
+ String response =
template.requestBodyAndHeaders("velocity://http://localhost:" + port +
"/test?name=header.vm", "", map, String.class);
- assertEquals("<?xml version=\"1.0\"
encoding=\"UTF-8\"?><goodbye>Camel</goodbye>", response);
+ assertEquals("Dear Doe, John", response);
}
@Override
@@ -74,7 +88,7 @@ public class JettyXsltTest extends Camel
String xml =
exchange.getContext().getTypeConverter().convertTo(String.class, is);
exchange.getOut().setBody(xml);
- exchange.getOut().setHeader(Exchange.CONTENT_TYPE,
"text/xml");
+ exchange.getOut().setHeader(Exchange.CONTENT_TYPE,
"text/plain");
}
});
}
Added:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.ftl
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.ftl?rev=1331887&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.ftl
(added)
+++
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.ftl
Sun Apr 29 09:28:24 2012
@@ -0,0 +1,19 @@
+<#--
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+-->
+Dear ${headers.lastName}, ${headers.firstName}
\ No newline at end of file
Added:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.vm
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.vm?rev=1331887&view=auto
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.vm
(added)
+++
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/header.vm
Sun Apr 29 09:28:24 2012
@@ -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.
+## ------------------------------------------------------------------------
+Dear ${headers.lastName}, ${headers.firstName}
\ No newline at end of file