diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000000..8546d0b294
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,49 @@
+version: 2
+updates:
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ target-branch: "3.1.x" # oldest OSS supported branch
+ schedule:
+ interval: "weekly"
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ target-branch: "4.0.x" # oldest OSS supported branch
+ schedule:
+ interval: "weekly"
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ target-branch: "main"
+ schedule:
+ interval: "weekly"
+ - package-ecosystem: maven
+ directory: /
+ schedule:
+ interval: daily
+ target-branch: 3.1.x
+ 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: 4.0.x
+ 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
\ No newline at end of file
diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml
new file mode 100644
index 0000000000..833dcbe09c
--- /dev/null
+++ b/.github/workflows/deploy-docs.yml
@@ -0,0 +1,32 @@
+name: Deploy Docs
+on:
+ push:
+ branches-ignore: [ gh-pages ]
+ tags: '**'
+ repository_dispatch:
+ types: request-build-reference # legacy
+ #schedule:
+ #- cron: '0 10 * * *' # Once per day at 10am UTC
+ workflow_dispatch:
+permissions:
+ actions: write
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ # if: github.repository_owner == 'spring-cloud'
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+ with:
+ ref: docs-build
+ fetch-depth: 1
+ - name: Dispatch (partial build)
+ if: github.ref_type == 'branch'
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) -f build-refname=${{ github.ref_name }}
+ - name: Dispatch (full build)
+ if: github.ref_type == 'tag'
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD)
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index b48f6ad444..efced2adef 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -5,9 +5,9 @@ name: Build
on:
push:
- branches: [ 3.1.x ]
+ branches: [ main ]
pull_request:
- branches: [ 3.1.x ]
+ branches: [ main ]
jobs:
build:
@@ -16,18 +16,18 @@ jobs:
strategy:
matrix:
- java: ["8"]
+ java: ["17"]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v4
with:
- distribution: 'zulu'
+ distribution: 'temurin'
java-version: ${{ matrix.java }}
cache: 'maven'
- name: Build with Maven
run: ./mvnw clean install -B -U -P sonar
- - uses: codecov/codecov-action@v3
+ - uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
diff --git a/.gitignore b/.gitignore
index af22db416c..0f77f4edf4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+/application.yml
+/application.properties
+asciidoctor.css
*~
#*
*#
@@ -5,6 +8,7 @@
.classpath
.project
.settings/
+.settings
.springBeans
target/
bin/
@@ -18,5 +22,16 @@ _site/
.shelf
*.swp
*.swo
+/spring-cloud-release-tools*.jar
+antrun
.vscode/
.flattened-pom.xml
+node
+node_modules
+build
+_configprops.adoc
+_spans.adoc
+_metrics.adoc
+_conventions.adoc
+/package.json
+package-lock.json
diff --git a/.java-version b/.java-version
new file mode 100644
index 0000000000..98d9bcb75a
--- /dev/null
+++ b/.java-version
@@ -0,0 +1 @@
+17
diff --git a/.mvn/maven.config b/.mvn/maven.config
index 3b8cf46e1e..4b93728449 100644
--- a/.mvn/maven.config
+++ b/.mvn/maven.config
@@ -1 +1,2 @@
--DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring
+-DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local
+-P spring
diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java
deleted file mode 100755
index 474be33d84..0000000000
--- a/.mvn/wrapper/MavenWrapperDownloader.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you 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.
-*/
-
-import java.util.Properties;
-
-public class MavenWrapperDownloader {
-
- /**
- * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
- */
- private static final String DEFAULT_DOWNLOAD_URL =
- "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar";
-
- /**
- * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
- * use instead of the default one.
- */
- private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
- ".mvn/wrapper/maven-wrapper.properties";
-
- /**
- * Path where the maven-wrapper.jar will be saved to.
- */
- private static final String MAVEN_WRAPPER_JAR_PATH =
- ".mvn/wrapper/maven-wrapper.jar";
-
- /**
- * Name of the property which should be used to override the default download url for the wrapper.
- */
- private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
-
- public static void main(String args[]) {
- System.out.println("- Downloader started");
- File baseDirectory = new File(args[0]);
- System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
-
- // If the maven-wrapper.properties exists, read it and check if it contains a custom
- // wrapperUrl parameter.
- File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
- String url = DEFAULT_DOWNLOAD_URL;
- if(mavenWrapperPropertyFile.exists()) {
- FileInputStream mavenWrapperPropertyFileInputStream = null;
- try {
- mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
- Properties mavenWrapperProperties = new Properties();
- mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
- url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
- } catch (IOException e) {
- System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
- } finally {
- try {
- if(mavenWrapperPropertyFileInputStream != null) {
- mavenWrapperPropertyFileInputStream.close();
- }
- } catch (IOException e) {
- // Ignore ...
- }
- }
- }
- System.out.println("- Downloading from: : " + url);
-
- File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
- if(!outputFile.getParentFile().exists()) {
- if(!outputFile.getParentFile().mkdirs()) {
- System.out.println(
- "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
- }
- }
- System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
- try {
- downloadFileFromURL(url, outputFile);
- System.out.println("Done");
- System.exit(0);
- } catch (Throwable e) {
- System.out.println("- Error downloading");
- e.printStackTrace();
- System.exit(1);
- }
- }
-
- private static void downloadFileFromURL(String urlString, File destination) throws Exception {
- URL website = new URL(urlString);
- ReadableByteChannel rbc;
- rbc = Channels.newChannel(website.openStream());
- FileOutputStream fos = new FileOutputStream(destination);
- fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
- fos.close();
- rbc.close();
- }
-
-}
diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar
old mode 100755
new mode 100644
index 08ebbb67f0..cb28b0e37c
Binary files a/.mvn/wrapper/maven-wrapper.jar and b/.mvn/wrapper/maven-wrapper.jar differ
diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties
index a5fcc11920..ac184013fc 100755
--- a/.mvn/wrapper/maven-wrapper.properties
+++ b/.mvn/wrapper/maven-wrapper.properties
@@ -1 +1,18 @@
-distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
\ No newline at end of file
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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
+#
+# http://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.
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip
+wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
diff --git a/.sdkmanrc b/.sdkmanrc
index 4db8676754..415f90832f 100644
--- a/.sdkmanrc
+++ b/.sdkmanrc
@@ -1,3 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
-java=8.0.292.hs-adpt
+java=17.0.1-tem
diff --git a/README.adoc b/README.adoc
index dccc040e48..2efa0bf4e1 100644
--- a/README.adoc
+++ b/README.adoc
@@ -5,60 +5,26 @@ Edit the files in the src/main/asciidoc/ directory instead.
////
-:doctype: book
-:idprefix:
-:idseparator: -
-:toc: left
-:toclevels: 4
-:tabsize: 4
-:numbered:
-:sectanchors:
-:sectnums:
-:icons: font
-:hide-uri-scheme:
-:docinfo: shared,private
-
-:sc-ext: java
-:project-full-name: Spring Cloud Netflix
-
-image::https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml/badge.svg?branch=3.1.x&style=svg["Build",link="https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml"]
-
-image:https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/3.1.x/graph/badge.svg["Codecov", link="https://app.codecov.io/gh/spring-cloud/spring-cloud-netflix/tree/3.1.x"]
-
-:doctype: book
-:idprefix:
-:idseparator: -
-:toc: left
-:toclevels: 4
-:tabsize: 4
-:numbered:
-:sectanchors:
-:sectnums:
-:icons: font
-:hide-uri-scheme:
-:docinfo: shared,private
-
-:sc-ext: java
-:project-full-name: Spring Cloud Netflix
-
-This project provides Netflix OSS integrations for Spring Boot apps through autoconfiguration
-and binding to the Spring Environment and other Spring programming model idioms. With a few
-simple annotations you can quickly enable and configure the common patterns inside your
-application and build large distributed systems with battle-tested Netflix components. The
-patterns provided include Service Discovery (Eureka).
+image::https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml/badge.svg?branch=main&style=svg["Build",link="https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml"]
+image:https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/main/graph/badge.svg["Codecov", link="https://app.codecov.io/gh/spring-cloud/spring-cloud-netflix/tree/main"]
+
+
+[[features]]
== Features
* Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
* Service Discovery: an embedded Eureka server can be created with declarative Java configuration
+[[building]]
== Building
-:jdkversion: 1.8
+:jdkversion: 17
-=== Basic Compile and Test
+[[basic-compile-and-test]]
+== Basic Compile and Test
To build the source you will need to install JDK {jdkversion}.
@@ -85,31 +51,36 @@ source control.
The projects that require middleware (i.e. Redis) for testing generally
require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running.
-
-=== Documentation
+[[documentation]]
+== Documentation
The spring-cloud-build module has a "docs" profile, and if you switch
-that on it will try to build asciidoc sources from
-`src/main/asciidoc`. As part of that process it will look for a
-`README.adoc` and process it by loading all the includes, but not
+that on it will try to build asciidoc sources using https://docs.antora.org/antora/latest/[Antora] from
+`modules/ROOT/`.
+
+As part of that process it will look for a
+`docs/src/main/asciidoc/README.adoc` and process it by loading all the includes, but not
parsing or rendering it, just copying it to `${main.basedir}`
-(defaults to `${basedir}`, i.e. the root of the project). If there are
+(defaults to `$\{basedir}`, i.e. the root of the project). If there are
any changes in the README it will then show up after a Maven build as
a modified file in the correct place. Just commit it and push the change.
-=== Working with the code
+[[working-with-the-code]]
+== Working with the code
If you don't have an IDE preference we would recommend that you use
https://www.springsource.com/developer/sts[Spring Tools Suite] or
https://eclipse.org[Eclipse] when working with the code. We use the
https://eclipse.org/m2e/[m2eclipse] eclipse plugin for maven support. Other IDEs and tools
should also work without issue as long as they use Maven 3.3.3 or better.
-==== Activate the Spring Maven profile
+[[activate-the-spring-maven-profile]]
+=== Activate the Spring Maven profile
Spring Cloud projects require the 'spring' Maven profile to be activated to resolve
the spring milestone and snapshot repositories. Use your preferred IDE to set this
profile to be active, or you may experience build errors.
-==== Importing into eclipse with m2eclipse
+[[importing-into-eclipse-with-m2eclipse]]
+=== Importing into eclipse with m2eclipse
We recommend the https://eclipse.org/m2e/[m2eclipse] eclipse plugin when working with
eclipse. If you don't already have m2eclipse installed it is available from the "eclipse
marketplace".
@@ -123,7 +94,8 @@ add the "spring" profile to your `settings.xml`. Alternatively you can
copy the repository settings from the "spring" profile of the parent
pom into your `settings.xml`.
-==== Importing into eclipse without m2eclipse
+[[importing-into-eclipse-without-m2eclipse]]
+=== Importing into eclipse without m2eclipse
If you prefer not to use m2eclipse you can generate eclipse project metadata using the
following command:
@@ -136,243 +108,15 @@ The generated eclipse projects can be imported by selecting `import existing pro
from the `file` menu.
-
NOTE: To build the module `spring-cloud-netflix-hystrix-contract` along with the entire Netflix project run the
`build.sh` script in the `scripts` directory.
+[[contributing]]
== Contributing
-:spring-cloud-build-branch: master
-
-Spring Cloud is released under the non-restrictive Apache 2.0 license,
-and follows a very standard Github development process, using Github
-tracker for issues and merging pull requests into master. If you want
-to contribute even something trivial please do not hesitate, but
-follow the guidelines below.
-
-=== Sign the Contributor License Agreement
-Before we accept a non-trivial patch or pull request we will need you to sign the
-https://cla.pivotal.io/sign/spring[Contributor License Agreement].
-Signing the contributor's agreement does not grant anyone commit rights to the main
-repository, but it does mean that we can accept your contributions, and you will get an
-author credit if we do. Active contributors might be asked to join the core team, and
-given the ability to merge pull requests.
-
-=== Code of Conduct
-This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc[code of
-conduct]. By participating, you are expected to uphold this code. Please report
-unacceptable behavior to spring-code-of-conduct@pivotal.io.
-
-=== Code Conventions and Housekeeping
-None of these is essential for a pull request, but they will all help. They can also be
-added after the original pull request but before a merge.
-
-* Use the Spring Framework code format conventions. If you use Eclipse
- you can import formatter settings using the
- `eclipse-code-formatter.xml` file from the
- https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring
- Cloud Build] project. If using IntelliJ, you can use the
- https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter
- Plugin] to import the same file.
-* Make sure all new `.java` files to have a simple Javadoc class comment with at least an
- `@author` tag identifying you, and preferably at least a paragraph on what the class is
- for.
-* Add the ASF license header comment to all new `.java` files (copy from existing files
- in the project)
-* Add yourself as an `@author` to the .java files that you modify substantially (more
- than cosmetic changes).
-* Add some Javadocs and, if you change the namespace, some XSD doc elements.
-* A few unit tests would help a lot as well -- someone has to do it.
-* If no-one else is using your branch, please rebase it against the current master (or
- other target branch in the main project).
-* When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions],
- if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit
- message (where XXXX is the issue number).
-
-=== Checkstyle
-
-Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are:
-
-.spring-cloud-build-tools/
-----
-└── src
- ├── checkstyle
- │ └── checkstyle-suppressions.xml <3>
- └── main
- └── resources
- ├── checkstyle-header.txt <2>
- └── checkstyle.xml <1>
-----
-<1> Default Checkstyle rules
-<2> File header setup
-<3> Default suppression rules
-
-==== Checkstyle configuration
-
-Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins.
-
-.pom.xml
-----
-
-true <1>
- true
- <2>
- true
- <3>
-
-
-
-
- <4>
- io.spring.javaformat
- spring-javaformat-maven-plugin
-
- <5>
- org.apache.maven.plugins
- maven-checkstyle-plugin
-
-
-
-
-
- <5>
- org.apache.maven.plugins
- maven-checkstyle-plugin
-
-
-
-
-----
-<1> Fails the build upon Checkstyle errors
-<2> Fails the build upon Checkstyle violations
-<3> Checkstyle analyzes also the test sources
-<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules
-<5> Add checkstyle plugin to your build and reporting phases
-
-If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example:
-
-.projectRoot/src/checkstyle/checkstyle-suppresions.xml
-----
-
-
-
-
-
-
-----
-
-It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script:
-
-```bash
-$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
-$ touch .springformat
-```
-
-=== IDE setup
-
-==== Intellij IDEA
-
-In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.
-The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools[Spring Cloud Build] project.
-
-.spring-cloud-build-tools/
-----
-└── src
- ├── checkstyle
- │ └── checkstyle-suppressions.xml <3>
- └── main
- └── resources
- ├── checkstyle-header.txt <2>
- ├── checkstyle.xml <1>
- └── intellij
- ├── Intellij_Project_Defaults.xml <4>
- └── Intellij_Spring_Boot_Java_Conventions.xml <5>
-----
-<1> Default Checkstyle rules
-<2> File header setup
-<3> Default suppression rules
-<4> Project defaults for Intellij that apply most of Checkstyle rules
-<5> Project style conventions for Intellij that apply most of Checkstyle rules
-
-.Code style
-
-image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-code-style.png[Code style]
-
-Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file.
-
-.Inspection profiles
-
-image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-inspections.png[Code style]
-
-Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file.
-
-.Checkstyle
-
-To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions
-
-image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring-cloud-build-branch}/docs/src/main/asciidoc/images/intellij-checkstyle.png[Checkstyle]
-
-Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables:
-
-- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL.
-- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL.
-- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`.
-
-IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
-
-=== Duplicate Finder
-
-Spring Cloud Build brings along the `basepom:duplicate-finder-maven-plugin`, that enables flagging duplicate and conflicting classes and resources on the java classpath.
-
-==== Duplicate Finder configuration
-
-Duplicate finder is *enabled by default* and will run in the `verify` phase of your Maven build, but it will only take effect in your project if you add the `duplicate-finder-maven-plugin` to the `build` section of the projecst's `pom.xml`.
-
-.pom.xml
-[source,xml]
-----
-
-
-
- org.basepom.maven
- duplicate-finder-maven-plugin
-
-
-
-----
-
-For other properties, we have set defaults as listed in the https://github.com/basepom/duplicate-finder-maven-plugin/wiki[plugin documentation].
-
-You can easily override them but setting the value of the selected property prefixed with `duplicate-finder-maven-plugin`. For example, set `duplicate-finder-maven-plugin.skip` to `true` in order to skip duplicates check in your build.
-
-If you need to add `ignoredClassPatterns` or `ignoredResourcePatterns` to your setup, make sure to add them in the plugin configuration section of your project:
-
-[source,xml]
-----
-
-
-
- org.basepom.maven
- duplicate-finder-maven-plugin
-
-
- org.joda.time.base.BaseDateTime
- .*module-info
-
-
- changelog.txt
-
-
-
-
-
-
-
-----
-
+NOTE: Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at {github-project}[github].
+[[license]]
== License
The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/main/LICENSE.txt[here].
diff --git a/docs/antora-playbook.yml b/docs/antora-playbook.yml
new file mode 100644
index 0000000000..2049eb0ea8
--- /dev/null
+++ b/docs/antora-playbook.yml
@@ -0,0 +1,33 @@
+antora:
+ extensions:
+ - require: '@springio/antora-extensions'
+ root_component_name: 'cloud-netflix'
+site:
+ title: Spring Cloud Netflix
+ url: https://docs.spring.io/spring-cloud-netflix/reference/
+content:
+ sources:
+ - url: ./..
+ branches: HEAD
+ start_path: docs
+ worktrees: true
+asciidoc:
+ attributes:
+ page-stackoverflow-url: https://stackoverflow.com/tags/spring-cloud
+ page-pagination: ''
+ hide-uri-scheme: '@'
+ tabs-sync-option: '@'
+ chomp: 'all'
+ extensions:
+ - '@asciidoctor/tabs'
+ - '@springio/asciidoctor-extensions'
+ sourcemap: true
+urls:
+ latest_version_segment: ''
+runtime:
+ log:
+ failure_level: warn
+ format: pretty
+ui:
+ bundle:
+ url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.15/ui-bundle.zip
diff --git a/docs/antora.yml b/docs/antora.yml
new file mode 100644
index 0000000000..2b2458e55a
--- /dev/null
+++ b/docs/antora.yml
@@ -0,0 +1,12 @@
+name: cloud-netflix
+version: true
+title: Spring Cloud Netflix
+nav:
+ - modules/ROOT/nav.adoc
+ext:
+ collector:
+ run:
+ command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests
+ local: true
+ scan:
+ dir: ./target/classes/antora-resources/
diff --git a/docs/modules/ROOT/assets/images/Hystrix.png b/docs/modules/ROOT/assets/images/Hystrix.png
new file mode 100644
index 0000000000..7d4e17ed45
Binary files /dev/null and b/docs/modules/ROOT/assets/images/Hystrix.png differ
diff --git a/docs/modules/ROOT/assets/images/HystrixFallback.png b/docs/modules/ROOT/assets/images/HystrixFallback.png
new file mode 100644
index 0000000000..372018c75a
Binary files /dev/null and b/docs/modules/ROOT/assets/images/HystrixFallback.png differ
diff --git a/docs/modules/ROOT/assets/images/HystrixGraph.png b/docs/modules/ROOT/assets/images/HystrixGraph.png
new file mode 100644
index 0000000000..c07c6bd585
Binary files /dev/null and b/docs/modules/ROOT/assets/images/HystrixGraph.png differ
diff --git a/docs/modules/ROOT/assets/images/RequestLatency.png b/docs/modules/ROOT/assets/images/RequestLatency.png
new file mode 100644
index 0000000000..6c7e93bebe
Binary files /dev/null and b/docs/modules/ROOT/assets/images/RequestLatency.png differ
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
new file mode 100644
index 0000000000..815f9d0893
--- /dev/null
+++ b/docs/modules/ROOT/nav.adoc
@@ -0,0 +1,5 @@
+* xref:index.adoc[Introduction]
+* xref:spring-cloud-netflix.adoc[]
+* xref:appendix.adoc[]
+** xref:configprops.adoc[]
+
diff --git a/docs/src/main/asciidoc/_attributes.adoc b/docs/modules/ROOT/pages/_attributes.adoc
similarity index 71%
rename from docs/src/main/asciidoc/_attributes.adoc
rename to docs/modules/ROOT/pages/_attributes.adoc
index 16af12202c..1fcb32f332 100644
--- a/docs/src/main/asciidoc/_attributes.adoc
+++ b/docs/modules/ROOT/pages/_attributes.adoc
@@ -1,8 +1,6 @@
:doctype: book
:idprefix:
:idseparator: -
-:toc: left
-:toclevels: 4
:tabsize: 4
:numbered:
:sectanchors:
@@ -12,4 +10,4 @@
:docinfo: shared,private
:sc-ext: java
-:project-full-name: Spring Cloud Netflix
\ No newline at end of file
+:project-full-name: Spring Cloud Netflix
diff --git a/docs/src/main/asciidoc/appendix.adoc b/docs/modules/ROOT/pages/appendix.adoc
similarity index 63%
rename from docs/src/main/asciidoc/appendix.adoc
rename to docs/modules/ROOT/pages/appendix.adoc
index 2c18b86531..e518fb807d 100644
--- a/docs/src/main/asciidoc/appendix.adoc
+++ b/docs/modules/ROOT/pages/appendix.adoc
@@ -1,14 +1,13 @@
:numbered!:
[appendix]
[[common-application-properties]]
-== Common application properties
+= Common application properties
+:page-section-summary-toc: 1
-include::_attributes.adoc[]
Various properties can be specified inside your `application.properties` file, inside your `application.yml` file, or as command line switches.
-This appendix provides a list of common {project-full-name} properties and references to the underlying classes that consume them.
+This appendix provides a list of common Spring Cloud Netflix properties and references to the underlying classes that consume them.
NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list.
Also, you can define your own properties.
-include::_configprops.adoc[]
\ No newline at end of file
diff --git a/docs/modules/ROOT/pages/configprops.adoc b/docs/modules/ROOT/pages/configprops.adoc
new file mode 100644
index 0000000000..32cbb8e589
--- /dev/null
+++ b/docs/modules/ROOT/pages/configprops.adoc
@@ -0,0 +1,6 @@
+[[configuration-properties]]
+= Configuration Properties
+
+Below you can find a list of configuration properties.
+
+include::partial$_configprops.adoc[]
diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc
new file mode 100644
index 0000000000..58168dfbe8
--- /dev/null
+++ b/docs/modules/ROOT/pages/index.adoc
@@ -0,0 +1 @@
+include::intro.adoc[]
\ No newline at end of file
diff --git a/docs/src/main/asciidoc/intro.adoc b/docs/modules/ROOT/pages/intro.adoc
similarity index 91%
rename from docs/src/main/asciidoc/intro.adoc
rename to docs/modules/ROOT/pages/intro.adoc
index 6d1e599eb7..9288ae6363 100644
--- a/docs/src/main/asciidoc/intro.adoc
+++ b/docs/modules/ROOT/pages/intro.adoc
@@ -1,4 +1,5 @@
-include::_attributes.adoc[]
+[[introduction]]
+= Spring Cloud Netflix
This project provides Netflix OSS integrations for Spring Boot apps through autoconfiguration
and binding to the Spring Environment and other Spring programming model idioms. With a few
diff --git a/docs/src/main/asciidoc/spring-cloud-netflix.adoc b/docs/modules/ROOT/pages/spring-cloud-netflix.adoc
similarity index 89%
rename from docs/src/main/asciidoc/spring-cloud-netflix.adoc
rename to docs/modules/ROOT/pages/spring-cloud-netflix.adoc
index 1f7562fb97..8e556ef9ca 100755
--- a/docs/src/main/asciidoc/spring-cloud-netflix.adoc
+++ b/docs/modules/ROOT/pages/spring-cloud-netflix.adoc
@@ -1,20 +1,5 @@
-include::_attributes.adoc[]
-
-
-:github-tag: main
-:github-repo: spring-cloud/spring-cloud-netflix
-:github-raw: https://raw.github.com/{github-repo}/{github-tag}
-:github-code: https://github.com/{github-repo}/tree/{github-tag}
-:all: {asterisk}{asterisk}
-:nofooter:
-:branch: main
-
-= Spring Cloud Netflix
-
-*{spring-cloud-version}*
-
-include::intro.adoc[]
-
+[[features]]
+= Spring Cloud Netflix Features
== Service Discovery: Eureka Clients
@@ -112,7 +97,7 @@ NOTE: Because of a limitation in Eureka, it is not possible to support per-serve
If you want to customize the RestTemplate used by the Eureka HTTP Client you may want to create a bean of `EurekaClientHttpRequestFactorySupplier` and provide your own logic for generating a `ClientHttpRequestFactory` instance.
-All default timeout-related properties for RestTemplate used by the Eureka HTTP Client are set to infinite. Therefore, to specify the timeout values, you must specify the value directly with the properties in `eureka.client.rest-template-timeout`. (All timeout properties are in milliseconds.)
+All default timeout-related properties for RestTemplate used by the Eureka HTTP Client are set to 3 minutes (in keeping with Apache HC5 default `RequestConfig` and `SocketConfig`). Therefore, to specify the timeout values, you must specify the value directly with the properties in `eureka.client.rest-template-timeout`. (All timeout properties are in milliseconds.)
.application.yml
[source,yaml]
@@ -282,32 +267,40 @@ Do not use the `EurekaClient` in a `@PostConstruct` method or in a `@Scheduled`
It is initialized in a `SmartLifecycle` (with `phase=0`), so the earliest you can rely on it being available is in another `SmartLifecycle` with a higher phase.
====
-==== EurekaClient with Jersey
+==== Underlying HTTP clients
+
+`EurekaClient` uses either `RestTemplate`, `WebClient` or `JerseyClient` under the hood. In order to use the `EurekaClient`, you need to have one of the supported HTTP clients on your classpath.
+
+To use `RestTemplate`, add `spring-boot-starter-web` to your dependencies. To use `WebClient`, add `spring-boot-starter-webflux` to your dependencies. If both `RestTemplate` and `WebClient` are on the classpath when `eureka.client.webclient.enabled` is set to `true`, `WebClient` is used. Otherwise, `RestTemplate` is used.
-By default, EurekaClient uses Spring's `RestTemplate` for HTTP communication.
If you wish to use Jersey instead, you need to add the Jersey dependencies to your classpath.
The following example shows the dependencies you need to add:
+[source,xml]
----
-
- com.sun.jersey
- jersey-client
-
-
- com.sun.jersey
- jersey-core
-
-
- com.sun.jersey.contribs
- jersey-apache-client4
-
+
+
+ com.sun.jersey
+ jersey-client
+
+
+ com.sun.jersey
+ jersey-core
+
+
+ com.sun.jersey.contribs
+ jersey-apache-client4
+
+
----
+If you have `JerseyClient` on the classpath but do not wish to use it in your `EuerekaClient`, make sure to set `eureka.client.jersey.enabled` to `false`.
+
=== Alternatives to the Native Netflix EurekaClient
You need not use the raw Netflix `EurekaClient`.
Also, it is usually more convenient to use it behind a wrapper of some sort.
-Spring Cloud has support for <> (a REST client builder) and https://docs.spring.io/spring-cloud-commons/docs/3.1.7/reference/html/#spring-cloud-loadbalancer[Spring Cloud LoadBalancer] through the logical Eureka service identifiers (VIPs) instead of physical URLs.
+Spring Cloud has support for <> (a REST client builder) and https://docs.spring.io/spring-cloud-commons/reference/4.1/spring-cloud-commons/loadbalancer.html[Spring Cloud LoadBalancer] through the logical Eureka service identifiers (VIPs) instead of physical URLs.
You can also use the `org.springframework.cloud.client.discovery.DiscoveryClient`, which provides a simple API (not specific to Netflix) for discovery clients, as shown in the following example:
@@ -379,6 +372,12 @@ it can use the domain name from the server hostname as a proxy for the zone.
If there is no other source of zone data, then a guess is made, based on the client configuration (as opposed to the instance configuration).
We take `eureka.client.availabilityZones`, which is a map from region name to a list of zones, and pull out the first zone for the instance's own region (that is, the `eureka.client.region`, which defaults to "us-east-1", for compatibility with native Netflix).
+=== AOT and Native Image Support
+
+Spring Cloud Netflix Eureka Client integration supports Spring AOT transformations and native images, however, only with refresh mode disabled.
+
+WARNING: If you want to run Eureka Client in AOT or native image modes, make sure to set `spring.cloud.refresh.enabled` to `false`
+
[[spring-cloud-eureka-server]]
== Service Discovery: Eureka Server
@@ -522,7 +521,7 @@ the registrations amongst themselves.
If the peers are physically separated (inside a data center or between multiple data centers), then the system can, in principle, survive "`split-brain`" type failures.
You can add multiple peers to a system, and as long as they are all
directly connected to each other, they will synchronize
-the registrations amongst themselves.
+the registrations amongst themselves.
.application.yml (Three Peer Aware Eureka Servers)
----
@@ -530,7 +529,7 @@ eureka:
client:
serviceUrl:
defaultZone: https://peer1/eureka/,http://peer2/eureka/,http://peer3/eureka/
-
+
---
spring:
profiles: peer1
@@ -563,33 +562,32 @@ Set `eureka.instance.preferIpAddress` to `true` and, when the application regist
====
If the hostname cannot be determined by Java, then the IP address is sent to Eureka.
Only explict way of setting the hostname is by setting `eureka.instance.hostname` property.
-You can set your hostname at the run-time by using an environment variable -- for example, `eureka.instance.hostname=${HOST_NAME}`.
+You can set your hostname at the run-time by using an environment variable -- for example, `eureka.instance.hostname=$\{HOST_NAME}`.
====
=== Securing The Eureka Server
You can secure your Eureka server simply by adding Spring Security to your
-server's classpath via `spring-boot-starter-security`. By default when Spring Security is on the classpath it will require that
+server's classpath via `spring-boot-starter-security`. By default, when Spring Security is on the classpath it will require that
a valid CSRF token be sent with every request to the app. Eureka clients will not generally possess a valid
cross site request forgery (CSRF) token you will need to disable this requirement for the `/eureka/**` endpoints.
-For example:
+For example:
[source,java,indent=0]
----
-@EnableWebSecurity
-class WebSecurityConfig extends WebSecurityConfigurerAdapter {
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.csrf().ignoringAntMatchers("/eureka/**");
- super.configure(http);
- }
+@Bean
+public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
+ http.authorizeHttpRequests((authz) -> authz
+ .anyRequest().authenticated())
+ .httpBasic(withDefaults());
+ http.csrf().ignoringRequestMatchers("/eureka/**");
+ return http.build();
}
----
For more information on CSRF see the https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#csrf[Spring Security documentation].
-A demo Eureka Server can be found in the Spring Cloud Samples https://github.com/spring-cloud-samples/eureka/tree/Eureka-With-Security[repo].
+A demo Eureka Server can be found in the Spring Cloud Samples https://github.com/spring-cloud-samples/eureka/tree/Eureka-With-Security-4.x[repo].
=== JDK 11 Support
@@ -604,6 +602,21 @@ when running a Eureka server you must include these dependencies in your POM or
----
+=== AOT and Native Image Support
+
+Spring Cloud Netflix Eureka Server does not support Spring AOT transformations or native images.
+
+=== Metrics
+
+`EurekaInstanceMonitor` listens to events related to Eureka instance registration and creates/updates `Gauge`s for Eureka instance information in Micrometer's `MeterRegistry`. By default, this behavior is disabled. If you want to enable it, you need to set `eureka.server.metrics.enabled` to `true`.
+
+By default, the `Gauge`s are named `eureka.server.instances` and have the following tags:
+
+- `application`: application name
+- `status`: instance status (`UP`, `DOWN`, `STARTING`, `OUT_OF_SERVICE`, `UNKNOWN`, see: `com.netflix.appinfo.InstanceInfo.InstanceStatus`)
+
+You can add additional tags by injecting your own implementation of `EurekaInstanceTagsProvider`.
+
== Configuration properties
To see the list of all Spring Cloud Netflix related configuration properties please check link:appendix.html[the Appendix page].
diff --git a/docs/modules/ROOT/partials/_configprops.adoc b/docs/modules/ROOT/partials/_configprops.adoc
new file mode 100644
index 0000000000..6bb8b81ac4
--- /dev/null
+++ b/docs/modules/ROOT/partials/_configprops.adoc
@@ -0,0 +1,261 @@
+|===
+|Name | Default | Description
+
+|eureka.client.allow-redirects | `+++false+++` | Indicates whether server can redirect a client request to a backup server/cluster. If set to false, the server will handle the request directly, If set to true, it may send HTTP redirect to the client, with a new server location.
+|eureka.client.availability-zones | | Gets the list of availability zones (used in AWS data centers) for the region in which this instance resides. The changes are effective at runtime at the next registry fetch cycle as specified by registryFetchIntervalSeconds.
+|eureka.client.backup-registry-impl | | Gets the name of the implementation which implements BackupRegistry to fetch the registry information as a fallback option for only the first time when the eureka client starts. This may be needed for applications which needs additional resiliency for registry information without which it cannot operate.
+|eureka.client.cache-refresh-executor-exponential-back-off-bound | `+++10+++` | Cache refresh executor exponential back off related property. It is a maximum multiplier value for retry delay, in case where a sequence of timeouts occurred.
+|eureka.client.cache-refresh-executor-thread-pool-size | `+++2+++` | The thread pool size for the cacheRefreshExecutor to initialise with.
+|eureka.client.client-data-accept | | EurekaAccept name for client data accept.
+|eureka.client.decoder-name | | This is a transient config and once the latest codecs are stable, can be removed (as there will only be one).
+|eureka.client.disable-delta | `+++false+++` | Indicates whether the eureka client should disable fetching of delta and should rather resort to getting the full registry information. Note that the delta fetches can reduce the traffic tremendously, because the rate of change with the eureka server is normally much lower than the rate of fetches. The changes are effective at runtime at the next registry fetch cycle as specified by registryFetchIntervalSeconds
+|eureka.client.dollar-replacement | `+++_-+++` | Get a replacement string for Dollar sign $ during serializing/deserializing information in eureka server.
+|eureka.client.enabled | `+++true+++` | Flag to indicate that the Eureka client is enabled.
+|eureka.client.encoder-name | | This is a transient config and once the latest codecs are stable, can be removed (as there will only be one).
+|eureka.client.escape-char-replacement | `+++__+++` | Get a replacement string for underscore sign _ during serializing/ deserializing information in eureka server.
+|eureka.client.eureka-connection-idle-timeout-seconds | `+++30+++` | Indicates how much time (in seconds) that the HTTP connections to eureka server can stay idle before it can be closed. In the AWS environment, it is recommended that the values is 30 seconds or less, since the firewall cleans up the connection information after a few mins leaving the connection hanging in limbo.
+|eureka.client.eureka-server-connect-timeout-seconds | `+++5+++` | Indicates how long to wait (in seconds) before a connection to eureka server needs to timeout. Note that the connections in the client are pooled by {@link HttpClient} and this setting affects the actual connection creation and also the wait time to get the connection from the pool.
+|eureka.client.eureka-server-d-n-s-name | | Gets the DNS name to be queried to get the list of eureka servers.This information is not required if the contract returns the service urls by implementing serviceUrls. The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
+|eureka.client.eureka-server-port | | Gets the port to be used to construct the service url to contact eureka server when the list of eureka servers come from the DNS.This information is not required if the contract returns the service urls eurekaServerServiceUrls(String). The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
+|eureka.client.eureka-server-read-timeout-seconds | `+++8+++` | Indicates how long to wait (in seconds) before a read from eureka server needs to timeout.
+|eureka.client.eureka-server-total-connections | `+++200+++` | Gets the total number of connections that is allowed from eureka client to all eureka servers.
+|eureka.client.eureka-server-total-connections-per-host | `+++50+++` | Gets the total number of connections that is allowed from eureka client to a eureka server host.
+|eureka.client.eureka-server-u-r-l-context | | Gets the URL context to be used to construct the service url to contact eureka server when the list of eureka servers come from the DNS. This information is not required if the contract returns the service urls from eurekaServerServiceUrls. The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
+|eureka.client.eureka-service-url-poll-interval-seconds | `+++0+++` | Indicates how often(in seconds) to poll for changes to eureka server information. Eureka servers could be added or removed and this setting controls how soon the eureka clients should know about it.
+|eureka.client.fetch-registry | `+++true+++` | Indicates whether this client should fetch eureka registry information from eureka server.
+|eureka.client.fetch-remote-regions-registry | | Comma separated list of regions for which the eureka registry information will be fetched. It is mandatory to define the availability zones for each of these regions as returned by availabilityZones. Failing to do so, will result in failure of discovery client startup.
+|eureka.client.filter-only-up-instances | `+++true+++` | Indicates whether to get the applications after filtering the applications for instances with only InstanceStatus UP states.
+|eureka.client.g-zip-content | `+++true+++` | Indicates whether the content fetched from eureka server has to be compressed whenever it is supported by the server. The registry information from the eureka server is compressed for optimum network traffic.
+|eureka.client.healthcheck.enabled | `+++true+++` | Enables the Eureka health check handler.
+|eureka.client.heartbeat-executor-exponential-back-off-bound | `+++10+++` | Heartbeat executor exponential back off related property. It is a maximum multiplier value for retry delay, in case where a sequence of timeouts occurred.
+|eureka.client.heartbeat-executor-thread-pool-size | `+++2+++` | The thread pool size for the heartbeatExecutor to initialise with.
+|eureka.client.initial-instance-info-replication-interval-seconds | `+++40+++` | Indicates how long initially (in seconds) to replicate instance info to the eureka server.
+|eureka.client.instance-info-replication-interval-seconds | `+++30+++` | Indicates how often(in seconds) to replicate instance changes to be replicated to the eureka server.
+|eureka.client.log-delta-diff | `+++false+++` | Indicates whether to log differences between the eureka server and the eureka client in terms of registry information. Eureka client tries to retrieve only delta changes from eureka server to minimize network traffic. After receiving the deltas, eureka client reconciles the information from the server to verify it has not missed out some information. Reconciliation failures could happen when the client has had network issues communicating to server.If the reconciliation fails, eureka client gets the full registry information. While getting the full registry information, the eureka client can log the differences between the client and the server and this setting controls that. The changes are effective at runtime at the next registry fetch cycle as specified by registryFetchIntervalSecondsr
+|eureka.client.on-demand-update-status-change | `+++true+++` | If set to true, local status updates via ApplicationInfoManager will trigger on-demand (but rate limited) register/updates to remote eureka servers.
+|eureka.client.order | `+++0+++` | Order of the discovery client used by `CompositeDiscoveryClient` for sorting available clients.
+|eureka.client.prefer-same-zone-eureka | `+++true+++` | Indicates whether or not this instance should try to use the eureka server in the same zone for latency and/or other reason. Ideally eureka clients are configured to talk to servers in the same zone The changes are effective at runtime at the next registry fetch cycle as specified by registryFetchIntervalSeconds
+|eureka.client.property-resolver | |
+|eureka.client.proxy-host | | Gets the proxy host to eureka server if any.
+|eureka.client.proxy-password | | Gets the proxy password if any.
+|eureka.client.proxy-port | | Gets the proxy port to eureka server if any.
+|eureka.client.proxy-user-name | | Gets the proxy user name if any.
+|eureka.client.refresh.enable | `+++true+++` | Determines whether the EurekaClient instance can be refreshed or not(If disabled none of the Eureka client properties will be refreshable).
+|eureka.client.region | `+++us-east-1+++` | Gets the region (used in AWS datacenters) where this instance resides.
+|eureka.client.register-with-eureka | `+++true+++` | Indicates whether or not this instance should register its information with eureka server for discovery by others. In some cases, you do not want your instances to be discovered whereas you just want do discover other instances.
+|eureka.client.registry-fetch-interval-seconds | `+++30+++` | Indicates how often(in seconds) to fetch the registry information from the eureka server.
+|eureka.client.registry-refresh-single-vip-address | | Indicates whether the client is only interested in the registry information for a single VIP.
+|eureka.client.rest-template-timeout.connect-request-timeout | `+++0+++` |
+|eureka.client.rest-template-timeout.connect-timeout | `+++0+++` | Default values are set to 180000, in keeping with {@link RequestConfig} and {@link SocketConfig} defaults.
+|eureka.client.rest-template-timeout.socket-timeout | `+++0+++` |
+|eureka.client.service-url | | Map of availability zone to list of fully qualified URLs to communicate with eureka server. Each value can be a single URL or a comma separated list of alternative locations. Typically the eureka server URLs carry protocol,host,port,context and version information if any. Example: https://ec2-256-156-243-129.compute-1.amazonaws.com:7001/eureka/ The changes are effective at runtime at the next service url refresh cycle as specified by eurekaServiceUrlPollIntervalSeconds.
+|eureka.client.should-enforce-registration-at-init | `+++false+++` | Indicates whether the client should enforce registration during initialization. Defaults to false.
+|eureka.client.should-unregister-on-shutdown | `+++true+++` | Indicates whether the client should explicitly unregister itself from the remote server on client shutdown.
+|eureka.client.tls.enabled | |
+|eureka.client.tls.key-password | |
+|eureka.client.tls.key-store | |
+|eureka.client.tls.key-store-password | |
+|eureka.client.tls.key-store-type | |
+|eureka.client.tls.trust-store | |
+|eureka.client.tls.trust-store-password | |
+|eureka.client.tls.trust-store-type | |
+|eureka.client.use-dns-for-fetching-service-urls | `+++false+++` | Indicates whether the eureka client should use the DNS mechanism to fetch a list of eureka servers to talk to. When the DNS name is updated to have additional servers, that information is used immediately after the eureka client polls for that information as specified in eurekaServiceUrlPollIntervalSeconds. Alternatively, the service urls can be returned serviceUrls, but the users should implement their own mechanism to return the updated list in case of changes. The changes are effective at runtime.
+|eureka.client.webclient.enabled | `+++false+++` | Enables the use of WebClient for Eureka HTTP Client.
+|eureka.dashboard.enabled | `+++true+++` | Flag to enable the Eureka dashboard. Default true.
+|eureka.dashboard.path | `+++/+++` | The path to the Eureka dashboard (relative to the servlet path). Defaults to "/".
+|eureka.datacenter | `+++default+++` | Eureka datacenter. Defaults to "default".
+|eureka.environment | `+++test+++` | Eureka environment. Defaults to "test".
+|eureka.instance.a-s-g-name | | Gets the AWS autoscaling group name associated with this instance. This information is specifically used in an AWS environment to automatically put an instance out of service after the instance is launched and it has been disabled for traffic..
+|eureka.instance.app-group-name | | Get the name of the application group to be registered with eureka.
+|eureka.instance.appname | `+++unknown+++` | Get the name of the application to be registered with eureka.
+|eureka.instance.async-client-initialization | `+++false+++` | If true the EurekaClient will be initialized asynchronously when the InstanceRegistry bean is created.
+|eureka.instance.data-center-info | | Returns the data center this instance is deployed. This information is used to get some AWS specific instance information if the instance is deployed in AWS.
+|eureka.instance.default-address-resolution-order | `+++[]+++` |
+|eureka.instance.environment | |
+|eureka.instance.health-check-url | | Gets the absolute health check page URL for this instance. The users can provide the healthCheckUrlPath if the health check page resides in the same instance talking to eureka, else in the cases where the instance is a proxy for some other server, users can provide the full URL. If the full URL is provided it takes precedence.
It is normally used for making educated decisions based on the health of the instance - for example, it can be used to determine whether to proceed deployments to an entire farm or stop the deployments without causing further damage. The full URL should follow the format http://${eureka.hostname}:7001/ where the value ${eureka.hostname} is replaced at runtime.
+|eureka.instance.health-check-url-path | | Gets the relative health check URL path for this instance. The health check page URL is then constructed out of the hostname and the type of communication - secure or unsecure as specified in securePort and nonSecurePort. It is normally used for making educated decisions based on the health of the instance - for example, it can be used to determine whether to proceed deployments to an entire farm or stop the deployments without causing further damage.
+|eureka.instance.home-page-url | | Gets the absolute home page URL for this instance. The users can provide the homePageUrlPath if the home page resides in the same instance talking to eureka, else in the cases where the instance is a proxy for some other server, users can provide the full URL. If the full URL is provided it takes precedence. It is normally used for informational purposes for other services to use it as a landing page. The full URL should follow the format http://${eureka.hostname}:7001/ where the value ${eureka.hostname} is replaced at runtime.
+|eureka.instance.home-page-url-path | `+++/+++` | Gets the relative home page URL Path for this instance. The home page URL is then constructed out of the hostName and the type of communication - secure or unsecure. It is normally used for informational purposes for other services to use it as a landing page.
+|eureka.instance.hostname | | The hostname if it can be determined at configuration time (otherwise it will be guessed from OS primitives).
+|eureka.instance.initial-status | | Initial status to register with remote Eureka server.
+|eureka.instance.instance-enabled-onit | `+++false+++` | Indicates whether the instance should be enabled for taking traffic as soon as it is registered with eureka. Sometimes the application might need to do some pre-processing before it is ready to take traffic.
+|eureka.instance.instance-id | | Get the unique Id (within the scope of the appName) of this instance to be registered with eureka.
+|eureka.instance.ip-address | | Get the IPAdress of the instance. This information is for academic purposes only as the communication from other instances primarily happen using the information supplied in {@link #getHostName(boolean)}.
+|eureka.instance.lease-expiration-duration-in-seconds | `+++90+++` | Indicates the time in seconds that the eureka server waits since it received the last heartbeat before it can remove this instance from its view and there by disallowing traffic to this instance. Setting this value too long could mean that the traffic could be routed to the instance even though the instance is not alive. Setting this value too small could mean, the instance may be taken out of traffic because of temporary network glitches.This value to be set to atleast higher than the value specified in leaseRenewalIntervalInSeconds.
+|eureka.instance.lease-renewal-interval-in-seconds | `+++30+++` | Indicates how often (in seconds) the eureka client needs to send heartbeats to eureka server to indicate that it is still alive. If the heartbeats are not received for the period specified in leaseExpirationDurationInSeconds, eureka server will remove the instance from its view, there by disallowing traffic to this instance. Note that the instance could still not take traffic if it implements HealthCheckCallback and then decides to make itself unavailable.
+|eureka.instance.metadata-map | | Gets the metadata name/value pairs associated with this instance. This information is sent to eureka server and can be used by other instances.
+|eureka.instance.metadata-map.weight | `+++1+++` | The weight of service instance for weighted load balancing.
+|eureka.instance.namespace | `+++eureka+++` | Get the namespace used to find properties. Ignored in Spring Cloud.
+|eureka.instance.non-secure-port | `+++80+++` | Get the non-secure port on which the instance should receive traffic.
+|eureka.instance.non-secure-port-enabled | `+++true+++` | Indicates whether the non-secure port should be enabled for traffic or not.
+|eureka.instance.prefer-ip-address | `+++false+++` | Flag to say that, when guessing a hostname, the IP address of the server should be used in preference to the hostname reported by the OS.
+|eureka.instance.registry.default-open-for-traffic-count | `+++1+++` | Value used in determining when leases are cancelled, default to 1 for standalone. Should be set to 0 for peer replicated eurekas
+|eureka.instance.registry.expected-number-of-clients-sending-renews | `+++1+++` |
+|eureka.instance.secure-health-check-url | | Gets the absolute secure health check page URL for this instance. The users can provide the secureHealthCheckUrl if the health check page resides in the same instance talking to eureka, else in the cases where the instance is a proxy for some other server, users can provide the full URL. If the full URL is provided it takes precedence.
It is normally used for making educated decisions based on the health of the instance - for example, it can be used to determine whether to proceed deployments to an entire farm or stop the deployments without causing further damage. The full URL should follow the format http://${eureka.hostname}:7001/ where the value ${eureka.hostname} is replaced at runtime.
+|eureka.instance.secure-port | `+++443+++` | Get the Secure port on which the instance should receive traffic.
+|eureka.instance.secure-port-enabled | `+++false+++` | Indicates whether the secure port should be enabled for traffic or not.
+|eureka.instance.secure-virtual-host-name | `+++unknown+++` | Gets the secure virtual host name defined for this instance. This is typically the way other instance would find this instance by using the secure virtual host name.Think of this as similar to the fully qualified domain name, that the users of your services will need to find this instance.
+|eureka.instance.status-page-url | | Gets the absolute status page URL path for this instance. The users can provide the statusPageUrlPath if the status page resides in the same instance talking to eureka, else in the cases where the instance is a proxy for some other server, users can provide the full URL. If the full URL is provided it takes precedence. It is normally used for informational purposes for other services to find about the status of this instance. Users can provide a simple HTML indicating what is the current status of the instance.
+|eureka.instance.status-page-url-path | | Gets the relative status page URL path for this instance. The status page URL is then constructed out of the hostName and the type of communication - secure or unsecure as specified in securePort and nonSecurePort. It is normally used for informational purposes for other services to find about the status of this instance. Users can provide a simple HTML indicating what is the current status of the instance.
+|eureka.instance.virtual-host-name | `+++unknown+++` | Gets the virtual host name defined for this instance. This is typically the way other instance would find this instance by using the virtual host name.Think of this as similar to the fully qualified domain name, that the users of your services will need to find this instance.
+|eureka.server.a-s-g-cache-expiry-timeout-ms | `+++0+++` |
+|eureka.server.a-s-g-query-timeout-ms | `+++300+++` |
+|eureka.server.a-s-g-update-interval-ms | `+++0+++` |
+|eureka.server.a-w-s-access-id | |
+|eureka.server.a-w-s-secret-key | |
+|eureka.server.batch-replication | `+++false+++` |
+|eureka.server.binding-strategy | |
+|eureka.server.delta-retention-timer-interval-in-ms | `+++0+++` |
+|eureka.server.disable-delta | `+++false+++` |
+|eureka.server.disable-delta-for-remote-regions | `+++false+++` |
+|eureka.server.disable-transparent-fallback-to-other-region | `+++false+++` |
+|eureka.server.e-i-p-bind-rebind-retries | `+++3+++` |
+|eureka.server.e-i-p-binding-retry-interval-ms | `+++0+++` |
+|eureka.server.e-i-p-binding-retry-interval-ms-when-unbound | `+++0+++` |
+|eureka.server.enable-replicated-request-compression | `+++false+++` |
+|eureka.server.enable-self-preservation | `+++true+++` |
+|eureka.server.eviction-interval-timer-in-ms | `+++0+++` |
+|eureka.server.expected-client-renewal-interval-seconds | `+++30+++` |
+|eureka.server.g-zip-content-from-remote-region | `+++true+++` |
+|eureka.server.initial-capacity-of-response-cache | `+++1000+++` |
+|eureka.server.json-codec-name | |
+|eureka.server.list-auto-scaling-groups-role-name | `+++ListAutoScalingGroups+++` |
+|eureka.server.log-identity-headers | `+++true+++` |
+|eureka.server.max-elements-in-peer-replication-pool | `+++10000+++` |
+|eureka.server.max-elements-in-status-replication-pool | `+++10000+++` |
+|eureka.server.max-idle-thread-age-in-minutes-for-peer-replication | `+++15+++` |
+|eureka.server.max-idle-thread-in-minutes-age-for-status-replication | `+++10+++` |
+|eureka.server.max-threads-for-peer-replication | `+++20+++` |
+|eureka.server.max-threads-for-status-replication | `+++1+++` |
+|eureka.server.max-time-for-replication | `+++30000+++` |
+|eureka.server.metrics.enabled | `+++false+++` | Indicates whether the metrics should be enabled for eureka instances.
+|eureka.server.min-available-instances-for-peer-replication | `+++-1+++` |
+|eureka.server.min-threads-for-peer-replication | `+++5+++` |
+|eureka.server.min-threads-for-status-replication | `+++1+++` |
+|eureka.server.my-url | |
+|eureka.server.number-of-replication-retries | `+++5+++` |
+|eureka.server.peer-eureka-nodes-update-interval-ms | `+++0+++` |
+|eureka.server.peer-eureka-status-refresh-time-interval-ms | `+++0+++` |
+|eureka.server.peer-node-connect-timeout-ms | `+++200+++` |
+|eureka.server.peer-node-connection-idle-timeout-seconds | `+++30+++` |
+|eureka.server.peer-node-read-timeout-ms | `+++200+++` |
+|eureka.server.peer-node-total-connections | `+++1000+++` |
+|eureka.server.peer-node-total-connections-per-host | `+++500+++` |
+|eureka.server.prime-aws-replica-connections | `+++true+++` |
+|eureka.server.property-resolver | |
+|eureka.server.rate-limiter-burst-size | `+++10+++` |
+|eureka.server.rate-limiter-enabled | `+++false+++` |
+|eureka.server.rate-limiter-full-fetch-average-rate | `+++100+++` |
+|eureka.server.rate-limiter-privileged-clients | |
+|eureka.server.rate-limiter-registry-fetch-average-rate | `+++500+++` |
+|eureka.server.rate-limiter-throttle-standard-clients | `+++false+++` |
+|eureka.server.registry-sync-retries | `+++0+++` |
+|eureka.server.registry-sync-retry-wait-ms | `+++0+++` |
+|eureka.server.remote-region-app-whitelist | |
+|eureka.server.remote-region-connect-timeout-ms | `+++1000+++` |
+|eureka.server.remote-region-connection-idle-timeout-seconds | `+++30+++` |
+|eureka.server.remote-region-fetch-thread-pool-size | `+++20+++` |
+|eureka.server.remote-region-read-timeout-ms | `+++1000+++` |
+|eureka.server.remote-region-registry-fetch-interval | `+++30+++` |
+|eureka.server.remote-region-total-connections | `+++1000+++` |
+|eureka.server.remote-region-total-connections-per-host | `+++500+++` |
+|eureka.server.remote-region-trust-store | |
+|eureka.server.remote-region-trust-store-password | `+++changeit+++` |
+|eureka.server.remote-region-urls | |
+|eureka.server.remote-region-urls-with-name | |
+|eureka.server.renewal-percent-threshold | `+++0.85+++` |
+|eureka.server.renewal-threshold-update-interval-ms | `+++0+++` |
+|eureka.server.response-cache-auto-expiration-in-seconds | `+++180+++` |
+|eureka.server.response-cache-update-interval-ms | `+++0+++` |
+|eureka.server.retention-time-in-m-s-in-delta-queue | `+++0+++` |
+|eureka.server.route53-bind-rebind-retries | `+++3+++` |
+|eureka.server.route53-binding-retry-interval-ms | `+++0+++` |
+|eureka.server.route53-domain-t-t-l | `+++30+++` |
+|eureka.server.sync-when-timestamp-differs | `+++true+++` |
+|eureka.server.use-read-only-response-cache | `+++true+++` |
+|eureka.server.wait-time-in-ms-when-sync-empty | `+++0+++` |
+|eureka.server.xml-codec-name | |
+|spring.cloud.compatibility-verifier.compatible-boot-versions | | Default accepted versions for the Spring Boot dependency. You can set {@code x} for the patch version if you don't want to specify a concrete value. Example: {@code 3.4.x}
+|spring.cloud.compatibility-verifier.enabled | `+++false+++` | Enables creation of Spring Cloud compatibility verification.
+|spring.cloud.config.allow-override | `+++true+++` | Flag to indicate that {@link #isOverrideSystemProperties() systemPropertiesOverride} can be used. Set to false to prevent users from changing the default accidentally. Default true.
+|spring.cloud.config.initialize-on-context-refresh | `+++false+++` | Flag to initialize bootstrap configuration on context refresh event. Default false.
+|spring.cloud.config.override-none | `+++false+++` | Flag to indicate that when {@link #setAllowOverride(boolean) allowOverride} is true, external properties should take lowest priority and should not override any existing property sources (including local config files). Default false. This will only have an effect when using config first bootstrap.
+|spring.cloud.config.override-system-properties | `+++true+++` | Flag to indicate that the external properties should override system properties. Default true.
+|spring.cloud.decrypt-environment-post-processor.enabled | `+++true+++` | Enable the DecryptEnvironmentPostProcessor.
+|spring.cloud.discovery.client.composite-indicator.enabled | `+++true+++` | Enables discovery client composite health indicator.
+|spring.cloud.discovery.client.health-indicator.enabled | `+++true+++` |
+|spring.cloud.discovery.client.health-indicator.include-description | `+++false+++` |
+|spring.cloud.discovery.client.health-indicator.use-services-query | `+++true+++` | Whether or not the indicator should use {@link DiscoveryClient#getServices} to check its health. When set to {@code false} the indicator instead uses the lighter {@link DiscoveryClient#probe()}. This can be helpful in large deployments where the number of services returned makes the operation unnecessarily heavy.
+|spring.cloud.discovery.client.simple.instances | |
+|spring.cloud.discovery.client.simple.local.host | |
+|spring.cloud.discovery.client.simple.local.instance-id | |
+|spring.cloud.discovery.client.simple.local.metadata | |
+|spring.cloud.discovery.client.simple.local.port | `+++0+++` |
+|spring.cloud.discovery.client.simple.local.secure | `+++false+++` |
+|spring.cloud.discovery.client.simple.local.service-id | |
+|spring.cloud.discovery.client.simple.local.uri | |
+|spring.cloud.discovery.client.simple.order | |
+|spring.cloud.discovery.enabled | `+++true+++` | Enables discovery client health indicators.
+|spring.cloud.features.enabled | `+++true+++` | Enables the features endpoint.
+|spring.cloud.httpclientfactories.apache.enabled | `+++true+++` | Enables creation of Apache Http Client factory beans.
+|spring.cloud.httpclientfactories.ok.enabled | `+++true+++` | Enables creation of OK Http Client factory beans.
+|spring.cloud.hypermedia.refresh.fixed-delay | `+++5000+++` |
+|spring.cloud.hypermedia.refresh.initial-delay | `+++10000+++` |
+|spring.cloud.inetutils.default-hostname | `+++localhost+++` | The default hostname. Used in case of errors.
+|spring.cloud.inetutils.default-ip-address | `+++127.0.0.1+++` | The default IP address. Used in case of errors.
+|spring.cloud.inetutils.ignored-interfaces | | List of Java regular expressions for network interfaces that will be ignored.
+|spring.cloud.inetutils.preferred-networks | | List of Java regular expressions for network addresses that will be preferred.
+|spring.cloud.inetutils.timeout-seconds | `+++1+++` | Timeout, in seconds, for calculating hostname.
+|spring.cloud.inetutils.use-only-site-local-interfaces | `+++false+++` | Whether to use only interfaces with site local addresses. See {@link InetAddress#isSiteLocalAddress()} for more details.
+|spring.cloud.loadbalancer.cache.caffeine.spec | | The spec to use to create caches. See CaffeineSpec for more details on the spec format.
+|spring.cloud.loadbalancer.cache.capacity | `+++256+++` | Initial cache capacity expressed as int.
+|spring.cloud.loadbalancer.cache.enabled | `+++true+++` | Enables Spring Cloud LoadBalancer caching mechanism.
+|spring.cloud.loadbalancer.cache.ttl | `+++35s+++` | Time To Live - time counted from writing of the record, after which cache entries are expired, expressed as a {@link Duration}. The property {@link String} has to be in keeping with the appropriate syntax as specified in Spring Boot StringToDurationConverter. @see StringToDurationConverter.java
+|spring.cloud.loadbalancer.call-get-with-request-on-delegates | `+++true+++` | If this flag is set to {@code true}, {@code ServiceInstanceListSupplier#get(Request request)} method will be implemented to call {@code delegate.get(request)} in classes assignable from {@code DelegatingServiceInstanceListSupplier} that don't already implement that method, with the exclusion of {@code CachingServiceInstanceListSupplier} and {@code HealthCheckServiceInstanceListSupplier}, which should be placed in the instance supplier hierarchy directly after the supplier performing instance retrieval over the network, before any request-based filtering is done, {@code true} by default.
+|spring.cloud.loadbalancer.clients | |
+|spring.cloud.loadbalancer.configurations | `+++default+++` | Enables a predefined LoadBalancer configuration.
+|spring.cloud.loadbalancer.eager-load.clients | | Names of the clients.
+|spring.cloud.loadbalancer.enabled | `+++true+++` | Enables Spring Cloud LoadBalancer.
+|spring.cloud.loadbalancer.eureka.approximate-zone-from-hostname | `+++false+++` | Used to determine whether we should try to get the `zone` value from host name.
+|spring.cloud.loadbalancer.health-check.initial-delay | `+++0+++` | Initial delay value for the HealthCheck scheduler.
+|spring.cloud.loadbalancer.health-check.interval | `+++25s+++` | Interval for rerunning the HealthCheck scheduler.
+|spring.cloud.loadbalancer.health-check.interval | `+++25s+++` | Interval for rerunning the HealthCheck scheduler.
+|spring.cloud.loadbalancer.health-check.path | | Path at which the health-check request should be made. Can be set up per `serviceId`. A `default` value can be set up as well. If none is set up, `/actuator/health` will be used.
+|spring.cloud.loadbalancer.health-check.port | | Path at which the health-check request should be made. If none is set, the port under which the requested service is available at the service instance.
+|spring.cloud.loadbalancer.health-check.refetch-instances | `+++false+++` | Indicates whether the instances should be refetched by the `HealthCheckServiceInstanceListSupplier`. This can be used if the instances can be updated and the underlying delegate does not provide an ongoing flux.
+|spring.cloud.loadbalancer.health-check.refetch-instances-interval | `+++25s+++` | Interval for refetching available service instances.
+|spring.cloud.loadbalancer.health-check.repeat-health-check | `+++true+++` | Indicates whether health checks should keep repeating. It might be useful to set it to `false` if periodically refetching the instances, as every refetch will also trigger a healthcheck.
+|spring.cloud.loadbalancer.health-check.update-results-list | `+++true+++` | Indicates whether the {@code healthCheckFlux} should emit on each alive {@link ServiceInstance} that has been retrieved. If set to {@code false}, the entire alive instances sequence is first collected into a list and only then emitted.
+|spring.cloud.loadbalancer.hint | | Allows setting the value of hint that is passed on to the LoadBalancer request and can subsequently be used in {@link ReactiveLoadBalancer} implementations.
+|spring.cloud.loadbalancer.hint-header-name | `+++X-SC-LB-Hint+++` | Allows setting the name of the header used for passing the hint for hint-based service instance filtering.
+|spring.cloud.loadbalancer.retry.avoid-previous-instance | `+++true+++` | Enables wrapping ServiceInstanceListSupplier beans with `RetryAwareServiceInstanceListSupplier` if Spring-Retry is in the classpath.
+|spring.cloud.loadbalancer.retry.backoff.enabled | `+++false+++` | Indicates whether Reactor Retry backoffs should be applied.
+|spring.cloud.loadbalancer.retry.backoff.jitter | `+++0.5+++` | Used to set `RetryBackoffSpec.jitter`.
+|spring.cloud.loadbalancer.retry.backoff.max-backoff | `+++Long.MAX ms+++` | Used to set `RetryBackoffSpec.maxBackoff`.
+|spring.cloud.loadbalancer.retry.backoff.min-backoff | `+++5 ms+++` | Used to set `RetryBackoffSpec#minBackoff`.
+|spring.cloud.loadbalancer.retry.enabled | `+++true+++` | Enables LoadBalancer retries.
+|spring.cloud.loadbalancer.retry.max-retries-on-next-service-instance | `+++1+++` | Number of retries to be executed on the next `ServiceInstance`. A `ServiceInstance` is chosen before each retry call.
+|spring.cloud.loadbalancer.retry.max-retries-on-same-service-instance | `+++0+++` | Number of retries to be executed on the same `ServiceInstance`.
+|spring.cloud.loadbalancer.retry.retry-on-all-exceptions | `+++false+++` | Indicates retries should be attempted for all exceptions, not only those specified in `retryableExceptions`.
+|spring.cloud.loadbalancer.retry.retry-on-all-operations | `+++false+++` | Indicates retries should be attempted on operations other than `HttpMethod.GET`.
+|spring.cloud.loadbalancer.retry.retryable-exceptions | `+++{}+++` | A `Set` of `Throwable` classes that should trigger a retry.
+|spring.cloud.loadbalancer.retry.retryable-status-codes | `+++{}+++` | A `Set` of status codes that should trigger a retry.
+|spring.cloud.loadbalancer.service-discovery.timeout | | String representation of Duration of the timeout for calls to service discovery.
+|spring.cloud.loadbalancer.stats.micrometer.enabled | `+++false+++` | Enables Spring Cloud LoadBalancer Micrometer stats.
+|spring.cloud.loadbalancer.sticky-session.add-service-instance-cookie | `+++false+++` | Indicates whether a cookie with the newly selected instance should be added by LoadBalancer.
+|spring.cloud.loadbalancer.sticky-session.instance-id-cookie-name | `+++sc-lb-instance-id+++` | The name of the cookie holding the preferred instance id.
+|spring.cloud.loadbalancer.subset.instance-id | | Instance id of deterministic subsetting. If not set, {@link IdUtils#getDefaultInstanceId(PropertyResolver)} will be used.
+|spring.cloud.loadbalancer.subset.size | `+++100+++` | Max subset size of deterministic subsetting.
+|spring.cloud.loadbalancer.x-forwarded.enabled | `+++false+++` | To Enable X-Forwarded Headers.
+|spring.cloud.loadbalancer.zone | | Spring Cloud LoadBalancer zone.
+|spring.cloud.refresh.additional-property-sources-to-retain | | Additional property sources to retain during a refresh. Typically only system property sources are retained. This property allows property sources, such as property sources created by EnvironmentPostProcessors to be retained as well.
+|spring.cloud.refresh.enabled | `+++true+++` | Enables autoconfiguration for the refresh scope and associated features.
+|spring.cloud.refresh.extra-refreshable | `+++true+++` | Additional class names for beans to post process into refresh scope.
+|spring.cloud.refresh.never-refreshable | `+++true+++` | Comma separated list of class names for beans to never be refreshed or rebound.
+|spring.cloud.refresh.on-restart.enabled | `+++true+++` | Enable refreshing context on start.
+|spring.cloud.service-registry.auto-registration.enabled | `+++true+++` | Whether service auto-registration is enabled. Defaults to true.
+|spring.cloud.service-registry.auto-registration.fail-fast | `+++false+++` | Whether startup fails if there is no AutoServiceRegistration. Defaults to false.
+|spring.cloud.service-registry.auto-registration.register-management | `+++true+++` | Whether to register the management as a service. Defaults to true.
+|spring.cloud.util.enabled | `+++true+++` | Enables creation of Spring Cloud utility beans.
+
+|===
\ No newline at end of file
diff --git a/docs/package.json b/docs/package.json
new file mode 100644
index 0000000000..c3570e2f8a
--- /dev/null
+++ b/docs/package.json
@@ -0,0 +1,10 @@
+{
+ "dependencies": {
+ "antora": "3.2.0-alpha.4",
+ "@antora/atlas-extension": "1.0.0-alpha.2",
+ "@antora/collector-extension": "1.0.0-alpha.3",
+ "@asciidoctor/tabs": "1.0.0-beta.6",
+ "@springio/antora-extensions": "1.11.1",
+ "@springio/asciidoctor-extensions": "1.0.0-alpha.10"
+ }
+}
diff --git a/docs/pom.xml b/docs/pom.xml
index 399155a1c7..654cd81457 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -1,23 +1,23 @@
-
+4.0.0
+ org.springframework.cloud
+ spring-cloud-netflix-docsorg.springframework.cloudspring-cloud-netflix
- 3.1.8-SNAPSHOT
+ 4.1.4-SNAPSHOT
+ ..
- spring-cloud-netflix-docsjarSpring Cloud Netflix Docs
- Spring Cloud Docs
+ Spring Cloud Netflix Docsspring-cloud-netflix${basedir}/..
-
- .*.eureka.*
-
- deploy
+ eureka.*|spring.cloud.*none
@@ -38,29 +38,39 @@
docs
+
+
+ src/main/antora/resources/antora-resources
+ true
+
+ pl.project13.mavengit-commit-id-plugin
+ org.apache.maven.pluginsmaven-dependency-plugin
-
- maven-resources-plugin
- org.codehaus.mojoexec-maven-plugin
- org.asciidoctor
- asciidoctor-maven-plugin
+ io.spring.maven.antora
+ antora-component-version-maven-plugin
+
+
+ org.antora
+ antora-maven-plugin
+ org.apache.maven.pluginsmaven-antrun-plugin
+ org.apache.maven.pluginsmaven-deploy-plugin
diff --git a/docs/src/main/antora/resources/antora-resources/antora.yml b/docs/src/main/antora/resources/antora-resources/antora.yml
new file mode 100644
index 0000000000..9148923fa3
--- /dev/null
+++ b/docs/src/main/antora/resources/antora-resources/antora.yml
@@ -0,0 +1,20 @@
+version: @antora-component.version@
+prerelease: @antora-component.prerelease@
+
+asciidoc:
+ attributes:
+ attribute-missing: 'warn'
+ chomp: 'all'
+ project-root: @maven.multiModuleProjectDirectory@
+ github-repo: @docs.main@
+ github-raw: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@
+ github-code: https://github.com/spring-cloud/@docs.main@/tree/@github-tag@
+ github-issues: https://github.com/spring-cloud/@docs.main@/issues/
+ github-wiki: https://github.com/spring-cloud/@docs.main@/wiki
+ spring-cloud-version: @project.version@
+ github-tag: @github-tag@
+ version-type: @version-type@
+ docs-url: https://docs.spring.io/@docs.main@/docs/@project.version@
+ raw-docs-url: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@
+ project-version: @project.version@
+ project-name: @docs.main@
diff --git a/docs/src/main/asciidoc/README.adoc b/docs/src/main/asciidoc/README.adoc
index 4383399754..1cb7cb3c43 100644
--- a/docs/src/main/asciidoc/README.adoc
+++ b/docs/src/main/asciidoc/README.adoc
@@ -1,28 +1,30 @@
-include::_attributes.adoc[]
-image::https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml/badge.svg?branch=3.1.x&style=svg["Build",link="https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml"]
+image::https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml/badge.svg?branch=main&style=svg["Build",link="https://github.com/spring-cloud/spring-cloud-netflix/actions/workflows/maven.yml"]
-image:https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/3.1.x/graph/badge.svg["Codecov", link="https://app.codecov.io/gh/spring-cloud/spring-cloud-netflix/tree/3.1.x"]
+image:https://codecov.io/gh/spring-cloud/spring-cloud-netflix/branch/main/graph/badge.svg["Codecov", link="https://app.codecov.io/gh/spring-cloud/spring-cloud-netflix/tree/main"]
-include::intro.adoc[]
+[[features]]
== Features
* Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
* Service Discovery: an embedded Eureka server can be created with declarative Java configuration
+[[building]]
== Building
-include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/3.1.x/docs/src/main/asciidoc/building-jdk8.adoc[]
+include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[]
NOTE: To build the module `spring-cloud-netflix-hystrix-contract` along with the entire Netflix project run the
`build.sh` script in the `scripts` directory.
+[[contributing]]
== Contributing
-include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/3.1.x/docs/src/main/asciidoc/contributing.adoc[]
+include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing-docs.adoc[]
+[[license]]
== License
-The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/main/LICENSE.txt[here].
\ No newline at end of file
+The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-netflix/main/LICENSE.txt[here].
diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc
deleted file mode 100644
index bf3454e5e3..0000000000
--- a/docs/src/main/asciidoc/_configprops.adoc
+++ /dev/null
@@ -1,19 +0,0 @@
-|===
-|Name | Default | Description
-
-|eureka.client.eureka-connection-idle-timeout-seconds | `+++30+++` | Indicates how much time (in seconds) that the HTTP connections to eureka server can stay idle before it can be closed. In the AWS environment, it is recommended that the values is 30 seconds or less, since the firewall cleans up the connection information after a few mins leaving the connection hanging in limbo.
-|eureka.client.eureka-server-connect-timeout-seconds | `+++5+++` | Indicates how long to wait (in seconds) before a connection to eureka server needs to timeout. Note that the connections in the client are pooled by org.apache.http.client.HttpClient and this setting affects the actual connection creation and also the wait time to get the connection from the pool.
-|eureka.client.eureka-server-d-n-s-name | | Gets the DNS name to be queried to get the list of eureka servers.This information is not required if the contract returns the service urls by implementing serviceUrls. The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
-|eureka.client.eureka-server-port | | Gets the port to be used to construct the service url to contact eureka server when the list of eureka servers come from the DNS.This information is not required if the contract returns the service urls eurekaServerServiceUrls(String). The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
-|eureka.client.eureka-server-read-timeout-seconds | `+++8+++` | Indicates how long to wait (in seconds) before a read from eureka server needs to timeout.
-|eureka.client.eureka-server-total-connections | `+++200+++` | Gets the total number of connections that is allowed from eureka client to all eureka servers.
-|eureka.client.eureka-server-total-connections-per-host | `+++50+++` | Gets the total number of connections that is allowed from eureka client to a eureka server host.
-|eureka.client.eureka-server-u-r-l-context | | Gets the URL context to be used to construct the service url to contact eureka server when the list of eureka servers come from the DNS. This information is not required if the contract returns the service urls from eurekaServerServiceUrls. The DNS mechanism is used when useDnsForFetchingServiceUrls is set to true and the eureka client expects the DNS to configured a certain way so that it can fetch changing eureka servers dynamically. The changes are effective at runtime.
-|eureka.client.eureka-service-url-poll-interval-seconds | `+++0+++` | Indicates how often(in seconds) to poll for changes to eureka server information. Eureka servers could be added or removed and this setting controls how soon the eureka clients should know about it.
-|eureka.client.prefer-same-zone-eureka | `+++true+++` | Indicates whether or not this instance should try to use the eureka server in the same zone for latency and/or other reason. Ideally eureka clients are configured to talk to servers in the same zone The changes are effective at runtime at the next registry fetch cycle as specified by registryFetchIntervalSeconds
-|eureka.client.register-with-eureka | `+++true+++` | Indicates whether or not this instance should register its information with eureka server for discovery by others. In some cases, you do not want your instances to be discovered whereas you just want do discover other instances.
-|eureka.server.peer-eureka-nodes-update-interval-ms | `+++0+++` |
-|eureka.server.peer-eureka-status-refresh-time-interval-ms | `+++0+++` |
-|spring.cloud.loadbalancer.eureka.approximate-zone-from-hostname | `+++false+++` | Used to determine whether we should try to get the `zone` value from host name.
-
-|===
\ No newline at end of file
diff --git a/docs/src/main/asciidoc/index.adoc b/docs/src/main/asciidoc/index.adoc
deleted file mode 120000
index 5d677a319a..0000000000
--- a/docs/src/main/asciidoc/index.adoc
+++ /dev/null
@@ -1 +0,0 @@
-spring-cloud-netflix.adoc
\ No newline at end of file
diff --git a/mvnw b/mvnw
index 4f6e87f042..8d937f4c14 100755
--- a/mvnw
+++ b/mvnw
@@ -8,7 +8,7 @@
# "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
+# http://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
@@ -19,7 +19,7 @@
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
-# Maven2 Start Up Batch script
+# Apache Maven Wrapper startup batch script, version 3.2.0
#
# Required ENV vars:
# ------------------
@@ -27,7 +27,6 @@
#
# Optional ENV vars
# -----------------
-# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@@ -36,6 +35,10 @@
if [ -z "$MAVEN_SKIP_RC" ] ; then
+ if [ -f /usr/local/etc/mavenrc ] ; then
+ . /usr/local/etc/mavenrc
+ fi
+
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
@@ -50,7 +53,7 @@ fi
cygwin=false;
darwin=false;
mingw=false
-case "`uname`" in
+case "$(uname)" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
@@ -58,9 +61,9 @@ case "`uname`" in
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
- export JAVA_HOME="`/usr/libexec/java_home`"
+ JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME
else
- export JAVA_HOME="/Library/Java/Home"
+ JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
fi
fi
;;
@@ -68,69 +71,38 @@ esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
- JAVA_HOME=`java-config --jre-home`
+ JAVA_HOME=$(java-config --jre-home)
fi
fi
-if [ -z "$M2_HOME" ] ; then
- ## resolve links - $0 may be a link to maven's home
- PRG="$0"
-
- # need this for relative symlinks
- while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG="`dirname "$PRG"`/$link"
- fi
- done
-
- saveddir=`pwd`
-
- M2_HOME=`dirname "$PRG"`/..
-
- # make it fully qualified
- M2_HOME=`cd "$M2_HOME" && pwd`
-
- cd "$saveddir"
- # echo Using m2 at $M2_HOME
-fi
-
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
- [ -n "$M2_HOME" ] &&
- M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
- JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+ JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
[ -n "$CLASSPATH" ] &&
- CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+ CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
- [ -n "$M2_HOME" ] &&
- M2_HOME="`(cd "$M2_HOME"; pwd)`"
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
- # TODO classpath?
+ [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] &&
+ JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)"
fi
if [ -z "$JAVA_HOME" ]; then
- javaExecutable="`which javac`"
- if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+ javaExecutable="$(which javac)"
+ if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
- readLink=`which readlink`
- if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+ readLink=$(which readlink)
+ if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then
if $darwin ; then
- javaHome="`dirname \"$javaExecutable\"`"
- javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+ javaHome="$(dirname "\"$javaExecutable\"")"
+ javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac"
else
- javaExecutable="`readlink -f \"$javaExecutable\"`"
+ javaExecutable="$(readlink -f "\"$javaExecutable\"")"
fi
- javaHome="`dirname \"$javaExecutable\"`"
- javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ javaHome="$(dirname "\"$javaExecutable\"")"
+ javaHome=$(expr "$javaHome" : '\(.*\)/bin')
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
@@ -146,7 +118,7 @@ if [ -z "$JAVACMD" ] ; then
JAVACMD="$JAVA_HOME/bin/java"
fi
else
- JAVACMD="`which java`"
+ JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)"
fi
fi
@@ -160,12 +132,9 @@ if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
-CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
-
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
-
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
@@ -181,76 +150,99 @@ find_maven_basedir() {
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
- wdir=`cd "$wdir/.."; pwd`
+ wdir=$(cd "$wdir/.." || exit 1; pwd)
fi
# end of workaround
done
- echo "${basedir}"
+ printf '%s' "$(cd "$basedir" || exit 1; pwd)"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
- echo "$(tr -s '\n' ' ' < "$1")"
+ # Remove \r in case we run on Windows within Git Bash
+ # and check out the repository with auto CRLF management
+ # enabled. Otherwise, we may read lines that are delimited with
+ # \r\n and produce $'-Xarg\r' rather than -Xarg due to word
+ # splitting rules.
+ tr -s '\r\n' ' ' < "$1"
fi
}
-BASE_DIR=`find_maven_basedir "$(pwd)"`
+log() {
+ if [ "$MVNW_VERBOSE" = true ]; then
+ printf '%s\n' "$1"
+ fi
+}
+
+BASE_DIR=$(find_maven_basedir "$(dirname "$0")")
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
+MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
+log "$MAVEN_PROJECTBASEDIR"
+
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
-if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Found .mvn/wrapper/maven-wrapper.jar"
- fi
+wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar"
+if [ -r "$wrapperJarPath" ]; then
+ log "Found $wrapperJarPath"
else
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+ log "Couldn't find $wrapperJarPath, downloading it ..."
+
+ if [ -n "$MVNW_REPOURL" ]; then
+ wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
+ else
+ wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
fi
- jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
- while IFS="=" read key value; do
- case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+ while IFS="=" read -r key value; do
+ # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
+ safeValue=$(echo "$value" | tr -d '\r')
+ case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;;
esac
- done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Downloading from: $jarUrl"
+ done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
+ log "Downloading from: $wrapperUrl"
+
+ if $cygwin; then
+ wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
fi
- wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if command -v wget > /dev/null; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Found wget ... using wget"
+ log "Found wget ... using wget"
+ [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet"
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
+ else
+ wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
fi
- wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Found curl ... using curl"
+ log "Found curl ... using curl"
+ [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent"
+ if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
+ curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
+ else
+ curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
fi
- curl -o "$wrapperJarPath" "$jarUrl"
else
- if [ "$MVNW_VERBOSE" = true ]; then
- echo "Falling back to using Java to download"
+ log "Falling back to using Java to download"
+ javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java"
+ javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class"
+ # For Cygwin, switch paths to Windows format before running javac
+ if $cygwin; then
+ javaSource=$(cygpath --path --windows "$javaSource")
+ javaClass=$(cygpath --path --windows "$javaClass")
fi
- javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
- if [ -e "$javaClass" ]; then
- if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
- if [ "$MVNW_VERBOSE" = true ]; then
- echo " - Compiling MavenWrapperDownloader.java ..."
- fi
- # Compiling the Java class
- ("$JAVA_HOME/bin/javac" "$javaClass")
+ if [ -e "$javaSource" ]; then
+ if [ ! -e "$javaClass" ]; then
+ log " - Compiling MavenWrapperDownloader.java ..."
+ ("$JAVA_HOME/bin/javac" "$javaSource")
fi
- if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
- # Running the downloader
- if [ "$MVNW_VERBOSE" = true ]; then
- echo " - Running MavenWrapperDownloader.java ..."
- fi
- ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+ if [ -e "$javaClass" ]; then
+ log " - Running MavenWrapperDownloader.java ..."
+ ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath"
fi
fi
fi
@@ -259,48 +251,58 @@ fi
# End of extension
##########################################################################################
-export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
-if [ "$MVNW_VERBOSE" = true ]; then
- echo $MAVEN_PROJECTBASEDIR
+# If specified, validate the SHA-256 sum of the Maven wrapper jar file
+wrapperSha256Sum=""
+while IFS="=" read -r key value; do
+ case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;;
+ esac
+done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
+if [ -n "$wrapperSha256Sum" ]; then
+ wrapperSha256Result=false
+ if command -v sha256sum > /dev/null; then
+ if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then
+ wrapperSha256Result=true
+ fi
+ elif command -v shasum > /dev/null; then
+ if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then
+ wrapperSha256Result=true
+ fi
+ else
+ echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available."
+ echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties."
+ exit 1
+ fi
+ if [ $wrapperSha256Result = false ]; then
+ echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2
+ echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2
+ echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2
+ exit 1
+ fi
fi
+
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
- [ -n "$M2_HOME" ] &&
- M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
- JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
[ -n "$CLASSPATH" ] &&
- CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+ CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
- MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+ MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
fi
-WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
-
-echo "Running version check"
-VERSION=$( sed '\!//' -e 's!.*$!!' )
-echo "The found version is [${VERSION}]"
+# Provide a "standardized" way to retrieve the CLI args that will
+# work with both Windows and non-Windows executions.
+MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*"
+export MAVEN_CMD_LINE_ARGS
-if echo $VERSION | egrep -q 'M|RC'; then
- echo Activating \"milestone\" profile for version=\"$VERSION\"
- echo $MAVEN_CONFIG | grep -q milestone || MAVEN_CONFIG="$MAVEN_CONFIG -Pmilestone"
-else
- echo Deactivating \"milestone\" profile for version=\"$VERSION\"
- echo $MAVEN_CONFIG | grep -q milestone && MAVEN_CONFIG=$(echo $MAVEN_CONFIG | sed -e 's/-Pmilestone//')
-fi
-
-if echo $VERSION | egrep -q 'RELEASE'; then
- echo Activating \"central\" profile for version=\"$VERSION\"
- echo $MAVEN_CONFIG | grep -q milestone || MAVEN_CONFIG="$MAVEN_CONFIG -Pcentral"
-else
- echo Deactivating \"central\" profile for version=\"$VERSION\"
- echo $MAVEN_CONFIG | grep -q central && MAVEN_CONFIG=$(echo $MAVEN_CONFIG | sed -e 's/-Pcentral//')
-fi
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+# shellcheck disable=SC2086 # safe args
exec "$JAVACMD" \
$MAVEN_OPTS \
+ $MAVEN_DEBUG_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
- "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+ "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
diff --git a/mvnw.cmd b/mvnw.cmd
old mode 100755
new mode 100644
index 080c510d2b..f80fbad3e7
--- a/mvnw.cmd
+++ b/mvnw.cmd
@@ -7,7 +7,7 @@
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
-@REM https://www.apache.org/licenses/LICENSE-2.0
+@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@@ -18,15 +18,14 @@
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
-@REM Maven2 Start Up Batch script
+@REM Apache Maven Wrapper startup batch script, version 3.2.0
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
-@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
-@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@@ -37,7 +36,7 @@
@echo off
@REM set title of command window
title %0
-@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
@@ -46,8 +45,8 @@ if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
-if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
-if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
+if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
+if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
:skipRcPre
@setlocal
@@ -120,24 +119,69 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
-set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
-FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
- IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
+set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
+
+FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
+ IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
- echo Found %WRAPPER_JAR%
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Found %WRAPPER_JAR%
+ )
) else (
- echo Couldn't find %WRAPPER_JAR%, downloading it ...
- echo Downloading from: %DOWNLOAD_URL%
- powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
- echo Finished downloading %WRAPPER_JAR%
+ if not "%MVNW_REPOURL%" == "" (
+ SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"
+ )
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Couldn't find %WRAPPER_JAR%, downloading it ...
+ echo Downloading from: %WRAPPER_URL%
+ )
+
+ powershell -Command "&{"^
+ "$webclient = new-object System.Net.WebClient;"^
+ "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
+ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
+ "}"^
+ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
+ "}"
+ if "%MVNW_VERBOSE%" == "true" (
+ echo Finished downloading %WRAPPER_JAR%
+ )
)
@REM End of extension
-%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file
+SET WRAPPER_SHA_256_SUM=""
+FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
+ IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B
+)
+IF NOT %WRAPPER_SHA_256_SUM%=="" (
+ powershell -Command "&{"^
+ "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^
+ "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^
+ " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^
+ " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^
+ " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^
+ " exit 1;"^
+ "}"^
+ "}"
+ if ERRORLEVEL 1 goto error
+)
+
+@REM Provide a "standardized" way to retrieve the CLI args that will
+@REM work with both Windows and non-Windows executions.
+set MAVEN_CMD_LINE_ARGS=%*
+
+%MAVEN_JAVA_EXE% ^
+ %JVM_CONFIG_MAVEN_PROPS% ^
+ %MAVEN_OPTS% ^
+ %MAVEN_DEBUG_OPTS% ^
+ -classpath %WRAPPER_JAR% ^
+ "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
+ %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
@@ -147,15 +191,15 @@ set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
-if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
+if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
-if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
-if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
+if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
+if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
-if "%MAVEN_BATCH_PAUSE%" == "on" pause
+if "%MAVEN_BATCH_PAUSE%"=="on" pause
-if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
+if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
-exit /B %ERROR_CODE%
+cmd /C exit /B %ERROR_CODE%
diff --git a/pom.xml b/pom.xml
index 62b7c38e7c..d0564cc4eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,14 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0spring-cloud-netflix
- 3.1.8-SNAPSHOT
+ 4.1.4-SNAPSHOTpomSpring Cloud NetflixSpring Cloud Netflixorg.springframework.cloudspring-cloud-build
- 3.1.9-SNAPSHOT
+ 4.1.4-SNAPSHOT
@@ -21,9 +21,9 @@
netflix
- 3.1.8-SNAPSHOT
- 3.1.9-SNAPSHOT
- 1.17.6
+ 4.1.5-SNAPSHOT
+ 4.1.4-SNAPSHOT
+ 1.19.85.15.0
@@ -31,8 +31,9 @@
reuseReports${project.basedir}/../target/jacoco.execjava
- 1.19.43.1.0
+
+ true
@@ -58,14 +59,6 @@
-
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
- io.spring.javaformatspring-javaformat-maven-plugin
@@ -123,31 +116,6 @@
1
-
- com.sun.jersey
- jersey-servlet
- ${eureka-jersey.version}
-
-
- com.sun.jersey
- jersey-core
- ${eureka-jersey.version}
-
-
- com.sun.jersey
- jersey-client
- ${eureka-jersey.version}
-
-
- com.sun.jersey
- jersey-server
- ${eureka-jersey.version}
-
-
- com.sun.jersey.contribs
- jersey-apache-client4
- ${eureka-jersey.version}
-
diff --git a/spring-cloud-netflix-dependencies/pom.xml b/spring-cloud-netflix-dependencies/pom.xml
index 855c42199c..f3688946c8 100644
--- a/spring-cloud-netflix-dependencies/pom.xml
+++ b/spring-cloud-netflix-dependencies/pom.xml
@@ -5,16 +5,16 @@
spring-cloud-dependencies-parentorg.springframework.cloud
- 3.1.9-SNAPSHOT
+ 4.1.4-SNAPSHOTspring-cloud-netflix-dependencies
- 3.1.8-SNAPSHOT
+ 4.1.4-SNAPSHOTpomspring-cloud-netflix-dependenciesSpring Cloud Netflix Dependencies
- 1.10.18
+ 2.0.3
@@ -51,6 +51,10 @@
com.github.vlsi.compactmapcompactmap
+
+ jakarta.servlet
+ jakarta.servlet-api
+ javax.servletservlet-api
@@ -67,6 +71,10 @@
com.google.code.findbugsannotations
+
+ org.glassfish.jersey.core
+ jersey-client
+
@@ -78,6 +86,10 @@
com.netflix.archaiusarchaius-core
+
+ jakarta.servlet
+ jakarta.servlet-api
+ javax.servletservlet-api
@@ -112,6 +124,22 @@
+
+ com.netflix.eureka
+ eureka-core-jersey3
+ ${eureka.version}
+
+
+ com.netflix.eureka
+ eureka-client-jersey3
+ ${eureka.version}
+
+
+ aopalliance
+ aopalliance
+
+
+
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/pom.xml b/spring-cloud-netflix-eureka-client-tls-tests/pom.xml
index 007dba0537..2f0b2e9245 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/pom.xml
+++ b/spring-cloud-netflix-eureka-client-tls-tests/pom.xml
@@ -5,7 +5,7 @@
org.springframework.cloudspring-cloud-netflix
- 3.1.8-SNAPSHOT
+ 4.1.4-SNAPSHOT..spring-cloud-netflix-eureka-client-tls-tests
@@ -82,6 +82,11 @@
spring-boot-autoconfigure-processortrue
+
+ org.springframework.cloud
+ spring-cloud-test-support
+ test
+ org.springframework.bootspring-boot-starter-test
@@ -96,7 +101,7 @@
org.bouncycastlebcpkix-jdk15on
- 1.68
+ 1.70test
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/AppRunner.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/AppRunner.java
index 6ae084e5d1..2c70d09bf6 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/AppRunner.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/AppRunner.java
@@ -22,15 +22,15 @@
import java.util.Map;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.test.TestSocketUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.util.SocketUtils;
public class AppRunner implements AutoCloseable {
- private Class> appClass;
+ private final Class> appClass;
- private Map props;
+ private final Map props;
private ConfigurableApplicationContext app;
@@ -56,7 +56,7 @@ public void start() {
}
private int availabeTcpPort() {
- return SocketUtils.findAvailableTcpPort();
+ return TestSocketUtils.findAvailableTcpPort();
}
private String[] props() {
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTest.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTests.java
similarity index 92%
rename from spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTest.java
rename to spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTests.java
index b87cf73992..1355c2d7ca 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTest.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2022 the original author or authors.
+ * Copyright 2018-2024 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.
@@ -33,9 +33,9 @@
import static org.assertj.core.api.Assertions.assertThat;
-abstract class BaseCertTest {
+abstract class BaseCertTests {
- private static final Log log = LogFactory.getLog(BaseCertTest.class);
+ private static final Log log = LogFactory.getLog(BaseCertTests.class);
protected static final String KEY_STORE_PASSWORD = "test-key-store-password";
@@ -53,9 +53,10 @@ abstract class BaseCertTest {
protected static File wrongClientCert;
- protected BaseCertTest() {
+ protected BaseCertTests() {
}
+ @SuppressWarnings("rawtypes")
static EurekaServerRunner startEurekaServer(Class config) {
EurekaServerRunner server = new EurekaServerRunner(config);
server.enableTls();
@@ -70,6 +71,7 @@ static void stopEurekaServer(EurekaServerRunner server) {
server.stop();
}
+ @SuppressWarnings("rawtypes")
static EurekaClientRunner startService(EurekaServerRunner server, Class config) {
EurekaClientRunner service = new EurekaClientRunner(config, server, "testservice");
enableTlsClient(service);
@@ -153,9 +155,7 @@ void wrongPasswordCauseFailure() {
EurekaClientRunner client = createEurekaClient();
enableTlsClient(client);
client.setKeyStore(clientCert, WRONG_PASSWORD, WRONG_PASSWORD);
- Assertions.assertThrows(BeanCreationException.class, () -> {
- client.start();
- });
+ Assertions.assertThrows(BeanCreationException.class, client::start);
}
@Test
@@ -163,9 +163,7 @@ void nonExistKeyStoreCauseFailure() {
EurekaClientRunner client = createEurekaClient();
enableTlsClient(client);
client.setKeyStore(new File("nonExistFile"));
- Assertions.assertThrows(BeanCreationException.class, () -> {
- client.start();
- });
+ Assertions.assertThrows(BeanCreationException.class, client::start);
}
@Test
@@ -183,7 +181,7 @@ private static File saveKeyAndCert(KeyAndCert keyCert) throws Exception {
}
private static File saveCert(KeyAndCert keyCert) throws Exception {
- return saveKeyStore(keyCert.subject(), () -> keyCert.storeCert());
+ return saveKeyStore(keyCert.subject(), keyCert::storeCert);
}
private static File saveKeyStore(String prefix, KeyStoreSupplier func) throws Exception {
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientRunner.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientRunner.java
index 6e1e0125fb..d789aa9106 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientRunner.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientRunner.java
@@ -72,13 +72,13 @@ private String pathOf(File file) {
}
public void waitServiceViaEureka(int seconds) {
- assertInSeconds(() -> foundServiceViaEureka(), seconds);
+ assertInSeconds(this::foundServiceViaEureka, seconds);
}
private void assertInSeconds(BooleanSupplier assertion, int seconds) {
long start = System.currentTimeMillis();
long limit = 1000L * seconds;
- long duration = 0;
+ long duration;
do {
if (assertion.getAsBoolean()) {
@@ -98,8 +98,9 @@ public boolean foundServiceViaEureka() {
return !discovery.getServices().isEmpty();
}
+ @SuppressWarnings("unchecked")
public AbstractDiscoveryClientOptionalArgs discoveryClientOptionalArgs() {
- return this.getBean(AbstractDiscoveryClientOptionalArgs.class);
+ return getBean(AbstractDiscoveryClientOptionalArgs.class);
}
}
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java
index 9fcaebe615..a6c054b630 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2022 the original author or authors.
+ * Copyright 2018-2024 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.
@@ -27,7 +27,7 @@
* already shutdown.
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({ EurekaClientTest.class, RestTemplateEurekaClientTest.class })
+@Suite.SuiteClasses({ EurekaClientTests.class, RestTemplateEurekaClientTests.class })
public class EurekaClientSuite {
}
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTest.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java
similarity index 74%
rename from spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTest.java
rename to spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java
index ca3c18ecd6..0ba9ca90d5 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTest.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2022 the original author or authors.
+ * Copyright 2018-2024 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.
@@ -16,20 +16,20 @@
package org.springframework.cloud.netflix.eureka;
-import com.netflix.discovery.DiscoveryClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.BeforeAll;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import static org.assertj.core.api.Assertions.assertThat;
-public class EurekaClientTest extends BaseCertTest {
+public class EurekaClientTests extends BaseCertTests {
- private static final Log log = LogFactory.getLog(EurekaClientTest.class);
+ private static final Log log = LogFactory.getLog(EurekaClientTests.class);
static EurekaServerRunner server;
@@ -37,13 +37,11 @@ public class EurekaClientTest extends BaseCertTest {
@BeforeAll
public static void setupAll() {
- server = startEurekaServer(EurekaClientTest.TestEurekaServer.class);
- service = startService(server, EurekaClientTest.TestApp.class);
- // Will use Jersey
- assertThat(service.discoveryClientOptionalArgs())
- .isInstanceOf(DiscoveryClient.DiscoveryClientOptionalArgs.class);
+ server = startEurekaServer(EurekaClientTests.TestEurekaServer.class);
+ service = startService(server, EurekaClientTests.TestApp.class);
+ assertThat(service.discoveryClientOptionalArgs()).isInstanceOf(RestTemplateDiscoveryClientOptionalArgs.class);
log.info("Successfully asserted that Jersey will be used");
- waitForRegistration(() -> new EurekaClientTest().createEurekaClient());
+ waitForRegistration(() -> new EurekaClientTests().createEurekaClient());
}
@Override
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyAndCert.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyAndCert.java
index 1b64c8777e..ae808937fe 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyAndCert.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyAndCert.java
@@ -25,9 +25,9 @@
public class KeyAndCert {
- private KeyPair keyPair;
+ private final KeyPair keyPair;
- private X509Certificate certificate;
+ private final X509Certificate certificate;
public KeyAndCert(KeyPair keyPair, X509Certificate certificate) {
this.keyPair = keyPair;
@@ -51,7 +51,7 @@ public X509Certificate certificate() {
}
public String subject() {
- String dn = certificate.getSubjectDN().getName();
+ String dn = certificate.getSubjectX500Principal().getName();
int index = dn.indexOf('=');
return dn.substring(index + 1);
}
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyTool.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyTool.java
index 8b4f209c66..b29173f188 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyTool.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/KeyTool.java
@@ -56,9 +56,7 @@ public KeyAndCert signCertificate(String subject, KeyAndCert signer) throws Exce
public KeyAndCert signCertificate(KeyPair keyPair, String subject, KeyAndCert signer) throws Exception {
X509Certificate certificate = createCert(keyPair.getPublic(), signer.privateKey(), signer.subject(), subject);
- KeyAndCert result = new KeyAndCert(keyPair, certificate);
-
- return result;
+ return new KeyAndCert(keyPair, certificate);
}
public KeyPair createKeyPair() throws Exception {
diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTest.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTests.java
similarity index 69%
rename from spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTest.java
rename to spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTests.java
index 5ce74316c2..633a081317 100644
--- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTest.java
+++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2022 the original author or authors.
+ * Copyright 2018-2024 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.
@@ -24,8 +24,11 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.configuration.TlsProperties;
import org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration;
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
@@ -35,9 +38,9 @@
import static org.assertj.core.api.Assertions.assertThat;
-public class RestTemplateEurekaClientTest extends BaseCertTest {
+public class RestTemplateEurekaClientTests extends BaseCertTests {
- private static final Log log = LogFactory.getLog(RestTemplateEurekaClientTest.class);
+ private static final Log log = LogFactory.getLog(RestTemplateEurekaClientTests.class);
private static EurekaServerRunner server;
@@ -45,12 +48,12 @@ public class RestTemplateEurekaClientTest extends BaseCertTest {
@BeforeAll
public static void setupAll() {
- server = startEurekaServer(RestTemplateEurekaClientTest.RestTemplateTestEurekaServer.class);
- service = startService(server, RestTemplateEurekaClientTest.RestTemplateTestApp.class);
+ server = startEurekaServer(RestTemplateEurekaClientTests.RestTemplateTestEurekaServer.class);
+ service = startService(server, RestTemplateEurekaClientTests.RestTemplateTestApp.class);
// Will use RestTemplate
assertThat(service.discoveryClientOptionalArgs()).isInstanceOf(RestTemplateDiscoveryClientOptionalArgs.class);
log.info("Successfully asserted that RestTemplate will be used");
- waitForRegistration(() -> new RestTemplateEurekaClientTest().createEurekaClient());
+ waitForRegistration(() -> new RestTemplateEurekaClientTests().createEurekaClient());
}
@AfterAll
@@ -76,7 +79,7 @@ public RestTemplateDiscoveryClientOptionalArgs forceRestTemplateDiscoveryClientO
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier)
throws GeneralSecurityException, IOException {
return configuration.restTemplateDiscoveryClientOptionalArgs(tlsProperties,
- eurekaClientHttpRequestFactorySupplier);
+ eurekaClientHttpRequestFactorySupplier, new RestTemplateBuilderObjectProvider());
}
}
@@ -88,4 +91,30 @@ public static class RestTemplateTestEurekaServer {
}
+ private static class RestTemplateBuilderObjectProvider implements ObjectProvider {
+
+ private final RestTemplateBuilder builder = new RestTemplateBuilder();
+
+ @Override
+ public RestTemplateBuilder getObject(Object... args) throws BeansException {
+ return builder;
+ }
+
+ @Override
+ public RestTemplateBuilder getIfAvailable() throws BeansException {
+ return builder;
+ }
+
+ @Override
+ public RestTemplateBuilder getIfUnique() throws BeansException {
+ return builder;
+ }
+
+ @Override
+ public RestTemplateBuilder getObject() throws BeansException {
+ return builder;
+ }
+
+ }
+
}
diff --git a/spring-cloud-netflix-eureka-client/pom.xml b/spring-cloud-netflix-eureka-client/pom.xml
index 04be3bd181..d4a2b1275b 100644
--- a/spring-cloud-netflix-eureka-client/pom.xml
+++ b/spring-cloud-netflix-eureka-client/pom.xml
@@ -1,11 +1,12 @@
-4.0.0org.springframework.cloudspring-cloud-netflix
- 3.1.8-SNAPSHOT
+ 4.1.4-SNAPSHOT..spring-cloud-netflix-eureka-client
@@ -14,7 +15,7 @@
Spring Cloud Netflix Eureka Client
- false
+ false
@@ -50,43 +51,6 @@
com.netflix.eurekaeureka-client
- true
-
-
- com.sun.jersey
- jersey-client
-
-
- com.sun.jersey
- jersey-core
-
-
- com.sun.jersey.contribs
- jersey-apache-client4
-
-
- aopalliance
- aopalliance
-
-
-
-
- com.sun.jersey
- jersey-core
- ${eureka-jersey.version}
- true
-
-
- com.sun.jersey
- jersey-client
- ${eureka-jersey.version}
- true
-
-
- com.sun.jersey.contribs
- jersey-apache-client4
- ${eureka-jersey.version}
- truejavax.inject
@@ -104,6 +68,10 @@
spring-boot-autoconfigure-processortrue
+
+ org.apache.httpcomponents.client5
+ httpclient5
+ org.springframework.bootspring-boot-starter-security
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/CloudEurekaClient.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/CloudEurekaClient.java
index f8252e0112..a430feb3bb 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/CloudEurekaClient.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/CloudEurekaClient.java
@@ -28,6 +28,7 @@
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import com.netflix.discovery.shared.transport.EurekaHttpResponse;
+import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -48,22 +49,23 @@ public class CloudEurekaClient extends DiscoveryClient {
private final AtomicLong cacheRefreshedCount = new AtomicLong(0);
- private ApplicationEventPublisher publisher;
+ private final ApplicationEventPublisher publisher;
- private Field eurekaTransportField;
+ private final Field eurekaTransportField;
- private ApplicationInfoManager applicationInfoManager;
+ private final ApplicationInfoManager applicationInfoManager;
- private AtomicReference eurekaHttpClient = new AtomicReference<>();
+ private final AtomicReference eurekaHttpClient = new AtomicReference<>();
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config,
- ApplicationEventPublisher publisher) {
- this(applicationInfoManager, config, null, publisher);
+ TransportClientFactories transportClientFactories, ApplicationEventPublisher publisher) {
+ this(applicationInfoManager, config, transportClientFactories, null, publisher);
}
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config,
- AbstractDiscoveryClientOptionalArgs> args, ApplicationEventPublisher publisher) {
- super(applicationInfoManager, config, args);
+ TransportClientFactories transportClientFactories, AbstractDiscoveryClientOptionalArgs> args,
+ ApplicationEventPublisher publisher) {
+ super(applicationInfoManager, config, transportClientFactories, args);
this.applicationInfoManager = applicationInfoManager;
this.publisher = publisher;
this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class, "eurekaTransport");
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EnableEurekaClient.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EnableEurekaClient.java
deleted file mode 100644
index 1e38660281..0000000000
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EnableEurekaClient.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2013-2022 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.netflix.eureka;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Convenience annotation for clients to enable Eureka discovery configuration
- * (specifically). Use this (optionally) in case you want discovery and know for sure that
- * it is Eureka you want. All it does is turn on discovery and let the autoconfiguration
- * find the eureka classes if they are available (i.e. you need Eureka on the classpath as
- * well).
- *
- * @author Dave Syer
- * @author Spencer Gibb
- */
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Inherited
-public @interface EnableEurekaClient {
-
-}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
index a591e63a44..68a06a859f 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -24,14 +24,36 @@
import java.util.Map;
import com.netflix.appinfo.ApplicationInfoManager;
+import com.netflix.appinfo.DataCenterInfo;
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
+import com.netflix.appinfo.LeaseInfo;
+import com.netflix.appinfo.MyDataCenterInfo;
import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
+import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
+import com.netflix.discovery.TimedSupervisorTask;
+import com.netflix.discovery.converters.jackson.DataCenterTypeInfoResolver;
+import com.netflix.discovery.converters.jackson.builder.ApplicationsJacksonBuilder;
+import com.netflix.discovery.converters.jackson.mixin.InstanceInfoJsonMixIn;
+import com.netflix.discovery.shared.Application;
+import com.netflix.discovery.shared.Applications;
+import com.netflix.discovery.shared.resolver.AsyncResolver;
+import com.netflix.discovery.shared.resolver.DefaultEndpoint;
+import com.netflix.discovery.shared.resolver.EurekaEndpoint;
+import com.netflix.discovery.shared.transport.EurekaHttpResponse;
+import com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator;
+import com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient;
+import com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient;
+import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.springframework.aop.support.AopUtils;
+import org.springframework.aot.hint.MemberCategory;
+import org.springframework.aot.hint.RuntimeHints;
+import org.springframework.aot.hint.RuntimeHintsRegistrar;
+import org.springframework.aot.hint.TypeReference;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
@@ -67,6 +89,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceId;
@@ -80,6 +103,7 @@
* @author Daniel Lavoie
* @author Olga Maciaszek-Sharma
* @author Tim Ysewyn
+ * @author Robert Bleyl
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@@ -93,7 +117,7 @@
"org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationAutoConfiguration" })
public class EurekaClientAutoConfiguration {
- private ConfigurableEnvironment env;
+ private final ConfigurableEnvironment env;
public EurekaClientAutoConfiguration(ConfigurableEnvironment env) {
this.env = env;
@@ -201,8 +225,8 @@ private void setupJmxPort(EurekaInstanceConfigBean instance, Integer jmxPort) {
}
@Bean
- public EurekaServiceRegistry eurekaServiceRegistry() {
- return new EurekaServiceRegistry();
+ public EurekaServiceRegistry eurekaServiceRegistry(EurekaInstanceConfigBean eurekaInstanceConfigBean) {
+ return new EurekaServiceRegistry(eurekaInstanceConfigBean);
}
// @Bean
@@ -234,13 +258,14 @@ protected static class EurekaClientConfiguration {
@Autowired
private ApplicationContext context;
- @Autowired
+ @Autowired(required = false)
private AbstractDiscoveryClientOptionalArgs> optionalArgs;
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class, search = SearchStrategy.CURRENT)
- public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config) {
- return new CloudEurekaClient(manager, config, this.optionalArgs, this.context);
+ public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config,
+ TransportClientFactories> transportClientFactories) {
+ return new CloudEurekaClient(manager, config, transportClientFactories, this.optionalArgs, this.context);
}
@Bean
@@ -269,7 +294,7 @@ protected static class RefreshableEurekaClientConfiguration {
@Autowired
private ApplicationContext context;
- @Autowired
+ @Autowired(required = false)
private AbstractDiscoveryClientOptionalArgs> optionalArgs;
@Bean(destroyMethod = "shutdown")
@@ -277,12 +302,13 @@ protected static class RefreshableEurekaClientConfiguration {
@org.springframework.cloud.context.config.annotation.RefreshScope
@Lazy
public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config,
- EurekaInstanceConfig instance, @Autowired(required = false) HealthCheckHandler healthCheckHandler) {
+ EurekaInstanceConfig instance, TransportClientFactories> transportClientFactories,
+ @Autowired(required = false) HealthCheckHandler healthCheckHandler) {
// If we use the proxy of the ApplicationInfoManager we could run into a
// problem
// when shutdown is called on the CloudEurekaClient where the
// ApplicationInfoManager bean is
- // requested but wont be allowed because we are shutting down. To avoid this
+ // requested but won't be allowed because we are shutting down. To avoid this
// we use the
// object directly.
ApplicationInfoManager appManager;
@@ -292,8 +318,8 @@ public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientCon
else {
appManager = manager;
}
- CloudEurekaClient cloudEurekaClient = new CloudEurekaClient(appManager, config, this.optionalArgs,
- this.context);
+ CloudEurekaClient cloudEurekaClient = new CloudEurekaClient(appManager, config, transportClientFactories,
+ this.optionalArgs, this.context);
cloudEurekaClient.registerHealthCheck(healthCheckHandler);
return cloudEurekaClient;
}
@@ -376,3 +402,84 @@ public EurekaHealthIndicator eurekaHealthIndicator(EurekaClient eurekaClient,
}
}
+
+// Remove after adding hints to GraalVM reachability metadata repo
+class EurekaClientHints implements RuntimeHintsRegistrar {
+
+ @Override
+ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
+ if (!ClassUtils.isPresent("com.netflix.discovery.DiscoveryClient", classLoader)) {
+ return;
+ }
+ hints.reflection().registerType(TypeReference.of(DiscoveryClient.class),
+ hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS, MemberCategory.INTROSPECT_DECLARED_METHODS))
+ .registerType(TypeReference.of(EurekaEndpoint.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS))
+ .registerType(TypeReference.of(DefaultEndpoint.class),
+ hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS))
+ .registerType(TypeReference.of(EurekaHttpClientDecorator.class),
+ hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS,
+ MemberCategory.INTROSPECT_DECLARED_METHODS))
+ .registerType(TypeReference.of(EurekaHttpResponse.class),
+ hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS))
+ .registerType(TypeReference.of(EurekaHttpClientDecorator.RequestExecutor.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS))
+ .registerType(TypeReference.of(ApplicationInfoManager.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS))
+ .registerType(TypeReference.of(InstanceInfo.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS))
+ .registerType(TypeReference.of(InstanceInfo.ActionType.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(InstanceInfo.PortWrapper.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(LeaseInfo.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(MyDataCenterInfo.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(DataCenterInfo.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(DataCenterInfo.Name.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(EurekaClient.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS))
+ .registerType(TypeReference.of(TimedSupervisorTask.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(DataCenterTypeInfoResolver.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
+ .registerType(TypeReference.of(ApplicationsJacksonBuilder.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(InstanceInfoJsonMixIn.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(Application.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(Applications.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(AsyncResolver.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(RetryableEurekaHttpClient.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(SessionedEurekaHttpClient.class),
+ hint -> hint.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS,
+ MemberCategory.DECLARED_FIELDS))
+ .registerType(TypeReference.of(EurekaServiceInstance.class),
+ hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_METHODS,
+ MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
+ }
+
+}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java
index 81c792194e..f0aea7ce60 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBean.java
@@ -25,6 +25,7 @@
import com.netflix.appinfo.EurekaAccept;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.EurekaTransportConfig;
+import org.apache.hc.client5.http.classic.HttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -126,14 +127,14 @@ public class EurekaClientConfigBean implements EurekaClientConfig, Ordered {
/**
* Indicates how long to wait (in seconds) before a connection to eureka server needs
* to timeout. Note that the connections in the client are pooled by
- * org.apache.http.client.HttpClient and this setting affects the actual connection
- * creation and also the wait time to get the connection from the pool.
+ * {@link HttpClient} and this setting affects the actual connection creation and also
+ * the wait time to get the connection from the pool.
*/
private int eurekaServerConnectTimeoutSeconds = 5;
/**
* Gets the name of the implementation which implements BackupRegistry to fetch the
- * registry information as a fall back option for only the first time when the eureka
+ * registry information as a fallback option for only the first time when the eureka
* client starts.
*
* This may be needed for applications which needs additional resiliency for registry
@@ -472,7 +473,7 @@ public List getEurekaServerServiceUrls(String myZone) {
if (serviceUrls == null || serviceUrls.isEmpty()) {
serviceUrls = this.serviceUrl.get(DEFAULT_ZONE);
}
- if (!StringUtils.isEmpty(serviceUrls)) {
+ if (StringUtils.hasText(serviceUrls)) {
final String[] serviceUrlsSplit = StringUtils.commaDelimitedListToStringArray(serviceUrls);
List eurekaServiceUrls = new ArrayList<>(serviceUrlsSplit.length);
for (String eurekaServiceUrl : serviceUrlsSplit) {
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientConfiguration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
index 1e7b650465..9879fc7b6a 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
@@ -84,8 +84,9 @@ protected static class EurekaClientConfigurationRefresher
private EurekaAutoServiceRegistration autoRegistration;
public void onApplicationEvent(RefreshScopeRefreshedEvent event) {
- // This will force the creation of the EurkaClient bean if not already created
- // to make sure the client will be reregistered after a refresh event
+ // This will force the creation of the EurekaClient bean if not already
+ // created
+ // to make sure the client will be re-registered after a refresh event
if (eurekaClient != null) {
eurekaClient.getApplications();
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java
index f0cc6db9d7..7156ecc726 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandler.java
@@ -67,7 +67,7 @@
public class EurekaHealthCheckHandler
implements HealthCheckHandler, ApplicationContextAware, InitializingBean, Ordered, Lifecycle {
- private static final Map STATUS_MAPPING = new HashMap() {
+ private static final Map STATUS_MAPPING = new HashMap<>() {
{
put(Status.UNKNOWN, InstanceStatus.UNKNOWN);
put(Status.OUT_OF_SERVICE, InstanceStatus.DOWN);
@@ -76,18 +76,18 @@ public class EurekaHealthCheckHandler
}
};
- private StatusAggregator statusAggregator;
+ private final StatusAggregator statusAggregator;
private ApplicationContext applicationContext;
- private Map healthContributors = new HashMap<>();
+ private final Map healthContributors = new HashMap<>();
/**
* {@code true} until the context is stopped.
*/
private boolean running = true;
- private Map reactiveHealthContributors = new HashMap<>();
+ private final Map reactiveHealthContributors = new HashMap<>();
public EurekaHealthCheckHandler(StatusAggregator statusAggregator) {
this.statusAggregator = statusAggregator;
@@ -110,8 +110,7 @@ void populateHealthContributors(Map healthContributor
for (Map.Entry entry : healthContributors.entrySet()) {
// ignore EurekaHealthIndicator and flatten the rest of the composite
// otherwise there is a never ending cycle of down. See gh-643
- if (entry.getValue() instanceof DiscoveryCompositeHealthContributor) {
- DiscoveryCompositeHealthContributor indicator = (DiscoveryCompositeHealthContributor) entry.getValue();
+ if (entry.getValue() instanceof DiscoveryCompositeHealthContributor indicator) {
indicator.getIndicators().forEach((name, discoveryHealthIndicator) -> {
if (!(discoveryHealthIndicator instanceof EurekaHealthIndicator)) {
this.healthContributors.put(name, (HealthIndicator) discoveryHealthIndicator::health);
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthIndicator.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthIndicator.java
index 3e409bfeb9..c109650f22 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthIndicator.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaHealthIndicator.java
@@ -92,7 +92,7 @@ private DiscoveryClient getDiscoveryClient() {
if (AopUtils.isAopProxy(eurekaClient)) {
discoveryClient = ProxyUtils.getTargetObject(eurekaClient);
}
- else if (DiscoveryClient.class.isInstance(eurekaClient)) {
+ else if (eurekaClient instanceof DiscoveryClient) {
discoveryClient = (DiscoveryClient) eurekaClient;
}
return discoveryClient;
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
index 474405986a..8468b8ad93 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -25,6 +25,7 @@
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import com.netflix.appinfo.MyDataCenterInfo;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtils.HostInfo;
@@ -37,6 +38,7 @@
* @author Spencer Gibb
* @author Ryan Baxter
* @author Gregor Zurowski
+ * @author Robert Bleyl
*/
@ConfigurationProperties("eureka.instance")
public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, EnvironmentAware {
@@ -268,6 +270,12 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig, Envi
*/
private boolean preferIpAddress = false;
+ /**
+ * If true the EurekaClient will be initialized asynchronously when the
+ * InstanceRegistry bean is created.
+ */
+ private boolean asyncClientInitialization;
+
/**
* Initial status to register with remote Eureka server.
*/
@@ -285,6 +293,7 @@ public String getHostname() {
private EurekaInstanceConfigBean() {
}
+ @Autowired
public EurekaInstanceConfigBean(InetUtils inetUtils) {
this.inetUtils = inetUtils;
this.hostInfo = this.inetUtils.findFirstNonLoopbackHostInfo();
@@ -545,6 +554,14 @@ public void setPreferIpAddress(boolean preferIpAddress) {
this.preferIpAddress = preferIpAddress;
}
+ public boolean isAsyncClientInitialization() {
+ return asyncClientInitialization;
+ }
+
+ public void setAsyncClientInitialization(boolean asyncClientInitialization) {
+ this.asyncClientInitialization = asyncClientInitialization;
+ }
+
public InstanceStatus getInitialStatus() {
return initialStatus;
}
@@ -595,6 +612,7 @@ public boolean equals(Object o) {
&& Objects.equals(namespace, that.namespace) && Objects.equals(hostname, that.hostname)
&& preferIpAddress == that.preferIpAddress && Objects.equals(initialStatus, that.initialStatus)
&& Arrays.equals(defaultAddressResolutionOrder, that.defaultAddressResolutionOrder)
+ && asyncClientInitialization == that.asyncClientInitialization
&& Objects.equals(environment, that.environment);
}
@@ -605,7 +623,7 @@ public int hashCode() {
leaseExpirationDurationInSeconds, virtualHostName, instanceId, secureVirtualHostName, aSGName,
metadataMap, dataCenterInfo, ipAddress, statusPageUrlPath, statusPageUrl, homePageUrlPath, homePageUrl,
healthCheckUrlPath, healthCheckUrl, secureHealthCheckUrl, namespace, hostname, preferIpAddress,
- initialStatus, defaultAddressResolutionOrder, environment);
+ asyncClientInitialization, initialStatus, Arrays.hashCode(defaultAddressResolutionOrder), environment);
}
@Override
@@ -629,6 +647,7 @@ public String toString() {
.append("', ").append("healthCheckUrl='").append(healthCheckUrl).append("', ")
.append("secureHealthCheckUrl='").append(secureHealthCheckUrl).append("', ").append("namespace='")
.append(namespace).append("', ").append("hostname='").append(hostname).append("', ")
+ .append("asyncClientInitialization=").append(asyncClientInitialization).append(", ")
.append("preferIpAddress=").append(preferIpAddress).append(", ").append("initialStatus=")
.append(initialStatus).append(", ").append("defaultAddressResolutionOrder=")
.append(Arrays.toString(defaultAddressResolutionOrder)).append(", ").append("environment=")
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java
index 48a9603c71..fadc024420 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaServiceInstance.java
@@ -39,7 +39,7 @@
*/
public class EurekaServiceInstance implements ServiceInstance {
- private InstanceInfo instance;
+ private final InstanceInfo instance;
public EurekaServiceInstance(InstanceInfo instance) {
Assert.notNull(instance, "Service instance required");
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/MutableDiscoveryClientOptionalArgs.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/MutableDiscoveryClientOptionalArgs.java
deleted file mode 100644
index 1ae628afd0..0000000000
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/MutableDiscoveryClientOptionalArgs.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2013-2022 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.netflix.eureka;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-
-import com.netflix.discovery.DiscoveryClient.DiscoveryClientOptionalArgs;
-import com.sun.jersey.api.client.filter.ClientFilter;
-
-/**
- * @author Dave Syer
- */
-public class MutableDiscoveryClientOptionalArgs extends DiscoveryClientOptionalArgs {
-
- private Collection additionalFilters;
-
- @Override
- public void setAdditionalFilters(Collection additionalFilters) {
- additionalFilters = new LinkedHashSet<>(additionalFilters);
- this.additionalFilters = additionalFilters;
- super.setAdditionalFilters(additionalFilters);
- }
-
- public Collection getAdditionalFilters() {
- return this.additionalFilters;
- }
-
-}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/RestTemplateTimeoutProperties.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/RestTemplateTimeoutProperties.java
index 7bdf70d92f..394420ddbc 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/RestTemplateTimeoutProperties.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/RestTemplateTimeoutProperties.java
@@ -18,7 +18,8 @@
import java.util.Objects;
-import org.apache.http.client.config.RequestConfig;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.core5.http.io.SocketConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient;
@@ -35,13 +36,14 @@
public class RestTemplateTimeoutProperties {
/**
- * Default values are set to -1 according to {@link RequestConfig .DEFAULT}.
+ * Default values are set to 180000, in keeping with {@link RequestConfig} and
+ * {@link SocketConfig} defaults.
*/
- private int connectTimeout = -1;
+ private int connectTimeout = 3 * 60 * 1000;
- private int connectRequestTimeout = -1;
+ private int connectRequestTimeout = 3 * 60 * 1000;
- private int socketTimeout = -1;
+ private int socketTimeout = 3 * 60 * 1000;
public int getConnectTimeout() {
return connectTimeout;
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
index 42d689858c..e62e618d1f 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/DiscoveryClientOptionalArgsConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -20,11 +20,15 @@
import java.security.GeneralSecurityException;
import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
+import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
+import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
@@ -32,20 +36,25 @@
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.configuration.SSLContextFactory;
import org.springframework.cloud.configuration.TlsProperties;
-import org.springframework.cloud.netflix.eureka.MutableDiscoveryClientOptionalArgs;
import org.springframework.cloud.netflix.eureka.RestTemplateTimeoutProperties;
import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs;
+import org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClientFactories;
import org.springframework.cloud.netflix.eureka.http.WebClientDiscoveryClientOptionalArgs;
+import org.springframework.cloud.netflix.eureka.http.WebClientTransportClientFactories;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
/**
* @author Daniel Lavoie
+ * @author Armin Krezovic
+ * @author Olga Maciaszek-Sharma
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(RestTemplateTimeoutProperties.class)
@@ -61,20 +70,31 @@ public TlsProperties tlsProperties() {
@Bean
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
- @ConditionalOnMissingClass("com.sun.jersey.api.client.filter.ClientFilter")
+ @Conditional(JerseyClientNotPresentOrNotEnabledCondition.class)
@ConditionalOnMissingBean(value = { AbstractDiscoveryClientOptionalArgs.class }, search = SearchStrategy.CURRENT)
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
havingValue = "false")
public RestTemplateDiscoveryClientOptionalArgs restTemplateDiscoveryClientOptionalArgs(TlsProperties tlsProperties,
- EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier)
- throws GeneralSecurityException, IOException {
+ EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier,
+ ObjectProvider restTemplateBuilders) throws GeneralSecurityException, IOException {
logger.info("Eureka HTTP Client uses RestTemplate.");
RestTemplateDiscoveryClientOptionalArgs result = new RestTemplateDiscoveryClientOptionalArgs(
- eurekaClientHttpRequestFactorySupplier);
+ eurekaClientHttpRequestFactorySupplier, restTemplateBuilders::getIfAvailable);
setupTLS(result, tlsProperties);
return result;
}
+ @Bean
+ @ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
+ @Conditional(JerseyClientNotPresentOrNotEnabledCondition.class)
+ @ConditionalOnMissingBean(value = { TransportClientFactories.class }, search = SearchStrategy.CURRENT)
+ @ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", matchIfMissing = true,
+ havingValue = "false")
+ public RestTemplateTransportClientFactories restTemplateTransportClientFactories(
+ RestTemplateDiscoveryClientOptionalArgs optionalArgs) {
+ return new RestTemplateTransportClientFactories(optionalArgs);
+ }
+
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "org.springframework.web.client.RestTemplate")
@@ -83,17 +103,6 @@ EurekaClientHttpRequestFactorySupplier defaultEurekaClientHttpRequestFactorySupp
return new DefaultEurekaClientHttpRequestFactorySupplier(restTemplateTimeoutProperties);
}
- @Bean
- @ConditionalOnClass(name = "com.sun.jersey.api.client.filter.ClientFilter")
- @ConditionalOnMissingBean(value = AbstractDiscoveryClientOptionalArgs.class, search = SearchStrategy.CURRENT)
- public MutableDiscoveryClientOptionalArgs discoveryClientOptionalArgs(TlsProperties tlsProperties)
- throws GeneralSecurityException, IOException {
- logger.info("Eureka HTTP Client uses Jersey");
- MutableDiscoveryClientOptionalArgs result = new MutableDiscoveryClientOptionalArgs();
- setupTLS(result, tlsProperties);
- return result;
- }
-
private static void setupTLS(AbstractDiscoveryClientOptionalArgs> args, TlsProperties properties)
throws GeneralSecurityException, IOException {
if (properties.isEnabled()) {
@@ -102,7 +111,20 @@ private static void setupTLS(AbstractDiscoveryClientOptionalArgs> args, TlsPro
}
}
- @ConditionalOnMissingClass("com.sun.jersey.api.client.filter.ClientFilter")
+ @Configuration(proxyBeanMethods = false)
+ @Conditional(JerseyClientPresentAndEnabledCondition.class)
+ @ConditionalOnBean(value = AbstractDiscoveryClientOptionalArgs.class, search = SearchStrategy.CURRENT)
+ static class DiscoveryClientOptionalArgsTlsConfiguration {
+
+ DiscoveryClientOptionalArgsTlsConfiguration(TlsProperties tlsProperties,
+ AbstractDiscoveryClientOptionalArgs optionalArgs) throws GeneralSecurityException, IOException {
+ logger.info("Eureka HTTP Client uses Jersey");
+ setupTLS(optionalArgs, tlsProperties);
+ }
+
+ }
+
+ @Conditional(JerseyClientNotPresentOrNotEnabledCondition.class)
@ConditionalOnClass(name = "org.springframework.web.reactive.function.client.WebClient")
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", havingValue = "true")
protected static class WebClientConfiguration {
@@ -123,11 +145,18 @@ public WebClientDiscoveryClientOptionalArgs webClientDiscoveryClientOptionalArgs
return result;
}
+ @Bean
+ @ConditionalOnMissingBean(value = TransportClientFactories.class, search = SearchStrategy.CURRENT)
+ public WebClientTransportClientFactories webClientTransportClientFactories(
+ ObjectProvider builder) {
+ return new WebClientTransportClientFactories(builder::getIfAvailable);
+ }
+
}
@Configuration
- @ConditionalOnMissingClass({ "com.sun.jersey.api.client.filter.ClientFilter",
- "org.springframework.web.reactive.function.client.WebClient" })
+ @Conditional(JerseyClientNotPresentOrNotEnabledCondition.class)
+ @ConditionalOnMissingClass("org.springframework.web.reactive.function.client.WebClient")
@ConditionalOnProperty(prefix = "eureka.client", name = "webclient.enabled", havingValue = "true")
protected static class WebClientNotFoundConfiguration {
@@ -139,4 +168,40 @@ public WebClientNotFoundConfiguration() {
}
+ static class JerseyClientPresentAndEnabledCondition extends AllNestedConditions {
+
+ JerseyClientPresentAndEnabledCondition() {
+ super(ConfigurationPhase.REGISTER_BEAN);
+ }
+
+ @ConditionalOnClass(name = "org.glassfish.jersey.client.JerseyClient")
+ static class OnJerseyClientPresent {
+
+ }
+
+ @ConditionalOnProperty(value = "eureka.client.jersey.enabled", matchIfMissing = true)
+ static class OnJerseyClientEnabled {
+
+ }
+
+ }
+
+ static class JerseyClientNotPresentOrNotEnabledCondition extends AnyNestedCondition {
+
+ JerseyClientNotPresentOrNotEnabledCondition() {
+ super(ConfigurationPhase.REGISTER_BEAN);
+ }
+
+ @ConditionalOnMissingClass("org.glassfish.jersey.client.JerseyClient")
+ static class OnJerseyClientMissing {
+
+ }
+
+ @ConditionalOnProperty(value = "eureka.client.jersey.enabled", havingValue = "false")
+ static class OnJerseyClientDisabled {
+
+ }
+
+ }
+
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfiguration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfiguration.java
index 34555cf058..f2c78efbdc 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfiguration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfiguration.java
@@ -16,10 +16,9 @@
package org.springframework.cloud.netflix.eureka.config;
-import javax.annotation.PostConstruct;
-
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.EurekaClient;
+import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfiguration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfiguration.java
index b4804bc4f1..104c6f1a12 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfiguration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -29,10 +29,12 @@
import org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration;
import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
import org.springframework.cloud.configuration.TlsProperties;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
+import org.springframework.cloud.netflix.eureka.RestTemplateTimeoutProperties;
import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier;
import org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient;
@@ -51,11 +53,12 @@
* discovery.
*
* @author Dave Syer
+ * @author Armin Krezovic
*/
@ConditionalOnClass(ConfigServicePropertySourceLocator.class)
@Conditional(EurekaConfigServerBootstrapConfiguration.EurekaConfigServerBootstrapCondition.class)
@Configuration(proxyBeanMethods = false)
-@EnableConfigurationProperties
+@EnableConfigurationProperties(RestTemplateTimeoutProperties.class)
public class EurekaConfigServerBootstrapConfiguration {
@Bean
@@ -70,16 +73,18 @@ public EurekaClientConfigBean eurekaClientConfigBean() {
havingValue = "false")
public RestTemplateEurekaHttpClient configDiscoveryRestTemplateEurekaHttpClient(EurekaClientConfigBean config,
Environment env, @Nullable TlsProperties properties,
- EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
+ EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier,
+ ObjectProvider restTemplateBuilders) {
return (RestTemplateEurekaHttpClient) new RestTemplateTransportClientFactory(properties,
- eurekaClientHttpRequestFactorySupplier)
+ eurekaClientHttpRequestFactorySupplier, restTemplateBuilders::getIfAvailable)
.newClient(HostnameBasedUrlRandomizer.randomEndpoint(config, env));
}
@Bean
@ConditionalOnMissingBean
- EurekaClientHttpRequestFactorySupplier defaultEurekaClientHttpRequestFactorySupplier() {
- return new DefaultEurekaClientHttpRequestFactorySupplier();
+ EurekaClientHttpRequestFactorySupplier defaultEurekaClientHttpRequestFactorySupplier(
+ RestTemplateTimeoutProperties restTemplateTimeoutProperties) {
+ return new DefaultEurekaClientHttpRequestFactorySupplier(restTemplateTimeoutProperties);
}
@Bean
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java
index edd935be0d..94383282a8 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java
@@ -17,18 +17,16 @@
package org.springframework.cloud.netflix.eureka.config;
import java.util.Collections;
-import java.util.List;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
-import org.apache.commons.logging.Log;
import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.BootstrapRegistryInitializer;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Binder;
-import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.config.client.ConfigClientProperties;
+import org.springframework.cloud.config.client.ConfigServerConfigDataLocationResolver.PropertyResolver;
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
import org.springframework.cloud.configuration.TlsProperties;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
@@ -45,52 +43,39 @@ public void initialize(BootstrapRegistry registry) {
return;
}
- // It is important that we pass a lambda for the Function or else we will get a
- // ClassNotFoundException when config is not on the classpath
- registry.registerIfAbsent(ConfigServerInstanceProvider.Function.class, EurekaFunction::create);
- }
-
- private static Boolean getDiscoveryEnabled(Binder binder) {
- return binder.bind(ConfigClientProperties.CONFIG_DISCOVERY_ENABLED, Boolean.class).orElse(false)
- && binder.bind("eureka.client.enabled", Boolean.class).orElse(true)
- && binder.bind("spring.cloud.discovery.enabled", Boolean.class).orElse(true);
- }
-
- final static class EurekaFunction implements ConfigServerInstanceProvider.Function {
-
- private final BootstrapContext context;
-
- static EurekaFunction create(BootstrapContext context) {
- return new EurekaFunction(context);
- }
-
- private EurekaFunction(BootstrapContext context) {
- this.context = context;
- }
-
- @Override
- public List apply(String serviceId, Binder binder, BindHandler bindHandler, Log log) {
- if (binder == null || !getDiscoveryEnabled(binder)) {
- return Collections.emptyList();
+ registry.registerIfAbsent(EurekaClientConfigBean.class, context -> {
+ if (!getDiscoveryEnabled(context)) {
+ return null;
}
-
- EurekaClientConfigBean config = binder.bind(EurekaClientConfigBean.PREFIX, EurekaClientConfigBean.class)
- .orElseGet(EurekaClientConfigBean::new);
+ PropertyResolver propertyResolver = getPropertyResolver(context);
+ return propertyResolver.resolveConfigurationProperties(EurekaClientConfigBean.PREFIX,
+ EurekaClientConfigBean.class, EurekaClientConfigBean::new);
+ });
+
+ registry.registerIfAbsent(ConfigServerInstanceProvider.Function.class, context -> {
+ if (!getDiscoveryEnabled(context)) {
+ return (id) -> Collections.emptyList();
+ }
+ EurekaClientConfigBean config = context.get(EurekaClientConfigBean.class);
EurekaHttpClient httpClient = new RestTemplateTransportClientFactory(
context.getOrElse(TlsProperties.class, null),
context.getOrElse(EurekaClientHttpRequestFactorySupplier.class,
- new DefaultEurekaClientHttpRequestFactorySupplier()))
- .newClient(HostnameBasedUrlRandomizer.randomEndpoint(config, binder));
- return new EurekaConfigServerInstanceProvider(httpClient, config).getInstances(serviceId);
- }
+ new DefaultEurekaClientHttpRequestFactorySupplier())).newClient(
+ HostnameBasedUrlRandomizer.randomEndpoint(config, getPropertyResolver(context)));
+ return new EurekaConfigServerInstanceProvider(httpClient, config)::getInstances;
+ });
+ }
- @Override
- public List apply(String serviceId) {
- // This should never be called now but is here for backward
- // compatibility
- return apply(serviceId, null, null, null);
- }
+ private static PropertyResolver getPropertyResolver(BootstrapContext context) {
+ return context.getOrElseSupply(PropertyResolver.class,
+ () -> new PropertyResolver(context.get(Binder.class), context.getOrElse(BindHandler.class, null)));
+ }
+ public static Boolean getDiscoveryEnabled(BootstrapContext bootstrapContext) {
+ PropertyResolver propertyResolver = getPropertyResolver(bootstrapContext);
+ return propertyResolver.get(ConfigClientProperties.CONFIG_DISCOVERY_ENABLED, Boolean.class, false)
+ && propertyResolver.get("eureka.client.enabled", Boolean.class, true)
+ && propertyResolver.get("spring.cloud.discovery.enabled", Boolean.class, true);
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerInstanceProvider.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerInstanceProvider.java
index 1f0934d030..c3ca68e744 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerInstanceProvider.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerInstanceProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -31,6 +31,9 @@
import org.springframework.cloud.netflix.eureka.EurekaServiceInstance;
import org.springframework.http.HttpStatus;
+/**
+ * @author Tang Xiong
+ */
public class EurekaConfigServerInstanceProvider {
private final Log log;
@@ -53,7 +56,11 @@ public List getInstances(String serviceId) {
if (log.isDebugEnabled()) {
log.debug("eurekaConfigServerInstanceProvider finding instances for " + serviceId);
}
- EurekaHttpResponse response = client.getApplications(config.getRegion());
+ String remoteRegionsStr = config.fetchRegistryForRemoteRegions();
+ String[] remoteRegions = remoteRegionsStr == null ? null : remoteRegionsStr.split(",");
+ EurekaHttpResponse response = config.getRegistryRefreshSingleVipAddress() == null
+ ? client.getApplications(remoteRegions)
+ : client.getVip(config.getRegistryRefreshSingleVipAddress(), remoteRegions);
List instances = new ArrayList<>();
if (!isSuccessful(response) || response.getEntity() == null) {
return instances;
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/HostnameBasedUrlRandomizer.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/HostnameBasedUrlRandomizer.java
index 4998b303f4..0d577f96f1 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/HostnameBasedUrlRandomizer.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/HostnameBasedUrlRandomizer.java
@@ -18,15 +18,19 @@
import java.util.List;
+import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.endpoint.EndpointUtils;
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
import org.springframework.boot.context.properties.bind.Binder;
+import org.springframework.cloud.config.client.ConfigServerConfigDataLocationResolver.PropertyResolver;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
-final class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandomizer {
+public final class HostnameBasedUrlRandomizer implements EndpointUtils.ServiceUrlRandomizer {
+
+ private static final String EUREKA_INSTANCE_HOSTNAME = "eureka.instance.hostname";
private final String hostname;
@@ -56,19 +60,24 @@ public void randomize(List urlList) {
}
}
- static String getEurekaUrl(EurekaClientConfigBean config, String hostname) {
+ public static String getEurekaUrl(EurekaClientConfig config, String hostname) {
List urls = EndpointUtils.getDiscoveryServiceUrls(config, EurekaClientConfigBean.DEFAULT_ZONE,
new HostnameBasedUrlRandomizer(hostname));
return urls.get(0);
}
- static DefaultEndpoint randomEndpoint(EurekaClientConfigBean config, Environment env) {
- String hostname = env.getProperty("eureka.instance.hostname");
+ public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, Environment env) {
+ String hostname = env.getProperty(EUREKA_INSTANCE_HOSTNAME);
+ return new DefaultEndpoint(getEurekaUrl(config, hostname));
+ }
+
+ public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, Binder binder) {
+ String hostname = binder.bind(EUREKA_INSTANCE_HOSTNAME, String.class).orElseGet(() -> null);
return new DefaultEndpoint(getEurekaUrl(config, hostname));
}
- static DefaultEndpoint randomEndpoint(EurekaClientConfigBean config, Binder binder) {
- String hostname = binder.bind("eureka.instance.hostname", String.class).orElseGet(() -> null);
+ public static DefaultEndpoint randomEndpoint(EurekaClientConfig config, PropertyResolver propertyResolver) {
+ String hostname = propertyResolver.get(EUREKA_INSTANCE_HOSTNAME, String.class, null);
return new DefaultEndpoint(getEurekaUrl(config, hostname));
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/DefaultEurekaClientHttpRequestFactorySupplier.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/DefaultEurekaClientHttpRequestFactorySupplier.java
index d65a642085..36bf1b35ae 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/DefaultEurekaClientHttpRequestFactorySupplier.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/DefaultEurekaClientHttpRequestFactorySupplier.java
@@ -16,13 +16,20 @@
package org.springframework.cloud.netflix.eureka.http;
+import java.util.concurrent.TimeUnit;
+
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
+import org.apache.hc.core5.http.io.SocketConfig;
+import org.apache.hc.core5.util.Timeout;
import org.springframework.cloud.netflix.eureka.RestTemplateTimeoutProperties;
import org.springframework.http.client.ClientHttpRequestFactory;
@@ -34,6 +41,7 @@
* {@link HttpClients}.
*
* @author Marcin Grzejszczak
+ * @author Olga Maciaszek-Sharma
* @author Jiwon Jeon
* @since 3.0.0
*/
@@ -56,12 +64,10 @@ public DefaultEurekaClientHttpRequestFactorySupplier(RestTemplateTimeoutProperti
@Override
public ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVerifier hostnameVerifier) {
- HttpClientBuilder httpClientBuilder = HttpClients.custom();
- if (sslContext != null) {
- httpClientBuilder = httpClientBuilder.setSSLContext(sslContext);
- }
- if (hostnameVerifier != null) {
- httpClientBuilder = httpClientBuilder.setSSLHostnameVerifier(hostnameVerifier);
+ HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
+ if (sslContext != null || hostnameVerifier != null || restTemplateTimeoutProperties != null) {
+ httpClientBuilder.setConnectionManager(
+ buildConnectionManager(sslContext, hostnameVerifier, restTemplateTimeoutProperties));
}
if (restTemplateTimeoutProperties != null) {
httpClientBuilder.setDefaultRequestConfig(buildRequestConfig());
@@ -73,10 +79,33 @@ public ClientHttpRequestFactory get(SSLContext sslContext, @Nullable HostnameVer
return requestFactory;
}
+ private HttpClientConnectionManager buildConnectionManager(SSLContext sslContext, HostnameVerifier hostnameVerifier,
+ RestTemplateTimeoutProperties restTemplateTimeoutProperties) {
+ PoolingHttpClientConnectionManagerBuilder connectionManagerBuilder = PoolingHttpClientConnectionManagerBuilder
+ .create();
+ SSLConnectionSocketFactoryBuilder sslConnectionSocketFactoryBuilder = SSLConnectionSocketFactoryBuilder
+ .create();
+ if (sslContext != null) {
+ sslConnectionSocketFactoryBuilder.setSslContext(sslContext);
+ }
+ if (hostnameVerifier != null) {
+ sslConnectionSocketFactoryBuilder.setHostnameVerifier(hostnameVerifier);
+ }
+ connectionManagerBuilder.setSSLSocketFactory(sslConnectionSocketFactoryBuilder.build());
+ if (restTemplateTimeoutProperties != null) {
+ connectionManagerBuilder.setDefaultSocketConfig(SocketConfig.custom()
+ .setSoTimeout(Timeout.of(restTemplateTimeoutProperties.getSocketTimeout(), TimeUnit.MILLISECONDS))
+ .build());
+ }
+ return connectionManagerBuilder.build();
+ }
+
private RequestConfig buildRequestConfig() {
- return RequestConfig.custom().setConnectTimeout(restTemplateTimeoutProperties.getConnectTimeout())
- .setConnectionRequestTimeout(restTemplateTimeoutProperties.getConnectRequestTimeout())
- .setSocketTimeout(restTemplateTimeoutProperties.getSocketTimeout()).build();
+ return RequestConfig.custom()
+ .setConnectTimeout(Timeout.of(restTemplateTimeoutProperties.getConnectTimeout(), TimeUnit.MILLISECONDS))
+ .setConnectionRequestTimeout(
+ Timeout.of(restTemplateTimeoutProperties.getConnectRequestTimeout(), TimeUnit.MILLISECONDS))
+ .build();
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateDiscoveryClientOptionalArgs.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateDiscoveryClientOptionalArgs.java
index 8ba4342b78..663afb6aec 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateDiscoveryClientOptionalArgs.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateDiscoveryClientOptionalArgs.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -16,28 +16,32 @@
package org.springframework.cloud.netflix.eureka.http;
+import java.util.function.Supplier;
+
import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
+import org.springframework.boot.web.client.RestTemplateBuilder;
+
/**
* @author Daniel Lavoie
+ * @author Armin Krezovic
*/
public class RestTemplateDiscoveryClientOptionalArgs extends AbstractDiscoveryClientOptionalArgs {
protected final EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier;
+ protected final Supplier restTemplateBuilderSupplier;
+
public RestTemplateDiscoveryClientOptionalArgs(
EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
- this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier;
- setTransportClientFactories(new RestTemplateTransportClientFactories(this));
+ this(eurekaClientHttpRequestFactorySupplier, RestTemplateBuilder::new);
}
- /**
- * @deprecated - use
- * {@link RestTemplateDiscoveryClientOptionalArgs#RestTemplateDiscoveryClientOptionalArgs(EurekaClientHttpRequestFactorySupplier)}
- */
- @Deprecated
- public RestTemplateDiscoveryClientOptionalArgs() {
- this(new DefaultEurekaClientHttpRequestFactorySupplier());
+ public RestTemplateDiscoveryClientOptionalArgs(
+ EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier,
+ Supplier restTemplateBuilderSupplier) {
+ this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier;
+ this.restTemplateBuilderSupplier = restTemplateBuilderSupplier;
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java
index d52bb2caa5..6218b10fcf 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -16,6 +16,7 @@
package org.springframework.cloud.netflix.eureka.http;
+import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -30,8 +31,6 @@
import com.netflix.discovery.shared.transport.EurekaHttpResponse;
import com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder;
import com.netflix.discovery.util.StringUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
@@ -40,17 +39,17 @@
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
import static com.netflix.discovery.shared.transport.EurekaHttpResponse.anEurekaHttpResponse;
/**
* @author Daniel Lavoie
+ * @author Václav Plic
*/
public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
- protected final Log logger = LogFactory.getLog(getClass());
-
- private RestTemplate restTemplate;
+ private final RestTemplate restTemplate;
private String serviceUrl;
@@ -66,41 +65,52 @@ public String getServiceUrl() {
return this.serviceUrl;
}
+ public RestTemplate getRestTemplate() {
+ return restTemplate;
+ }
+
@Override
public EurekaHttpResponse register(InstanceInfo info) {
- String urlPath = serviceUrl + "apps/" + info.getAppName();
+ URI uri = UriComponentsBuilder.fromHttpUrl(serviceUrl).path("apps/{appName}").buildAndExpand(info.getAppName())
+ .toUri();
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.ACCEPT_ENCODING, "gzip");
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
- ResponseEntity response = restTemplate.exchange(urlPath, HttpMethod.POST, new HttpEntity<>(info, headers),
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.POST, new HttpEntity<>(info, headers),
Void.class);
- return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
+ return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
public EurekaHttpResponse cancel(String appName, String id) {
- String urlPath = serviceUrl + "apps/" + appName + '/' + id;
+ URI uri = UriComponentsBuilder.fromHttpUrl(serviceUrl).path("apps/{appName}/{id}").buildAndExpand(appName, id)
+ .toUri();
- ResponseEntity response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class);
- return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
+ return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
public EurekaHttpResponse sendHeartBeat(String appName, String id, InstanceInfo info,
InstanceStatus overriddenStatus) {
- String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString()
- + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString()
- + (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : "");
+ UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(serviceUrl).path("apps/{appName}/{id}")
+ .queryParam("status", info.getStatus().toString())
+ .queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString());
- ResponseEntity response = restTemplate.exchange(urlPath, HttpMethod.PUT, null,
- InstanceInfo.class);
+ if (overriddenStatus != null) {
+ uriBuilder = uriBuilder.queryParam("overriddenstatus", overriddenStatus.name());
+ }
+
+ URI uri = uriBuilder.buildAndExpand(appName, id).toUri();
+
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.PUT, null, InstanceInfo.class);
EurekaHttpResponseBuilder eurekaResponseBuilder = anEurekaHttpResponse(
- response.getStatusCodeValue(), InstanceInfo.class).headers(headersOf(response));
+ response.getStatusCode().value(), InstanceInfo.class).headers(headersOf(response));
if (response.hasBody()) {
eurekaResponseBuilder.entity(response.getBody());
@@ -112,22 +122,25 @@ public EurekaHttpResponse sendHeartBeat(String appName, String id,
@Override
public EurekaHttpResponse statusUpdate(String appName, String id, InstanceStatus newStatus,
InstanceInfo info) {
- String urlPath = serviceUrl + "apps/" + appName + '/' + id + "/status?value=" + newStatus.name()
- + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString();
+ URI uri = UriComponentsBuilder.fromHttpUrl(serviceUrl).path("apps/{appName}/{id}/status")
+ .queryParam("value", newStatus.name())
+ .queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).buildAndExpand(appName, id)
+ .toUri();
- ResponseEntity response = restTemplate.exchange(urlPath, HttpMethod.PUT, null, Void.class);
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.PUT, null, Void.class);
- return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
+ return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
public EurekaHttpResponse deleteStatusOverride(String appName, String id, InstanceInfo info) {
- String urlPath = serviceUrl + "apps/" + appName + '/' + id + "/status?lastDirtyTimestamp="
- + info.getLastDirtyTimestamp().toString();
+ URI uri = UriComponentsBuilder.fromHttpUrl(serviceUrl).path("apps/{appName}/{id}/status")
+ .queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).buildAndExpand(appName, id)
+ .toUri();
- ResponseEntity response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.DELETE, null, Void.class);
- return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
+ return anEurekaHttpResponse(response.getStatusCode().value()).headers(headersOf(response)).build();
}
@Override
@@ -136,16 +149,18 @@ public EurekaHttpResponse getApplications(String... regions) {
}
private EurekaHttpResponse getApplicationsInternal(String urlPath, String[] regions) {
- String url = serviceUrl + urlPath;
+ UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(serviceUrl).path(urlPath);
if (regions != null && regions.length > 0) {
- url = url + (urlPath.contains("?") ? "&" : "?") + "regions=" + StringUtil.join(regions);
+ uriBuilder = uriBuilder.queryParam("regions", StringUtil.join(regions));
}
- ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, null,
+ URI uri = uriBuilder.build().toUri();
+
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, null,
EurekaApplications.class);
- return anEurekaHttpResponse(response.getStatusCodeValue(),
+ return anEurekaHttpResponse(response.getStatusCode().value(),
response.getStatusCode().value() == HttpStatus.OK.value() && response.hasBody()
? (Applications) response.getBody() : null).headers(headersOf(response)).build();
}
@@ -167,34 +182,33 @@ public EurekaHttpResponse getSecureVip(String secureVipAddress, St
@Override
public EurekaHttpResponse getApplication(String appName) {
- String urlPath = serviceUrl + "apps/" + appName;
+ URI uri = UriComponentsBuilder.fromHttpUrl(serviceUrl).path("apps/{appName}").buildAndExpand(appName).toUri();
- ResponseEntity response = restTemplate.exchange(urlPath, HttpMethod.GET, null, Application.class);
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, null, Application.class);
- Application application = response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody()
+ Application application = response.getStatusCode().value() == HttpStatus.OK.value() && response.hasBody()
? response.getBody() : null;
- return anEurekaHttpResponse(response.getStatusCodeValue(), application).headers(headersOf(response)).build();
+ return anEurekaHttpResponse(response.getStatusCode().value(), application).headers(headersOf(response)).build();
}
@Override
public EurekaHttpResponse getInstance(String appName, String id) {
- return getInstanceInternal("apps/" + appName + '/' + id);
+ return getInstanceInternal("apps", appName, id);
}
@Override
public EurekaHttpResponse getInstance(String id) {
- return getInstanceInternal("instances/" + id);
+ return getInstanceInternal("instances", id);
}
- private EurekaHttpResponse getInstanceInternal(String urlPath) {
- urlPath = serviceUrl + urlPath;
+ private EurekaHttpResponse getInstanceInternal(String... pathSegments) {
+ URI uri = UriComponentsBuilder.fromHttpUrl(serviceUrl).pathSegment(pathSegments).build().toUri();
- ResponseEntity response = restTemplate.exchange(urlPath, HttpMethod.GET, null,
- InstanceInfo.class);
+ ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, null, InstanceInfo.class);
- return anEurekaHttpResponse(response.getStatusCodeValue(),
- response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody() ? response.getBody()
+ return anEurekaHttpResponse(response.getStatusCode().value(),
+ response.getStatusCode().value() == HttpStatus.OK.value() && response.hasBody() ? response.getBody()
: null).headers(headersOf(response)).build();
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactories.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactories.java
index 97f9952e2c..09f4c1c0a6 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactories.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactories.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -25,11 +25,11 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.TransportClientFactory;
-import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
/**
* @author Daniel Lavoie
+ * @author Armin Krezovic
*/
public class RestTemplateTransportClientFactories implements TransportClientFactories {
@@ -39,17 +39,11 @@ public RestTemplateTransportClientFactories(RestTemplateDiscoveryClientOptionalA
this.args = args;
}
- @Override
- public TransportClientFactory newTransportClientFactory(Collection additionalFilters,
- EurekaJerseyClient providedJerseyClient) {
- throw new UnsupportedOperationException();
- }
-
@Override
public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig,
Collection additionalFilters, InstanceInfo myInstanceInfo) {
return new RestTemplateTransportClientFactory(this.args.getSSLContext(), this.args.getHostnameVerifier(),
- this.args.eurekaClientHttpRequestFactorySupplier);
+ this.args.eurekaClientHttpRequestFactorySupplier, this.args.restTemplateBuilderSupplier);
}
@Override
@@ -57,7 +51,7 @@ public TransportClientFactory newTransportClientFactory(final EurekaClientConfig
final Collection additionalFilters, final InstanceInfo myInstanceInfo,
final Optional sslContext, final Optional hostnameVerifier) {
return new RestTemplateTransportClientFactory(this.args.getSSLContext(), this.args.getHostnameVerifier(),
- this.args.eurekaClientHttpRequestFactorySupplier);
+ this.args.eurekaClientHttpRequestFactorySupplier, this.args.restTemplateBuilderSupplier);
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java
index 448b4e5306..36e5e7e278 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -16,9 +16,12 @@
package org.springframework.cloud.netflix.eureka.http;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;
+import java.util.function.Supplier;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
@@ -27,7 +30,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -42,14 +45,19 @@
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import com.netflix.discovery.shared.transport.TransportClientFactory;
+import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.configuration.SSLContextFactory;
import org.springframework.cloud.configuration.TlsProperties;
+import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
+import org.springframework.http.HttpStatusCode;
import org.springframework.http.client.ClientHttpRequestFactory;
+import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.support.BasicAuthenticationInterceptor;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
+import org.springframework.web.util.UriComponentsBuilder;
/**
* Provides the custom {@link RestTemplate} required by the
@@ -57,6 +65,7 @@
* deserialization.
*
* @author Daniel Lavoie
+ * @author Armin Krezovic
*/
public class RestTemplateTransportClientFactory implements TransportClientFactory {
@@ -66,11 +75,20 @@ public class RestTemplateTransportClientFactory implements TransportClientFactor
private final EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier;
+ private final Supplier restTemplateBuilderSupplier;
+
public RestTemplateTransportClientFactory(TlsProperties tlsProperties,
- EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
+ EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier,
+ Supplier restTemplateBuilderSupplier) {
this.sslContext = context(tlsProperties);
this.hostnameVerifier = Optional.empty();
this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier;
+ this.restTemplateBuilderSupplier = restTemplateBuilderSupplier;
+ }
+
+ public RestTemplateTransportClientFactory(TlsProperties tlsProperties,
+ EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
+ this(tlsProperties, eurekaClientHttpRequestFactorySupplier, RestTemplateBuilder::new);
}
private Optional context(TlsProperties properties) {
@@ -87,25 +105,49 @@ private Optional context(TlsProperties properties) {
public RestTemplateTransportClientFactory(Optional sslContext,
Optional hostnameVerifier,
- EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
+ EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier,
+ Supplier restTemplateBuilderSupplier) {
this.sslContext = sslContext;
this.hostnameVerifier = hostnameVerifier;
this.eurekaClientHttpRequestFactorySupplier = eurekaClientHttpRequestFactorySupplier;
+ this.restTemplateBuilderSupplier = restTemplateBuilderSupplier;
+ }
+
+ public RestTemplateTransportClientFactory(Optional sslContext,
+ Optional hostnameVerifier,
+ EurekaClientHttpRequestFactorySupplier eurekaClientHttpRequestFactorySupplier) {
+
+ this(sslContext, hostnameVerifier, eurekaClientHttpRequestFactorySupplier, RestTemplateBuilder::new);
}
public RestTemplateTransportClientFactory() {
- this.sslContext = Optional.empty();
- this.hostnameVerifier = Optional.empty();
- this.eurekaClientHttpRequestFactorySupplier = new DefaultEurekaClientHttpRequestFactorySupplier();
+ this(Optional.empty(), Optional.empty(), new DefaultEurekaClientHttpRequestFactorySupplier());
}
@Override
public EurekaHttpClient newClient(EurekaEndpoint serviceUrl) {
- return new RestTemplateEurekaHttpClient(restTemplate(serviceUrl.getServiceUrl()), serviceUrl.getServiceUrl());
+ return new RestTemplateEurekaHttpClient(restTemplate(serviceUrl.getServiceUrl()),
+ stripUserInfo(serviceUrl.getServiceUrl()));
+ }
+
+ // apache http client 5.2 fails with non-null userinfo
+ // basic auth added in restTemplate() below
+ private String stripUserInfo(String serviceUrl) {
+ return UriComponentsBuilder.fromUriString(serviceUrl).userInfo(null).toUriString();
}
private RestTemplate restTemplate(String serviceUrl) {
- RestTemplate restTemplate = restTemplate();
+ ClientHttpRequestFactory requestFactory = this.eurekaClientHttpRequestFactorySupplier
+ .get(this.sslContext.orElse(null), this.hostnameVerifier.orElse(null));
+
+ RestTemplate restTemplate;
+
+ if (restTemplateBuilderSupplier != null && restTemplateBuilderSupplier.get() != null) {
+ restTemplate = restTemplateBuilderSupplier.get().requestFactory(() -> requestFactory).build();
+ }
+ else {
+ restTemplate = new RestTemplate(requestFactory);
+ }
try {
URI serviceURI = new URI(serviceUrl);
@@ -124,13 +166,15 @@ private RestTemplate restTemplate(String serviceUrl) {
restTemplate.getMessageConverters().add(0, mappingJacksonHttpMessageConverter());
restTemplate.setErrorHandler(new ErrorHandler());
- return restTemplate;
- }
+ restTemplate.getInterceptors().add((request, body, execution) -> {
+ ClientHttpResponse response = execution.execute(request, body);
+ if (!response.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
+ return response;
+ }
+ return new NotFoundHttpResponse(response);
+ });
- private RestTemplate restTemplate() {
- ClientHttpRequestFactory requestFactory = this.eurekaClientHttpRequestFactorySupplier
- .get(this.sslContext.orElse(null), this.hostnameVerifier.orElse(null));
- return new RestTemplate(requestFactory);
+ return restTemplate;
}
/**
@@ -139,13 +183,13 @@ private RestTemplate restTemplate() {
* serialized or deserialized. Achived with
* {@link SerializationFeature#WRAP_ROOT_VALUE} and
* {@link DeserializationFeature#UNWRAP_ROOT_VALUE}.
- * {@link PropertyNamingStrategy.SnakeCaseStrategy} is applied to the underlying
+ * {@link PropertyNamingStrategies.SnakeCaseStrategy} is applied to the underlying
* {@link ObjectMapper}.
* @return a {@link MappingJackson2HttpMessageConverter} object
*/
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
- converter.setObjectMapper(new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE));
+ converter.setObjectMapper(new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE));
SimpleModule jsonModule = new SimpleModule();
jsonModule.setSerializerModifier(createJsonSerializerModifier());
@@ -164,11 +208,6 @@ public static BeanSerializerModifier createJsonSerializerModifier() {
@Override
public JsonSerializer> modifySerializer(SerializationConfig config, BeanDescription beanDesc,
JsonSerializer> serializer) {
- /*
- * if (beanDesc.getBeanClass().isAssignableFrom(Applications.class)) {
- * return new ApplicationsJsonBeanSerializer((BeanSerializerBase)
- * serializer, keyFormatter); }
- */
if (beanDesc.getBeanClass().isAssignableFrom(InstanceInfo.class)) {
return new InstanceInfoJsonBeanSerializer((BeanSerializerBase) serializer, false);
}
@@ -181,15 +220,54 @@ public JsonSerializer> modifySerializer(SerializationConfig config, BeanDescri
public void shutdown() {
}
+ /**
+ * Response that ignores body, specifically for 404 errors.
+ */
+ private static class NotFoundHttpResponse implements ClientHttpResponse {
+
+ private final ClientHttpResponse response;
+
+ NotFoundHttpResponse(ClientHttpResponse response) {
+ this.response = response;
+ }
+
+ @Override
+ public HttpStatusCode getStatusCode() throws IOException {
+ return response.getStatusCode();
+ }
+
+ @Override
+ public String getStatusText() throws IOException {
+ return response.getStatusText();
+ }
+
+ @Override
+ public void close() {
+ response.close();
+ }
+
+ @Override
+ public InputStream getBody() throws IOException {
+ // ignore body on 404 for heartbeat, see gh-4145
+ return null;
+ }
+
+ @Override
+ public HttpHeaders getHeaders() {
+ return response.getHeaders();
+ }
+
+ }
+
class ErrorHandler extends DefaultResponseErrorHandler {
@Override
- protected boolean hasError(HttpStatus statusCode) {
+ protected boolean hasError(HttpStatusCode statusCode) {
/**
- * When the Eureka server restarts and a client tries to sent a heartbeat the
- * server will respond with a 404. By default RestTemplate will throw an
+ * When the Eureka server restarts and a client tries to send a heartbeat the
+ * server will respond with a 404. By default, RestTemplate will throw an
* exception in this case. What we want is to return the 404 to the upstream
- * code so it will send another registration request to the server.
+ * code, so it will send another registration request to the server.
*/
if (statusCode.is4xxClientError()) {
return false;
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientDiscoveryClientOptionalArgs.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientDiscoveryClientOptionalArgs.java
index 84834fe640..5521625006 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientDiscoveryClientOptionalArgs.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientDiscoveryClientOptionalArgs.java
@@ -29,7 +29,6 @@
public class WebClientDiscoveryClientOptionalArgs extends AbstractDiscoveryClientOptionalArgs {
public WebClientDiscoveryClientOptionalArgs(Supplier builder) {
- setTransportClientFactories(new WebClientTransportClientFactories(builder));
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClient.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClient.java
index 6e130c487b..9684119a01 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClient.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClient.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -17,6 +17,7 @@
package org.springframework.cloud.netflix.eureka.http;
import java.util.Map;
+import java.util.Optional;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
@@ -30,6 +31,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
+import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.reactive.function.BodyInserters;
@@ -41,6 +43,7 @@
/**
* @author Daniel Lavoie
* @author Haytham Mohamed
+ * @author Václav Plic
*/
public class WebClientEurekaHttpClient implements EurekaHttpClient {
@@ -52,31 +55,31 @@ public WebClientEurekaHttpClient(WebClient webClient) {
@Override
public EurekaHttpResponse register(InstanceInfo info) {
- return webClient.post().uri("apps/" + info.getAppName()).body(BodyInserters.fromValue(info))
- .header(HttpHeaders.ACCEPT_ENCODING, "gzip")
+ return webClient.post().uri(uriBuilder -> uriBuilder.path("apps/{appName}").build(info.getAppName()))
+ .body(BodyInserters.fromValue(info)).header(HttpHeaders.ACCEPT_ENCODING, "gzip")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).retrieve()
- .onStatus(HttpStatus::isError, this::ignoreError).toBodilessEntity().map(this::eurekaHttpResponse)
+ .onStatus(HttpStatusCode::isError, this::ignoreError).toBodilessEntity().map(this::eurekaHttpResponse)
.block();
}
@Override
public EurekaHttpResponse cancel(String appName, String id) {
- return webClient.delete().uri("apps/" + appName + '/' + id).retrieve()
- .onStatus(HttpStatus::isError, this::ignoreError).toBodilessEntity().map(this::eurekaHttpResponse)
- .block();
+ return webClient.delete().uri(uriBuilder -> uriBuilder.path("apps/{appName}/{id}").build(appName, id))
+ .retrieve().onStatus(HttpStatusCode::isError, this::ignoreError).toBodilessEntity()
+ .map(this::eurekaHttpResponse).block();
}
@Override
public EurekaHttpResponse sendHeartBeat(String appName, String id, InstanceInfo info,
InstanceStatus overriddenStatus) {
- String urlPath = "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString()
- + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString()
- + (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : "");
- ResponseEntity response = webClient.put().uri(urlPath)
+ ResponseEntity response = webClient.put()
+ .uri(uriBuilder -> uriBuilder.path("apps/{appName}/{id}")
+ .queryParam("status", info.getStatus().toString())
+ .queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).build(appName, id))
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).retrieve()
- .onStatus(HttpStatus::isError, this::ignoreError).toEntity(InstanceInfo.class).block();
+ .onStatus(HttpStatusCode::isError, this::ignoreError).toEntity(InstanceInfo.class).block();
EurekaHttpResponseBuilder builder = anEurekaHttpResponse(statusCodeValueOf(response),
InstanceInfo.class).headers(headersOf(response));
@@ -94,22 +97,22 @@ public EurekaHttpResponse sendHeartBeat(String appName, String id,
@Override
public EurekaHttpResponse statusUpdate(String appName, String id, InstanceStatus newStatus,
InstanceInfo info) {
- String urlPath = "apps/" + appName + '/' + id + "/status?value=" + newStatus.name() + "&lastDirtyTimestamp="
- + info.getLastDirtyTimestamp().toString();
-
- return webClient.put().uri(urlPath).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
- .retrieve().onStatus(HttpStatus::isError, this::ignoreError).toBodilessEntity()
- .map(this::eurekaHttpResponse).block();
+ return webClient.put()
+ .uri(uriBuilder -> uriBuilder.path("apps/{appName}/{id}/status").queryParam("value", newStatus.name())
+ .queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).build(appName, id))
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).retrieve()
+ .onStatus(HttpStatusCode::isError, this::ignoreError).toBodilessEntity().map(this::eurekaHttpResponse)
+ .block();
}
@Override
public EurekaHttpResponse deleteStatusOverride(String appName, String id, InstanceInfo info) {
- String urlPath = "apps/" + appName + '/' + id + "/status?lastDirtyTimestamp="
- + info.getLastDirtyTimestamp().toString();
-
- return webClient.delete().uri(urlPath).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
- .retrieve().onStatus(HttpStatus::isError, this::ignoreError).toBodilessEntity()
- .map(this::eurekaHttpResponse).block();
+ return webClient.delete()
+ .uri(uriBuilder -> uriBuilder.path("apps/{appName}/{id}/status")
+ .queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString()).build(appName, id))
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).retrieve()
+ .onStatus(HttpStatusCode::isError, this::ignoreError).toBodilessEntity().map(this::eurekaHttpResponse)
+ .block();
}
@Override
@@ -118,16 +121,14 @@ public EurekaHttpResponse getApplications(String... regions) {
}
private EurekaHttpResponse getApplicationsInternal(String urlPath, String[] regions) {
- String url = urlPath;
-
- if (regions != null && regions.length > 0) {
- url = url + (urlPath.contains("?") ? "&" : "?") + "regions=" + StringUtil.join(regions);
- }
+ Optional regionsParam = (regions != null && regions.length > 0) ? Optional.of(StringUtil.join(regions))
+ : Optional.empty();
- ResponseEntity response = webClient.get().uri(url)
+ ResponseEntity response = webClient.get()
+ .uri(uriBuilder -> uriBuilder.path(urlPath).queryParamIfPresent("regions", regionsParam).build())
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).retrieve()
- .onStatus(HttpStatus::isError, this::ignoreError).toEntity(Applications.class).block();
+ .onStatus(HttpStatusCode::isError, this::ignoreError).toEntity(Applications.class).block();
int statusCode = statusCodeValueOf(response);
@@ -155,9 +156,10 @@ public EurekaHttpResponse getSecureVip(String secureVipAddress, St
@Override
public EurekaHttpResponse getApplication(String appName) {
- ResponseEntity response = webClient.get().uri("apps/" + appName)
+ ResponseEntity response = webClient.get()
+ .uri(uriBuilder -> uriBuilder.path("apps/{appName}").build(appName))
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).retrieve()
- .onStatus(HttpStatus::isError, this::ignoreError).toEntity(Application.class).block();
+ .onStatus(HttpStatusCode::isError, this::ignoreError).toEntity(Application.class).block();
int statusCode = statusCodeValueOf(response);
Application body = response.getBody();
@@ -169,18 +171,19 @@ public EurekaHttpResponse getApplication(String appName) {
@Override
public EurekaHttpResponse getInstance(String appName, String id) {
- return getInstanceInternal("apps/" + appName + '/' + id);
+ return getInstanceInternal("apps", appName, id);
}
@Override
public EurekaHttpResponse getInstance(String id) {
- return getInstanceInternal("instances/" + id);
+ return getInstanceInternal("instances", id);
}
- private EurekaHttpResponse getInstanceInternal(String urlPath) {
- ResponseEntity response = webClient.get().uri(urlPath)
+ private EurekaHttpResponse getInstanceInternal(String... pathSegments) {
+ ResponseEntity response = webClient.get()
+ .uri(uriBuilder -> uriBuilder.pathSegment(pathSegments).build())
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE).retrieve()
- .onStatus(HttpStatus::isError, this::ignoreError).toEntity(InstanceInfo.class).block();
+ .onStatus(HttpStatusCode::isError, this::ignoreError).toEntity(InstanceInfo.class).block();
int statusCode = statusCodeValueOf(response);
InstanceInfo body = response.getBody();
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactories.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactories.java
index 2b4f9ca1b8..b3315b5ec2 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactories.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactories.java
@@ -26,7 +26,6 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.transport.TransportClientFactory;
-import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient;
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.springframework.web.reactive.function.client.WebClient;
@@ -43,12 +42,6 @@ public WebClientTransportClientFactories(Supplier builder) {
this.builder = builder;
}
- @Override
- public TransportClientFactory newTransportClientFactory(Collection additionalFilters,
- EurekaJerseyClient providedJerseyClient) {
- throw new UnsupportedOperationException();
- }
-
@Override
public TransportClientFactory newTransportClientFactory(EurekaClientConfig clientConfig,
Collection additionalFilters, InstanceInfo myInstanceInfo) {
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactory.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactory.java
index a3b12c4d9a..9a96b25a83 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactory.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -24,7 +24,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -38,6 +38,7 @@
import com.netflix.discovery.shared.resolver.EurekaEndpoint;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
import com.netflix.discovery.shared.transport.TransportClientFactory;
+import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.http.HttpStatus;
@@ -49,6 +50,7 @@
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
import org.springframework.web.reactive.function.client.WebClient;
+import org.springframework.web.util.UriComponentsBuilder;
/**
* Provides the custom {@link WebClient.Builder} required by the
@@ -57,6 +59,7 @@
*
* @author Daniel Lavoie
* @author Haytham Mohamed
+ * @author Armin Krezovic
*/
public class WebClientTransportClientFactory implements TransportClientFactory {
@@ -77,14 +80,14 @@ public EurekaHttpClient newClient(EurekaEndpoint endpoint) {
}
private WebClient.Builder setUrl(WebClient.Builder builder, String serviceUrl) {
- String url = serviceUrl;
+ String url = UriComponentsBuilder.fromUriString(serviceUrl).userInfo(null).toUriString();
+
try {
URI serviceURI = new URI(serviceUrl);
if (serviceURI.getUserInfo() != null) {
String[] credentials = serviceURI.getUserInfo().split(":");
if (credentials.length == 2) {
builder.filter(ExchangeFilterFunctions.basicAuthentication(credentials[0], credentials[1]));
- url = serviceUrl.replace(credentials[0] + ":" + credentials[1] + "@", "");
}
}
}
@@ -122,13 +125,13 @@ private void setCodecs(WebClient.Builder builder) {
* serialized or deserialized. Achieved with
* {@link SerializationFeature#WRAP_ROOT_VALUE} and
* {@link DeserializationFeature#UNWRAP_ROOT_VALUE}.
- * {@link PropertyNamingStrategy.SnakeCaseStrategy} is applied to the underlying
+ * {@link PropertyNamingStrategies.SnakeCaseStrategy} is applied to the underlying
* {@link ObjectMapper}.
* @return a {@link ObjectMapper} object
*/
private ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
+ objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
SimpleModule jsonModule = new SimpleModule();
jsonModule.setSerializerModifier(createJsonSerializerModifier());
@@ -147,10 +150,16 @@ private ExchangeFilterFunction http4XxErrorExchangeFilterFunction() {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
// literally 400 pass the tests, not 4xxClientError
if (clientResponse.statusCode().value() == 400) {
- ClientResponse newResponse = ClientResponse.from(clientResponse).statusCode(HttpStatus.OK).build();
+ ClientResponse newResponse = clientResponse.mutate().statusCode(HttpStatus.OK).build();
newResponse.body((clientHttpResponse, context) -> clientHttpResponse.getBody());
return Mono.just(newResponse);
}
+ if (clientResponse.statusCode().equals(HttpStatus.NOT_FOUND)) {
+ ClientResponse newResponse = clientResponse.mutate().statusCode(clientResponse.statusCode())
+ // ignore body on 404 for heartbeat, see gh-4145
+ .body(Flux.empty()).build();
+ return Mono.just(newResponse);
+ }
return Mono.just(clientResponse);
});
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfiguration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfiguration.java
index 01d756b3ed..bdcf6c5091 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfiguration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfiguration.java
@@ -16,10 +16,9 @@
package org.springframework.cloud.netflix.eureka.loadbalancer;
-import javax.annotation.PostConstruct;
-
import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.discovery.EurekaClientConfig;
+import jakarta.annotation.PostConstruct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -66,11 +65,11 @@ public EurekaLoadBalancerClientConfiguration(@Autowired(required = false) Eureka
@PostConstruct
public void postprocess() {
- if (!StringUtils.isEmpty(zoneConfig.getZone())) {
+ if (StringUtils.hasText(zoneConfig.getZone())) {
return;
}
String zone = getZoneFromEureka();
- if (!StringUtils.isEmpty(zone)) {
+ if (StringUtils.hasText(zone)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Setting the value of '" + LOADBALANCER_ZONE + "' to " + zone);
}
@@ -86,7 +85,7 @@ private String getZoneFromEureka() {
}
else {
zone = eurekaConfig == null ? null : eurekaConfig.getMetadataMap().get("zone");
- if (StringUtils.isEmpty(zone) && clientConfig != null) {
+ if (!StringUtils.hasText(zone) && clientConfig != null) {
String[] zones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
// Pick the first one from the regions we want to connect to
zone = zones != null && zones.length > 0 ? zones[0] : null;
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistration.java
index bf4807c4a1..37a105b2d3 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2023 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.
@@ -23,6 +23,7 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.web.context.WebServerInitializedEvent;
+import org.springframework.cloud.client.discovery.event.InstancePreRegisteredEvent;
import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistration;
import org.springframework.context.ApplicationContext;
@@ -33,28 +34,32 @@
import org.springframework.core.Ordered;
/**
+ * Provides an implementation of {@link AutoServiceRegistration} for registering service
+ * instances in Eureka.
+ *
* @author Dave Syer
* @author Spencer Gibb
* @author Jon Schneider
* @author Jakub Narloch
* @author Raiyan Raiyan
+ * @author Olga Maciaszek-Sharma
*/
public class EurekaAutoServiceRegistration
implements AutoServiceRegistration, SmartLifecycle, Ordered, SmartApplicationListener {
private static final Log log = LogFactory.getLog(EurekaAutoServiceRegistration.class);
- private AtomicBoolean running = new AtomicBoolean(false);
+ private final AtomicBoolean running = new AtomicBoolean(false);
- private int order = 0;
+ private final int order = 0;
- private AtomicInteger port = new AtomicInteger(0);
+ private final AtomicInteger port = new AtomicInteger(0);
- private ApplicationContext context;
+ private final ApplicationContext context;
- private EurekaServiceRegistry serviceRegistry;
+ private final EurekaServiceRegistry serviceRegistry;
- private EurekaRegistration registration;
+ private final EurekaRegistration registration;
public EurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry serviceRegistry,
EurekaRegistration registration) {
@@ -65,37 +70,38 @@ public EurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRe
@Override
public void start() {
- // only set the port if the nonSecurePort or securePort is 0 and this.port != 0
- if (this.port.get() != 0) {
- if (this.registration.getNonSecurePort() == 0) {
- this.registration.setNonSecurePort(this.port.get());
+ // only set the port if the nonSecurePort or securePort is 0 and port != 0
+ if (port.get() != 0) {
+ if (registration.getNonSecurePort() == 0) {
+ registration.setNonSecurePort(port.get());
}
- if (this.registration.getSecurePort() == 0 && this.registration.isSecure()) {
- this.registration.setSecurePort(this.port.get());
+ if (registration.getSecurePort() == 0 && registration.isSecure()) {
+ registration.setSecurePort(port.get());
}
}
// only initialize if nonSecurePort is greater than 0 and it isn't already running
// because of containerPortInitializer below
- if (!this.running.get() && this.registration.getNonSecurePort() > 0) {
+ if (!running.get() && registration.getNonSecurePort() > 0) {
+ context.publishEvent(new InstancePreRegisteredEvent(this, registration));
- this.serviceRegistry.register(this.registration);
+ serviceRegistry.register(registration);
- this.context.publishEvent(new InstanceRegisteredEvent<>(this, this.registration.getInstanceConfig()));
- this.running.set(true);
+ context.publishEvent(new InstanceRegisteredEvent<>(this, registration.getInstanceConfig()));
+ running.set(true);
}
}
@Override
public void stop() {
- this.serviceRegistry.deregister(this.registration);
- this.running.set(false);
+ serviceRegistry.deregister(registration);
+ running.set(false);
}
@Override
public boolean isRunning() {
- return this.running.get();
+ return running.get();
}
@Override
@@ -116,7 +122,7 @@ public void stop(Runnable callback) {
@Override
public int getOrder() {
- return this.order;
+ return order;
}
@Override
@@ -140,9 +146,9 @@ public void onApplicationEvent(WebServerInitializedEvent event) {
String contextName = event.getApplicationContext().getServerNamespace();
if (contextName == null || !contextName.equals("management")) {
int localPort = event.getWebServer().getPort();
- if (this.port.get() == 0) {
+ if (port.get() == 0) {
log.info("Updating port to " + localPort);
- this.port.compareAndSet(0, localPort);
+ port.compareAndSet(0, localPort);
start();
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaRegistration.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaRegistration.java
index f7458358a1..babd712580 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaRegistration.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaRegistration.java
@@ -25,6 +25,7 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
+import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -59,7 +60,7 @@ public class EurekaRegistration implements Registration {
private ObjectProvider healthCheckHandler;
- private EurekaRegistration(CloudEurekaInstanceConfig instanceConfig, EurekaClient eurekaClient,
+ public EurekaRegistration(CloudEurekaInstanceConfig instanceConfig, EurekaClient eurekaClient,
ApplicationInfoManager applicationInfoManager, ObjectProvider healthCheckHandler) {
this.eurekaClient = eurekaClient;
this.instanceConfig = instanceConfig;
@@ -181,6 +182,8 @@ public static class Builder {
private ApplicationEventPublisher publisher;
+ private TransportClientFactories> transportClientFactories;
+
Builder(CloudEurekaInstanceConfig instanceConfig) {
this.instanceConfig = instanceConfig;
}
@@ -200,6 +203,11 @@ public Builder with(ObjectProvider healthCheckHandler) {
return this;
}
+ public Builder with(TransportClientFactories> transportClientFactories) {
+ this.transportClientFactories = transportClientFactories;
+ return this;
+ }
+
public Builder with(EurekaClientConfig clientConfig, ApplicationEventPublisher publisher) {
this.clientConfig = clientConfig;
this.publisher = publisher;
@@ -216,9 +224,11 @@ public EurekaRegistration build() {
if (this.eurekaClient == null) {
Assert.notNull(this.clientConfig, "if eurekaClient is null, EurekaClientConfig may not be null");
Assert.notNull(this.publisher, "if eurekaClient is null, ApplicationEventPublisher may not be null");
+ Assert.notNull(this.transportClientFactories,
+ "if eurekaClient is null, TransportClientFactories may not be null");
this.eurekaClient = new CloudEurekaClient(this.applicationInfoManager, this.clientConfig,
- this.publisher);
+ this.transportClientFactories, this.publisher);
}
return new EurekaRegistration(instanceConfig, eurekaClient, applicationInfoManager, healthCheckHandler);
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistry.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistry.java
index 9410f8a618..31f95a565a 100644
--- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistry.java
+++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -17,25 +17,54 @@
package org.springframework.cloud.netflix.eureka.serviceregistry;
import java.util.HashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import com.netflix.appinfo.InstanceInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
+import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import static com.netflix.appinfo.InstanceInfo.InstanceStatus.UNKNOWN;
/**
* @author Spencer Gibb
+ * @author Robert Bleyl
*/
public class EurekaServiceRegistry implements ServiceRegistry {
private static final Log log = LogFactory.getLog(EurekaServiceRegistry.class);
+ private EurekaInstanceConfigBean eurekaInstanceConfigBean;
+
+ public EurekaServiceRegistry() {
+
+ }
+
+ public EurekaServiceRegistry(EurekaInstanceConfigBean eurekaInstanceConfigBean) {
+ this.eurekaInstanceConfigBean = eurekaInstanceConfigBean;
+ }
+
@Override
public void register(EurekaRegistration reg) {
- maybeInitializeClient(reg);
+ if (eurekaInstanceConfigBean != null && eurekaInstanceConfigBean.isAsyncClientInitialization()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing client asynchronously...");
+ }
+
+ ExecutorService executorService = Executors.newSingleThreadExecutor();
+ executorService.submit(() -> {
+ maybeInitializeClient(reg);
+ if (log.isDebugEnabled()) {
+ log.debug("Asynchronous client initialization done.");
+ }
+ });
+ }
+ else {
+ maybeInitializeClient(reg);
+ }
if (log.isInfoEnabled()) {
log.info("Registering application " + reg.getApplicationInfoManager().getInfo().getAppName()
@@ -86,6 +115,7 @@ public void setStatus(EurekaRegistration registration, String status) {
registration.getEurekaClient().setStatus(newStatus, info);
}
+ @SuppressWarnings("unchecked")
@Override
public Object getStatus(EurekaRegistration registration) {
String appname = registration.getApplicationInfoManager().getInfo().getAppName();
diff --git a/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index 0342fced7b..ff9a557fa6 100644
--- a/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -17,6 +17,13 @@
"name": "eureka.client.webclient.enabled",
"description": "Enables the use of WebClient for Eureka HTTP Client.",
"type": "java.lang.Boolean"
+ },
+ {
+ "defaultValue": 1,
+ "name": "eureka.instance.metadata-map.weight",
+ "description": "The weight of service instance for weighted load balancing.",
+ "type": "java.lang.Integer",
+ "sourceType": "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean"
}
]
}
diff --git a/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring.factories b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring.factories
index 8ff70e92f6..c2189497aa 100644
--- a/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring.factories
+++ b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring.factories
@@ -1,11 +1,3 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration,\
-org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration,\
-org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration,\
-org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration,\
-org.springframework.cloud.netflix.eureka.reactive.EurekaReactiveDiscoveryClientConfiguration,\
-org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration
-
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.netflix.eureka.config.EurekaConfigServerBootstrapConfiguration
diff --git a/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/aot.factories b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/aot.factories
new file mode 100644
index 0000000000..281a4a28d3
--- /dev/null
+++ b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/aot.factories
@@ -0,0 +1,2 @@
+org.springframework.aot.hint.RuntimeHintsRegistrar=\
+org.springframework.cloud.netflix.eureka.EurekaClientHints
\ No newline at end of file
diff --git a/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000000..8c150801e8
--- /dev/null
+++ b/spring-cloud-netflix-eureka-client/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1,6 @@
+org.springframework.cloud.netflix.eureka.config.EurekaClientConfigServerAutoConfiguration
+org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration
+org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
+org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
+org.springframework.cloud.netflix.eureka.reactive.EurekaReactiveDiscoveryClientConfiguration
+org.springframework.cloud.netflix.eureka.loadbalancer.LoadBalancerEurekaAutoConfiguration
\ No newline at end of file
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
index 235e67427b..1f31e884c0 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
@@ -23,10 +23,10 @@
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.HealthCheckHandler;
+import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
-import com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient;
-import com.sun.jersey.client.apache4.ApacheHttpClient4;
+import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -38,7 +38,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
-import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -48,6 +47,7 @@
import org.springframework.cloud.client.discovery.health.DiscoveryClientHealthIndicator;
import org.springframework.cloud.client.serviceregistry.AutoServiceRegistrationProperties;
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
+import org.springframework.cloud.context.config.ContextRefreshedWithApplicationEvent;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.scope.GenericScope;
import org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration;
@@ -74,7 +74,7 @@
*/
class EurekaClientAutoConfigurationTests {
- private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+ private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@AfterEach
void after() {
@@ -95,7 +95,7 @@ private void setupContext(Class>... config) {
}
@Test
- void shouldSetManagementPortInMetadataMapIfEqualToServerPort() throws Exception {
+ void shouldSetManagementPortInMetadataMapIfEqualToServerPort() {
TestPropertyValues.of("server.port=8989").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -105,7 +105,7 @@ void shouldSetManagementPortInMetadataMapIfEqualToServerPort() throws Exception
}
@Test
- void shouldNotSetManagementAndJmxPortsInMetadataMap() throws Exception {
+ void shouldNotSetManagementAndJmxPortsInMetadataMap() {
TestPropertyValues.of("server.port=8989", "management.server.port=0").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -116,7 +116,7 @@ void shouldNotSetManagementAndJmxPortsInMetadataMap() throws Exception {
}
@Test
- void shouldSetManagementAndJmxPortsInMetadataMap() throws Exception {
+ void shouldSetManagementAndJmxPortsInMetadataMap() {
TestPropertyValues.of("management.server.port=9999", "com.sun.management.jmxremote.port=6789")
.applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -127,7 +127,7 @@ void shouldSetManagementAndJmxPortsInMetadataMap() throws Exception {
}
@Test
- void shouldNotResetManagementAndJmxPortsInMetadataMap() throws Exception {
+ void shouldNotResetManagementAndJmxPortsInMetadataMap() {
TestPropertyValues.of("management.server.port=9999", "eureka.instance.metadata-map.jmx.port=9898",
"eureka.instance.metadata-map.management.port=7878").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -202,7 +202,7 @@ void healthCheckUrlPathAndManagementPort() {
}
@Test
- void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() throws Exception {
+ void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() {
TestPropertyValues.of("server.port=8989", "management.server.port=9999", "server.contextPath=/service")
.applyTo(this.context);
@@ -215,7 +215,7 @@ void statusPageUrl_and_healthCheckUrl_do_not_contain_server_context_path() throw
}
@Test
- void statusPageUrl_and_healthCheckUrl_contain_management_context_path() throws Exception {
+ void statusPageUrl_and_healthCheckUrl_contain_management_context_path() {
TestPropertyValues.of("server.port=8989", "management.server.servlet.context-path=/management")
.applyTo(this.context);
@@ -228,7 +228,7 @@ void statusPageUrl_and_healthCheckUrl_contain_management_context_path() throws E
}
@Test
- void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port() throws Exception {
+ void statusPageUrl_and_healthCheckUrl_contain_management_context_path_random_port() {
TestPropertyValues.of("server.port=0", "management.server.servlet.context-path=/management")
.applyTo(this.context);
@@ -287,7 +287,7 @@ void healthCheckUrlPathAndManagementPortAndContextPathKebobCase() {
}
@Test
- void statusPageUrl_and_healthCheckUrl_contain_management_base_path() throws Exception {
+ void statusPageUrl_and_healthCheckUrl_contain_management_base_path() {
TestPropertyValues.of("server.port=8989", "management.server.base-path=/management").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -299,7 +299,7 @@ void statusPageUrl_and_healthCheckUrl_contain_management_base_path() throws Exce
}
@Test
- void statusPageUrl_and_healthCheckUrl_contain_management_base_path_random_port() throws Exception {
+ void statusPageUrl_and_healthCheckUrl_contain_management_base_path_random_port() {
TestPropertyValues.of("server.port=0", "management.server.base-path=/management").applyTo(this.context);
setupContext(RefreshAutoConfiguration.class);
@@ -470,9 +470,9 @@ void shouldReregisterHealthCheckHandlerAfterRefresh() throws Exception {
ContextRefresher refresher = this.context.getBean(ContextRefresher.class);
if (refresher instanceof ApplicationListener) {
- ApplicationListener listener = (ApplicationListener) refresher;
- listener.onApplicationEvent(
- new ApplicationPreparedEvent(Mockito.mock(SpringApplication.class), new String[0], this.context));
+ ApplicationListener listener = (ApplicationListener) refresher;
+ listener.onApplicationEvent(new ContextRefreshedWithApplicationEvent(Mockito.mock(SpringApplication.class),
+ new String[0], this.context));
}
refresher.refresh();
@@ -501,17 +501,7 @@ void shouldCloseDiscoveryClient() throws Exception {
}
@Test
- void basicAuth() {
- TestPropertyValues
- .of("server.port=8989", "eureka.client.serviceUrl.defaultZone=https://user:foo@example.com:80/eureka")
- .applyTo(this.context);
- setupContext(MockClientConfiguration.class);
- // ApacheHttpClient4 http = this.context.getBean(ApacheHttpClient4.class);
- // Mockito.verify(http).addFilter(Matchers.any(HTTPBasicAuthFilter.class));
- }
-
- @Test
- void testDefaultAppName() throws Exception {
+ void testDefaultAppName() {
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("unknown");
assertThat(getInstanceConfig().getVirtualHostName()).isEqualTo("unknown");
@@ -519,7 +509,7 @@ void testDefaultAppName() throws Exception {
}
@Test
- void testAppName() throws Exception {
+ void testAppName() {
TestPropertyValues.of("spring.application.name=mytest").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytest");
@@ -528,7 +518,7 @@ void testAppName() throws Exception {
}
@Test
- void testAppNameUpper() throws Exception {
+ void testAppNameUpper() {
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestupper");
setupContext();
assertThat(getInstanceConfig().getAppname()).isEqualTo("mytestupper");
@@ -570,7 +560,7 @@ private static int getSeparatorIndex(String pair) {
}
@Test
- void testInstanceNamePreferred() throws Exception {
+ void testInstanceNamePreferred() {
addSystemEnvironment(this.context.getEnvironment(), "SPRING_APPLICATION_NAME=mytestspringappname");
TestPropertyValues.of("eureka.instance.appname=mytesteurekaappname").applyTo(this.context);
setupContext();
@@ -616,6 +606,7 @@ void shouldNotHaveDiscoveryClientWhenBlockingDiscoveryDisabled() {
});
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
private void assertBeanNotPresent(Class beanClass) {
try {
context.getBean(beanClass);
@@ -671,8 +662,9 @@ public CountDownLatch countDownLatch() {
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class, search = SearchStrategy.CURRENT)
public EurekaClient eurekaClient(ApplicationInfoManager manager, EurekaClientConfig config,
- ApplicationContext context) {
- return new CloudEurekaClient(manager, config, null, context) {
+ TransportClientFactories> transportClientFactories, ApplicationContext context,
+ AbstractDiscoveryClientOptionalArgs optionalArgs) {
+ return new CloudEurekaClient(manager, config, transportClientFactories, optionalArgs, context) {
@Override
public synchronized void shutdown() {
CountDownLatch latch = countDownLatch();
@@ -686,23 +678,6 @@ public synchronized void shutdown() {
}
- @Configuration(proxyBeanMethods = false)
- protected static class MockClientConfiguration {
-
- @Bean
- public EurekaJerseyClient jerseyClient() {
- EurekaJerseyClient mock = Mockito.mock(EurekaJerseyClient.class);
- Mockito.when(mock.getClient()).thenReturn(apacheClient());
- return mock;
- }
-
- @Bean
- public ApacheHttpClient4 apacheClient() {
- return Mockito.mock(ApacheHttpClient4.class);
- }
-
- }
-
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(AutoServiceRegistrationProperties.class)
public static class AutoServiceRegistrationConfiguration {
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBeanTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBeanTests.java
index 9f9ab21b96..b1c3f2e4a1 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBeanTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientConfigBeanTests.java
@@ -36,7 +36,7 @@
*/
class EurekaClientConfigBeanTests {
- private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+ private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@AfterEach
void init() {
@@ -67,7 +67,7 @@ void serviceUrl() {
void serviceUrlWithCompositePropertySource() {
CompositePropertySource source = new CompositePropertySource("composite");
this.context.getEnvironment().getPropertySources().addFirst(source);
- source.addPropertySource(new MapPropertySource("config", Collections.singletonMap(
+ source.addPropertySource(new MapPropertySource("config", Collections.singletonMap(
"eureka.client.serviceUrl.defaultZone",
"https://example.com,https://example2.com, https://www.hugedomains.com/domain_profile.cfm?d=example3&e=com")));
this.context.register(PropertyPlaceholderAutoConfiguration.class, TestConfiguration.class);
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandlerTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandlerTests.java
index 5448bb49c0..21a0782260 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandlerTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaHealthCheckHandlerTests.java
@@ -321,7 +321,7 @@ public HealthContributor getContributor(String name) {
@Override
public Iterator> iterator() {
Iterator> iterator = contributorMap.entrySet().iterator();
- return new Iterator>() {
+ return new Iterator<>() {
@Override
public boolean hasNext() {
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
index 3b1dcae10d..109d5e2f9b 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
@@ -18,11 +18,9 @@
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -46,14 +44,14 @@
*/
class EurekaInstanceConfigBeanTests {
- private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+ private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
private String hostName;
private String ipAddress;
@BeforeEach
- void init() throws Exception {
+ void init() {
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
InetUtils.HostInfo hostInfo = utils.findFirstNonLoopbackHostInfo();
this.hostName = hostInfo.getHostname();
@@ -158,13 +156,6 @@ void testDefaultInitialStatus() {
assertThat(getInstanceConfig().getInitialStatus()).as("initialStatus wrong").isEqualTo(InstanceStatus.UP);
}
- void testBadInitialStatus() {
- TestPropertyValues.of("eureka.instance.initial-status:FOO").applyTo(this.context);
- Assertions.assertThrows(BeanCreationException.class, () -> {
- setupContext();
- });
- }
-
@Test
void testCustomInitialStatus() {
TestPropertyValues.of("eureka.instance.initial-status:STARTING").applyTo(this.context);
@@ -173,7 +164,7 @@ void testCustomInitialStatus() {
}
@Test
- void testPreferIpAddress() throws Exception {
+ void testPreferIpAddress() {
TestPropertyValues.of("eureka.instance.preferIpAddress:true").applyTo(this.context);
setupContext();
EurekaInstanceConfigBean instance = getInstanceConfig();
@@ -183,7 +174,7 @@ void testPreferIpAddress() throws Exception {
}
@Test
- void testDefaultVirtualHostName() throws Exception {
+ void testDefaultVirtualHostName() {
TestPropertyValues.of("spring.application.name:myapp").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getVirtualHostName()).as("virtualHostName wrong").isEqualTo("myapp");
@@ -192,7 +183,7 @@ void testDefaultVirtualHostName() throws Exception {
}
@Test
- void testCustomVirtualHostName() throws Exception {
+ void testCustomVirtualHostName() {
TestPropertyValues.of("spring.application.name:myapp", "eureka.instance.virtualHostName=myvirthost",
"eureka.instance.secureVirtualHostName=mysecurevirthost").applyTo(this.context);
setupContext();
@@ -203,7 +194,7 @@ void testCustomVirtualHostName() throws Exception {
}
@Test
- void testDefaultAppName() throws Exception {
+ void testDefaultAppName() {
setupContext();
assertThat(getInstanceConfig().getAppname()).as("default app name is wrong").isEqualTo("unknown");
assertThat(getInstanceConfig().getVirtualHostName()).as("default virtual hostname is wrong")
@@ -213,21 +204,21 @@ void testDefaultAppName() throws Exception {
}
@Test
- void testCustomInstanceId() throws Exception {
+ void testCustomInstanceId() {
TestPropertyValues.of("eureka.instance.instanceId=myinstance").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
}
@Test
- void testCustomInstanceIdWithMetadata() throws Exception {
+ void testCustomInstanceIdWithMetadata() {
TestPropertyValues.of("eureka.instance.metadataMap.instanceId=myinstance").applyTo(this.context);
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("instance id is wrong").isEqualTo("myinstance");
}
@Test
- void testDefaultInstanceId() throws Exception {
+ void testDefaultInstanceId() {
setupContext();
assertThat(getInstanceConfig().getInstanceId()).as("default instance id is wrong").isEqualTo(null);
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/InstanceInfoFactoryTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/InstanceInfoFactoryTests.java
index 00a9c7bf29..1e58aac3a3 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/InstanceInfoFactoryTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/InstanceInfoFactoryTests.java
@@ -16,8 +16,6 @@
package org.springframework.cloud.netflix.eureka;
-import java.io.IOException;
-
import com.netflix.appinfo.InstanceInfo;
import org.junit.jupiter.api.Test;
@@ -34,10 +32,10 @@
class InstanceInfoFactoryTests {
- private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
+ private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@Test
- void instanceIdIsHostNameByDefault() throws IOException {
+ void instanceIdIsHostNameByDefault() {
InstanceInfo instanceInfo = setupInstance();
try (InetUtils utils = new InetUtils(new InetUtilsProperties())) {
assertThat(instanceInfo.getId()).isEqualTo(utils.findFirstNonLoopbackHostInfo().getHostname());
@@ -45,7 +43,7 @@ void instanceIdIsHostNameByDefault() throws IOException {
}
@Test
- void instanceIdIsIpWhenIpPreferred() throws Exception {
+ void instanceIdIsIpWhenIpPreferred() {
InstanceInfo instanceInfo = setupInstance("eureka.instance.preferIpAddress:true");
assertThat(instanceInfo.getId().matches("(\\d+\\.){3}\\d+")).isTrue();
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/ConfigRefreshTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/ConfigRefreshTests.java
index 40e2ae6c09..987ffcc8fe 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/ConfigRefreshTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/ConfigRefreshTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -31,6 +31,7 @@
/**
* @author Ryan Baxter
+ * @author Kaiyao Ke
*/
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = RefreshEurekaSampleApplication.class)
class ConfigRefreshTests {
@@ -42,6 +43,8 @@ class ConfigRefreshTests {
// Mocked in RefreshEurekaSampleApplication
private EurekaClient client;
+ private static boolean isFirstRun = true;
+
@Test
// This test is used to verify that getApplications is called the correct number of
// times when a refresh event is fired. The getApplications call in
@@ -49,8 +52,9 @@ class ConfigRefreshTests {
// ensures that the EurekaClient bean is recreated after a refresh event and that we
// reregister the client with the server
void verifyGetApplications() {
- if (publisher != null) {
+ if (publisher != null && isFirstRun) {
publisher.publishEvent(new RefreshScopeRefreshedEvent());
+ isFirstRun = false;
}
verify(client, times(3)).getApplications();
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfigurationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfigurationTests.java
index 042baef311..b663c77fcf 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfigurationTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaClientConfigServerAutoConfigurationTests.java
@@ -21,6 +21,7 @@
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.cloud.commons.util.UtilAutoConfiguration;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
@@ -35,16 +36,15 @@ class EurekaClientConfigServerAutoConfigurationTests {
@Test
void offByDefault() {
new ApplicationContextRunner()
- .withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class)).run(c -> {
- assertThat(c.getBeanNamesForType(EurekaInstanceConfigBean.class).length).isEqualTo(0);
- });
+ .withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class))
+ .run(c -> assertThat(c.getBeanNamesForType(EurekaInstanceConfigBean.class).length).isEqualTo(0));
}
@Test
void onWhenRequested() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class,
- ConfigServerProperties.class, EurekaInstanceConfigBean.class))
+ UtilAutoConfiguration.class, ConfigServerProperties.class, EurekaInstanceConfigBean.class))
.withPropertyValues("spring.cloud.config.server.prefix=/config").run(c -> {
assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length).isEqualTo(1);
EurekaInstanceConfig instance = c.getBean(EurekaInstanceConfig.class);
@@ -56,7 +56,7 @@ void onWhenRequested() {
void notOverridingMetamapSettings() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaClientConfigServerAutoConfiguration.class,
- ConfigServerProperties.class, EurekaInstanceConfigBean.class))
+ UtilAutoConfiguration.class, ConfigServerProperties.class, EurekaInstanceConfigBean.class))
.withPropertyValues("spring.cloud.config.server.prefix=/config")
.withPropertyValues("eureka.instance.metadataMap.configPath=/differentpath").run(c -> {
assertThat(c.getBeanNamesForType(EurekaInstanceConfig.class).length).isEqualTo(1);
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationTests.java
index de6e935bf7..cc17a6a23a 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -51,6 +51,7 @@
/**
* @author Spencer Gibb
+ * @author Tang Xiong
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("spring-webflux-*")
@@ -63,63 +64,50 @@ public class EurekaConfigServerBootstrapConfigurationTests {
public void offByDefault() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
- .run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .run(this::assertEurekaBeansNotPresent);
}
@Test
public void properBeansCreatedWhenDiscoveryEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
- .withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
- assertEurekaBeansPresent(context);
- });
+ .withPropertyValues("spring.cloud.config.discovery.enabled=true").run(this::assertEurekaBeansPresent);
}
@Test
public void beansNotCreatedWhenDiscoveryNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
- .withPropertyValues("spring.cloud.config.discovery.enabled=false").run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .withPropertyValues("spring.cloud.config.discovery.enabled=false")
+ .run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenDiscoveryDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
- .withPropertyValues("spring.cloud.config.discovery.disabled").run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .withPropertyValues("spring.cloud.config.discovery.disabled").run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenEurekaClientEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
- .withPropertyValues("eureka.client.enabled=true").run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .withPropertyValues("eureka.client.enabled=true").run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenEurekaClientNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
- .withPropertyValues("eureka.client.enabled=false").run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .withPropertyValues("eureka.client.enabled=false").run(this::assertEurekaBeansNotPresent);
}
@Test
public void beansNotCreatedWhenEurekaClientDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
- .withPropertyValues("eureka.client.disabled").run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .withPropertyValues("eureka.client.disabled").run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -127,9 +115,7 @@ public void properBeansCreatedWhenDiscoveryEnabled_EurekaEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true")
- .run(context -> {
- assertEurekaBeansPresent(context);
- });
+ .run(this::assertEurekaBeansPresent);
}
@Test
@@ -137,9 +123,7 @@ public void beansNotCreatedWhenDiscoveryEnabled_EurekaNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=false")
- .run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -147,9 +131,7 @@ public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=true")
- .run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -157,9 +139,7 @@ public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=false")
- .run(context -> {
- assertEurekaBeansNotPresent(context);
- });
+ .run(this::assertEurekaBeansNotPresent);
}
@Test
@@ -171,9 +151,8 @@ public void eurekaDnsConfigurationWorks() {
"eureka.client.use-dns-for-fetching-service-urls=true",
"eureka.client.eureka-server-d-n-s-name=myeurekahost",
"eureka.client.eureka-server-u-r-l-context=eureka", "eureka.client.eureka-server-port=30000")
- .run(context -> {
- assertThat(output).contains("Cannot get cnames bound to the region:txt.us-east-1.myeurekahost");
- });
+ .run(context -> assertThat(output)
+ .contains("Cannot get cnames bound to the region:txt.us-east-1.myeurekahost"));
}
@Test
@@ -185,7 +164,34 @@ public void eurekaConfigServerInstanceProviderCalled() {
"eureka.client.enabled=true",
"spring.main.sources=" + TestConfigDiscoveryBootstrapConfiguration.class.getName(),
"logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
- .run();
+ .run().close();
+ assertThat(output).contains("eurekaConfigServerInstanceProvider finding instances for configserver")
+ .contains("eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
+ }
+
+ @Test
+ public void eurekaConfigServerInstanceProviderCalledWithRemoteRegions() {
+ TomcatURLStreamHandlerFactory.disable();
+ new SpringApplicationBuilder(TestConfigDiscoveryConfiguration.class)
+ .properties("spring.config.use-legacy-processing=true", "spring.cloud.config.discovery.enabled=true",
+ "eureka.client.enabled=true", "eureka.client.fetchRemoteRegionsRegistry=us-east-1,us-east-2",
+ "spring.main.sources=" + TestConfigDiscoveryBootstrapConfiguration.class.getName(),
+ "logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
+ .run().close();
+ assertThat(output).contains("eurekaConfigServerInstanceProvider finding instances for configserver")
+ .contains("eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
+ }
+
+ @Test
+ public void eurekaConfigServerInstanceProviderCalledWithVipAddress() {
+ TomcatURLStreamHandlerFactory.disable();
+ new SpringApplicationBuilder(TestConfigDiscoveryConfiguration.class)
+ .properties("spring.config.use-legacy-processing=true", "spring.cloud.config.discovery.enabled=true",
+ "eureka.client.enabled=true", "eureka.client.registryRefreshSingleVipAddress=vip1",
+ "eureka.client.fetchRemoteRegionsRegistry=us-east-1,us-east-2",
+ "spring.main.sources=" + TestConfigDiscoveryBootstrapConfiguration.class.getName(),
+ "logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
+ .run().close();
assertThat(output).contains("eurekaConfigServerInstanceProvider finding instances for configserver")
.contains("eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
}
@@ -230,7 +236,9 @@ public EurekaHttpClient mockEurekaHttpClient() {
when(response.getEntity()).thenReturn(applications);
EurekaHttpClient client = mock(EurekaHttpClient.class);
- when(client.getApplications("us-east-1")).thenReturn(response);
+ when(client.getApplications("us-east-1", "us-east-2")).thenReturn(response);
+ when(client.getApplications((String) null)).thenReturn(response);
+ when(client.getVip("vip1", "us-east-1", "us-east-2")).thenReturn(response);
return client;
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests.java
index be9cad4f8d..6de938e26f 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -22,14 +22,16 @@
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.netflix.eureka.http.WebClientEurekaHttpClient;
+import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import static org.assertj.core.api.Assertions.assertThat;
@@ -52,29 +54,28 @@ class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@Test
void webClientRespectsCodecProperties() {
WebClient webClient = eurekaHttpClient.getWebClient();
- ClientResponse response = webClient.get().uri("http://localhost:" + port).exchange().block();
+ ResponseEntity response = webClient.get().uri("http://localhost:" + port).retrieve()
+ .toEntity(String.class).block();
+
assertThat(response).isNotNull();
- assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
- assertThat(response.bodyToMono(String.class).block()).startsWith("....").hasSize(300000);
+ assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
+ assertThat(response.getBody()).startsWith("....").hasSize(300000);
}
@SpringBootConfiguration
@EnableAutoConfiguration
@RestController
- static class WebClientController extends WebSecurityConfigurerAdapter {
+ static class WebClientController {
- @GetMapping
+ @GetMapping("/")
public String hello() {
- StringBuilder s = new StringBuilder();
- for (int i = 0; i < 300000; i++) {
- s.append(".");
- }
- return s.toString();
+ return ".".repeat(300000);
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
+ @Bean
+ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
+ return http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
+ .csrf(AbstractHttpConfigurer::disable).build();
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperIT.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperIntegrationTests.java
similarity index 98%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperIT.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperIntegrationTests.java
index 10d4940301..ad08ab30c6 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperIT.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2023 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -59,7 +59,7 @@
* @author Ryan Baxter
*/
@Testcontainers
-public class EurekaConfigServerBootstrapperIT {
+public class EurekaConfigServerBootstrapperIntegrationTests {
public static final DockerImageName MOCKSERVER_IMAGE = DockerImageName.parse("mockserver/mockserver")
.withTag("mockserver-" + MockServerClient.class.getPackage().getImplementationVersion());
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationNoWebfluxTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationNoWebFluxTests.java
similarity index 89%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationNoWebfluxTest.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationNoWebFluxTests.java
index d849965d78..705d13511a 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationNoWebfluxTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationNoWebFluxTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -37,10 +37,9 @@
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "jersey-client-*", "jersey-core-*", "jersey-apache-client4-*", "spring-webflux-*" })
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
-public class EurekaHttpClientsOptionalArgsConfigurationNoWebfluxTest {
+public class EurekaHttpClientsOptionalArgsConfigurationNoWebFluxTests {
@Test
- @SuppressWarnings("unchecked")
public void contextFailsWithoutWebClient() {
ConfigurableApplicationContext ctx = null;
@@ -52,7 +51,7 @@ public void contextFailsWithoutWebClient() {
}
catch (Exception e) {
// this is the desired state
- assertThat(e).hasMessageContaining("WebClient is not on the classpath");
+ assertThat(e).hasStackTraceContaining("WebClient is not on the classpath");
}
if (ctx != null) {
ctx.close();
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTests.java
similarity index 95%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTest.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTests.java
index fd4cac8949..fd710ef1d0 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaHttpClientsOptionalArgsConfigurationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -36,7 +36,7 @@
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions({ "jersey-client-*", "jersey-core-*", "jersey-apache-client4-*" })
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
-public class EurekaHttpClientsOptionalArgsConfigurationTest {
+public class EurekaHttpClientsOptionalArgsConfigurationTests {
@Test
public void contextLoadsWithRestTemplate() {
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyClientOptionalArgsConfigurationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyClientOptionalArgsConfigurationTests.java
new file mode 100644
index 0000000000..1b0b506d8b
--- /dev/null
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyClientOptionalArgsConfigurationTests.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2017-2024 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.netflix.eureka.config;
+
+import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
+import org.junit.jupiter.api.Test;
+
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for Jersey client setup in DiscoveryClientOptionalArgsConfiguration.
+ *
+ * @author Olga Maciaszek-Sharma
+ */
+public class JerseyClientOptionalArgsConfigurationTests {
+
+ @SuppressWarnings("OptionalGetWithoutIsPresent")
+ @Test
+ void shouldCreateRestTemplateDiscoveryClientOptionalArgsWhenJerseyClientDisabled() {
+ new ApplicationContextRunner()
+ .withConfiguration(AutoConfigurations.of(DiscoveryClientOptionalArgsConfiguration.class))
+ .withPropertyValues("eureka.client.jersey.enabled=false").run(context -> {
+ assertThat(context).hasSingleBean(AbstractDiscoveryClientOptionalArgs.class);
+ assertThat(context.getBeansOfType(AbstractDiscoveryClientOptionalArgs.class).values().stream()
+ .findFirst().get()).isInstanceOf(RestTemplateDiscoveryClientOptionalArgs.class);
+ assertThat(context).hasSingleBean(RestTemplateDiscoveryClientOptionalArgs.class);
+ });
+ }
+
+}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyOptionalArgsConfigurationTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyOptionalArgsConfigurationApplicationTests.java
similarity index 84%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyOptionalArgsConfigurationTest.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyOptionalArgsConfigurationApplicationTests.java
index 1d64c682a2..ed2405583b 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyOptionalArgsConfigurationTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/JerseyOptionalArgsConfigurationApplicationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -16,7 +16,7 @@
package org.springframework.cloud.netflix.eureka.config;
-import com.netflix.discovery.DiscoveryClient.DiscoveryClientOptionalArgs;
+import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,10 +32,10 @@
*/
@DirtiesContext
@SpringBootTest(classes = EurekaSampleApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
-class JerseyOptionalArgsConfigurationTest {
+class JerseyOptionalArgsConfigurationApplicationTests {
@Autowired
- private DiscoveryClientOptionalArgs optionalArgs;
+ private AbstractDiscoveryClientOptionalArgs optionalArgs;
@Test
void contextLoads() {
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/AbstractEurekaHttpClientTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/AbstractEurekaHttpClientTests.java
similarity index 64%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/AbstractEurekaHttpClientTest.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/AbstractEurekaHttpClientTests.java
index a48a6b218f..27463880d7 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/AbstractEurekaHttpClientTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/AbstractEurekaHttpClientTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2022 the original author or authors.
+ * Copyright 2012-2024 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.
@@ -19,7 +19,10 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.Applications;
import com.netflix.discovery.shared.transport.EurekaHttpClient;
+import com.netflix.discovery.shared.transport.EurekaHttpResponse;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.http.HttpStatus;
@@ -27,8 +30,9 @@
/**
* @author Haytham Mohamed
+ * @author Václav Plic
**/
-abstract class AbstractEurekaHttpClientTest {
+abstract class AbstractEurekaHttpClientTests {
protected EurekaHttpClient eurekaHttpClient;
@@ -46,10 +50,12 @@ void testCancel() {
assertThat(eurekaHttpClient.cancel("test", "test").getStatusCode()).isEqualTo(HttpStatus.OK.value());
}
- @Test
- void testSendHeartBeat() {
- assertThat(eurekaHttpClient.sendHeartBeat("test", "test", info, null).getStatusCode())
- .isEqualTo(HttpStatus.OK.value());
+ @ParameterizedTest
+ @ValueSource(strings = { "test", "test#1.[3.?]!" })
+ void testSendHeartBeat(String instanceId) {
+ EurekaHttpResponse response = eurekaHttpClient.sendHeartBeat("test", instanceId, info, null);
+ assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK.value());
+ assertThat(response.getEntity()).isNotNull();
}
@Test
@@ -59,9 +65,17 @@ void testSendHeartBeatFourOFour() {
}
@Test
- void testStatusUpdate() {
- assertThat(eurekaHttpClient.statusUpdate("test", "test", InstanceInfo.InstanceStatus.UP, info).getStatusCode())
- .isEqualTo(HttpStatus.OK.value());
+ void testSendHeartBeatFourOFourWithBody() {
+ assertThat(eurekaHttpClient.sendHeartBeat("fourOFourWithBody", "test", info, null).getStatusCode())
+ .isEqualTo(HttpStatus.NOT_FOUND.value());
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = { "test", "test#1.[3.?]!" })
+ void testStatusUpdate(String instanceId) {
+ assertThat(
+ eurekaHttpClient.statusUpdate("test", instanceId, InstanceInfo.InstanceStatus.UP, info).getStatusCode())
+ .isEqualTo(HttpStatus.OK.value());
}
@Test
@@ -100,10 +114,11 @@ void testGetApplication() {
eurekaHttpClient.getApplication("test");
}
- @Test
- void testGetInstance() {
- eurekaHttpClient.getInstance("test");
- eurekaHttpClient.getInstance("test", "test");
+ @ParameterizedTest
+ @ValueSource(strings = { "test", "test#1.[3.?]!" })
+ void testGetInstance(String instanceId) {
+ eurekaHttpClient.getInstance(instanceId);
+ eurekaHttpClient.getInstance("test", instanceId);
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/EurekaServerMockApplication.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/EurekaServerMockApplication.java
index 0d14e441d8..5534f62788 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/EurekaServerMockApplication.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/EurekaServerMockApplication.java
@@ -35,16 +35,17 @@
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
-import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
@@ -60,6 +61,7 @@
*/
@Configuration(proxyBeanMethods = false)
@RestController
+@RequestMapping("/eureka")
@SpringBootApplication
public class EurekaServerMockApplication {
@@ -116,6 +118,11 @@ public ResponseEntity sendHeartBeat(@PathVariable String appName, @PathVariable
if ("fourOFour".equals(appName)) {
return new ResponseEntity(HttpStatus.NOT_FOUND);
}
+ if ("fourOFourWithBody".equals(appName)) {
+ return new ResponseEntity(
+ "{ \"error\": \"Not Found\", \"message\": null, \"path\": \"/1\", \"requestId\": \"9e5d3244-1\", \"status\": 404, \"timestamp\": \"2023-03-04T03:31:20.810+00:00\" }",
+ HttpStatus.NOT_FOUND);
+ }
return new ResponseEntity<>(new InstanceInfo(null, null, null, null, null, null, null, null, null, null, null,
null, null, 0, null, null, null, null, null, null, null, new HashMap<>(), 0L, 0L, null, null),
HttpStatus.OK);
@@ -135,7 +142,7 @@ public void deleteStatusOverride(@PathVariable String appName, @PathVariable Str
}
- @GetMapping({ "/apps", "/apps/delta", "/vips/{address}", "/svips/{address}" })
+ @GetMapping({ "/apps/", "/apps/delta", "/vips/{address}", "/svips/{address}" })
public Applications getApplications(@PathVariable(required = false) String address,
@RequestParam(required = false) String regions) {
Applications applications = new Applications();
@@ -155,23 +162,23 @@ public InstanceInfo getInstance(@PathVariable(required = false) String appName,
@Configuration(proxyBeanMethods = false)
@Order(Ordered.HIGHEST_PRECEDENCE)
- protected static class TestSecurityConfiguration extends WebSecurityConfigurerAdapter {
-
- TestSecurityConfiguration() {
- super(true);
- }
+ protected static class TestSecurityConfiguration {
@Bean
- public UserDetailsService userDetailsService() {
- InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
- manager.createUser(User.withUsername("test").password("{noop}test").roles("USER").build());
- return manager;
+ public InMemoryUserDetailsManager userDetailsService() {
+ UserDetails user = User.withDefaultPasswordEncoder().username("test").password("test").roles("USER")
+ .build();
+ return new InMemoryUserDetailsManager(user);
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- // super.configure(http);
- http.antMatcher("/apps/**").httpBasic();
+ @Bean
+ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
+ // @formatter:off
+ http
+ .securityMatcher("/v2/apps/**")
+ .httpBasic();
+ // @formatter:on
+ return http.build();
}
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTests.java
similarity index 63%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTest.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTests.java
index 704c42f94f..8c6f32b820 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTests.java
@@ -16,9 +16,12 @@
package org.springframework.cloud.netflix.eureka.http;
+import java.util.List;
+
import com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider;
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -26,20 +29,27 @@
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
+import org.springframework.http.client.ClientHttpRequestInterceptor;
+import org.springframework.http.client.support.BasicAuthenticationInterceptor;
import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.web.client.RestTemplate;
+
+import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Daniel Lavoie
*/
@SpringBootTest(classes = EurekaServerMockApplication.class,
- properties = { "debug=true", "security.basic.enabled=true" }, webEnvironment = WebEnvironment.RANDOM_PORT)
+ properties = { "debug=true", "security.basic.enabled=true", "eureka.client.fetch-registry=false",
+ "eureka.client.register-with-eureka=false", "logging.level.org.springframework=INFO" },
+ webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
-class RestTemplateEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
+class RestTemplateEurekaHttpClientTests extends AbstractEurekaHttpClientTests {
@Autowired
private InetUtils inetUtils;
- @Value("http://${security.user.name}:${security.user.password}@localhost:${local.server.port}")
+ @Value("http://${security.user.name}:${security.user.password}@localhost:${local.server.port}/eureka")
private String serviceUrl;
@BeforeEach
@@ -61,4 +71,15 @@ void setup() {
info = new EurekaConfigBasedInstanceInfoProvider(config).get();
}
+ @Test
+ void basicAuth() {
+ assertThat(eurekaHttpClient).isInstanceOf(RestTemplateEurekaHttpClient.class);
+ RestTemplateEurekaHttpClient restTemplateEurekaHttpClient = (RestTemplateEurekaHttpClient) eurekaHttpClient;
+ RestTemplate restTemplate = restTemplateEurekaHttpClient.getRestTemplate();
+ List interceptors = restTemplate.getInterceptors();
+ boolean hasBasicAuth = interceptors.stream()
+ .anyMatch(interceptor -> interceptor instanceof BasicAuthenticationInterceptor);
+ assertThat(hasBasicAuth).as("Basic Auth not configured").isTrue();
+ }
+
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTests.java
similarity index 93%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTest.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTests.java
index 33d1b7af00..9241e76570 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -24,7 +24,7 @@
/**
* @author Daniel Lavoie
*/
-class RestTemplateTransportClientFactoryTest {
+class RestTemplateTransportClientFactoryTests {
private RestTemplateTransportClientFactory transportClientFatory;
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClientTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClientTests.java
similarity index 90%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClientTest.java
rename to spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClientTests.java
index c2a83040ae..3dd7030cfe 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClientTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientEurekaHttpClientTests.java
@@ -33,15 +33,16 @@
* @author Daniel Lavoie
*/
@SpringBootTest(classes = EurekaServerMockApplication.class,
- properties = { "debug=true", "security.basic.enabled=true", "eureka.client.webclient.enabled=true" },
+ properties = { "debug=true", "security.basic.enabled=true", "eureka.client.webclient.enabled=true",
+ "eureka.client.fetch-registry=false", "eureka.client.register-with-eureka=false" },
webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
-class WebClientEurekaHttpClientTest extends AbstractEurekaHttpClientTest {
+class WebClientEurekaHttpClientTests extends AbstractEurekaHttpClientTests {
@Autowired
private InetUtils inetUtils;
- @Value("http://${security.user.name}:${security.user.password}@localhost:${local.server.port}")
+ @Value("http://${security.user.name}:${security.user.password}@localhost:${local.server.port}/eureka/")
private String serviceUrl;
@BeforeEach
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactoriesTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactoriesTest.java
deleted file mode 100644
index 3e27383c6a..0000000000
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactoriesTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2017-2022 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.netflix.eureka.http;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import org.springframework.web.reactive.function.client.WebClient;
-
-/**
- * @author Daniel Lavoie
- */
-class WebClientTransportClientFactoriesTest {
-
- @Test
- void testJerseyIsUnsupported() {
- Assertions.assertThrows(UnsupportedOperationException.class, () -> {
- new WebClientTransportClientFactories(WebClient::builder).newTransportClientFactory(null, null);
- });
-
- }
-
-}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactoryTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactoryTest.java
index b7d2d17baf..469d83911d 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactoryTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/WebClientTransportClientFactoryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2017-2024 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.
@@ -16,23 +16,57 @@
package org.springframework.cloud.netflix.eureka.http;
+import java.time.Duration;
+
import com.netflix.discovery.shared.resolver.DefaultEndpoint;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+import reactor.core.publisher.Mono;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.reactive.function.client.ClientRequest;
+import org.springframework.web.reactive.function.client.ClientResponse;
+import org.springframework.web.reactive.function.client.ExchangeFunction;
import org.springframework.web.reactive.function.client.WebClient;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
/**
* @author Daniel Lavoie
+ * @author Armin Krezovic
*/
+@MockitoSettings(strictness = Strictness.LENIENT)
class WebClientTransportClientFactoryTest {
+ @Mock
+ private ExchangeFunction exchangeFunction;
+
+ @Captor
+ private ArgumentCaptor captor;
+
private WebClientTransportClientFactory transportClientFatory;
@BeforeEach
void setup() {
- transportClientFatory = new WebClientTransportClientFactory(WebClient::builder);
+ ClientResponse mockResponse = mock();
+ when(mockResponse.statusCode()).thenReturn(HttpStatus.OK);
+ when(mockResponse.bodyToMono(Void.class)).thenReturn(Mono.empty());
+ given(exchangeFunction.exchange(captor.capture())).willReturn(Mono.just(mockResponse));
+
+ transportClientFatory = new WebClientTransportClientFactory(
+ () -> WebClient.builder().exchangeFunction(exchangeFunction));
}
@Test
@@ -45,6 +79,23 @@ void testInvalidUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://test@localhost:8761"));
}
+ @Test
+ void testUserInfoWithEncodedCharacters() {
+ String encodedBasicAuth = HttpHeaders.encodeBasicAuth("test", "MyPassword@", null);
+ String expectedAuthHeader = "Basic " + encodedBasicAuth;
+ String expectedUrl = "http://localhost:8761";
+
+ WebClientEurekaHttpClient client = (WebClientEurekaHttpClient) transportClientFatory
+ .newClient(new DefaultEndpoint("http://test:MyPassword%40@localhost:8761"));
+
+ client.getWebClient().get().retrieve().bodyToMono(Void.class).block(Duration.ofSeconds(10));
+
+ ClientRequest request = verifyAndGetRequest();
+
+ assertThat(request.headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo(expectedAuthHeader);
+ assertThat(request.url().toString()).isEqualTo(expectedUrl);
+ }
+
@Test
void testUserInfo() {
transportClientFatory.newClient(new DefaultEndpoint("http://test:test@localhost:8761"));
@@ -55,4 +106,11 @@ void shutdown() {
transportClientFatory.shutdown();
}
+ private ClientRequest verifyAndGetRequest() {
+ ClientRequest request = captor.getValue();
+ verify(exchangeFunction).exchange(request);
+ verifyNoMoreInteractions(exchangeFunction);
+ return request;
+ }
+
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfigurationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfigurationTests.java
index 8598e90e97..1b6bf181ab 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfigurationTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/loadbalancer/EurekaLoadBalancerClientConfigurationTests.java
@@ -35,16 +35,16 @@
*/
class EurekaLoadBalancerClientConfigurationTests {
- private EurekaClientConfigBean eurekaClientConfig = new EurekaClientConfigBean();
+ private final EurekaClientConfigBean eurekaClientConfig = new EurekaClientConfigBean();
- private EurekaInstanceConfigBean eurekaInstanceConfig = new EurekaInstanceConfigBean(
+ private final EurekaInstanceConfigBean eurekaInstanceConfig = new EurekaInstanceConfigBean(
new InetUtils(new InetUtilsProperties()));
- private LoadBalancerZoneConfig zoneConfig = new LoadBalancerZoneConfig(null);
+ private final LoadBalancerZoneConfig zoneConfig = new LoadBalancerZoneConfig(null);
- private EurekaLoadBalancerProperties eurekaLoadBalancerProperties = new EurekaLoadBalancerProperties();
+ private final EurekaLoadBalancerProperties eurekaLoadBalancerProperties = new EurekaLoadBalancerProperties();
- private EurekaLoadBalancerClientConfiguration postprocessor = new EurekaLoadBalancerClientConfiguration(
+ private final EurekaLoadBalancerClientConfiguration postprocessor = new EurekaLoadBalancerClientConfiguration(
eurekaClientConfig, eurekaInstanceConfig, zoneConfig, eurekaLoadBalancerProperties);
@Test
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProviderTest.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProviderTest.java
index 4fea87786d..c002b695f6 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProviderTest.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/metadata/DefaultManagementMetadataProviderTest.java
@@ -33,7 +33,7 @@ class DefaultManagementMetadataProviderTest {
private final ManagementMetadataProvider provider = new DefaultManagementMetadataProvider();
@BeforeEach
- void setUp() throws Exception {
+ void setUp() {
when(INSTANCE.getHostname()).thenReturn("host");
when(INSTANCE.getHealthCheckUrlPath()).thenReturn("health");
when(INSTANCE.getStatusPageUrlPath()).thenReturn("info");
@@ -41,7 +41,7 @@ void setUp() throws Exception {
}
@Test
- void serverPortIsRandomAndManagementPortIsNull() throws Exception {
+ void serverPortIsRandomAndManagementPortIsNull() {
int serverPort = 0;
String serverContextPath = "/";
String managementContextPath = null;
@@ -53,7 +53,7 @@ void serverPortIsRandomAndManagementPortIsNull() throws Exception {
}
@Test
- void managementPortIsRandom() throws Exception {
+ void managementPortIsRandom() {
int serverPort = 0;
String serverContextPath = "/";
String managementContextPath = null;
@@ -65,7 +65,7 @@ void managementPortIsRandom() throws Exception {
}
@Test
- void serverPort() throws Exception {
+ void serverPort() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = null;
@@ -80,7 +80,7 @@ void serverPort() throws Exception {
}
@Test
- void serverPortManagementPort() throws Exception {
+ void serverPortManagementPort() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = null;
@@ -95,7 +95,7 @@ void serverPortManagementPort() throws Exception {
}
@Test
- void serverPortManagementPortServerContextPath() throws Exception {
+ void serverPortManagementPortServerContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = null;
@@ -110,7 +110,7 @@ void serverPortManagementPortServerContextPath() throws Exception {
}
@Test
- void serverPortManagementPortServerContextPathManagementContextPath() throws Exception {
+ void serverPortManagementPortServerContextPathManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = "/Management";
@@ -125,7 +125,7 @@ void serverPortManagementPortServerContextPathManagementContextPath() throws Exc
}
@Test
- void serverPortServerContextPathManagementContextPath() throws Exception {
+ void serverPortServerContextPathManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = "/Management";
@@ -140,7 +140,7 @@ void serverPortServerContextPathManagementContextPath() throws Exception {
}
@Test
- void serverPortManagementContextPath() throws Exception {
+ void serverPortManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -155,7 +155,7 @@ void serverPortManagementContextPath() throws Exception {
}
@Test
- void serverPortServerContextPath() throws Exception {
+ void serverPortServerContextPath() {
int serverPort = 7777;
String serverContextPath = "/Server";
String managementContextPath = null;
@@ -170,7 +170,7 @@ void serverPortServerContextPath() throws Exception {
}
@Test
- void serverPortManagementPortManagementContextPath() throws Exception {
+ void serverPortManagementPortManagementContextPath() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
@@ -186,7 +186,7 @@ void serverPortManagementPortManagementContextPath() throws Exception {
}
@Test
- void setSecureHealthCheckUrl() throws Exception {
+ void setSecureHealthCheckUrl() {
int serverPort = 7777;
String serverContextPath = "/";
String managementContextPath = "/Management";
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientConfigurationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientConfigurationTests.java
index 22603b4d21..2a80deab8b 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientConfigurationTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientConfigurationTests.java
@@ -35,7 +35,7 @@
*/
class EurekaReactiveDiscoveryClientConfigurationTests {
- private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(UtilAutoConfiguration.class,
ReactiveCommonsClientAutoConfiguration.class, EurekaClientAutoConfiguration.class,
DiscoveryClientOptionalArgsConfiguration.class, EurekaReactiveDiscoveryClientConfiguration.class));
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientTests.java
index adb527c3af..3fe553b87e 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/reactive/EurekaReactiveDiscoveryClientTests.java
@@ -18,7 +18,6 @@
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
-import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.shared.Application;
import com.netflix.discovery.shared.Applications;
import org.junit.jupiter.api.Test;
@@ -47,9 +46,6 @@ class EurekaReactiveDiscoveryClientTests {
@Mock
private EurekaClient eurekaClient;
- @Mock
- private EurekaClientConfig clientConfig;
-
@InjectMocks
private EurekaReactiveDiscoveryClient client;
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/sample/EurekaSampleApplication.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/sample/EurekaSampleApplication.java
index d2736b84c5..8341b4c72f 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/sample/EurekaSampleApplication.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/sample/EurekaSampleApplication.java
@@ -17,7 +17,6 @@
package org.springframework.cloud.netflix.eureka.sample;
import java.io.Closeable;
-import java.io.IOException;
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
@@ -103,7 +102,7 @@ public String deregister() {
}
@Override
- public void close() throws IOException {
+ public void close() {
deregister();
}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistrationIntegrationTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistrationIntegrationTests.java
new file mode 100644
index 0000000000..a8d96ce71a
--- /dev/null
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaAutoServiceRegistrationIntegrationTests.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2013-2023 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.netflix.eureka.serviceregistry;
+
+import org.junit.jupiter.api.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.cloud.client.discovery.event.InstancePreRegisteredEvent;
+import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent;
+import org.springframework.cloud.client.serviceregistry.Registration;
+import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration tests for {@link EurekaAutoServiceRegistration}.
+ *
+ * @author Olga Maciaszek-Sharma
+ */
+@SpringBootTest(classes = EurekaAutoServiceRegistrationIntegrationTests.Config.class,
+ webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+class EurekaAutoServiceRegistrationIntegrationTests {
+
+ @LocalServerPort
+ private int serverPort;
+
+ @Autowired
+ private PreEventListener preEventListener;
+
+ @Autowired
+ private PostEventListener postEventListener;
+
+ @Test
+ void shouldPublishRegistrationEvents() {
+ assertThat(preEventListener.wasFired).isTrue();
+ assertThat(preEventListener.registration).isInstanceOf(EurekaRegistration.class);
+ assertThat(preEventListener.registration.getPort()).isEqualTo(serverPort);
+ assertThat(postEventListener.wasFired).isTrue();
+ assertThat(postEventListener.config.getNonSecurePort()).isEqualTo(serverPort);
+ }
+
+ @EnableAutoConfiguration
+ @Configuration(proxyBeanMethods = false)
+ public static class Config {
+
+ @Bean
+ public PreEventListener preRegisterListener() {
+ return new PreEventListener();
+ }
+
+ @Bean
+ public PostEventListener postEventListener() {
+ return new PostEventListener();
+ }
+
+ }
+
+ public static class PreEventListener implements ApplicationListener {
+
+ public boolean wasFired = false;
+
+ public Registration registration;
+
+ @Override
+ public void onApplicationEvent(InstancePreRegisteredEvent event) {
+ this.registration = event.getRegistration();
+ this.wasFired = true;
+ }
+
+ }
+
+ public static class PostEventListener implements ApplicationListener {
+
+ public boolean wasFired = false;
+
+ public EurekaInstanceConfigBean config;
+
+ @Override
+ public void onApplicationEvent(InstanceRegisteredEvent event) {
+ this.config = (EurekaInstanceConfigBean) event.getConfig();
+ this.wasFired = true;
+ }
+
+ }
+
+}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistryTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistryTests.java
index e5ee4462c9..2d64cd5209 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistryTests.java
+++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/serviceregistry/EurekaServiceRegistryTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -16,14 +16,20 @@
package org.springframework.cloud.netflix.eureka.serviceregistry;
+import java.time.Duration;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.InstanceInfo;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtilsProperties;
+import org.springframework.cloud.loadbalancer.support.SimpleObjectProvider;
import org.springframework.cloud.netflix.eureka.CloudEurekaClient;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
@@ -33,16 +39,24 @@
import static com.netflix.appinfo.InstanceInfo.InstanceStatus.OUT_OF_SERVICE;
import static com.netflix.appinfo.InstanceInfo.InstanceStatus.UNKNOWN;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
/**
* @author Spencer Gibb
* @author Tim Ysewyn
+ * @author Robert Bleyl
*/
+@ExtendWith(MockitoExtension.class)
class EurekaServiceRegistryTests {
+ @Mock
+ private EurekaInstanceConfigBean eurekaInstanceConfigBean;
+
@Test
void eurekaClientNotShutdownInDeregister() {
EurekaServiceRegistry registry = new EurekaServiceRegistry();
@@ -62,6 +76,7 @@ void eurekaClientNotShutdownInDeregister() {
verifyNoInteractions(eurekaClient);
}
+ @SuppressWarnings("unchecked")
@Test
void eurekaClientGetStatus() {
EurekaServiceRegistry registry = new EurekaServiceRegistry();
@@ -98,6 +113,7 @@ void eurekaClientGetStatus() {
OUT_OF_SERVICE.toString());
}
+ @SuppressWarnings("unchecked")
@Test
void eurekaClientGetStatusNoInstance() {
EurekaServiceRegistry registry = new EurekaServiceRegistry();
@@ -108,8 +124,6 @@ void eurekaClientGetStatusNoInstance() {
CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
- when(eurekaClient.getInstanceInfo("myapp", "1234")).thenReturn(null);
-
ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
@@ -128,4 +142,54 @@ void eurekaClientGetStatusNoInstance() {
assertThat(map).hasSize(1).containsEntry("status", UNKNOWN.toString());
}
+ @Test
+ void eurekaClientInitializesClientAsynchronously() {
+ when(eurekaInstanceConfigBean.isAsyncClientInitialization()).thenReturn(true);
+ EurekaServiceRegistry registry = new EurekaServiceRegistry(eurekaInstanceConfigBean);
+
+ final AtomicBoolean applicationsFetched = new AtomicBoolean();
+
+ CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
+ when(eurekaClient.getApplications()).thenAnswer((answer) -> {
+ applicationsFetched.set(true);
+ return answer;
+ });
+
+ ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
+
+ when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
+
+ EurekaRegistration registration = EurekaRegistration
+ .builder(new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()))).with(eurekaClient)
+ .with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
+ .with(new SimpleObjectProvider<>(null)).build();
+
+ registry.register(registration);
+
+ await().atMost(Duration.ofSeconds(5)).pollInterval(Duration.ofMillis(500)).until(applicationsFetched::get);
+
+ verify(eurekaClient).getApplications();
+ assertThat(applicationsFetched).isTrue();
+ }
+
+ @Test
+ void eurekaClientInitializesClientSynchronously() {
+ EurekaServiceRegistry registry = new EurekaServiceRegistry(eurekaInstanceConfigBean);
+
+ CloudEurekaClient eurekaClient = mock(CloudEurekaClient.class);
+ ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
+
+ when(applicationInfoManager.getInfo()).thenReturn(mock(InstanceInfo.class));
+
+ EurekaRegistration registration = EurekaRegistration
+ .builder(new EurekaInstanceConfigBean(new InetUtils(new InetUtilsProperties()))).with(eurekaClient)
+ .with(applicationInfoManager).with(new EurekaClientConfigBean(), mock(ApplicationEventPublisher.class))
+ .with(new SimpleObjectProvider<>(null)).build();
+
+ registry.register(registration);
+
+ verify(eurekaClient).getApplications();
+ verify(eurekaClient, never()).getEurekaClientConfig();
+ }
+
}
diff --git a/spring-cloud-netflix-eureka-server/pom.xml b/spring-cloud-netflix-eureka-server/pom.xml
index 5367b4bc1a..cc41eab9d2 100644
--- a/spring-cloud-netflix-eureka-server/pom.xml
+++ b/spring-cloud-netflix-eureka-server/pom.xml
@@ -5,15 +5,17 @@
org.springframework.cloudspring-cloud-netflix
- 3.1.8-SNAPSHOT
+ 4.1.4-SNAPSHOT..spring-cloud-netflix-eureka-serverSpring Cloud Netflix Eureka Serverhttps://projects.spring.io/spring-cloud/
- 1.8.0
+ 1.10.12.27.2
+
+ true
@@ -48,39 +50,33 @@
com.netflix.eureka
- eureka-client
-
-
- aopalliance
- aopalliance
-
-
+ eureka-client-jersey3
- com.sun.jersey
- jersey-servlet
+ com.netflix.eureka
+ eureka-core-jersey3
+
+
+ org.glassfish.jersey.containers
+ jersey-container-servlet
- com.sun.jersey
+ org.glassfish.jersey.corejersey-server
- com.sun.jersey
+ org.glassfish.jersey.corejersey-client
- com.netflix.eureka
- eureka-core
-
-
- blitz4j
- com.netflix.blitz4j
-
-
+ org.glassfish.jersey.inject
+ jersey-hk2
- javax.inject
- javax.inject
+ org.glassfish.hk2
+ spring-bridge
+
+ 3.1.1
@@ -176,6 +172,12 @@
${basedir}/src/main/wro
+
+
+ org.webjars.npm
+ glob
+ 7.2.0
+ org.webjars.npmjquery
@@ -186,11 +188,6 @@
bootstrap5.1.3
-
- org.mockito
- mockito-core
- 3.6.28
-
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/CloudJacksonJson.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/CloudJacksonJson.java
index d7aae59ff4..e4d87a3aae 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/CloudJacksonJson.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/CloudJacksonJson.java
@@ -65,7 +65,7 @@ public String codecName() {
}
@Override
- public String encode(T object) throws IOException {
+ public String encode(T object) {
return this.codec.writeToString(object);
}
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java
index 2f744bf335..119b05533d 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaController.java
@@ -24,8 +24,6 @@
import java.util.List;
import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-
import com.netflix.appinfo.AmazonInfo;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.DataCenterInfo;
@@ -39,6 +37,7 @@
import com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl;
import com.netflix.eureka.resources.StatusResource;
import com.netflix.eureka.util.StatusInfo;
+import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
@@ -57,19 +56,10 @@ public class EurekaController {
@Value("${eureka.dashboard.path:/}")
private String dashboardPath = "";
- private ApplicationInfoManager applicationInfoManager;
+ private final ApplicationInfoManager applicationInfoManager;
private final EurekaProperties eurekaProperties;
- /**
- * @deprecated in favour of
- * {@link EurekaController#EurekaController(ApplicationInfoManager, EurekaProperties)}
- */
- @Deprecated
- public EurekaController(ApplicationInfoManager applicationInfoManager) {
- this(applicationInfoManager, null);
- }
-
public EurekaController(ApplicationInfoManager applicationInfoManager, EurekaProperties eurekaProperties) {
this.applicationInfoManager = applicationInfoManager;
this.eurekaProperties = eurekaProperties;
@@ -129,14 +119,8 @@ protected void populateBase(HttpServletRequest request, Map mode
private void populateHeader(Map model) {
model.put("currentTime", StatusResource.getCurrentTimeAsString());
model.put("upTime", StatusInfo.getUpTime());
- if (eurekaProperties != null) {
- model.put("environment", eurekaProperties.getEnvironment());
- model.put("datacenter", eurekaProperties.getDatacenter());
- }
- else {
- model.put("environment", "N/A");
- model.put("datacenter", "N/A");
- }
+ model.put("environment", eurekaProperties.getEnvironment());
+ model.put("datacenter", eurekaProperties.getDatacenter());
PeerAwareInstanceRegistry registry = getRegistry();
model.put("registry", registry);
model.put("isBelowRenewThreshold", registry.isBelowRenewThresold() == 1);
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java
index 3ce51d75f0..748f85a258 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -16,46 +16,84 @@
package org.springframework.cloud.netflix.eureka.server;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
+import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
-
-import javax.servlet.Filter;
-import javax.ws.rs.Path;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.ext.Provider;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.regex.Pattern;
import com.netflix.appinfo.ApplicationInfoManager;
+import com.netflix.discovery.AbstractDiscoveryClientOptionalArgs;
import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig;
+import com.netflix.discovery.Jersey3DiscoveryClientOptionalArgs;
import com.netflix.discovery.converters.EurekaJacksonCodec;
import com.netflix.discovery.converters.wrappers.CodecWrapper;
import com.netflix.discovery.converters.wrappers.CodecWrappers;
+import com.netflix.discovery.shared.transport.jersey.TransportClientFactories;
+import com.netflix.discovery.shared.transport.jersey3.EurekaIdentityHeaderFilter;
+import com.netflix.discovery.shared.transport.jersey3.EurekaJersey3Client;
+import com.netflix.discovery.shared.transport.jersey3.EurekaJersey3ClientImpl;
+import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories;
import com.netflix.eureka.DefaultEurekaServerContext;
import com.netflix.eureka.EurekaServerConfig;
import com.netflix.eureka.EurekaServerContext;
+import com.netflix.eureka.EurekaServerIdentity;
import com.netflix.eureka.cluster.PeerEurekaNode;
import com.netflix.eureka.cluster.PeerEurekaNodes;
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
import com.netflix.eureka.resources.DefaultServerCodecs;
import com.netflix.eureka.resources.ServerCodecs;
-import com.netflix.eureka.transport.JerseyReplicationClient;
-import com.sun.jersey.api.core.DefaultResourceConfig;
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-
+import com.netflix.eureka.transport.EurekaServerHttpClientFactory;
+import com.netflix.eureka.transport.Jersey3DynamicGZIPContentEncodingFilter;
+import com.netflix.eureka.transport.Jersey3EurekaServerHttpClientFactory;
+import com.netflix.eureka.transport.Jersey3ReplicationClient;
+import jakarta.servlet.Filter;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequestWrapper;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientRequestFilter;
+import jakarta.ws.rs.core.Application;
+import jakarta.ws.rs.ext.Provider;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.server.spi.Container;
+import org.glassfish.jersey.server.spi.ContainerLifecycleListener;
+import org.glassfish.jersey.servlet.ServletContainer;
+import org.glassfish.jersey.servlet.ServletProperties;
+import org.jvnet.hk2.spring.bridge.api.SpringBridge;
+import org.jvnet.hk2.spring.bridge.api.SpringIntoHK2Bridge;
+
+import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.actuator.HasFeatures;
+import org.springframework.cloud.configuration.SSLContextFactory;
+import org.springframework.cloud.configuration.TlsProperties;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.netflix.eureka.EurekaConstants;
+import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
@@ -67,6 +105,8 @@
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.util.ClassUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
@@ -74,6 +114,8 @@
* @author Biju Kunjummen
* @author Fahim Farook
* @author Weix Sun
+ * @author Robert Bleyl
+ * @author Olga Maciaszek-Sharma
*/
@Configuration(proxyBeanMethods = false)
@Import(EurekaServerInitializerConfiguration.class)
@@ -83,11 +125,18 @@
@PropertySource("classpath:/eureka/server.properties")
public class EurekaServerAutoConfiguration implements WebMvcConfigurer {
+ private static final Log log = LogFactory.getLog(EurekaServerAutoConfiguration.class);
+
/**
* List of packages containing Jersey resources required by the Eureka server.
*/
private static final String[] EUREKA_PACKAGES = new String[] { "com.netflix.discovery", "com.netflix.eureka" };
+ /**
+ * Static content pattern for dashboard elements (images, css, etc...).
+ */
+ private static final String STATIC_CONTENT_PATTERN = "/(fonts|images|css|js)/.*";
+
@Autowired
private ApplicationInfoManager applicationInfoManager;
@@ -146,9 +195,53 @@ public ReplicationClientAdditionalFilters replicationClientAdditionalFilters() {
}
@Bean
- public PeerAwareInstanceRegistry peerAwareInstanceRegistry(ServerCodecs serverCodecs) {
- this.eurekaClient.getApplications(); // force initialization
+ @ConditionalOnMissingBean(TransportClientFactories.class)
+ public Jersey3TransportClientFactories jersey3TransportClientFactories() {
+ return Jersey3TransportClientFactories.getInstance();
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Bean
+ @ConditionalOnMissingBean(EurekaServerHttpClientFactory.class)
+ public Jersey3EurekaServerHttpClientFactory jersey3EurekaServerHttpClientFactory() {
+ return new Jersey3EurekaServerHttpClientFactory();
+ }
+
+ @Bean
+ @ConditionalOnMissingBean(AbstractDiscoveryClientOptionalArgs.class)
+ public Jersey3DiscoveryClientOptionalArgs jersey3DiscoveryClientOptionalArgs(
+ @Autowired(required = false) TlsProperties tlsProperties) throws GeneralSecurityException, IOException {
+ Jersey3DiscoveryClientOptionalArgs optionalArgs = new Jersey3DiscoveryClientOptionalArgs();
+ if (tlsProperties != null && tlsProperties.isEnabled()) {
+ SSLContextFactory factory = new SSLContextFactory(tlsProperties);
+ optionalArgs.setSSLContext(factory.createSSLContext());
+ }
+ return optionalArgs;
+ }
+
+ @Bean
+ public PeerAwareInstanceRegistry peerAwareInstanceRegistry(ServerCodecs serverCodecs,
+ EurekaServerHttpClientFactory eurekaServerHttpClientFactory,
+ EurekaInstanceConfigBean eurekaInstanceConfigBean) {
+ if (eurekaInstanceConfigBean.isAsyncClientInitialization()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing client asynchronously...");
+ }
+
+ ExecutorService executorService = Executors.newSingleThreadExecutor();
+ executorService.submit(() -> {
+ this.eurekaClient.getApplications();
+ if (log.isDebugEnabled()) {
+ log.debug("Asynchronous client initialization done.");
+ }
+ });
+ }
+ else {
+ this.eurekaClient.getApplications(); // force initialization
+ }
+
return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig, serverCodecs, this.eurekaClient,
+ eurekaServerHttpClientFactory,
this.instanceRegistryProperties.getExpectedNumberOfClientsSendingRenews(),
this.instanceRegistryProperties.getDefaultOpenForTrafficCount());
}
@@ -182,24 +275,84 @@ public EurekaServerBootstrap eurekaServerBootstrap(PeerAwareInstanceRegistry reg
* @return a jersey {@link FilterRegistrationBean}
*/
@Bean
- public FilterRegistrationBean> jerseyFilterRegistration(javax.ws.rs.core.Application eurekaJerseyApp) {
- FilterRegistrationBean bean = new FilterRegistrationBean();
- bean.setFilter(new ServletContainer(eurekaJerseyApp));
+ public FilterRegistrationBean> jerseyFilterRegistration(ResourceConfig eurekaJerseyApp) {
+ FilterRegistrationBean bean = new FilterRegistrationBean<>();
+ ServletContainer servletContainer = new ServletContainer(eurekaJerseyApp);
+ bean.setFilter(servletContainer);
bean.setOrder(Ordered.LOWEST_PRECEDENCE);
bean.setUrlPatterns(Collections.singletonList(EurekaConstants.DEFAULT_PREFIX + "/*"));
return bean;
}
+ @Bean
+ public FilterRegistrationBean> eurekaVersionFilterRegistration(ServerProperties serverProperties,
+ Environment env) {
+ final String contextPath = serverProperties.getServlet().getContextPath();
+ String regex = EurekaConstants.DEFAULT_PREFIX + STATIC_CONTENT_PATTERN;
+ if (StringUtils.hasText(contextPath)) {
+ regex = contextPath + regex;
+ }
+ String debugResponseHeader = env.getProperty("eureka.server.version.filter.debug.response-header");
+ boolean addDebugResponseHeader = StringUtils.hasText(debugResponseHeader);
+ Pattern staticPattern = Pattern.compile(regex);
+ FilterRegistrationBean bean = new FilterRegistrationBean<>();
+ bean.setFilter(new OncePerRequestFilter() {
+ @Override
+ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
+ FilterChain filterChain) throws ServletException, IOException {
+ HttpServletRequest req = request;
+ String requestURI = request.getRequestURI();
+ if (!requestURI.startsWith(EurekaConstants.DEFAULT_PREFIX + "/v2")
+ // don't forward static requests (images, js, etc...) to /v2
+ && !staticPattern.matcher(requestURI).matches()) {
+
+ String prefix = EurekaConstants.DEFAULT_PREFIX;
+ if (StringUtils.hasText(contextPath)) {
+ prefix = contextPath + prefix;
+ }
+ String updatedPath = EurekaConstants.DEFAULT_PREFIX + "/v2" + requestURI.substring(prefix.length());
+ if (StringUtils.hasText(contextPath)) {
+ updatedPath = contextPath + updatedPath;
+ }
+ final String computedPath = updatedPath;
+ // only used if a special debug property is set, so in prod this is
+ // always skipped.
+ if (addDebugResponseHeader) {
+ response.addHeader(debugResponseHeader, computedPath);
+ }
+ HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {
+ @Override
+ public String getRequestURI() {
+ return computedPath;
+ }
+
+ @Override
+ public String getServletPath() {
+ return computedPath;
+ }
+ };
+ req = wrapper;
+ }
+ filterChain.doFilter(req, response);
+ }
+ });
+ bean.setOrder(0);
+ bean.setUrlPatterns(Collections.singletonList(EurekaConstants.DEFAULT_PREFIX + "/*"));
+
+ return bean;
+ }
+
/**
- * Construct a Jersey {@link javax.ws.rs.core.Application} with all the resources
+ * Construct a Jersey {@link jakarta.ws.rs.core.Application} with all the resources
* required by the Eureka server.
* @param environment an {@link Environment} instance to retrieve classpath resources
* @param resourceLoader a {@link ResourceLoader} instance to get classloader from
* @return created {@link Application} object
*/
@Bean
- public javax.ws.rs.core.Application jerseyApplication(Environment environment, ResourceLoader resourceLoader) {
+ public ResourceConfig jerseyApplication(Environment environment, ResourceLoader resourceLoader,
+ BeanFactory beanFactory) {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false,
environment);
@@ -220,15 +373,32 @@ public javax.ws.rs.core.Application jerseyApplication(Environment environment, R
}
}
+ // https://javaee.github.io/hk2/spring-bridge
+
// Construct the Jersey ResourceConfig
- Map propsAndFeatures = new HashMap<>();
- propsAndFeatures.put(
+ ResourceConfig rc = new ResourceConfig(classes).property(
// Skip static content used by the webapp
- ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX,
- EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*");
+ ServletProperties.FILTER_STATIC_CONTENT_REGEX, EurekaConstants.DEFAULT_PREFIX + STATIC_CONTENT_PATTERN);
+
+ rc.register(new ContainerLifecycleListener() {
+ @Override
+ public void onStartup(Container container) {
+ ServiceLocator serviceLocator = container.getApplicationHandler().getInjectionManager()
+ .getInstance(ServiceLocator.class);
+ SpringBridge.getSpringBridge().initializeSpringBridge(serviceLocator);
+ serviceLocator.getService(SpringIntoHK2Bridge.class).bridgeSpringBeanFactory(beanFactory);
+ }
+
+ @Override
+ public void onReload(Container container) {
+
+ }
+
+ @Override
+ public void onShutdown(Container container) {
- DefaultResourceConfig rc = new DefaultResourceConfig(classes);
- rc.setPropertiesAndFeatures(propsAndFeatures);
+ }
+ });
return rc;
}
@@ -236,7 +406,7 @@ public javax.ws.rs.core.Application jerseyApplication(Environment environment, R
@Bean
@ConditionalOnBean(name = "httpTraceFilter")
public FilterRegistrationBean> traceFilterRegistration(@Qualifier("httpTraceFilter") Filter filter) {
- FilterRegistrationBean bean = new FilterRegistrationBean();
+ FilterRegistrationBean bean = new FilterRegistrationBean<>();
bean.setFilter(filter);
bean.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
return bean;
@@ -273,7 +443,7 @@ public EurekaServerConfig eurekaServerConfig(EurekaClientConfig clientConfig) {
static class RefreshablePeerEurekaNodes extends PeerEurekaNodes
implements ApplicationListener {
- private ReplicationClientAdditionalFilters replicationClientAdditionalFilters;
+ /* for testing */ ReplicationClientAdditionalFilters replicationClientAdditionalFilters;
RefreshablePeerEurekaNodes(final PeerAwareInstanceRegistry registry, final EurekaServerConfig serverConfig,
final EurekaClientConfig clientConfig, final ServerCodecs serverCodecs,
@@ -285,10 +455,8 @@ static class RefreshablePeerEurekaNodes extends PeerEurekaNodes
@Override
protected PeerEurekaNode createPeerEurekaNode(String peerEurekaNodeUrl) {
- JerseyReplicationClient replicationClient = JerseyReplicationClient.createReplicationClient(serverConfig,
- serverCodecs, peerEurekaNodeUrl);
-
- this.replicationClientAdditionalFilters.getFilters().forEach(replicationClient::addReplicationClientFilter);
+ Jersey3ReplicationClient replicationClient = createReplicationClient(serverConfig, serverCodecs,
+ peerEurekaNodeUrl, this.replicationClientAdditionalFilters.getFilters());
String targetHost = hostFromUrl(peerEurekaNodeUrl);
if (targetHost == null) {
@@ -297,6 +465,64 @@ protected PeerEurekaNode createPeerEurekaNode(String peerEurekaNodeUrl) {
return new PeerEurekaNode(registry, targetHost, peerEurekaNodeUrl, replicationClient, serverConfig);
}
+ // FIXME: 4.0 update Jersey3ReplicationClient.createReplicationClient to handle
+ // additional filters
+ private static Jersey3ReplicationClient createReplicationClient(EurekaServerConfig config,
+ ServerCodecs serverCodecs, String serviceUrl, Collection additionalFilters) {
+ String name = Jersey3ReplicationClient.class.getSimpleName() + ": " + serviceUrl + "apps/: ";
+
+ EurekaJersey3Client jerseyClient;
+ try {
+ String hostname;
+ try {
+ hostname = new URL(serviceUrl).getHost();
+ }
+ catch (MalformedURLException e) {
+ hostname = serviceUrl;
+ }
+
+ String jerseyClientName = "Discovery-PeerNodeClient-" + hostname;
+ EurekaJersey3ClientImpl.EurekaJersey3ClientBuilder clientBuilder = new EurekaJersey3ClientImpl.EurekaJersey3ClientBuilder()
+ .withClientName(jerseyClientName).withUserAgent("Java-EurekaClient-Replication")
+ .withEncoderWrapper(serverCodecs.getFullJsonCodec())
+ .withDecoderWrapper(serverCodecs.getFullJsonCodec())
+ .withConnectionTimeout(config.getPeerNodeConnectTimeoutMs())
+ .withReadTimeout(config.getPeerNodeReadTimeoutMs())
+ .withMaxConnectionsPerHost(config.getPeerNodeTotalConnectionsPerHost())
+ .withMaxTotalConnections(config.getPeerNodeTotalConnections())
+ .withConnectionIdleTimeout(config.getPeerNodeConnectionIdleTimeoutSeconds());
+
+ if (serviceUrl.startsWith("https://") && "true"
+ .equals(System.getProperty("com.netflix.eureka.shouldSSLConnectionsUseSystemSocketFactory"))) {
+ clientBuilder.withSystemSSLConfiguration();
+ }
+ jerseyClient = clientBuilder.build();
+ }
+ catch (Throwable e) {
+ throw new RuntimeException("Cannot Create new Replica Node :" + name, e);
+ }
+
+ String ip = null;
+ try {
+ ip = InetAddress.getLocalHost().getHostAddress();
+ }
+ catch (UnknownHostException e) {
+ log.warn("Cannot find localhost ip", e);
+ }
+
+ Client jerseyApacheClient = jerseyClient.getClient();
+ jerseyApacheClient.register(new Jersey3DynamicGZIPContentEncodingFilter(config));
+
+ for (ClientRequestFilter filter : additionalFilters) {
+ jerseyApacheClient.register(filter);
+ }
+
+ EurekaServerIdentity identity = new EurekaServerIdentity(ip);
+ jerseyApacheClient.register(new EurekaIdentityHeaderFilter(identity));
+
+ return new Jersey3ReplicationClient(jerseyClient, serviceUrl);
+ }
+
@Override
public void onApplicationEvent(final EnvironmentChangeEvent event) {
if (shouldUpdate(event.getKeys())) {
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerBootstrap.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerBootstrap.java
index 131fbc898c..8535b721d9 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerBootstrap.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerBootstrap.java
@@ -16,8 +16,6 @@
package org.springframework.cloud.netflix.eureka.server;
-import javax.servlet.ServletContext;
-
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.DataCenterInfo;
import com.netflix.appinfo.InstanceInfo;
@@ -33,6 +31,7 @@
import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
import com.netflix.eureka.util.EurekaMonitors;
import com.thoughtworks.xstream.XStream;
+import jakarta.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerConfigBean.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerConfigBean.java
index 5a291ee259..0c27890232 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerConfigBean.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerConfigBean.java
@@ -1049,11 +1049,11 @@ public int hashCode() {
registrySyncRetryWaitMs, remoteRegionAppWhitelist, remoteRegionConnectTimeoutMs,
remoteRegionConnectionIdleTimeoutSeconds, remoteRegionFetchThreadPoolSize, remoteRegionReadTimeoutMs,
remoteRegionRegistryFetchInterval, remoteRegionTotalConnections, remoteRegionTotalConnectionsPerHost,
- remoteRegionTrustStore, remoteRegionTrustStorePassword, remoteRegionUrls, remoteRegionUrlsWithName,
- renewalPercentThreshold, renewalThresholdUpdateIntervalMs, responseCacheAutoExpirationInSeconds,
- responseCacheUpdateIntervalMs, retentionTimeInMSInDeltaQueue, route53BindRebindRetries,
- route53BindingRetryIntervalMs, route53DomainTTL, syncWhenTimestampDiffers, useReadOnlyResponseCache,
- waitTimeInMsWhenSyncEmpty, xmlCodecName, initialCapacityOfResponseCache,
+ remoteRegionTrustStore, remoteRegionTrustStorePassword, Arrays.hashCode(remoteRegionUrls),
+ remoteRegionUrlsWithName, renewalPercentThreshold, renewalThresholdUpdateIntervalMs,
+ responseCacheAutoExpirationInSeconds, responseCacheUpdateIntervalMs, retentionTimeInMSInDeltaQueue,
+ route53BindRebindRetries, route53BindingRetryIntervalMs, route53DomainTTL, syncWhenTimestampDiffers,
+ useReadOnlyResponseCache, waitTimeInMsWhenSyncEmpty, xmlCodecName, initialCapacityOfResponseCache,
expectedClientRenewalIntervalSeconds, useAwsAsgApi, myUrl);
}
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java
index c9f037d9af..0af1cfbab5 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerInitializerConfiguration.java
@@ -16,9 +16,8 @@
package org.springframework.cloud.netflix.eureka.server;
-import javax.servlet.ServletContext;
-
import com.netflix.eureka.EurekaServerConfig;
+import jakarta.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -53,7 +52,7 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
private boolean running;
- private int order = 1;
+ private final int order = 1;
@Override
public void setServletContext(ServletContext servletContext) {
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistry.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistry.java
index e7f0b5ecb7..64be8ccd4a 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistry.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/InstanceRegistry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -25,6 +25,7 @@
import com.netflix.eureka.lease.Lease;
import com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl;
import com.netflix.eureka.resources.ServerCodecs;
+import com.netflix.eureka.transport.EurekaServerHttpClientFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -38,6 +39,7 @@
/**
* @author Spencer Gibb
+ * @author Wonchul Heo
*/
public class InstanceRegistry extends PeerAwareInstanceRegistryImpl implements ApplicationContextAware {
@@ -45,11 +47,12 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl implements A
private ApplicationContext ctxt;
- private int defaultOpenForTrafficCount;
+ private final int defaultOpenForTrafficCount;
public InstanceRegistry(EurekaServerConfig serverConfig, EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
- EurekaClient eurekaClient, int expectedNumberOfClientsSendingRenews, int defaultOpenForTrafficCount) {
- super(serverConfig, clientConfig, serverCodecs, eurekaClient);
+ EurekaClient eurekaClient, EurekaServerHttpClientFactory eurekaServerHttpClientFactory,
+ int expectedNumberOfClientsSendingRenews, int defaultOpenForTrafficCount) {
+ super(serverConfig, clientConfig, serverCodecs, eurekaClient, eurekaServerHttpClientFactory);
this.expectedNumberOfClientsSendingRenews = expectedNumberOfClientsSendingRenews;
this.defaultOpenForTrafficCount = defaultOpenForTrafficCount;
@@ -76,52 +79,65 @@ public void openForTraffic(ApplicationInfoManager applicationInfoManager, int co
@Override
public void register(InstanceInfo info, int leaseDuration, boolean isReplication) {
- handleRegistration(info, leaseDuration, isReplication);
super.register(info, leaseDuration, isReplication);
+ handleRegistration(info, leaseDuration, isReplication);
}
@Override
public void register(final InstanceInfo info, final boolean isReplication) {
- handleRegistration(info, resolveInstanceLeaseDuration(info), isReplication);
super.register(info, isReplication);
+ handleRegistration(info, resolveInstanceLeaseDuration(info), isReplication);
}
@Override
public boolean cancel(String appName, String serverId, boolean isReplication) {
- handleCancelation(appName, serverId, isReplication);
- return super.cancel(appName, serverId, isReplication);
+ final boolean cancelled = super.cancel(appName, serverId, isReplication);
+ if (cancelled) {
+ handleCancelation(appName, serverId, isReplication);
+ }
+ return cancelled;
}
@Override
public boolean renew(final String appName, final String serverId, boolean isReplication) {
- log("renew " + appName + " serverId " + serverId + ", isReplication {}" + isReplication);
- Application application = getApplication(appName);
- if (application != null) {
- InstanceInfo instanceInfo = application.getByInstanceId(serverId);
- if (instanceInfo != null) {
- publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, instanceInfo, isReplication));
- }
+ final boolean renewed = super.renew(appName, serverId, isReplication);
+ if (renewed) {
+ handleRenewal(appName, serverId, isReplication);
}
- return super.renew(appName, serverId, isReplication);
+ return renewed;
}
@Override
protected boolean internalCancel(String appName, String id, boolean isReplication) {
- handleCancelation(appName, id, isReplication);
- return super.internalCancel(appName, id, isReplication);
+ final boolean cancelled = super.internalCancel(appName, id, isReplication);
+ if (cancelled) {
+ handleCancelation(appName, id, isReplication);
+ }
+ return cancelled;
}
private void handleCancelation(String appName, String id, boolean isReplication) {
- log("cancel " + appName + ", serverId " + id + ", isReplication " + isReplication);
+ log("cancelled " + appName + ", serverId " + id + ", isReplication " + isReplication);
publishEvent(new EurekaInstanceCanceledEvent(this, appName, id, isReplication));
}
private void handleRegistration(InstanceInfo info, int leaseDuration, boolean isReplication) {
- log("register " + info.getAppName() + ", vip " + info.getVIPAddress() + ", leaseDuration " + leaseDuration
+ log("registered " + info.getAppName() + ", vip " + info.getVIPAddress() + ", leaseDuration " + leaseDuration
+ ", isReplication " + isReplication);
publishEvent(new EurekaInstanceRegisteredEvent(this, info, leaseDuration, isReplication));
}
+ private void handleRenewal(final String appName, final String serverId, boolean isReplication) {
+ log("renewed " + appName + ", serverId " + serverId + ", isReplication " + isReplication);
+ final Application application = getApplication(appName);
+ if (application != null) {
+ final InstanceInfo instanceInfo = application.getByInstanceId(serverId);
+ if (instanceInfo != null) {
+ publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, instanceInfo, isReplication));
+ }
+ }
+ }
+
private void log(String message) {
if (log.isDebugEnabled()) {
log.debug(message);
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/ReplicationClientAdditionalFilters.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/ReplicationClientAdditionalFilters.java
index 06f1360067..26b044717c 100644
--- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/ReplicationClientAdditionalFilters.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/ReplicationClientAdditionalFilters.java
@@ -19,20 +19,20 @@
import java.util.Collection;
import java.util.LinkedHashSet;
-import com.sun.jersey.api.client.filter.ClientFilter;
+import jakarta.ws.rs.client.ClientRequestFilter;
/**
* @author Yuxin Bai
*/
public class ReplicationClientAdditionalFilters {
- private Collection filters;
+ private final Collection filters;
- public ReplicationClientAdditionalFilters(Collection filters) {
+ public ReplicationClientAdditionalFilters(Collection filters) {
this.filters = new LinkedHashSet<>(filters);
}
- public Collection getFilters() {
+ public Collection getFilters() {
return this.filters;
}
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/DefaultEurekaInstanceTagsProvider.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/DefaultEurekaInstanceTagsProvider.java
new file mode 100644
index 0000000000..3dbf097f90
--- /dev/null
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/DefaultEurekaInstanceTagsProvider.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2013-2024 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.netflix.eureka.server.metrics;
+
+import com.netflix.appinfo.InstanceInfo;
+import io.micrometer.core.instrument.Tag;
+import io.micrometer.core.instrument.Tags;
+
+/**
+ * Default implementation for {@link EurekaInstanceTagsProvider}.
+ *
+ * @author Wonchul Heo
+ * @since 4.1.2
+ */
+class DefaultEurekaInstanceTagsProvider implements EurekaInstanceTagsProvider {
+
+ @Override
+ public Tags eurekaInstanceTags(InstanceInfo instanceInfo) {
+ return Tags.of(Tag.of("application", instanceInfo.getAppName()),
+ Tag.of("status", instanceInfo.getStatus().name()));
+ }
+
+}
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceMetricsAutoConfiguration.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceMetricsAutoConfiguration.java
new file mode 100644
index 0000000000..62bce04e12
--- /dev/null
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceMetricsAutoConfiguration.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2013-2024 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.netflix.eureka.server.metrics;
+
+import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
+import io.micrometer.core.instrument.MeterRegistry;
+
+import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
+import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+
+/**
+ * Auto-configuration for Eureka Instance metrics.
+ *
+ * @author Wonchul Heo
+ * @since 4.1.2
+ */
+@ConditionalOnClass(MeterRegistry.class)
+@ConditionalOnBean(MeterRegistry.class)
+@AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class,
+ EurekaServerAutoConfiguration.class })
+@ConditionalOnProperty(name = "eureka.server.metrics.enabled", havingValue = "true")
+class EurekaInstanceMetricsAutoConfiguration {
+
+ @ConditionalOnMissingBean
+ @Bean
+ public EurekaInstanceTagsProvider eurekaInstanceTagProvider() {
+ return new DefaultEurekaInstanceTagsProvider();
+ }
+
+ @ConditionalOnMissingBean
+ @Bean
+ public EurekaInstanceMonitor eurekaInstanceMeterBinder(MeterRegistry meterRegistry,
+ PeerAwareInstanceRegistry instanceRegistry, EurekaInstanceTagsProvider tagProvider) {
+ return new EurekaInstanceMonitor(meterRegistry, instanceRegistry, tagProvider);
+ }
+
+}
diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceMonitor.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceMonitor.java
new file mode 100644
index 0000000000..5c029fed59
--- /dev/null
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceMonitor.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2013-2024 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.netflix.eureka.server.metrics;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import com.netflix.eureka.registry.PeerAwareInstanceRegistry;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.MultiGauge;
+import io.micrometer.core.instrument.Tags;
+
+import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
+import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
+import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.event.SmartApplicationListener;
+
+/**
+ * {@link SmartApplicationListener} for collecting event metrics from
+ * {@link PeerAwareInstanceRegistry}.
+ *
+ * @author Wonchul Heo
+ * @since 4.1.2
+ */
+public class EurekaInstanceMonitor implements SmartApplicationListener {
+
+ private final MultiGauge eurekaInstances;
+
+ private final PeerAwareInstanceRegistry instanceRegistry;
+
+ private final EurekaInstanceTagsProvider tagProvider;
+
+ EurekaInstanceMonitor(MeterRegistry meterRegistry, PeerAwareInstanceRegistry instanceRegistry,
+ EurekaInstanceTagsProvider tagProvider) {
+ Objects.requireNonNull(meterRegistry);
+ this.instanceRegistry = Objects.requireNonNull(instanceRegistry);
+ this.tagProvider = Objects.requireNonNull(tagProvider);
+ this.eurekaInstances = MultiGauge.builder("eureka.server.instances")
+ .description("Number of application instances registered with the Eureka server.")
+ .register(meterRegistry);
+ }
+
+ @Override
+ public boolean supportsEventType(Class extends ApplicationEvent> eventType) {
+ // If events that change state are added, an event class must be added.
+ return EurekaInstanceCanceledEvent.class.isAssignableFrom(eventType)
+ || EurekaInstanceRegisteredEvent.class.isAssignableFrom(eventType)
+ || EurekaInstanceRenewedEvent.class.isAssignableFrom(eventType);
+ }
+
+ @Override
+ public void onApplicationEvent(ApplicationEvent event) {
+ final Map aggregatedCounts = instanceRegistry.getApplications().getRegisteredApplications().stream()
+ .flatMap(application -> application.getInstances().stream())
+ .collect(Collectors.groupingBy(tagProvider::eurekaInstanceTags, Collectors.counting()));
+ eurekaInstances.register(aggregatedCounts.entrySet().stream()
+ .map(entry -> MultiGauge.Row.of(entry.getKey(), entry.getValue())).collect(Collectors.toList()), true);
+ }
+
+}
diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoriesTest.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceTagsProvider.java
similarity index 52%
rename from spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoriesTest.java
rename to spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceTagsProvider.java
index 8366ce9590..d162d35d42 100644
--- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateTransportClientFactoriesTest.java
+++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/metrics/EurekaInstanceTagsProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2022 the original author or authors.
+ * Copyright 2013-2024 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.
@@ -14,22 +14,19 @@
* limitations under the License.
*/
-package org.springframework.cloud.netflix.eureka.http;
+package org.springframework.cloud.netflix.eureka.server.metrics;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
+import com.netflix.appinfo.InstanceInfo;
+import io.micrometer.core.instrument.Tags;
/**
- * @author Daniel Lavoie
+ * Provides {@link Tags} for Eureka instance metrics.
+ *
+ * @author Wonchul Heo
+ * @since 4.1.2
*/
-class RestTemplateTransportClientFactoriesTest {
+public interface EurekaInstanceTagsProvider {
- @Test
- void testJerseyIsUnsupported() {
- Assertions.assertThrows(UnsupportedOperationException.class, () -> {
- new RestTemplateTransportClientFactories(new RestTemplateDiscoveryClientOptionalArgs(null))
- .newTransportClientFactory(null, null);
- });
- }
+ Tags eurekaInstanceTags(InstanceInfo instanceInfo);
}
diff --git a/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json
new file mode 100644
index 0000000000..14d30bdd0f
--- /dev/null
+++ b/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -0,0 +1,10 @@
+{
+ "properties": [
+ {
+ "name": "eureka.server.metrics.enabled",
+ "type": "java.lang.Boolean",
+ "defaultValue": "false",
+ "description": "Indicates whether the metrics should be enabled for eureka instances."
+ }
+ ]
+}
diff --git a/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/spring.factories b/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index 1ce4b307e7..0000000000
--- a/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/spring.factories
+++ /dev/null
@@ -1,2 +0,0 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
- org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration
\ No newline at end of file
diff --git a/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000000..ac59ffdca3
--- /dev/null
+++ b/spring-cloud-netflix-eureka-server/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1,2 @@
+org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration
+org.springframework.cloud.netflix.eureka.server.metrics.EurekaInstanceMetricsAutoConfiguration
diff --git a/spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/ApplicationContextTests.java b/spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/ApplicationContextTests.java
index f85ffe4b03..c4e2f46f69 100644
--- a/spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/ApplicationContextTests.java
+++ b/spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/ApplicationContextTests.java
@@ -26,7 +26,7 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
-import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.cloud.netflix.eureka.server.ApplicationContextTests.Application;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
@@ -40,7 +40,8 @@
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
properties = { "spring.application.name=eureka", "server.servlet.context-path=/context",
- "management.security.enabled=false", "management.endpoints.web.exposure.include=*" })
+ "management.security.enabled=false", "management.endpoints.web.exposure.include=*",
+ "eureka.server.version.filter.debug.response-header=X-Version-Filter-Computed-Path" })
class ApplicationContextTests {
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
@@ -54,6 +55,8 @@ void catalogLoads() {
ResponseEntity