This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit b8fe9ed8f2c1d7ff2d9a4430c1433e69ddb6128d
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Wed Mar 7 13:22:05 2018 +0100

    CAMEL-12115: Camel-Consul: Upgrade to 1.0.0 consul client
---
 .../src/main/docs/consul-component.adoc            |  9 ++---
 .../consul/ConsulClientConfiguration.java          |  2 +-
 .../camel/component/consul/ConsulRegistry.java     | 44 +++++++++++-----------
 .../consul/cluster/ConsulClusterView.java          | 16 +++-----
 .../consul/endpoint/ConsulEventConsumer.java       |  2 +-
 .../consul/endpoint/ConsulKeyValueConsumer.java    |  8 ++--
 .../consul/endpoint/ConsulKeyValueProducer.java    |  4 +-
 .../consul/endpoint/ConsulSessionProducer.java     |  4 +-
 .../consul/health/ConsulHealthCheckRepository.java |  4 +-
 .../component/consul/policy/ConsulRoutePolicy.java |  2 +-
 .../camel/component/consul/ConsulKeyValueTest.java |  3 +-
 parent/pom.xml                                     |  4 +-
 .../springboot/ConsulComponentConfiguration.java   |  5 +--
 13 files changed, 50 insertions(+), 57 deletions(-)

diff --git a/components/camel-consul/src/main/docs/consul-component.adoc 
b/components/camel-consul/src/main/docs/consul-component.adoc
index 8009fc1..b1de011 100644
--- a/components/camel-consul/src/main/docs/consul-component.adoc
+++ b/components/camel-consul/src/main/docs/consul-component.adoc
@@ -71,24 +71,21 @@ with the following path and query parameters:
 
 ==== Path Parameters (1 parameters):
 
-
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
 | *apiEndpoint* | *Required* The API endpoint |  | String
 |===
 
-
 ==== Query Parameters (4 parameters):
 
