diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index f85cb0d91..524a45f9a 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,15 +1,5 @@
version: 2
updates:
- - package-ecosystem: "github-actions"
- directory: "/"
- target-branch: "4.1.x"
- schedule:
- interval: "weekly"
- - package-ecosystem: "github-actions"
- directory: "/"
- target-branch: "4.2.x"
- schedule:
- interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "main"
@@ -19,7 +9,7 @@ updates:
directory: /
schedule:
interval: daily
- target-branch: 4.1.x
+ target-branch: 4.3.x
ignore:
# only upgrade patch versions for maintenance branch
- dependency-name: "*"
@@ -30,23 +20,13 @@ updates:
directory: /
schedule:
interval: daily
- target-branch: 4.2.x
+ target-branch: main
ignore:
# only upgrade patch versions for maintenance branch
- dependency-name: "*"
update-types:
- version-update:semver-major
- version-update:semver-minor
- - package-ecosystem: maven
- directory: /
- schedule:
- interval: daily
- target-branch: main
- ignore:
- # only upgrade by minor or patch
- - dependency-name: "*"
- update-types:
- - version-update:semver-major
- package-ecosystem: npm
target-branch: docs-build
directory: /
@@ -58,12 +38,7 @@ updates:
schedule:
interval: weekly
- package-ecosystem: npm
- target-branch: 4.1.x
- directory: /docs
- schedule:
- interval: weekly
- - package-ecosystem: npm
- target-branch: 4.2.x
+ target-branch: 4.3.x
directory: /docs
schedule:
interval: weekly
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index b5281c4bf..06ee74428 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -3,6 +3,7 @@ name: Spring Cloud Consul CI Job
on:
push:
branches:
+ - main
- 4.3.x
# Scheduled builds run daily at midnight UTC
@@ -15,7 +16,7 @@ on:
branches:
description: "Which branch should be built (can be a comma-separated list of branches)"
required: true
- default: '4.3.x'
+ default: 'main'
type: string
jobs:
diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml
index dd90e16bc..19839c052 100644
--- a/.github/workflows/deploy-docs.yml
+++ b/.github/workflows/deploy-docs.yml
@@ -16,7 +16,7 @@ jobs:
# if: github.repository_owner == 'spring-cloud'
steps:
- name: Checkout
- uses: actions/checkout@v5
+ uses: actions/checkout@v6
with:
ref: docs-build
fetch-depth: 1
diff --git a/docs/modules/ROOT/pages/retry.adoc b/docs/modules/ROOT/pages/retry.adoc
index 3bd928f35..ddf16dc4b 100644
--- a/docs/modules/ROOT/pages/retry.adoc
+++ b/docs/modules/ROOT/pages/retry.adoc
@@ -3,7 +3,7 @@
If you expect that the consul agent may occasionally be unavailable when
your app starts, you can ask it to keep trying after a failure. You need to add
-`spring-retry` and `spring-boot-starter-aop` to your classpath. The default
+`spring-retry` and `spring-boot-starter-aspectj` to your classpath. The default
behaviour is to retry 6 times with an initial backoff interval of 1000ms and an
exponential multiplier of 1.1 for subsequent backoffs. You can configure these
properties (and others) using `spring.cloud.consul.retry.*` configuration properties.
diff --git a/docs/pom.xml b/docs/pom.xml
index 6ad7df237..3d886eb25 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -6,7 +6,7 @@
org.springframework.cloud
spring-cloud-consul
- 4.3.3-SNAPSHOT
+ 5.0.2-SNAPSHOT
..
spring-cloud-consul-docs
diff --git a/pom.xml b/pom.xml
index 209e3ce31..73ebcc552 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.springframework.cloud
spring-cloud-consul
- 4.3.3-SNAPSHOT
+ 5.0.2-SNAPSHOT
pom
Spring Cloud Consul
Spring Cloud Consul
@@ -16,20 +16,20 @@
org.springframework.cloud
spring-cloud-build
- 4.3.4-SNAPSHOT
+ 5.0.2-SNAPSHOT
- 4.3.1
- 4.3.3-SNAPSHOT
- 4.3.2
+ 5.0.2-SNAPSHOT
+ 5.0.2-SNAPSHOT
+ 5.0.2
2.8.3
- 4.3.3-SNAPSHOT
- 4.3.3-SNAPSHOT
- 1.21.2
- 5.15.0
+ 5.0.2-SNAPSHOT
+ 5.0.2-SNAPSHOT
+ 1.21.4
+ 5.15.0
@@ -123,10 +123,10 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.14.0
+ 3.15.0
- 1.8
- 1.8
+ 17
+ 17
@@ -164,6 +164,12 @@
${spring-cloud-deployer.version}
test
+
+ org.springframework.cloud
+ spring-cloud-deployer-spi
+ ${spring-cloud-deployer.version}
+ test
+
org.springframework.cloud
spring-cloud-stream-binder-test
@@ -239,7 +245,12 @@
org.mock-server
mockserver-client-java
- ${mockserverclient.version}
+ ${mockserver.version}
+
+
+ org.mock-server
+ mockserver-netty
+ ${mockserver.version}
diff --git a/spring-cloud-consul-binder/pom.xml b/spring-cloud-consul-binder/pom.xml
index ea50c6fb8..a7f992d10 100644
--- a/spring-cloud-consul-binder/pom.xml
+++ b/spring-cloud-consul-binder/pom.xml
@@ -12,7 +12,7 @@
org.springframework.cloud
spring-cloud-consul
- 4.3.3-SNAPSHOT
+ 5.0.2-SNAPSHOT
..
@@ -32,13 +32,13 @@
spring-cloud-stream
- com.ecwid.consul
- consul-api
- true
+ org.springframework.cloud
+ spring-cloud-deployer-local
+ test
org.springframework.cloud
- spring-cloud-deployer-local
+ spring-cloud-deployer-spi
test
diff --git a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducer.java b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducer.java
index 1b1f703d5..f03a886bd 100644
--- a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducer.java
+++ b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducer.java
@@ -23,11 +23,10 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
-import com.ecwid.consul.v1.OperationException;
-import com.ecwid.consul.v1.event.model.Event;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.cloud.consul.model.http.event.Event;
import org.springframework.integration.endpoint.MessageProducerSupport;
/**
@@ -103,11 +102,6 @@ public void getEvents() {
.build());
}
}
- catch (OperationException e) {
- if (logger.isErrorEnabled()) {
- logger.error("Error getting consul events: " + e);
- }
- }
catch (Exception e) {
if (logger.isErrorEnabled()) {
logger.error("Error getting consul events: " + e.getMessage());
diff --git a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulSendingHandler.java b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulSendingHandler.java
index a192b56be..becc4f3d0 100644
--- a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulSendingHandler.java
+++ b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/ConsulSendingHandler.java
@@ -18,12 +18,9 @@
import java.util.Arrays;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.event.model.Event;
-import com.ecwid.consul.v1.event.model.EventParams;
-
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.model.http.event.Event;
+import org.springframework.http.ResponseEntity;
import org.springframework.integration.handler.AbstractMessageHandler;
import org.springframework.messaging.Message;
@@ -56,8 +53,7 @@ protected void handleMessageInternal(Message> message) {
// TODO: support headers
// TODO: support consul event filters: NodeFilter, ServiceFilter, TagFilter
- Response event = this.consul.eventFire(this.eventName, (String) payload, new EventParams(),
- QueryParams.DEFAULT);
+ ResponseEntity event = this.consul.eventFire(this.eventName, (String) payload);
// TODO: return event?
}
diff --git a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java
index 9f6f95d1c..ebe84e3ab 100644
--- a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java
+++ b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/EventService.java
@@ -19,16 +19,14 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.event.EventListRequest;
-import com.ecwid.consul.v1.event.model.Event;
-import com.ecwid.consul.v1.event.model.EventParams;
-import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.PostConstruct;
+import tools.jackson.databind.ObjectMapper;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.binder.config.ConsulBinderProperties;
+import org.springframework.cloud.consul.model.http.ConsulHeaders;
+import org.springframework.cloud.consul.model.http.event.Event;
+import org.springframework.http.ResponseEntity;
/**
* @author Spencer Gibb
@@ -62,24 +60,24 @@ public Long getLastIndex() {
return this.lastIndex.get();
}
- private void setLastIndex(Response> response) {
- Long consulIndex = response.getConsulIndex();
+ private void setLastIndex(ResponseEntity> response) {
+ Long consulIndex = ConsulHeaders.getConsulIndex(response);
if (consulIndex != null) {
- this.lastIndex.set(response.getConsulIndex());
+ this.lastIndex.set(consulIndex);
}
}
public Event fire(String name, String payload) {
- Response response = this.consul.eventFire(name, payload, new EventParams(), QueryParams.DEFAULT);
- return response.getValue();
+ ResponseEntity response = this.consul.eventFire(name, payload);
+ return response.getBody();
}
- public Response> getEventsResponse() {
- return this.consul.eventList(EventListRequest.newBuilder().setQueryParams(QueryParams.DEFAULT).build());
+ public ResponseEntity> getEventsResponse() {
+ return this.consul.eventList();
}
public List getEvents() {
- return getEventsResponse().getValue();
+ return getEventsResponse().getBody();
}
public List getEvents(Long lastIndex) {
@@ -100,14 +98,13 @@ public List watch(Long lastIndex) {
if (this.properties != null) {
eventTimeout = this.properties.getEventTimeout();
}
- Response> watch = this.consul
- .eventList(EventListRequest.newBuilder().setQueryParams(new QueryParams(eventTimeout, index)).build());
+ ResponseEntity> watch = this.consul.eventList(eventTimeout, index);
return filterEvents(readEvents(watch), lastIndex);
}
- protected List readEvents(Response> response) {
+ protected List readEvents(ResponseEntity> response) {
setLastIndex(response);
- return response.getValue();
+ return response.getBody();
}
/**
diff --git a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/config/ConsulBinderConfiguration.java b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/config/ConsulBinderConfiguration.java
index cdea5025c..7f1ec8276 100644
--- a/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/config/ConsulBinderConfiguration.java
+++ b/spring-cloud-consul-binder/src/main/java/org/springframework/cloud/consul/binder/config/ConsulBinderConfiguration.java
@@ -16,14 +16,14 @@
package org.springframework.cloud.consul.binder.config;
-import com.ecwid.consul.v1.ConsulClient;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import tools.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.cloud.consul.ConditionalOnConsulEnabled;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.binder.ConsulBinder;
import org.springframework.cloud.consul.binder.EventService;
import org.springframework.cloud.stream.binder.Binder;
diff --git a/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulBinderApplicationTests.java b/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulBinderApplicationTests.java
index 88ad4f655..2e767c01a 100644
--- a/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulBinderApplicationTests.java
+++ b/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulBinderApplicationTests.java
@@ -16,9 +16,12 @@
package org.springframework.cloud.consul.binder;
+import java.io.IOException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
import java.util.concurrent.TimeUnit;
-import com.ecwid.consul.v1.ConsulClient;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import org.junit.Before;
import org.junit.Ignore;
@@ -29,6 +32,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.cloud.consul.ConsulAutoConfiguration;
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.ConsulProperties;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -112,8 +118,12 @@ interface Events {
public static class Application {
@Bean
- public ConsulClient consulClient() {
- return new ConsulClient("localhost", 18500);
+ public ConsulClient consulClient()
+ throws CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException {
+ ConsulProperties consulProperties = new ConsulProperties();
+ consulProperties.setHost("localhost");
+ consulProperties.setPort(18500);
+ return ConsulAutoConfiguration.createNewConsulClient(consulProperties);
}
@Bean
diff --git a/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducerTests.java b/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducerTests.java
index 88303d51d..d4e3e395b 100644
--- a/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducerTests.java
+++ b/spring-cloud-consul-binder/src/test/java/org/springframework/cloud/consul/binder/ConsulInboundMessageProducerTests.java
@@ -16,7 +16,6 @@
package org.springframework.cloud.consul.binder;
-import com.ecwid.consul.v1.OperationException;
import org.junit.Test;
import static org.assertj.core.api.Assertions.fail;
@@ -31,7 +30,7 @@ public class ConsulInboundMessageProducerTests {
@Test
public void getEventsShouldNotThrowException() {
EventService eventService = mock(EventService.class);
- when(eventService.watch()).thenThrow(new OperationException(500, "error", ""));
+ when(eventService.watch()).thenThrow(new RuntimeException("error"));
ConsulInboundMessageProducer producer = new ConsulInboundMessageProducer(eventService);
diff --git a/spring-cloud-consul-config/pom.xml b/spring-cloud-consul-config/pom.xml
index cd160ad9d..1bd35e4ae 100644
--- a/spring-cloud-consul-config/pom.xml
+++ b/spring-cloud-consul-config/pom.xml
@@ -12,7 +12,7 @@
org.springframework.cloud
spring-cloud-consul
- 4.3.3-SNAPSHOT
+ 5.0.2-SNAPSHOT
..
@@ -36,11 +36,6 @@
spring-boot-starter-actuator
true
-
- com.ecwid.consul
- consul-api
- true
-
org.springframework.cloud
spring-cloud-consul-core
@@ -69,7 +64,7 @@
org.springframework.boot
- spring-boot-starter-aop
+ spring-boot-starter-aspectj
test
@@ -82,6 +77,11 @@
junit-vintage-engine
test
+
+ com.ecwid.consul
+ consul-api
+ test
+
org.testcontainers
consul
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java
index a340543ec..68821e23e 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConfigWatch.java
@@ -16,25 +16,27 @@
package org.springframework.cloud.consul.config;
+import java.time.Duration;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicBoolean;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.kv.model.GetValue;
import io.micrometer.core.annotation.Timed;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.model.http.ConsulHeaders;
+import org.springframework.cloud.consul.model.http.kv.GetValue;
import org.springframework.cloud.endpoint.event.RefreshEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.SmartLifecycle;
import org.springframework.core.style.ToStringCreator;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.ObjectUtils;
@@ -93,7 +95,7 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
public void start() {
if (this.running.compareAndSet(false, true)) {
this.watchFuture = this.taskScheduler.scheduleWithFixedDelay(this::watchConfigKeyValues,
- this.properties.getWatch().getDelay());
+ Duration.ofMillis(this.properties.getWatch().getDelay()));
}
}
@@ -154,13 +156,14 @@ public void watchConfigKeyValues() {
aclToken = null;
}
- Response> response = this.consul.getKVValues(context, aclToken,
- new QueryParams(this.properties.getWatch().getWaitTime(), currentIndex));
+ ResponseEntity> response = this.consul.getKVValues(context, aclToken,
+ (long) properties.getWatch().getWaitTime(), currentIndex);
// if response.value == null, response was a 404, otherwise it was a
// 200, reducing churn if there wasn't anything
- if (response.getValue() != null && !response.getValue().isEmpty()) {
- Long newIndex = response.getConsulIndex();
+ if (HttpStatus.OK.isSameCodeAs(response.getStatusCode()) && response.hasBody()
+ && !response.getBody().isEmpty()) {
+ Long newIndex = ConsulHeaders.getConsulIndex(response);
if (newIndex != null && !newIndex.equals(currentIndex)) {
// don't publish the same index again, don't publish the first
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java
index 12ccf515a..7e9be2c95 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulBootstrapper.java
@@ -19,14 +19,13 @@
import java.util.function.BiFunction;
import java.util.function.Function;
-import com.ecwid.consul.v1.ConsulClient;
-
-import org.springframework.boot.BootstrapContext;
-import org.springframework.boot.BootstrapRegistry;
-import org.springframework.boot.BootstrapRegistryInitializer;
+import org.springframework.boot.bootstrap.BootstrapContext;
+import org.springframework.boot.bootstrap.BootstrapRegistry;
+import org.springframework.boot.bootstrap.BootstrapRegistryInitializer;
import org.springframework.boot.context.config.ConfigData;
import org.springframework.boot.context.config.ConfigDataLoaderContext;
import org.springframework.boot.context.properties.bind.Binder;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.ConsulProperties;
import org.springframework.util.Assert;
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigAutoConfiguration.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigAutoConfiguration.java
index df3a4254b..3122b2a72 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigAutoConfiguration.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigAutoConfiguration.java
@@ -16,14 +16,13 @@
package org.springframework.cloud.consul.config;
-import com.ecwid.consul.v1.ConsulClient;
-
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.consul.ConditionalOnConsulEnabled;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.endpoint.RefreshEndpoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java
index a58a3b148..5b009abbc 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration.java
@@ -16,14 +16,12 @@
package org.springframework.cloud.consul.config;
-import com.ecwid.consul.v1.ConsulClient;
-
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.consul.ConditionalOnConsulEnabled;
import org.springframework.cloud.consul.ConsulAutoConfiguration;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -44,9 +42,12 @@ public class ConsulConfigBootstrapConfiguration {
@ConditionalOnProperty(name = "spring.cloud.consul.config.enabled", matchIfMissing = true)
protected static class ConsulPropertySourceConfiguration {
- @Autowired
private ConsulClient consul;
+ public ConsulPropertySourceConfiguration(ConsulClient consul) {
+ this.consul = consul;
+ }
+
@Bean
@ConditionalOnMissingBean
public ConsulConfigProperties consulConfigProperties(Environment env) {
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLoader.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLoader.java
index 86d32996d..a38c15227 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLoader.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLoader.java
@@ -21,7 +21,6 @@
import java.util.EnumSet;
import java.util.List;
-import com.ecwid.consul.v1.ConsulClient;
import org.apache.commons.logging.Log;
import org.springframework.boot.context.config.ConfigData;
@@ -32,6 +31,7 @@
import org.springframework.boot.context.config.ConfigDataResourceNotFoundException;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.config.ConsulBootstrapper.LoadContext;
import org.springframework.cloud.consul.config.ConsulBootstrapper.LoaderInterceptor;
import org.springframework.util.StringUtils;
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java
index 94bbfdd8f..15dc741f3 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolver.java
@@ -23,12 +23,11 @@
import java.util.List;
import java.util.stream.Collectors;
-import com.ecwid.consul.v1.ConsulClient;
import org.apache.commons.logging.Log;
-import org.springframework.boot.BootstrapContext;
-import org.springframework.boot.BootstrapRegistry.InstanceSupplier;
-import org.springframework.boot.ConfigurableBootstrapContext;
+import org.springframework.boot.bootstrap.BootstrapContext;
+import org.springframework.boot.bootstrap.BootstrapRegistry.InstanceSupplier;
+import org.springframework.boot.bootstrap.ConfigurableBootstrapContext;
import org.springframework.boot.context.config.ConfigDataLocation;
import org.springframework.boot.context.config.ConfigDataLocationNotFoundException;
import org.springframework.boot.context.config.ConfigDataLocationResolver;
@@ -39,10 +38,10 @@
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.cloud.consul.ConsulAutoConfiguration;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.ConsulProperties;
import org.springframework.cloud.consul.config.ConsulPropertySources.Context;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponents;
@@ -143,7 +142,6 @@ protected List getSuffixes(ConsulConfigProperties properties) {
return DIR_SUFFIXES;
}
- @Nullable
protected UriComponents parseLocation(ConfigDataLocationResolverContext context, ConfigDataLocation location) {
String originalLocation = location.getNonPrefixedValue(PREFIX);
if (!StringUtils.hasText(originalLocation)) {
@@ -185,8 +183,12 @@ protected void registerBean(ConfigDataLocationResolverContext context, Class
protected ConsulClient createConsulClient(BootstrapContext context) {
ConsulProperties properties = context.get(ConsulProperties.class);
- return ConsulAutoConfiguration.createConsulClient(properties,
- ConsulAutoConfiguration.createConsulRawClientBuilder());
+ try {
+ return ConsulAutoConfiguration.createNewConsulClient(properties);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
protected ConsulProperties loadProperties(ConfigDataLocationResolverContext resolverContext,
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulFilesPropertySource.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulFilesPropertySource.java
index 7fb5cd2d8..15fc10f11 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulFilesPropertySource.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulFilesPropertySource.java
@@ -16,8 +16,8 @@
package org.springframework.cloud.consul.config;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.kv.model.GetValue;
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.model.http.kv.GetValue;
import static org.springframework.cloud.consul.config.ConsulConfigProperties.Format.PROPERTIES;
import static org.springframework.cloud.consul.config.ConsulConfigProperties.Format.YAML;
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java
index 4c564decd..ddf15f30b 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySource.java
@@ -26,14 +26,13 @@
import java.util.Properties;
import java.util.Set;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.kv.model.GetValue;
-
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.model.http.ConsulHeaders;
+import org.springframework.cloud.consul.model.http.kv.GetValue;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.io.ByteArrayResource;
+import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.consul.config.ConsulConfigProperties.Format.PROPERTIES;
@@ -66,13 +65,16 @@ public void init() {
if (this.context.startsWith("/")) {
this.context = this.context.substring(1);
}
+ if (this.context.contains("//")) {
+ this.context = this.context.replace("//", "/");
+ }
- Response> response = this.source.getKVValues(this.context, this.configProperties.getAclToken(),
- QueryParams.DEFAULT);
+ ResponseEntity> response = this.source.getKVValues(this.context,
+ this.configProperties.getAclToken());
- this.initialIndex = response.getConsulIndex();
+ this.initialIndex = ConsulHeaders.getConsulIndex(response);
- final List values = response.getValue();
+ final List values = response.getBody();
ConsulConfigProperties.Format format = this.configProperties.getFormat();
switch (format) {
case KEY_VALUE:
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java
index 93be8a75f..0592ebe46 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocator.java
@@ -22,11 +22,11 @@
import java.util.LinkedHashMap;
import java.util.List;
-import com.ecwid.consul.v1.ConsulClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySources.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySources.java
index 0b46b62ba..17e9f375d 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySources.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulPropertySources.java
@@ -23,12 +23,14 @@
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.kv.model.GetValue;
import org.apache.commons.logging.Log;
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.ConsulException;
+import org.springframework.cloud.consul.model.http.ConsulHeaders;
+import org.springframework.cloud.consul.model.http.kv.GetValue;
import org.springframework.core.style.ToStringCreator;
+import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.consul.config.ConsulConfigProperties.Format.FILES;
@@ -124,12 +126,29 @@ public ConsulPropertySource createPropertySource(String propertySourceContext, C
ConsulPropertySource propertySource = null;
if (properties.getFormat() == FILES) {
- Response response = consul.getKVValue(propertySourceContext, properties.getAclToken());
- indexConsumer.accept(propertySourceContext, response.getConsulIndex());
- if (response.getValue() != null) {
+ ResponseEntity> response = consul.getKVValue(propertySourceContext,
+ properties.getAclToken());
+
+ GetValue value = null;
+ if (response.getStatusCode().is2xxSuccessful()) {
+ List values = response.getBody();
+ if (values.size() == 0) {
+ value = new GetValue();
+ }
+ else if (values.size() == 1) {
+ value = values.get(0);
+ }
+ else {
+ throw new ConsulException("Strange response (list size=" + values.size() + ")");
+ }
+ }
+
+ Long consulIndex = ConsulHeaders.getConsulIndex(response);
+ indexConsumer.accept(propertySourceContext, consulIndex);
+ if (response.hasBody()) {
ConsulFilesPropertySource filesPropertySource = new ConsulFilesPropertySource(propertySourceContext,
consul, properties);
- filesPropertySource.init(response.getValue());
+ filesPropertySource.init(value);
propertySource = filesPropertySource;
}
}
diff --git a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulRetryBootstrapper.java b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulRetryBootstrapper.java
index 16a78efe6..b615e49ef 100644
--- a/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulRetryBootstrapper.java
+++ b/spring-cloud-consul-config/src/main/java/org/springframework/cloud/consul/config/ConsulRetryBootstrapper.java
@@ -16,8 +16,8 @@
package org.springframework.cloud.consul.config;
-import org.springframework.boot.BootstrapRegistry;
-import org.springframework.boot.BootstrapRegistryInitializer;
+import org.springframework.boot.bootstrap.BootstrapRegistry;
+import org.springframework.boot.bootstrap.BootstrapRegistryInitializer;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.cloud.consul.RetryProperties;
import org.springframework.cloud.consul.config.ConsulBootstrapper.LoaderInterceptor;
diff --git a/spring-cloud-consul-config/src/main/resources/META-INF/spring.factories b/spring-cloud-consul-config/src/main/resources/META-INF/spring.factories
index d9dd0d088..6b7f22480 100644
--- a/spring-cloud-consul-config/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-consul-config/src/main/resources/META-INF/spring.factories
@@ -3,7 +3,7 @@ org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.consul.config.ConsulConfigBootstrapConfiguration
# Environment PostProcessor
-org.springframework.boot.env.EnvironmentPostProcessor=\
+org.springframework.boot.EnvironmentPostProcessor=\
org.springframework.cloud.consul.config.ConsulConfigDataMissingEnvironmentPostProcessor
org.springframework.boot.diagnostics.FailureAnalyzer=\
@@ -18,5 +18,5 @@ org.springframework.boot.context.config.ConfigDataLoader=\
org.springframework.cloud.consul.config.ConsulConfigDataLoader
# Spring Boot Bootstrappers
-org.springframework.boot.BootstrapRegistryInitializer=\
+org.springframework.boot.bootstrap.BootstrapRegistryInitializer=\
org.springframework.cloud.consul.config.ConsulRetryBootstrapper
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java
index 54b56f799..60d16ec92 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConfigWatchTests.java
@@ -21,18 +21,22 @@
import java.util.LinkedHashMap;
import java.util.List;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.kv.model.GetValue;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.model.http.ConsulHeaders;
+import org.springframework.cloud.consul.model.http.kv.GetValue;
import org.springframework.cloud.endpoint.event.RefreshEvent;
import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.ResponseEntity.BodyBuilder;
import org.springframework.util.StringUtils;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
@@ -102,12 +106,21 @@ private void setupWatch(ApplicationEventPublisher eventPublisher, GetValue getVa
ConsulClient consul = mock(ConsulClient.class);
List getValues = null;
+ BodyBuilder response;
if (getValue != null) {
getValues = Arrays.asList(getValue);
+ response = ResponseEntity.status(HttpStatus.OK);
+ }
+ else {
+ response = ResponseEntity.status(HttpStatus.NOT_FOUND);
}
- Response> response = new Response<>(getValues, 1L, false, 1L);
- when(consul.getKVValues(eq(context), nullable(String.class), any(QueryParams.class))).thenReturn(response);
+ HttpHeaders headers = new HttpHeaders();
+ headers.add(ConsulHeaders.INDEX_HEADER, "1");
+ headers.add(ConsulHeaders.LAST_CONTACT_HEADER, "1");
+ response.headers(headers);
+ when(consul.getKVValues(eq(context), nullable(String.class), anyLong(), anyLong()))
+ .thenReturn(response.body(getValues));
if (StringUtils.hasText(aclToken)) {
this.configProperties.setAclToken(aclToken);
@@ -132,10 +145,10 @@ public void firstCallDoesNotPublishEvent() {
ConsulClient consul = mock(ConsulClient.class);
List getValues = Collections.singletonList(getValue);
- Response> response = new Response<>(getValues, 1L, false, 1L);
- when(consul.getKVValues(eq(context), anyString(), any(QueryParams.class))).thenReturn(response);
+ ResponseEntity> response = ResponseEntity.ok(getValues);
+ when(consul.getKVValues(eq(context), anyString(), anyLong(), anyLong())).thenReturn(response);
- ConfigWatch watch = new ConfigWatch(this.configProperties, consul, new LinkedHashMap());
+ ConfigWatch watch = new ConfigWatch(this.configProperties, consul, new LinkedHashMap<>());
watch.setApplicationEventPublisher(eventPublisher);
watch.watchConfigKeyValues();
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfigurationTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfigurationTests.java
index 2a61deda0..a35e2eb19 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfigurationTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigBootstrapConfigurationTests.java
@@ -66,7 +66,7 @@ public void testConfigPropsBeanKicksIn() {
/**
* Test config that simulates a "user provided bean".
*/
- private static class TestConfig {
+ private static final class TestConfig {
@Bean
public ConsulConfigProperties consulConfigProperties() {
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java
index 6ef9a1289..bcd58654f 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataCustomizationIntegrationTests.java
@@ -18,22 +18,22 @@
import java.util.UUID;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.springframework.boot.BootstrapRegistry;
-import org.springframework.boot.BootstrapRegistryInitializer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.bootstrap.BootstrapRegistry;
+import org.springframework.boot.bootstrap.BootstrapRegistryInitializer;
import org.springframework.boot.context.config.ConfigData;
import org.springframework.boot.context.properties.bind.BindContext;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
-import org.springframework.cloud.consul.ConsulProperties;
+import org.springframework.cloud.consul.ConsulAutoConfiguration;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -67,7 +67,8 @@ public static void setup() {
application.setWebApplicationType(WebApplicationType.NONE);
bindHandlerBootstrapper = new BindHandlerBootstrapper();
application.addBootstrapRegistryInitializer(bindHandlerBootstrapper);
- application.addBootstrapRegistryInitializer(ConsulBootstrapper.fromConsulProperties(TestConsulClient::new));
+ application.addBootstrapRegistryInitializer(
+ ConsulBootstrapper.fromConsulProperties(ConsulAutoConfiguration::createNewConsulClient));
application.addBootstrapRegistryInitializer(
registry -> registry.register(ConsulBootstrapper.LoaderInterceptor.class, context1 -> loadContext -> {
ConfigData configData = loadContext.getInvocation()
@@ -102,20 +103,12 @@ public static void teardown() {
}
@Test
- public void consulClientIsCustom() {
+ void consulClientIsCustom() {
ConsulClient client = context.getBean(ConsulClient.class);
- assertThat(client).isInstanceOf(TestConsulClient.class);
+ assertThat(client).isInstanceOf(ConsulClient.class);
assertThat(bindHandlerBootstrapper.onSuccessCount).isGreaterThan(0);
}
- static class TestConsulClient extends ConsulClient {
-
- TestConsulClient(ConsulProperties properties) {
- super(properties.getHost(), properties.getPort());
- }
-
- }
-
@Configuration
@EnableAutoConfiguration
static class Config {
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataFileIntegrationTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataFileIntegrationTests.java
index c670d9f54..c34022f47 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataFileIntegrationTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataFileIntegrationTests.java
@@ -20,7 +20,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -28,6 +27,7 @@
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
@@ -75,35 +75,33 @@ public class ConsulConfigDataFileIntegrationTests {
private static ConfigurableEnvironment environment;
- private static ConsulClient client;
+ private static ConsulClient testClient;
@BeforeAll
public static void setup() {
ConsulTestcontainers.start();
- client = ConsulTestcontainers.client();
- client.deleteKVValues(PREFIX);
- client.setKVValue(KEY1, TEST_PROP + "=" + VALUE1 + "\n" + TEST_PROP2 + "=" + VALUE2);
+ testClient = ConsulTestcontainers.client();
+ testClient.deleteKVValues(PREFIX);
+ testClient.setKVValue(KEY1, TEST_PROP + "=" + VALUE1 + "\n" + TEST_PROP2 + "=" + VALUE2);
context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
.run("--spring.application.name=" + APP_NAME, "--spring.cloud.consul.config.format=files",
"--spring.config.import=optional:consul:" + ConsulTestcontainers.getHost() + ":"
+ ConsulTestcontainers.getPort(),
"--spring.cloud.consul.config.prefix=" + ROOT, "--spring.cloud.consul.config.watch.delay=10");
-
- client = context.getBean(ConsulClient.class);
environment = context.getEnvironment();
}
@AfterAll
public static void teardown() {
- client.deleteKVValues(PREFIX);
+ testClient.deleteKVValues(PREFIX);
if (context != null) {
context.close();
}
}
@Test
- public void propertyLoaded() {
+ void propertyLoaded() {
String testProp = environment.getProperty(TEST_PROP_CANONICAL);
assertThat(testProp).as(TEST_PROP + " was wrong").isEqualTo(VALUE1);
String testProp2 = environment.getProperty(TEST_PROP2_CANONICAL);
@@ -111,11 +109,11 @@ public void propertyLoaded() {
}
@Test
- public void propertyLoadedAndUpdated() throws Exception {
+ void propertyLoadedAndUpdated() throws Exception {
String testProp = environment.getProperty(TEST_PROP_CANONICAL);
assertThat(testProp).as("testProp was wrong").isEqualTo(VALUE1);
- client.setKVValue(KEY1, TEST_PROP + "=testPropValUpdate\n" + TEST_PROP2 + "=" + VALUE2);
+ testClient.setKVValue(KEY1, TEST_PROP + "=testPropValUpdate\n" + TEST_PROP2 + "=" + VALUE2);
CountDownLatch latch = context.getBean("countDownLatch1", CountDownLatch.class);
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
@@ -126,11 +124,11 @@ public void propertyLoadedAndUpdated() throws Exception {
}
@Test
- public void contextDoesNotExistThenExists() throws Exception {
+ void contextDoesNotExistThenExists() throws Exception {
String testProp = environment.getProperty(TEST_PROP3_CANONICAL);
assertThat(testProp).as(TEST_PROP3 + " was wrong").isNull();
- client.setKVValue(KEY3, TEST_PROP3 + "=testPropValInsert");
+ testClient.setKVValue(KEY3, TEST_PROP3 + "=testPropValInsert");
CountDownLatch latch = context.getBean("countDownLatch2", CountDownLatch.class);
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataIntegrationTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataIntegrationTests.java
index 3d81f9635..6216b8968 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataIntegrationTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataIntegrationTests.java
@@ -20,7 +20,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -28,6 +27,7 @@
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
@@ -81,16 +81,16 @@ public class ConsulConfigDataIntegrationTests {
private static ConfigurableEnvironment environment;
- private static ConsulClient client;
+ private static ConsulClient testClient;
@BeforeAll
public static void setup() {
ConsulTestcontainers.start();
- client = ConsulTestcontainers.client();
- client.deleteKVValues(PREFIX);
- client.setKVValue(KEY1, VALUE1);
- client.setKVValue(KEY2, VALUE2_DEFAULT);
- client.setKVValue(KEY2_APP_NAME, VALUE2);
+ testClient = ConsulTestcontainers.client();
+ testClient.deleteKVValues(PREFIX);
+ testClient.setKVValue(KEY1, VALUE1);
+ testClient.setKVValue(KEY2, VALUE2_DEFAULT);
+ testClient.setKVValue(KEY2_APP_NAME, VALUE2);
context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
.run("--logging.level.org.springframework.cloud.consul.config.ConfigWatch=TRACE",
@@ -99,31 +99,29 @@ public static void setup() {
+ ConsulTestcontainers.getPort(),
"--spring.cloud.consul.config.prefix=" + ROOT, "--spring.cloud.consul.config.watch.delay=10",
"--spring.cloud.consul.config.watch.wait-time=1");
-
- client = context.getBean(ConsulClient.class);
environment = context.getEnvironment();
}
@AfterAll
public static void teardown() {
- client.deleteKVValues(PREFIX);
+ testClient.deleteKVValues(PREFIX);
if (context != null) {
context.close();
}
}
@Test
- public void propertyLoaded() {
+ void propertyLoaded() {
String testProp2 = environment.getProperty(TEST_PROP2_CANONICAL);
assertThat(testProp2).as(TEST_PROP2 + " was wrong").isEqualTo(VALUE2);
}
@Test
- public void propertyLoadedAndUpdated() throws Exception {
+ void propertyLoadedAndUpdated() throws Exception {
String testProp = environment.getProperty(TEST_PROP_CANONICAL);
assertThat(testProp).as("testProp was wrong").isEqualTo(VALUE1);
- client.setKVValue(KEY1, "testPropValUpdate");
+ testClient.setKVValue(KEY1, "testPropValUpdate");
CountDownLatch latch = context.getBean("countDownLatch1", CountDownLatch.class);
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
@@ -134,11 +132,11 @@ public void propertyLoadedAndUpdated() throws Exception {
}
@Test
- public void contextDoesNotExistThenExists() throws Exception {
+ void contextDoesNotExistThenExists() throws Exception {
String testProp = environment.getProperty(TEST_PROP3_CANONICAL);
assertThat(testProp).as("testProp was wrong").isNull();
- client.setKVValue(KEY3, "testPropValInsert");
+ testClient.setKVValue(KEY3, "testPropValInsert");
CountDownLatch latch = context.getBean("countDownLatch2", CountDownLatch.class);
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolverTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolverTests.java
index e5ab26ba5..3270b3295 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolverTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataLocationResolverTests.java
@@ -25,8 +25,8 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import org.springframework.boot.BootstrapRegistry.InstanceSupplier;
-import org.springframework.boot.DefaultBootstrapContext;
+import org.springframework.boot.bootstrap.BootstrapRegistry.InstanceSupplier;
+import org.springframework.boot.bootstrap.DefaultBootstrapContext;
import org.springframework.boot.context.config.ConfigDataLocation;
import org.springframework.boot.context.config.ConfigDataLocationResolverContext;
import org.springframework.boot.context.config.Profiles;
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataMultiplePrefixesIntegrationTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataMultiplePrefixesIntegrationTests.java
index 04386cba0..7243866f4 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataMultiplePrefixesIntegrationTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataMultiplePrefixesIntegrationTests.java
@@ -18,7 +18,6 @@
import java.util.UUID;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -26,6 +25,7 @@
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -88,8 +88,6 @@ public static void setup() {
+ ConsulTestcontainers.getPort(),
"--spring.cloud.consul.config.prefixes=" + ROOT + "," + ROOT2,
"--spring.cloud.consul.config.watch.delay=10", "--spring.cloud.consul.config.watch.wait-time=1");
-
- client = context.getBean(ConsulClient.class);
environment = context.getEnvironment();
}
@@ -103,7 +101,7 @@ public static void teardown() {
}
@Test
- public void propertyLoaded() {
+ void propertyLoaded() {
String testProp = environment.getProperty(TEST_PROP_CANONICAL);
assertThat(testProp).as(TEST_PROP + " was wrong").isEqualTo(VALUE1);
String testProp2 = environment.getProperty(TEST_PROP2_CANONICAL);
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataNoImportIntegrationTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataNoImportIntegrationTests.java
index 6ede3a328..500dbeb5c 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataNoImportIntegrationTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulConfigDataNoImportIntegrationTests.java
@@ -16,7 +16,6 @@
package org.springframework.cloud.consul.config;
-import com.ecwid.consul.v1.ConsulClient;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -29,6 +28,7 @@
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertyPrefixTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertyPrefixTests.java
index 59b8a2543..094ee4c2b 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertyPrefixTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertyPrefixTests.java
@@ -16,36 +16,41 @@
package org.springframework.cloud.consul.config;
-import com.ecwid.consul.v1.ConsulClient;
+import java.io.IOException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import static org.assertj.core.api.Assertions.assertThat;
public class ConsulPropertyPrefixTests {
- private ConsulClient client;
+ private ConsulClient consulClient;
@Before
- public void setup() {
+ public void setup() throws CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException {
ConsulTestcontainers.start();
- this.client = ConsulTestcontainers.client();
+ this.consulClient = ConsulTestcontainers.client();
}
@After
public void teardown() {
- this.client.deleteKVValues("");
+ this.consulClient.deleteKVValues("");
}
@Test
public void testEmptyPrefix() {
// because prefix is empty, a leading forward slash is omitted
String kvContext = "appname";
- this.client.setKVValue(kvContext + "/fooprop", "fookvval");
- this.client.setKVValue(kvContext + "/bar/prop", "8080");
+ this.consulClient.setKVValue(kvContext + "/fooprop", "fookvval");
+ this.consulClient.setKVValue(kvContext + "/bar/prop", "8080");
ConsulPropertySource source = getConsulPropertySource(new ConsulConfigProperties(), kvContext);
assertProperties(source, "fookvval", "8080");
@@ -58,7 +63,7 @@ private void assertProperties(ConsulPropertySource source, Object fooval, Object
@SuppressWarnings("Duplicates")
private ConsulPropertySource getConsulPropertySource(ConsulConfigProperties configProperties, String context) {
- ConsulPropertySource source = new ConsulPropertySource(context, this.client, configProperties);
+ ConsulPropertySource source = new ConsulPropertySource(context, this.consulClient, configProperties);
source.init();
String[] names = source.getPropertyNames();
assertThat(names).as("names was null").isNotNull();
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorAppNameCustomizedTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorAppNameCustomizedTests.java
index 3bf74fed5..9f35dec33 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorAppNameCustomizedTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorAppNameCustomizedTests.java
@@ -18,7 +18,6 @@
import java.util.UUID;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -26,6 +25,7 @@
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -62,15 +62,15 @@ public class ConsulPropertySourceLocatorAppNameCustomizedTests {
private ConfigurableEnvironment environment;
- private ConsulClient client;
+ private ConsulClient testClient;
@Before
public void setup() {
ConsulTestcontainers.start();
- this.client = ConsulTestcontainers.client();
- this.client.deleteKVValues(PREFIX);
- this.client.setKVValue(KEY1, VALUE1);
- this.client.setKVValue(KEY2, VALUE2);
+ this.testClient = ConsulTestcontainers.client();
+ this.testClient.deleteKVValues(PREFIX);
+ this.testClient.setKVValue(KEY1, VALUE1);
+ this.testClient.setKVValue(KEY2, VALUE2);
this.context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
.run("--spring.application.name=testConsulPropertySourceLocatorAppNameCustomized",
@@ -78,14 +78,12 @@ public void setup() {
"--spring.cloud.consul.host=" + ConsulTestcontainers.getHost(),
"--spring.cloud.consul.port=" + ConsulTestcontainers.getPort(),
"--spring.cloud.consul.config.name=" + CONFIG_NAME, "--spring.cloud.consul.config.prefix=" + ROOT);
-
- this.client = this.context.getBean(ConsulClient.class);
this.environment = this.context.getEnvironment();
}
@After
public void teardown() {
- this.client.deleteKVValues(PREFIX);
+ this.testClient.deleteKVValues(PREFIX);
if (context != null) {
this.context.close();
}
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorFilesTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorFilesTests.java
index 3666386d8..c30f055df 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorFilesTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorFilesTests.java
@@ -18,7 +18,6 @@
import java.util.UUID;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -26,6 +25,7 @@
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -59,17 +59,17 @@ public class ConsulPropertySourceLocatorFilesTests {
private ConfigurableEnvironment environment;
- private ConsulClient client;
+ private ConsulClient testClient;
@Before
public void setup() {
ConsulTestcontainers.start();
- this.client = ConsulTestcontainers.client();
- this.client.setKVValue(ROOT + APPLICATION_YML, "foo: bar\nmy.baz: ${foo}");
- this.client.setKVValue(ROOT + APPLICATION_DEV_YML, "foo: bar-dev\nmy.baz: ${foo}");
- this.client.setKVValue(ROOT + "/master.ref", UUID.randomUUID().toString());
- this.client.setKVValue(ROOT + APP_NAME_PROPS, "foo: bar-app\nmy.baz: ${foo}");
- this.client.setKVValue(ROOT + APP_NAME_DEV_PROPS, "foo: bar-app-dev\nmy.baz: ${foo}");
+ this.testClient = ConsulTestcontainers.client();
+ this.testClient.setKVValue(ROOT + APPLICATION_YML, "foo: bar\nmy.baz: ${foo}");
+ this.testClient.setKVValue(ROOT + APPLICATION_DEV_YML, "foo: bar-dev\nmy.baz: ${foo}");
+ this.testClient.setKVValue(ROOT + "/master.ref", UUID.randomUUID().toString());
+ this.testClient.setKVValue(ROOT + APP_NAME_PROPS, "foo: bar-app\nmy.baz: ${foo}");
+ this.testClient.setKVValue(ROOT + APP_NAME_DEV_PROPS, "foo: bar-app-dev\nmy.baz: ${foo}");
this.context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
.run("--spring.application.name=" + APP_NAME, "--spring.config.use-legacy-processing=true",
@@ -77,14 +77,12 @@ public void setup() {
"--spring.cloud.consul.port=" + ConsulTestcontainers.getPort(),
"--spring.cloud.consul.config.prefix=" + ROOT, "--spring.cloud.consul.config.format=FILES",
"--spring.profiles.active=dev", "spring.cloud.consul.config.watch.delay=1");
-
- this.client = this.context.getBean(ConsulClient.class);
this.environment = this.context.getEnvironment();
}
@After
public void teardown() {
- this.client.deleteKVValues(PREFIX);
+ this.testClient.deleteKVValues(PREFIX);
if (this.context != null) {
this.context.close();
}
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorRetryTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorRetryTests.java
index c81947e78..109394518 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorRetryTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorRetryTests.java
@@ -16,7 +16,6 @@
package org.springframework.cloud.consul.config;
-import com.ecwid.consul.transport.TransportException;
import org.junit.Rule;
import org.junit.Test;
@@ -24,6 +23,7 @@
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.ResourceAccessException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -49,7 +49,7 @@ public void testRetry() {
"spring.cloud.consul.config.failFast=true")
.run();
fail("Did not throw expected exception");
- }).hasCauseInstanceOf(TransportException.class);
+ }).hasCauseInstanceOf(ResourceAccessException.class);
assertThat(output).contains("RetryContext retrieved");
}
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorTests.java
index 16fcbb370..4e3cdc4d9 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceLocatorTests.java
@@ -20,7 +20,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -28,6 +27,7 @@
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
@@ -77,29 +77,27 @@ public class ConsulPropertySourceLocatorTests {
private static ConfigurableEnvironment environment;
- private static ConsulClient client;
+ private static ConsulClient testClient;
@BeforeAll
public static void setup() {
ConsulTestcontainers.start();
- client = ConsulTestcontainers.client();
- client.deleteKVValues(PREFIX);
- client.setKVValue(KEY1, VALUE1);
- client.setKVValue(KEY2, VALUE2);
+ testClient = ConsulTestcontainers.client();
+ testClient.deleteKVValues(PREFIX);
+ testClient.setKVValue(KEY1, VALUE1);
+ testClient.setKVValue(KEY2, VALUE2);
context = new SpringApplicationBuilder(Config.class).web(WebApplicationType.NONE)
.run("--spring.application.name=" + APP_NAME, "--spring.config.use-legacy-processing=true",
"--spring.cloud.consul.host=" + ConsulTestcontainers.getHost(),
"--spring.cloud.consul.port=" + ConsulTestcontainers.getPort(),
"--spring.cloud.consul.config.prefixes=" + ROOT, "--spring.cloud.consul.config.watch.delay=10");
-
- client = context.getBean(ConsulClient.class);
environment = context.getEnvironment();
}
@AfterAll
public static void teardown() {
- client.deleteKVValues(PREFIX);
+ testClient.deleteKVValues(PREFIX);
if (context != null) {
context.close();
}
@@ -116,7 +114,7 @@ public void propertyLoadedAndUpdated() throws Exception {
String testProp = environment.getProperty(TEST_PROP_CANONICAL);
assertThat(testProp).as("testProp was wrong").isEqualTo(VALUE1);
- client.setKVValue(KEY1, "testPropValUpdate");
+ testClient.setKVValue(KEY1, "testPropValUpdate");
CountDownLatch latch = context.getBean("countDownLatch1", CountDownLatch.class);
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
@@ -131,7 +129,7 @@ public void contextDoesNotExistThenExists() throws Exception {
String testProp = environment.getProperty(TEST_PROP3_CANONICAL);
assertThat(testProp).as("testProp was wrong").isNull();
- client.setKVValue(KEY3, "testPropValInsert");
+ testClient.setKVValue(KEY3, "testPropValInsert");
CountDownLatch latch = context.getBean("countDownLatch2", CountDownLatch.class);
boolean receivedEvent = latch.await(15, TimeUnit.SECONDS);
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java
index 2097e2a28..029363fa0 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourceTests.java
@@ -16,14 +16,20 @@
package org.springframework.cloud.consul.config;
+import java.io.IOException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
import java.util.Random;
-import com.ecwid.consul.v1.ConsulClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.springframework.cloud.consul.ConsulClient;
import org.springframework.cloud.consul.test.ConsulTestcontainers;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@@ -32,7 +38,7 @@
*/
public class ConsulPropertySourceTests {
- private ConsulClient client;
+ private ConsulClient consulClient;
private String prefix;
@@ -41,23 +47,30 @@ public class ConsulPropertySourceTests {
private String propertiesContext;
@Before
- public void setup() {
+ public void setup() throws CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException {
ConsulTestcontainers.start();
- this.prefix = "/consulPropertySourceTests" + new Random().nextInt(Integer.MAX_VALUE);
- this.client = ConsulTestcontainers.client();
+ this.prefix = "consulPropertySourceTests" + new Random().nextInt(Integer.MAX_VALUE);
+ this.consulClient = ConsulTestcontainers.client();
}
@After
public void teardown() {
- this.client.deleteKVValues(this.prefix);
+ this.consulClient.deleteKVValues(this.prefix);
}
@Test
public void testKv() {
// key value properties
this.kvContext = this.prefix + "/kv";
- this.client.setKVValue(this.kvContext + "/fooprop", "fookvval");
- this.client.setKVValue(this.prefix + "/kv" + "/bar/prop", "8080");
+ ResponseEntity fookvval = this.consulClient.setKVValue(this.kvContext + "/fooprop", "fookvval");
+ assertThat(fookvval).isNotNull();
+ assertThat(fookvval.getStatusCode()).isEqualTo(HttpStatus.OK);
+ assertThat(fookvval.getBody()).isTrue();
+ ResponseEntity listResponseEntity = this.consulClient.setKVValue(this.prefix + "/kv" + "/bar/prop",
+ "8080");
+ assertThat(listResponseEntity).isNotNull();
+ assertThat(listResponseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
+ assertThat(listResponseEntity.getBody()).isTrue();
ConsulPropertySource source = getConsulPropertySource(new ConsulConfigProperties(), this.kvContext);
@@ -73,7 +86,7 @@ private void assertProperties(ConsulPropertySource source, Object fooval, Object
public void testProperties() {
// properties file property
this.propertiesContext = this.prefix + "/properties";
- this.client.setKVValue(this.propertiesContext + "/data", "fooprop=foopropval\nbar.prop=8080");
+ this.consulClient.setKVValue(this.propertiesContext + "/data", "fooprop=foopropval\nbar.prop=8080");
ConsulConfigProperties configProperties = new ConsulConfigProperties();
configProperties.setFormat(ConsulConfigProperties.Format.PROPERTIES);
@@ -86,7 +99,7 @@ public void testProperties() {
public void testYaml() {
// yaml file property
String yamlContext = this.prefix + "/yaml";
- this.client.setKVValue(yamlContext + "/data", "fooprop: fooymlval\nbar:\n prop: 8080");
+ this.consulClient.setKVValue(yamlContext + "/data", "fooprop: fooymlval\nbar:\n prop: 8080");
ConsulConfigProperties configProperties = new ConsulConfigProperties();
configProperties.setFormat(ConsulConfigProperties.Format.YAML);
@@ -99,17 +112,17 @@ public void testYaml() {
public void testEmptyYaml() {
// yaml file property
String yamlContext = this.prefix + "/yaml";
- this.client.setKVValue(yamlContext + "/data", "");
+ this.consulClient.setKVValue(yamlContext + "/data", "");
ConsulConfigProperties configProperties = new ConsulConfigProperties();
configProperties.setFormat(ConsulConfigProperties.Format.YAML);
- ConsulPropertySource source = new ConsulPropertySource(yamlContext, this.client, configProperties);
+ ConsulPropertySource source = new ConsulPropertySource(yamlContext, this.consulClient, configProperties);
// Should NOT throw a NPE
source.init();
}
private ConsulPropertySource getConsulPropertySource(ConsulConfigProperties configProperties, String context) {
- ConsulPropertySource source = new ConsulPropertySource(context, this.client, configProperties);
+ ConsulPropertySource source = new ConsulPropertySource(context, this.consulClient, configProperties);
source.init();
String[] names = source.getPropertyNames();
assertThat(names).as("names was null").isNotNull();
@@ -119,7 +132,7 @@ private ConsulPropertySource getConsulPropertySource(ConsulConfigProperties conf
@Test
public void testExtraSlashInContext() {
- ConsulPropertySource source = new ConsulPropertySource("/my/very/custom/context", this.client,
+ ConsulPropertySource source = new ConsulPropertySource("/my/very/custom/context", this.consulClient,
new ConsulConfigProperties());
source.init();
assertThat(source.getContext()).as("context was wrong").isEqualTo("my/very/custom/context/");
diff --git a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourcesTests.java b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourcesTests.java
index 560ec07b7..627abf33d 100644
--- a/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourcesTests.java
+++ b/spring-cloud-consul-config/src/test/java/org/springframework/cloud/consul/config/ConsulPropertySourcesTests.java
@@ -20,15 +20,16 @@
import java.util.LinkedHashMap;
import java.util.List;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.QueryParams;
-import com.ecwid.consul.v1.Response;
-import com.ecwid.consul.v1.kv.model.GetValue;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
+import org.springframework.cloud.consul.ConsulClient;
+import org.springframework.cloud.consul.model.http.kv.GetValue;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
@@ -48,8 +49,8 @@ public class ConsulPropertySourcesTests {
@Test
public void createPropertySourceStoresNormalizedContextInIndex() {
ConsulClient consul = mock(ConsulClient.class);
- Response> response = new Response<>(Collections.emptyList(), 1L, false, 1L);
- when(consul.getKVValues(eq("test/"), nullable(String.class), any(QueryParams.class))).thenReturn(response);
+ ResponseEntity> response = new ResponseEntity>(HttpStatus.OK);
+ when(consul.getKVValues(eq("test/"), nullable(String.class))).thenReturn(response);
ConsulConfigProperties properties = new ConsulConfigProperties();
ConsulPropertySources sources = new ConsulPropertySources(properties,
@@ -65,7 +66,10 @@ public void createPropertySourceStoresNormalizedContextInIndex() {
@Test
public void createPropertySourceFilesFormatStoresNormalizedContextInIndex() {
ConsulClient consul = mock(ConsulClient.class);
- Response response = new Response<>(null, 1L, false, 1L);
+ ResponseEntity> response = mock(ResponseEntity.class);
+ when(response.getStatusCode()).thenReturn(HttpStatus.OK);
+ when(response.getBody()).thenReturn(Collections.emptyList());
+ when(response.getHeaders()).thenReturn(new HttpHeaders());
when(consul.getKVValue(eq("test.yml"), nullable(String.class))).thenReturn(response);
ConsulConfigProperties properties = new ConsulConfigProperties();
diff --git a/spring-cloud-consul-core/pom.xml b/spring-cloud-consul-core/pom.xml
index dfc3a91bf..f721b71f6 100644
--- a/spring-cloud-consul-core/pom.xml
+++ b/spring-cloud-consul-core/pom.xml
@@ -12,7 +12,7 @@
org.springframework.cloud
spring-cloud-consul
- 4.3.3-SNAPSHOT
+ 5.0.2-SNAPSHOT
..
@@ -26,6 +26,10 @@
org.springframework.boot
spring-boot-starter-validation
+
+ org.springframework.boot
+ spring-boot-restclient
+
org.springframework.boot
spring-boot-starter-web
@@ -43,7 +47,7 @@
org.springframework.boot
- spring-boot-starter-aop
+ spring-boot-starter-aspectj
true
@@ -93,18 +97,33 @@
junit-vintage-engine
test
+
+ org.testcontainers
+ junit-jupiter
+ test
+
org.testcontainers
consul
test
+
+ org.testcontainers
+ mockserver
+ test
+
+
+ org.mock-server
+ mockserver-netty
+ test
+
org.apache.maven.plugins
maven-jar-plugin
- 3.4.2
+ 3.5.0
@@ -113,6 +132,6 @@
-
+
diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConditionalOnConsulEnabled.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConditionalOnConsulEnabled.java
index 6d3f4253f..a6f87f8eb 100644
--- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConditionalOnConsulEnabled.java
+++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConditionalOnConsulEnabled.java
@@ -21,12 +21,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import com.ecwid.consul.v1.ConsulClient;
-
-import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.context.annotation.Conditional;
/**
* When both property and consul classes are on the classpath.
@@ -35,34 +30,7 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
-@Conditional(ConditionalOnConsulEnabled.OnConsulEnabledCondition.class)
+@ConditionalOnProperty(value = "spring.cloud.consul.enabled", matchIfMissing = true)
public @interface ConditionalOnConsulEnabled {
- /**
- * Verifies multiple conditions to see if Consul should be enabled.
- */
- class OnConsulEnabledCondition extends AllNestedConditions {
-
- OnConsulEnabledCondition() {
- super(ConfigurationPhase.REGISTER_BEAN);
- }
-
- /**
- * Consul property is enabled.
- */
- @ConditionalOnProperty(value = "spring.cloud.consul.enabled", matchIfMissing = true)
- static class FoundProperty {
-
- }
-
- /**
- * Consul client class found.
- */
- @ConditionalOnClass(ConsulClient.class)
- static class FoundClass {
-
- }
-
- }
-
}
diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java
index 3773de2dd..673496ab9 100644
--- a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java
+++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulAutoConfiguration.java
@@ -16,30 +16,58 @@
package org.springframework.cloud.consul;
-import java.util.function.Supplier;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.util.Collections;
-import com.ecwid.consul.transport.TLSConfig;
-import com.ecwid.consul.v1.ConsulClient;
-import com.ecwid.consul.v1.ConsulRawClient;
-import com.ecwid.consul.v1.ConsulRawClient.Builder;
import org.aspectj.lang.annotation.Aspect;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
-import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.health.autoconfigure.contributor.ConditionalOnEnabledHealthIndicator;
+import org.springframework.boot.health.contributor.Health;
+import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder;
+import org.springframework.boot.http.client.HttpClientSettings;
+import org.springframework.boot.ssl.SslBundle;
+import org.springframework.boot.ssl.SslStoreBundle;
+import org.springframework.cloud.consul.ConsulClient.QueryParams;
+import org.springframework.cloud.consul.model.http.KeyStoreInstanceType;
+import org.springframework.cloud.consul.model.http.format.WaitTimeAnnotationFormatterFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
+import org.springframework.core.MethodParameter;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.format.support.DefaultFormattingConversionService;
+import org.springframework.http.HttpStatusCode;
+import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.retry.annotation.Retryable;
import org.springframework.retry.interceptor.RetryInterceptorBuilder;
import org.springframework.retry.interceptor.RetryOperationsInterceptor;
import org.springframework.util.StringUtils;
+import org.springframework.web.client.RestClient;
+import org.springframework.web.client.support.RestClientAdapter;
+import org.springframework.web.service.invoker.HttpExchangeAdapter;
+import org.springframework.web.service.invoker.HttpRequestValues;
+import org.springframework.web.service.invoker.HttpServiceArgumentResolver;
+import org.springframework.web.service.invoker.HttpServiceProxyFactory;
+import org.springframework.web.util.DefaultUriBuilderFactory;
+import org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode;
+import org.springframework.web.util.UriBuilder;
/**
* @author Spencer Gibb
@@ -49,6 +77,8 @@
@ConditionalOnConsulEnabled
public class ConsulAutoConfiguration {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConsulAutoConfiguration.class);
+
@Bean
@ConditionalOnMissingBean
public ConsulProperties consulProperties() {
@@ -56,49 +86,108 @@ public ConsulProperties consulProperties() {
}
@Bean
- @ConditionalOnMissingBean(value = ConsulRawClient.Builder.class, parameterizedContainer = Supplier.class)
- public Supplier consulRawClientBuilderSupplier() {
- return createConsulRawClientBuilder();
+ @ConditionalOnMissingBean
+ public ConsulClientSettings consulClientRestClientAdapter(ConsulProperties consulProperties) {
+ String baseUrl = createConsulClientBaseUrl(consulProperties);
+ return createConsulClientSettings(baseUrl, consulProperties.getTls());
}
@Bean
@ConditionalOnMissingBean
- public ConsulClient consulClient(ConsulProperties consulProperties,
- Supplier consulRawClientBuilderSupplier) {
- return createConsulClient(consulProperties, consulRawClientBuilderSupplier);
+ public ConsulClient coreConsulClient(ConsulProperties consulProperties) {
+ return createNewConsulClient(consulProperties);
}
- public static Supplier createConsulRawClientBuilder() {
- return Builder::builder;
- }
+ public static String createConsulClientBaseUrl(ConsulProperties consulProperties) {
+ UriBuilder uriBuilder = new DefaultUriBuilderFactory().builder();
- public static ConsulClient createConsulClient(ConsulProperties consulProperties,
- Supplier consulRawClientBuilderSupplier) {
- ConsulRawClient.Builder builder = consulRawClientBuilderSupplier.get();
- final String agentPath = consulProperties.getPath();
- final String agentHost = StringUtils.hasLength(consulProperties.getScheme())
- ? consulProperties.getScheme() + "://" + consulProperties.getHost() : consulProperties.getHost();
- builder.setHost(agentHost).setPort(consulProperties.getPort());
-
- if (consulProperties.getTls() != null) {
- ConsulProperties.TLSConfig tls = consulProperties.getTls();
- TLSConfig tlsConfig = new TLSConfig(tls.getKeyStoreInstanceType(), tls.getCertificatePath(),
- tls.getCertificatePassword(), tls.getKeyStorePath(), tls.getKeyStorePassword());
- builder.setTlsConfig(tlsConfig);
+ if (StringUtils.hasLength(consulProperties.getScheme())) {
+ uriBuilder.scheme(consulProperties.getScheme());
+ }
+ else {
+ uriBuilder.scheme("http");
}
+ uriBuilder.host(consulProperties.getHost()).port(consulProperties.getPort());
+
+ final String agentPath = consulProperties.getPath();
if (StringUtils.hasLength(agentPath)) {
String normalizedAgentPath = StringUtils.trimTrailingCharacter(agentPath, '/');
normalizedAgentPath = StringUtils.trimLeadingCharacter(normalizedAgentPath, '/');
- builder.setPath(normalizedAgentPath);
+ uriBuilder.path(normalizedAgentPath);
}
- return new ConsulClient(builder.build());
+ String baseUrl = uriBuilder.build().toString();
+ return baseUrl;
+ }
+
+ public static ConsulClient createNewConsulClient(ConsulProperties consulProperties) {
+ String baseUrl = createConsulClientBaseUrl(consulProperties);
+ HttpExchangeAdapter adapter = createConsulClientSettings(baseUrl, consulProperties.getTls()).adapter();
+ return createNewConsulClient(adapter);
+ }
+
+ public static ConsulClient createNewConsulClient(HttpExchangeAdapter adapter) {
+ HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter)
+ .customArgumentResolver(new QueryParamsArgumentResolver())
+ .conversionService(createConsulClientConversionService())
+ .build();
+
+ return factory.createClient(ConsulClient.class);
+ }
+
+ // TODO: migrate to boot managed sslbundle
+ public static ConsulClientSettings createConsulClientSettings(String baseUrl,
+ ConsulProperties.TLSConfig tlsConfig) {
+ try {
+ DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory(baseUrl);
+ uriBuilderFactory.setEncodingMode(EncodingMode.NONE);
+ RestClient.Builder builder = RestClient.builder()
+ .defaultStatusHandler(HttpStatusCode::is4xxClientError, (request, response) -> {
+ })
+ .defaultStatusHandler(HttpStatusCode::is5xxServerError,
+ (request, response) -> LOGGER
+ .error(new String(response.getBody().readAllBytes(), StandardCharsets.UTF_8)))
+ .uriBuilderFactory(uriBuilderFactory);
+
+ HttpClientSettings settings = null;
+ if (tlsConfig != null) {
+ KeyStore clientStore = KeyStore.getInstance(tlsConfig.getKeyStoreInstanceType().name());
+ clientStore.load(Files.newInputStream(Paths.get(tlsConfig.getCertificatePath())),
+ tlsConfig.getCertificatePassword().toCharArray());
+
+ KeyStore trustStore = KeyStore.getInstance(KeyStoreInstanceType.JKS.name());
+ trustStore.load(Files.newInputStream(Paths.get(tlsConfig.getKeyStorePath())),
+ tlsConfig.getKeyStorePassword().toCharArray());
+
+ SslStoreBundle sslStoreBundle = SslStoreBundle.of(clientStore, tlsConfig.getKeyStorePassword(),
+ trustStore);
+ SslBundle sslBundle = SslBundle.of(sslStoreBundle);
+ settings = HttpClientSettings.ofSslBundle(sslBundle);
+ ClientHttpRequestFactory requestFactory = ClientHttpRequestFactoryBuilder.detect().build(settings);
+ builder.requestFactory(requestFactory);
+ }
+
+ return new ConsulClientSettings(baseUrl, settings, RestClientAdapter.create(builder.build()));
+ }
+ catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static ConversionService createConsulClientConversionService() {
+ DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
+ conversionService.addFormatterForFieldAnnotation(new WaitTimeAnnotationFormatterFactory());
+ return conversionService;
+ }
+
+ public record ConsulClientSettings(String baseUrl, HttpClientSettings httpClientSettings,
+ RestClientAdapter adapter) {
}
@Configuration(proxyBeanMethods = false)
- @ConditionalOnClass(Endpoint.class)
+ @ConditionalOnClass({ Endpoint.class, Health.class })
@EnableConfigurationProperties(ConsulHealthIndicatorProperties.class)
protected static class ConsulHealthConfig {
@@ -139,4 +228,40 @@ public RetryOperationsInterceptor consulRetryInterceptor(RetryProperties propert
}
+ static class QueryParamsArgumentResolver implements HttpServiceArgumentResolver {
+
+ @Override
+ public boolean resolve(Object argument, MethodParameter parameter, HttpRequestValues.Builder builder) {
+ if (parameter.getParameterType().equals(QueryParams.class)) {
+ if (argument == null) {
+ return false;
+ }
+ QueryParams params = (QueryParams) argument;
+ if (params.getDatacenter() != null) {
+ builder.addRequestParameter("dc", params.getDatacenter());
+ }
+
+ if (params.getConsistencyMode() != ConsulClient.ConsistencyMode.DEFAULT) {
+ builder.configureRequestParams(
+ map -> map.put(params.getConsistencyMode().getParamName(), Collections.emptyList()));
+ }
+
+ if (params.getWaitTime() != -1) {
+ builder.addRequestParameter("wait", params.getWaitTime() + "s");
+ }
+
+ if (params.getIndex() != -1) {
+ builder.addRequestParameter("index", Long.toUnsignedString(params.getIndex()));
+ }
+
+ if (params.getNear() != null) {
+ builder.addRequestParameter("near", params.getNear());
+ }
+ return true;
+ }
+ return false;
+ }
+
+ }
+
}
diff --git a/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulClient.java b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulClient.java
new file mode 100644
index 000000000..eaaeec554
--- /dev/null
+++ b/spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/ConsulClient.java
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2013-present the original author or authors.
+ *
+ * Licensed 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
+ *
+ * https://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.springframework.cloud.consul;
+
+import java.util.List;
+import java.util.Map;
+
+import org.springframework.cloud.consul.model.http.agent.NewService;
+import org.springframework.cloud.consul.model.http.agent.Service;
+import org.springframework.cloud.consul.model.http.catalog.CatalogService;
+import org.springframework.cloud.consul.model.http.catalog.Node;
+import org.springframework.cloud.consul.model.http.event.Event;
+import org.springframework.cloud.consul.model.http.format.WaitTimeFormat;
+import org.springframework.cloud.consul.model.http.health.Check;
+import org.springframework.cloud.consul.model.http.health.HealthService;
+import org.springframework.cloud.consul.model.http.kv.GetValue;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.service.annotation.DeleteExchange;
+import org.springframework.web.service.annotation.GetExchange;
+import org.springframework.web.service.annotation.PostExchange;
+import org.springframework.web.service.annotation.PutExchange;
+
+public interface ConsulClient {
+
+ /**
+ * Header name for Consul ACL Tokens.
+ */
+ String ACL_TOKEN_HEADER = "X-Consul-Token";
+
+ @GetExchange("/v1/status/leader")
+ ResponseEntity getStatusLeader();
+
+ @GetExchange("/v1/status/peers")
+ ResponseEntity> getStatusPeers();
+
+ @GetExchange("/v1/catalog/datacenters")
+ ResponseEntity> getCatalogDatacenters(
+ @RequestHeader(name = ACL_TOKEN_HEADER, required = false) String aclToken);
+
+ @GetExchange("/v1/catalog/services")
+ ResponseEntity