You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2017/03/01 17:27:01 UTC
camel git commit: CAMEL-10917 Implementations of RestProducerFact...
Repository: camel
Updated Branches:
refs/heads/master da87d1b9a -> b2bb23a2d
CAMEL-10917 Implementations of RestProducerFact...
...ory should handle empty or null basePath and uriTemplate
This changes the way resulting URI is computed taking into account that
either `basePath` or `uriTemplate` can be `null` or empty.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b2bb23a2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b2bb23a2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b2bb23a2
Branch: refs/heads/master
Commit: b2bb23a2d76395d5f139c6d21faa8c100fa4e8c7
Parents: da87d1b
Author: Zoran Regvart <zr...@apache.org>
Authored: Wed Mar 1 18:19:25 2017 +0100
Committer: Zoran Regvart <zr...@apache.org>
Committed: Wed Mar 1 18:20:36 2017 +0100
----------------------------------------------------------------------
.../org/apache/camel/component/rest/RestProducer.java | 12 +++++++-----
.../org/apache/camel/component/http/HttpComponent.java | 13 ++++++-------
.../apache/camel/component/http4/HttpComponent.java | 12 ++++++------
.../camel/component/jetty/JettyHttpComponent.java | 11 ++++++-----
.../component/netty4/http/NettyHttpComponent.java | 12 ++++++------
.../camel/component/restlet/RestletComponent.java | 12 +++++++-----
.../camel/component/undertow/UndertowComponent.java | 11 ++++++-----
7 files changed, 44 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b2bb23a2/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java
index ff44d97..eab1f3f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestProducer.java
@@ -36,6 +36,7 @@ import org.apache.camel.util.CollectionStringBuffer;
import org.apache.camel.util.EndpointHelper;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ServiceHelper;
import org.apache.camel.util.URISupport;
@@ -198,11 +199,12 @@ public class RestProducer extends DefaultAsyncProducer {
basePath = FileUtil.stripLeadingSeparator(basePath);
resolvedUriTemplate = FileUtil.stripLeadingSeparator(resolvedUriTemplate);
// if so us a header for the dynamic uri template so we reuse same endpoint but the header overrides the actual url to use
- String overrideUri;
- if (basePath != null) {
- overrideUri = String.format("%s/%s/%s", host, basePath, resolvedUriTemplate);
- } else {
- overrideUri = String.format("%s/%s", host, resolvedUriTemplate);
+ String overrideUri = host;
+ if (!ObjectHelper.isEmpty(basePath)) {
+ overrideUri += "/" + basePath;
+ }
+ if (!ObjectHelper.isEmpty(resolvedUriTemplate)) {
+ overrideUri += "/" + resolvedUriTemplate;
}
// the http uri for the rest call to be used
exchange.getIn().setHeader(Exchange.REST_HTTP_URI, overrideUri);
http://git-wip-us.apache.org/repos/asf/camel/blob/b2bb23a2/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
index e414070..b790277 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
@@ -296,13 +296,12 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
uriTemplate = FileUtil.stripLeadingSeparator(uriTemplate);
// get the endpoint
- String url;
- if (uriTemplate != null) {
- // http is already prefixed in base path
- url = String.format("%s/%s/%s", host, basePath, uriTemplate);
- } else {
- // http is already prefixed in base path
- url = String.format("%s/%s", host, basePath);
+ String url = host;
+ if (!ObjectHelper.isEmpty(basePath)) {
+ url += "/" + basePath;
+ }
+ if (!ObjectHelper.isEmpty(uriTemplate)) {
+ url += "/" + uriTemplate;
}
HttpEndpoint endpoint = camelContext.getEndpoint(url, HttpEndpoint.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/b2bb23a2/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
index f9101e1..9917976 100644
--- a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
+++ b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
@@ -379,12 +379,12 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
host = host.replace("http", "http4");
// get the endpoint
- String url;
- if (uriTemplate != null) {
-
- url = String.format("%s/%s/%s", host, basePath, uriTemplate);
- } else {
- url = String.format("%s/%s", host, basePath);
+ String url = host;
+ if (!ObjectHelper.isEmpty(basePath)) {
+ url += "/" + basePath;
+ }
+ if (!ObjectHelper.isEmpty(uriTemplate)) {
+ url += "/" + uriTemplate;
}
HttpEndpoint endpoint = camelContext.getEndpoint(url, HttpEndpoint.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/b2bb23a2/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index a16ddd2..2071e4a 100644
--- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -1185,11 +1185,12 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
uriTemplate = FileUtil.stripLeadingSeparator(uriTemplate);
// get the endpoint
- String url;
- if (uriTemplate != null) {
- url = String.format("jetty:%s/%s/%s", host, basePath, uriTemplate);
- } else {
- url = String.format("jetty:%s/%s", host, basePath);
+ String url = "jetty:" + host;
+ if (!ObjectHelper.isEmpty(basePath)) {
+ url += "/" + basePath;
+ }
+ if (!ObjectHelper.isEmpty(uriTemplate)) {
+ url += "/" + uriTemplate;
}
JettyHttpEndpoint endpoint = camelContext.getEndpoint(url, JettyHttpEndpoint.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/b2bb23a2/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
index d5d4ec2..dfa296d 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
@@ -402,13 +402,13 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
uriTemplate = FileUtil.stripLeadingSeparator(uriTemplate);
// get the endpoint
- String url;
- if (uriTemplate != null) {
- url = String.format("netty4-http:%s/%s/%s", host, basePath, uriTemplate);
- } else {
- url = String.format("netty4-http:%s/%s", host, basePath);
+ String url = "netty4-http:" + host;
+ if (!ObjectHelper.isEmpty(basePath)) {
+ url += "/" + basePath;
+ }
+ if (!ObjectHelper.isEmpty(uriTemplate)) {
+ url += "/" + uriTemplate;
}
-
NettyHttpEndpoint endpoint = camelContext.getEndpoint(url, NettyHttpEndpoint.class);
if (parameters != null && !parameters.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/b2bb23a2/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
index e7bd6f5..38a80c3 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
@@ -845,12 +845,14 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
String restletMethod = verb.toUpperCase(Locale.US);
// get the endpoint
- String url;
- if (uriTemplate != null) {
- url = String.format("restlet:%s/%s/%s?restletMethods=%s", host, basePath, uriTemplate, restletMethod);
- } else {
- url = String.format("restlet:%s/%s?restletMethods=%s", host, basePath, restletMethod);
+ String url = "restlet:" + host;
+ if (!ObjectHelper.isEmpty(basePath)) {
+ url += "/" + basePath;
+ }
+ if (!ObjectHelper.isEmpty(uriTemplate)) {
+ url += "/" + uriTemplate;
}
+ url += "?restletMethods=" + restletMethod;
RestletEndpoint endpoint = camelContext.getEndpoint(url, RestletEndpoint.class);
if (parameters != null && !parameters.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/b2bb23a2/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
index f9dc6ca..494d5ec 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
@@ -235,11 +235,12 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
uriTemplate = FileUtil.stripLeadingSeparator(uriTemplate);
// get the endpoint
- String url;
- if (uriTemplate != null) {
- url = String.format("undertow:%s/%s/%s", host, basePath, uriTemplate);
- } else {
- url = String.format("undertow:%s/%s", host, basePath);
+ String url = "undertow:" + host;
+ if (!ObjectHelper.isEmpty(basePath)) {
+ url += "/" + basePath;
+ }
+ if (!ObjectHelper.isEmpty(uriTemplate)) {
+ url += "/" + uriTemplate;
}
UndertowEndpoint endpoint = camelContext.getEndpoint(url, UndertowEndpoint.class);