You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/02/28 14:05:20 UTC
camel git commit: CAMEL-9655: rest-dsl - Default hostname should be
0.0.0.0 and ensure they all use it.
Repository: camel
Updated Branches:
refs/heads/master 14914c798 -> 0cb8d93aa
CAMEL-9655: rest-dsl - Default hostname should be 0.0.0.0 and ensure they all use it.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0cb8d93a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0cb8d93a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0cb8d93a
Branch: refs/heads/master
Commit: 0cb8d93aa6ab28dc638ec14409866fa0d7e58336
Parents: 14914c7
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 28 13:50:40 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 28 13:50:40 2016 +0100
----------------------------------------------------------------------
.../camel/component/rest/RestApiEndpoint.java | 4 +++-
.../camel/component/rest/RestEndpoint.java | 4 +++-
.../camel/model/rest/RestHostNameResolver.java | 2 +-
.../org/apache/camel/spi/RestConfiguration.java | 4 ++--
.../org/apache/camel/coap/CoAPComponent.java | 25 +++++++++++++++++---
.../component/jetty/JettyHttpComponent.java | 4 +++-
.../netty/http/NettyHttpComponent.java | 4 +++-
.../netty4/http/NettyHttpComponent.java | 4 +++-
.../component/restlet/RestletComponent.java | 4 +++-
.../component/sparkrest/SparkComponent.java | 21 ++++++++++++++--
.../component/undertow/UndertowComponent.java | 14 ++++++++++-
11 files changed, 75 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
index 113d9d4..eca625c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestApiEndpoint.java
@@ -172,7 +172,9 @@ public class RestApiEndpoint extends DefaultEndpoint {
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
- if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
host = HostUtils.getLocalHostName();
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
host = HostUtils.getLocalIp();
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index d2be1f2..e38ffec 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -269,7 +269,9 @@ public class RestEndpoint extends DefaultEndpoint {
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
- if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
host = HostUtils.getLocalHostName();
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
host = HostUtils.getLocalIp();
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/camel-core/src/main/java/org/apache/camel/model/rest/RestHostNameResolver.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestHostNameResolver.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestHostNameResolver.java
index b2551ba..7998854 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestHostNameResolver.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestHostNameResolver.java
@@ -29,6 +29,6 @@ import org.apache.camel.spi.Metadata;
@XmlEnum
public enum RestHostNameResolver {
- localIp, localHostName
+ allLocalIp, localIp, localHostName
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
index aec8453..e5f0f93 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
@@ -34,7 +34,7 @@ public class RestConfiguration {
}
public enum RestHostNameResolver {
- localIp, localHostName
+ allLocalIp, localIp, localHostName
}
private String component;
@@ -47,7 +47,7 @@ public class RestConfiguration {
private String apiContextRouteId;
private String apiContextIdPattern;
private boolean apiContextListing;
- private RestHostNameResolver restHostNameResolver = RestHostNameResolver.localHostName;
+ private RestHostNameResolver restHostNameResolver = RestHostNameResolver.allLocalIp;
private RestBindingMode bindingMode = RestBindingMode.off;
private boolean skipBindingOnErrorCode = true;
private boolean enableCORS;
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
index 32397f8..281d58b 100644
--- a/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
+++ b/components/camel-coap/src/main/java/org/apache/camel/coap/CoAPComponent.java
@@ -28,6 +28,8 @@ import org.apache.camel.Processor;
import org.apache.camel.impl.UriEndpointComponent;
import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
+import org.apache.camel.util.HostUtils;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
import org.eclipse.californium.core.CoapServer;
import org.eclipse.californium.core.network.config.NetworkConfig;
@@ -89,6 +91,18 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
config = getCamelContext().getRestConfiguration("coap", true);
}
+ String host = config.getHost();
+ if (ObjectHelper.isEmpty(host)) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ host = HostUtils.getLocalHostName();
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
+ host = HostUtils.getLocalIp();
+ }
+ }
+
+
Map<String, Object> map = new HashMap<String, Object>();
// setup endpoint options
if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
@@ -97,8 +111,7 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
String query = URISupport.createQueryString(map);
- String url = (config.getScheme() == null ? "coap" : config.getScheme())
- + "://" + config.getHost();
+ String url = (config.getScheme() == null ? "coap" : config.getScheme()) + "://" + host;
if (config.getPort() != -1) {
url += ":" + config.getPort();
}
@@ -113,7 +126,13 @@ public class CoAPComponent extends UriEndpointComponent implements RestConsumerF
CoAPEndpoint endpoint = camelContext.getEndpoint(url, CoAPEndpoint.class);
setProperties(endpoint, parameters);
- return endpoint.createConsumer(processor);
+
+ // configure consumer properties
+ Consumer consumer = endpoint.createConsumer(processor);
+ if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
+ setProperties(consumer, config.getConsumerProperties());
+ }
+ return consumer;
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/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 e3621a4..79110fc 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
@@ -1040,7 +1040,9 @@ public abstract class JettyHttpComponent extends HttpCommonComponent implements
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
- if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
host = HostUtils.getLocalHostName();
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
host = HostUtils.getLocalIp();
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
index b0a1b1e..6cf8474 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
@@ -317,7 +317,9 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
- if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
host = HostUtils.getLocalHostName();
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
host = HostUtils.getLocalIp();
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/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 fc15a25..081e2d0 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
@@ -324,7 +324,9 @@ public class NettyHttpComponent extends NettyComponent implements HeaderFilterSt
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
- if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
host = HostUtils.getLocalHostName();
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
host = HostUtils.getLocalIp();
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/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 6a09a41..8978cee 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
@@ -711,7 +711,9 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
- if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
host = HostUtils.getLocalHostName();
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
host = HostUtils.getLocalIp();
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
----------------------------------------------------------------------
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 10db4eb..1fdc957 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
@@ -30,6 +30,7 @@ import org.apache.camel.spi.RestApiConsumerFactory;
import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.HostUtils;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
@@ -216,8 +217,24 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
CamelSpark.port(port);
}
}
- if (getIpAddress() != null) {
- CamelSpark.ipAddress(getIpAddress());
+
+ String host = getIpAddress();
+ if (host != null) {
+ CamelSpark.ipAddress(host);
+ } else {
+ // if no explicit port configured, then use port from rest configuration
+ RestConfiguration config = getCamelContext().getRestConfiguration("spark-rest", true);
+ host = config.getHost();
+ if (ObjectHelper.isEmpty(host)) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ host = HostUtils.getLocalHostName();
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
+ host = HostUtils.getLocalIp();
+ }
+ }
+ CamelSpark.ipAddress(host);
}
if (keystoreFile != null || truststoreFile != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/0cb8d93a/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 3015559..1d93fd7 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
@@ -43,6 +43,7 @@ import org.apache.camel.spi.RestApiConsumerFactory;
import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.HostUtils;
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
@@ -129,7 +130,7 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
}
path = FileUtil.stripLeadingSeparator(path);
String scheme = "http";
- String host = "localhost";
+ String host = "";
int port = 0;
RestConfiguration config = configuration;
@@ -157,6 +158,17 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
}
}
+ // if no explicit hostname set then resolve the hostname
+ if (ObjectHelper.isEmpty(host)) {
+ if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
+ host = "0.0.0.0";
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
+ host = HostUtils.getLocalHostName();
+ } else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
+ host = HostUtils.getLocalIp();
+ }
+ }
+
Map<String, Object> map = new HashMap<String, Object>();
// build query string, and append any endpoint configuration properties
if (config.getComponent() == null || config.getComponent().equals("undertow")) {