You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/12/20 09:01:34 UTC
[camel] 05/06: CAMEL-14303: Add spark-rest match on uri prefix fix.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 5dc41c43d71ef24cbeea6740edbf017e9537715d
Author: Bob Paulin <bo...@bobpaulin.com>
AuthorDate: Thu Dec 19 21:29:44 2019 -0600
CAMEL-14303: Add spark-rest match on uri prefix fix.
---
.../camel/component/sparkrest/SparkComponent.java | 17 +++++------------
.../org/apache/camel/support/RestComponentHelper.java | 16 ++++++++++++++++
2 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
index be537a4..868f484 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
@@ -31,6 +31,7 @@ import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.RestComponentHelper;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.HostUtils;
import org.apache.camel.util.ObjectHelper;
@@ -335,20 +336,12 @@ public class SparkComponent extends DefaultComponent implements RestConsumerFact
path = contextPath + "/" + path;
}
}
-
- String url;
+
if (api) {
- url = "spark-rest:%s:%s?matchOnUriPrefix=true";
- } else {
- url = "spark-rest:%s:%s";
- }
-
- url = String.format(url, verb, path);
+ map.put("matchOnUriPrefix", "true");
+ }
- String query = URISupport.createQueryString(map);
- if (!query.isEmpty()) {
- url = url + "?" + query;
- }
+ String url = RestComponentHelper.createRestConsumerUrl("spark-rest", verb, path, map);
// get the endpoint
SparkEndpoint endpoint = camelContext.getEndpoint(url, SparkEndpoint.class);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RestComponentHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/RestComponentHelper.java
index aa20d9a..8262b8c 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RestComponentHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RestComponentHelper.java
@@ -95,6 +95,22 @@ public final class RestComponentHelper {
* Creates the Rest consumers url based on component and url options.
*
* @param componentName the name of the rest component
+ * @param verb the HTTP verb
+ * @param path the HTTP path of the route
+ * @param queryMap the endpoint query options
+ * @return a string of the component route url
+ * @throws URISyntaxException - is thrown if uri has invalid syntax.
+ */
+ public static String createRestConsumerUrl(String componentName, String verb, String path, Map<String, Object> queryMap) throws URISyntaxException {
+ String query = URISupport.createQueryString(queryMap);
+ return applyFormatAndQuery("%s:%s:%s", query, componentName, verb, path);
+ }
+
+ /**
+ *
+ * Creates the Rest consumers url based on component and url options.
+ *
+ * @param componentName the name of the rest component
* @param path the HTTP path of the route
* @param queryMap the endpoint query options
* @return a string of the component route url