-
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the 
Camel routing Error Handler, which mean any exceptions occurred while the 
consumer is trying to pickup incoming messages, or the likes, will now be 
processed as a message and handled by the routing Error Handler. By default the 
consumer will use the org.apache.camel.spi.ExceptionHandler to deal with 
exceptions, that will be logged at WARN or ERROR level and ignored. | false | 
boolean
-| *exceptionHandler* (consumer) | To let the consumer use a custom 
ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this 
options is not in use. By default the consumer will deal with exceptions, that 
will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
+| *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the 
Camel routing Error Handler which mean any exceptions occurred while the 
consumer is trying to pickup incoming messages or the likes will now be 
processed as a message and handled by the routing Error Handler. By default the 
consumer will use the org.apache.camel.spi.ExceptionHandler to deal with 
exceptions that will be logged at WARN or ERROR level and ignored. | false | 
boolean
+| *exceptionHandler* (consumer) | To let the consumer use a custom 
ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this 
options is not in use. By default the consumer will deal with exceptions that 
will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer 
creates an exchange. |  | ExchangePattern
-| *synchronous* (advanced) | Sets whether synchronous processing should be 
strictly used, or Camel is allowed to use asynchronous processing (if 
supported). | false | boolean
+| *synchronous* (advanced) | Sets whether synchronous processing should be 
strictly used or Camel is allowed to use asynchronous processing (if 
supported). | false | boolean
 |===
 // endpoint options: END
 
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
index ab893da..aa5e4d7 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
@@ -67,7 +67,7 @@ public class ConsulClientConfiguration implements Cloneable {
     @UriParam(label = "consumer,watch", defaultValue = "10")
     private Integer blockSeconds = 10;
     @UriParam(label = "consumer,watch", defaultValue = "0")
-    private BigInteger firstIndex;
+    private BigInteger firstIndex = BigInteger.valueOf(0L);
     @UriParam(label = "consumer,watch", defaultValue = "false")
     private boolean recursive;
 
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
index 1486fe5..7c7bab1 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulRegistry.java
@@ -31,15 +31,12 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
-import com.google.common.base.Optional;
-import com.google.common.net.HostAndPort;
 import com.orbitz.consul.Consul;
 import com.orbitz.consul.ConsulException;
 import com.orbitz.consul.KeyValueClient;
 import com.orbitz.consul.SessionClient;
 import com.orbitz.consul.model.session.ImmutableSession;
 import com.orbitz.consul.model.session.SessionCreatedResponse;
-
 import org.apache.camel.NoSuchBeanException;
 import org.apache.camel.spi.Registry;
 
@@ -64,16 +61,14 @@ public class ConsulRegistry implements Registry {
         super();
         this.hostname = hostname;
         this.port = port;
-        HostAndPort hostAndPort = HostAndPort.fromParts(hostname, port);
-        this.consul = Consul.builder().withHostAndPort(hostAndPort).build();
+        this.consul = Consul.builder().withUrl("http://"; + this.hostname + ":" 
+ this.port).build();
     }
 
     /* builder pattern */
     private ConsulRegistry(Builder builder) {
         this.hostname = builder.hostname;
         this.port = builder.port;
-        HostAndPort hostAndPort = HostAndPort.fromParts(hostname, port);
-        this.consul = Consul.builder().withHostAndPort(hostAndPort).build();
+        this.consul = Consul.builder().withUrl("http://"; + this.hostname + ":" 
+ this.port).build();
     }
 
     @Override
@@ -81,12 +76,13 @@ public class ConsulRegistry implements Registry {
         // Substitute $ character in key
         key = key.replaceAll("\\$", "/");
         kvClient = consul.keyValueClient();
-        Optional<String> result = kvClient.getValueAsString(key);
-        if (result.isPresent()) {
-            byte[] postDecodedValue = 
ConsulRegistryUtils.decodeBase64(result.get());
-            return ConsulRegistryUtils.deserialize(postDecodedValue);
-        }
-        return null;
+
+        return kvClient.getValueAsString(key).map(
+            result -> {
+                byte[] postDecodedValue = 
ConsulRegistryUtils.decodeBase64(result);
+                return ConsulRegistryUtils.deserialize(postDecodedValue);
+            }
+        ).orElse(null);
     }
 
     @Override
@@ -106,18 +102,21 @@ public class ConsulRegistry implements Registry {
 
     @Override
     public <T> Map<String, T> findByTypeWithName(Class<T> type) {
-        Object obj = null;
-        Map<String, T> result = new HashMap<String, T>();
+        Map<String, T> result = new HashMap<>();
         // encode $ signs as they occur in subclass types
         String keyPrefix = type.getName().replaceAll("\\$", "/");
         kvClient = consul.keyValueClient();
+
         List<String> keys;
         try {
             keys = kvClient.getKeys(keyPrefix);
         } catch (ConsulException e) {
             return result;
         }
+
         if (keys != null) {
+            Object obj;
+
             for (String key : keys) {
                 // change bookmark back into actual key
                 key = key.substring(key.lastIndexOf('/') + 1);
@@ -133,21 +132,24 @@ public class ConsulRegistry implements Registry {
     @Override
     public <T> Set<T> findByType(Class<T> type) {
         String keyPrefix = type.getName().replaceAll("\\$", "/");
-        Object object = null;
-        Set<T> result = new HashSet<T>();
-        List<String> keys = null;
+        Set<T> result = new HashSet<>();
+
+        List<String> keys;
         try {
             keys = kvClient.getKeys(keyPrefix);
         } catch (ConsulException e) {
             return result;
         }
+
         if (keys != null) {
+            Object obj;
+
             for (String key : keys) {
                 // change bookmark back into actual key
                 key = key.substring(key.lastIndexOf('/') + 1);
-                object = lookupByName(key.replaceAll("\\$", "/"));
-                if (type.isInstance(object)) {
-                    result.add(type.cast(object));
+                obj = lookupByName(key.replaceAll("\\$", "/"));
+                if (type.isInstance(obj)) {
+                    result.add(type.cast(obj));
                 }
             }
         }
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java
index 74d0b35..bfd6dfd 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/cluster/ConsulClusterView.java
@@ -68,11 +68,7 @@ final class ConsulClusterView extends 
AbstractCamelClusterView {
             return Optional.empty();
         }
 
-        return Optional.ofNullable(
-            keyValueClient.getSession(configuration.getRootPath())
-                .transform(ConsulClusterMember::new)
-                .orNull()
-        );
+        return 
keyValueClient.getSession(configuration.getRootPath()).map(ConsulClusterMember::new);
     }
 
     @Override
@@ -137,7 +133,7 @@ final class ConsulClusterView extends 
AbstractCamelClusterView {
             String sid = sessionId.get();
 
             return (sid != null)
-                ? sessionClient.getSessionInfo(sid).transform(si -> 
keyValueClient.acquireLock(path, sid)).or(Boolean.FALSE)
+                ? sessionClient.getSessionInfo(sid).map(si -> 
keyValueClient.acquireLock(path, sid)).orElse(Boolean.FALSE)
                 : false;
         }
     }
@@ -238,7 +234,7 @@ final class ConsulClusterView extends 
AbstractCamelClusterView {
     // Watch
     // 
*************************************************************************
 
-    private class Watcher implements 
ConsulResponseCallback<com.google.common.base.Optional<Value>> {
+    private class Watcher implements ConsulResponseCallback<Optional<Value>> {
         private final AtomicReference<BigInteger> index;
 
         public Watcher() {
@@ -246,11 +242,11 @@ final class ConsulClusterView extends 
AbstractCamelClusterView {
         }
 
         @Override
-        public void 
onComplete(ConsulResponse<com.google.common.base.Optional<Value>> 
consulResponse) {
+        public void onComplete(ConsulResponse<Optional<Value>> consulResponse) 
{
             if (isStarting() || isStarted()) {
-                com.google.common.base.Optional<Value> value = 
consulResponse.getResponse();
+                Optional<Value> value = consulResponse.getResponse();
                 if (value.isPresent()) {
-                    com.google.common.base.Optional<String> sid = 
value.get().getSession();
+                    Optional<String> sid = value.get().getSession();
                     if (!sid.isPresent()) {
                         // If the key is not held by any session, try acquire a
                         // lock (become leader)
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
index 3432716..2e8a141 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulEventConsumer.java
@@ -99,7 +99,7 @@ public final class ConsulEventConsumer extends 
AbstractConsulConsumer<EventClien
                 message.setHeader(ConsulConstants.CONSUL_TAG_FILTER, 
event.getTagFilter().get());
             }
 
-            message.setBody(event.getPayload().orNull());
+            message.setBody(event.getPayload().orElse(null));
 
             try {
                 getProcessor().process(exchange);
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueConsumer.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueConsumer.java
index 9e5b3ee..822a73e 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueConsumer.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueConsumer.java
@@ -17,8 +17,8 @@
 package org.apache.camel.component.consul.endpoint;
 
 import java.util.List;
+import java.util.Optional;
 
-import com.google.common.base.Optional;
 import com.orbitz.consul.Consul;
 import com.orbitz.consul.KeyValueClient;
 import com.orbitz.consul.async.ConsulResponseCallback;
@@ -85,7 +85,7 @@ public final class ConsulKeyValueConsumer extends 
AbstractConsulConsumer<KeyValu
                 message.setHeader(ConsulConstants.CONSUL_SESSION, 
value.getSession().get());
             }
 
-            message.setBody(configuration.isValueAsString() ? 
value.getValueAsString().orNull() : value.getValue().orNull());
+            message.setBody(configuration.isValueAsString() ? 
value.getValueAsString().orElse(null) : value.getValue().orElse(null));
 
             try {
                 getProcessor().process(exchange);
@@ -109,9 +109,7 @@ public final class ConsulKeyValueConsumer extends 
AbstractConsulConsumer<KeyValu
 
         @Override
         public void onResponse(Optional<Value> value) {
-            if (value.isPresent()) {
-                onValue(value.get());
-            }
+            value.ifPresent(this::onValue);
         }
     }
 
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueProducer.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueProducer.java
index e74f8fe..615f33e 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueProducer.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulKeyValueProducer.java
@@ -53,12 +53,12 @@ public final class ConsulKeyValueProducer extends 
AbstractConsulProducer<KeyValu
         if (asString) {
             result = getClient().getValueAsString(
                 getMandatoryHeader(message, ConsulConstants.CONSUL_KEY, 
getConfiguration().getKey(), String.class)
-            ).orNull();
+            ).orElse(null);
         } else {
             result = getClient().getValue(
                 getMandatoryHeader(message, ConsulConstants.CONSUL_KEY, 
getConfiguration().getKey(), String.class),
                 message.getHeader(ConsulConstants.CONSUL_OPTIONS, 
QueryOptions.BLANK, QueryOptions.class)
-            ).orNull();
+            ).orElse(null);
         }
 
         setBodyAndResult(message, result);
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulSessionProducer.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulSessionProducer.java
index 37315f0..b0da064 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulSessionProducer.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/endpoint/ConsulSessionProducer.java
@@ -72,7 +72,7 @@ public final class ConsulSessionProducer extends 
AbstractConsulProducer<SessionC
                 getClient().getSessionInfo(
                     message.getMandatoryBody(String.class),
                     message.getHeader(ConsulConstants.CONSUL_DATACENTER, 
String.class)
-                ).orNull()
+                ).orElse(null)
             );
         } else {
             setBodyAndResult(
@@ -80,7 +80,7 @@ public final class ConsulSessionProducer extends 
AbstractConsulProducer<SessionC
                 getClient().getSessionInfo(
                     sessionId,
                     message.getHeader(ConsulConstants.CONSUL_DATACENTER, 
String.class)
-                ).orNull()
+                ).orElse(null)
             );
         }
     }
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/health/ConsulHealthCheckRepository.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/health/ConsulHealthCheckRepository.java
index e7ca18a..96dd3c0 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/health/ConsulHealthCheckRepository.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/health/ConsulHealthCheckRepository.java
@@ -151,8 +151,8 @@ public class ConsulHealthCheckRepository implements 
HealthCheckRepository, Camel
                     builder.down();
                 }
 
-                builder.detail("consul.service.name", 
check.getServiceName().orNull());
-                builder.detail("consul.service.id", 
check.getServiceId().orNull());
+                builder.detail("consul.service.name", 
check.getServiceName().orElse(null));
+                builder.detail("consul.service.id", 
check.getServiceId().orElse(null));
                 builder.detail("consul.check.status", check.getStatus());
                 builder.detail("consul.check.id", check.getCheckId());
             }
diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
index a18f42f..ee6e3bb 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
@@ -18,12 +18,12 @@ package org.apache.camel.component.consul.policy;
 
 import java.math.BigInteger;
 import java.util.HashSet;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
-import com.google.common.base.Optional;
 import com.orbitz.consul.Consul;
 import com.orbitz.consul.KeyValueClient;
 import com.orbitz.consul.SessionClient;
diff --git 
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulKeyValueTest.java
 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulKeyValueTest.java
index 13d2576..a0e4f05 100644
--- 
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulKeyValueTest.java
+++ 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulKeyValueTest.java
@@ -16,7 +16,8 @@
  */
 package org.apache.camel.component.consul;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
+
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.consul.endpoint.ConsulKeyValueActions;
 import org.apache.camel.component.mock.MockEndpoint;
diff --git a/parent/pom.xml b/parent/pom.xml
index cb721fa..c368783 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -168,8 +168,8 @@
     <commons-text-version>1.2</commons-text-version>
     <commons-vfs2-version>2.0</commons-vfs2-version>
     <compress-lzf-version>1.0.4</compress-lzf-version>
-    <consul-client-version>0.16.3</consul-client-version>
-    <consul-client-bundle-version>0.16.2_1</consul-client-bundle-version>
+    <consul-client-version>1.0.0</consul-client-version>
+    <consul-client-bundle-version>1.0.0_1</consul-client-bundle-version>
     <cobertura-maven-plugin-version>2.7</cobertura-maven-plugin-version>
     <couchbase-client-version>1.4.13</couchbase-client-version>
     <couchbase-client-bundle-version>1.4.13_1</couchbase-client-bundle-version>
diff --git 
a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
 
b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
index b634a1e..3c5cbad 100644
--- 
a/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
+++ 
b/platforms/spring-boot/components-starter/camel-consul-starter/src/main/java/org/apache/camel/component/consul/springboot/ConsulComponentConfiguration.java
@@ -28,9 +28,8 @@ import 
org.springframework.boot.context.properties.DeprecatedConfigurationProper
 import org.springframework.boot.context.properties.NestedConfigurationProperty;
 
 /**
- * The camel consul component allows you to work with Consul, a distributed,
- * highly available, datacenter-aware, service discovery and configuration
- * system.
+ * The camel consul component allows you to work with Consul a distributed
+ * highly available datacenter-aware service discovery and configuration 
system.
  * 
  * Generated by camel-package-maven-plugin - do not edit this file!
  */

-- 
To stop receiving notification emails like this one, please contact
lburgazz...@apache.org.

Reply via email to