From 78037a11619724084cf3614f149f45c428654a3f Mon Sep 17 00:00:00 2001 From: buildmaster Date: Mon, 18 Nov 2019 15:10:50 +0000 Subject: [PATCH 1/4] Update SNAPSHOT to 2.1.4.RELEASE --- README.adoc | 145 +++++++++++++++++++- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 6 files changed, 151 insertions(+), 12 deletions(-) diff --git a/README.adoc b/README.adoc index 0c6d1d35..a5cff315 100644 --- a/README.adoc +++ b/README.adoc @@ -1,4 +1,8 @@ -// Do not edit this file (e.g. go instead to src/main/asciidoc) +//// +DO NOT EDIT THIS FILE. IT WAS GENERATED. +Manual changes to this file will be lost when it is generated again. +Edit the files in the src/main/asciidoc/ directory instead. +//// image:https://circleci.com/gh/spring-cloud/spring-cloud-openfeign.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-openfeign"] @@ -51,7 +55,7 @@ credentials and you already have those. The projects that require middleware generally include a `docker-compose.yml`, so consider using -https://compose.docker.io/[Docker Compose] to run the middeware servers +https://docs.docker.com/compose/[Docker Compose] to run the middeware servers in Docker containers. See the README in the https://github.com/spring-cloud-samples/scripts[scripts demo repository] for specific instructions about the common cases of mongo, @@ -108,6 +112,8 @@ from the `file` menu. == 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 @@ -151,4 +157,137 @@ added after the original pull request but before a merge. 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). \ No newline at end of file + 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. \ No newline at end of file diff --git a/docs/pom.xml b/docs/pom.xml index 86e5557c..5ba0e8f9 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.4.RELEASE spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index f399ff14..ce376be5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.4.RELEASE pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.1.8.BUILD-SNAPSHOT + 2.1.9.RELEASE @@ -26,8 +26,8 @@ ${basedir} 2.7.3 - 2.1.4.BUILD-SNAPSHOT - 2.1.4.BUILD-SNAPSHOT + 2.1.4.RELEASE + 2.1.4.RELEASE 3.6.1 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index a8e7fc9b..f70c97c6 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.4.RELEASE .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 84eecc97..848fe914 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.1.8.BUILD-SNAPSHOT + 2.1.9.RELEASE spring-cloud-openfeign-dependencies - 2.1.4.BUILD-SNAPSHOT + 2.1.4.RELEASE pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index 4842673d..3cbac529 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.4.RELEASE .. spring-cloud-starter-openfeign From de39e67e18f08c599c4c4e864feb9a7494598ea8 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Mon, 18 Nov 2019 15:11:21 +0000 Subject: [PATCH 2/4] Going back to snapshots --- README.adoc | 145 +------------------- docs/pom.xml | 2 +- pom.xml | 8 +- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 +- spring-cloud-starter-openfeign/pom.xml | 2 +- 6 files changed, 12 insertions(+), 151 deletions(-) diff --git a/README.adoc b/README.adoc index a5cff315..0c6d1d35 100644 --- a/README.adoc +++ b/README.adoc @@ -1,8 +1,4 @@ -//// -DO NOT EDIT THIS FILE. IT WAS GENERATED. -Manual changes to this file will be lost when it is generated again. -Edit the files in the src/main/asciidoc/ directory instead. -//// +// Do not edit this file (e.g. go instead to src/main/asciidoc) image:https://circleci.com/gh/spring-cloud/spring-cloud-openfeign.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-openfeign"] @@ -55,7 +51,7 @@ credentials and you already have those. The projects that require middleware generally include a `docker-compose.yml`, so consider using -https://docs.docker.com/compose/[Docker Compose] to run the middeware servers +https://compose.docker.io/[Docker Compose] to run the middeware servers in Docker containers. See the README in the https://github.com/spring-cloud-samples/scripts[scripts demo repository] for specific instructions about the common cases of mongo, @@ -112,8 +108,6 @@ from the `file` menu. == 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 @@ -157,137 +151,4 @@ added after the original pull request but before a merge. 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. \ No newline at end of file + message (where XXXX is the issue number). \ No newline at end of file diff --git a/docs/pom.xml b/docs/pom.xml index 5ba0e8f9..86e5557c 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.RELEASE + 2.1.4.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index ce376be5..f399ff14 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.1.4.RELEASE + 2.1.4.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.1.9.RELEASE + 2.1.8.BUILD-SNAPSHOT @@ -26,8 +26,8 @@ ${basedir} 2.7.3 - 2.1.4.RELEASE - 2.1.4.RELEASE + 2.1.4.BUILD-SNAPSHOT + 2.1.4.BUILD-SNAPSHOT 3.6.1 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index f70c97c6..a8e7fc9b 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.RELEASE + 2.1.4.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 848fe914..84eecc97 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.1.9.RELEASE + 2.1.8.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.1.4.RELEASE + 2.1.4.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index 3cbac529..4842673d 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.RELEASE + 2.1.4.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From f97cbb9a73265516a226fbb8c2d6dca91e942783 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Mon, 18 Nov 2019 15:11:21 +0000 Subject: [PATCH 3/4] Bumping versions to 2.1.5.BUILD-SNAPSHOT after release --- docs/pom.xml | 2 +- pom.xml | 8 ++++---- spring-cloud-openfeign-core/pom.xml | 2 +- spring-cloud-openfeign-dependencies/pom.xml | 4 ++-- spring-cloud-starter-openfeign/pom.xml | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 86e5557c..65af77f0 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.5.BUILD-SNAPSHOT spring-cloud-openfeign-docs pom diff --git a/pom.xml b/pom.xml index f399ff14..aa35b41c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.5.BUILD-SNAPSHOT pom Spring Cloud OpenFeign Spring Cloud OpenFeign org.springframework.cloud spring-cloud-build - 2.1.8.BUILD-SNAPSHOT + 2.1.10.BUILD-SNAPSHOT @@ -26,8 +26,8 @@ ${basedir} 2.7.3 - 2.1.4.BUILD-SNAPSHOT - 2.1.4.BUILD-SNAPSHOT + 2.1.5.BUILD-SNAPSHOT + 2.1.5.BUILD-SNAPSHOT 3.6.1 diff --git a/spring-cloud-openfeign-core/pom.xml b/spring-cloud-openfeign-core/pom.xml index a8e7fc9b..ae0f99ae 100644 --- a/spring-cloud-openfeign-core/pom.xml +++ b/spring-cloud-openfeign-core/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.5.BUILD-SNAPSHOT .. spring-cloud-openfeign-core diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml index 84eecc97..06616fad 100644 --- a/spring-cloud-openfeign-dependencies/pom.xml +++ b/spring-cloud-openfeign-dependencies/pom.xml @@ -6,11 +6,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 2.1.8.BUILD-SNAPSHOT + 2.1.10.BUILD-SNAPSHOT spring-cloud-openfeign-dependencies - 2.1.4.BUILD-SNAPSHOT + 2.1.5.BUILD-SNAPSHOT pom spring-cloud-openfeign-dependencies Spring Cloud OpenFeign Dependencies diff --git a/spring-cloud-starter-openfeign/pom.xml b/spring-cloud-starter-openfeign/pom.xml index 4842673d..88f00fc5 100644 --- a/spring-cloud-starter-openfeign/pom.xml +++ b/spring-cloud-starter-openfeign/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-openfeign - 2.1.4.BUILD-SNAPSHOT + 2.1.5.BUILD-SNAPSHOT .. spring-cloud-starter-openfeign From 80d206713405c2968dc636a8c20edba5bc14628e Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Thu, 9 Jan 2020 17:59:15 +0100 Subject: [PATCH 4/4] Merge fix 255 to 21x (#273) * Fix bug in SpringEncoder (#225) This commit fixes a bug in the SpringEncoder that causes the bodyType to be ignored and not passed to generic message converters. Fixes gh-225 * Fix after cherry-pick. * Add Ahmad Mozafarnia to authors. * Refactor tests. Co-authored-by: Ahmad Mozafarnia --- .../openfeign/support/SpringEncoder.java | 89 ++++++++---- .../openfeign/support/SpringEncoderTests.java | 135 ++++++++++++++---- 2 files changed, 169 insertions(+), 55 deletions(-) diff --git a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java index 471445cc..bb82c76c 100644 --- a/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java +++ b/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringEncoder.java @@ -35,10 +35,12 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.ObjectFactory; import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.cloud.openfeign.encoding.HttpEncoding; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.converter.ByteArrayHttpMessageConverter; +import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; import org.springframework.web.multipart.MultipartFile; @@ -49,6 +51,7 @@ import static org.springframework.cloud.openfeign.support.FeignUtils.getHttpHead /** * @author Spencer Gibb * @author Scien Jus + * @author Ahmad Mozafarnia */ public class SpringEncoder implements Encoder { @@ -67,8 +70,8 @@ public class SpringEncoder implements Encoder { throws EncodeException { // template.body(conversionService.convert(object, String.class)); if (requestBody != null) { - Class requestType = requestBody.getClass(); - Collection contentTypes = request.headers().get("Content-Type"); + Collection contentTypes = request.headers() + .get(HttpEncoding.CONTENT_TYPE); MediaType requestContentType = null; if (contentTypes != null && !contentTypes.isEmpty()) { @@ -89,31 +92,24 @@ public class SpringEncoder implements Encoder { } } - for (HttpMessageConverter messageConverter : this.messageConverters + for (HttpMessageConverter messageConverter : this.messageConverters .getObject().getConverters()) { - if (messageConverter.canWrite(requestType, requestContentType)) { - if (log.isDebugEnabled()) { - if (requestContentType != null) { - log.debug("Writing [" + requestBody + "] as \"" - + requestContentType + "\" using [" + messageConverter - + "]"); - } - else { - log.debug("Writing [" + requestBody + "] using [" - + messageConverter + "]"); - } - + FeignOutputMessage outputMessage; + try { + if (messageConverter instanceof GenericHttpMessageConverter) { + outputMessage = checkAndWrite(requestBody, bodyType, + requestContentType, + (GenericHttpMessageConverter) messageConverter, request); } - - FeignOutputMessage outputMessage = new FeignOutputMessage(request); - try { - @SuppressWarnings("unchecked") - HttpMessageConverter copy = (HttpMessageConverter) messageConverter; - copy.write(requestBody, requestContentType, outputMessage); - } - catch (IOException ex) { - throw new EncodeException("Error converting request body", ex); + else { + outputMessage = checkAndWrite(requestBody, requestContentType, + messageConverter, request); } + } + catch (IOException ex) { + throw new EncodeException("Error converting request body", ex); + } + if (outputMessage != null) { // clear headers request.headers(null); // converters can modify headers, so update the request @@ -139,7 +135,7 @@ public class SpringEncoder implements Encoder { } } String message = "Could not write request: no suitable HttpMessageConverter " - + "found for request type [" + requestType.getName() + "]"; + + "found for request type [" + requestBody.getClass().getName() + "]"; if (requestContentType != null) { message += " and content type [" + requestContentType + "]"; } @@ -147,6 +143,49 @@ public class SpringEncoder implements Encoder { } } + @SuppressWarnings("unchecked") + private FeignOutputMessage checkAndWrite(Object body, MediaType contentType, + HttpMessageConverter converter, RequestTemplate request) throws IOException { + if (converter.canWrite(body.getClass(), contentType)) { + logBeforeWrite(body, contentType, converter); + FeignOutputMessage outputMessage = new FeignOutputMessage(request); + converter.write(body, contentType, outputMessage); + return outputMessage; + } + else { + return null; + } + } + + @SuppressWarnings("unchecked") + private FeignOutputMessage checkAndWrite(Object body, Type genericType, + MediaType contentType, GenericHttpMessageConverter converter, + RequestTemplate request) throws IOException { + if (converter.canWrite(genericType, body.getClass(), contentType)) { + logBeforeWrite(body, contentType, converter); + FeignOutputMessage outputMessage = new FeignOutputMessage(request); + converter.write(body, genericType, contentType, outputMessage); + return outputMessage; + } + else { + return null; + } + } + + private void logBeforeWrite(Object requestBody, MediaType requestContentType, + HttpMessageConverter messageConverter) { + if (log.isDebugEnabled()) { + if (requestContentType != null) { + log.debug("Writing [" + requestBody + "] as \"" + requestContentType + + "\" using [" + messageConverter + "]"); + } + else { + log.debug( + "Writing [" + requestBody + "] using [" + messageConverter + "]"); + } + } + } + private final class FeignOutputMessage implements HttpOutputMessage { private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); diff --git a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java index eeedb90f..86c3a5b9 100644 --- a/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java +++ b/spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringEncoderTests.java @@ -16,10 +16,11 @@ package org.springframework.cloud.openfeign.support; -import java.io.IOException; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.Collections; import java.util.List; import feign.RequestTemplate; @@ -27,7 +28,6 @@ import feign.codec.EncodeException; import feign.codec.Encoder; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentMatcher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -35,12 +35,15 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.cloud.openfeign.FeignContext; +import org.springframework.cloud.openfeign.encoding.HttpEncoding; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.converter.AbstractGenericHttpMessageConverter; +import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; @@ -60,6 +63,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; /** * @author Spencer Gibb * @author Olga Maciaszek-Sharma + * @author Ahmad Mozafarnia */ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SpringEncoderTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = { @@ -74,6 +78,10 @@ public class SpringEncoderTests { @Qualifier("myHttpMessageConverter") private HttpMessageConverter myConverter; + @Autowired + @Qualifier("myGenericHttpMessageConverter") + private GenericHttpMessageConverter myGenericConverter; + @Test public void testCustomHttpMessageConverter() { Encoder encoder = this.context.getInstance("foo", Encoder.class); @@ -93,7 +101,35 @@ public class SpringEncoderTests { assertThat(request.requestCharset()).as("request charset is null").isNotNull(); assertThat(request.requestCharset()).as("request charset is wrong") - .isEqualTo(Charset.forName("UTF-8")); + .isEqualTo(StandardCharsets.UTF_8); + } + + // gh-225 + @Test + public void testCustomGenericHttpMessageConverter() { + Encoder encoder = this.context.getInstance("foo", Encoder.class); + assertThat(encoder).isNotNull(); + RequestTemplate request = new RequestTemplate(); + + ParameterizedTypeReference> stringListType = new ParameterizedTypeReference>() { + }; + + request.header(HttpEncoding.CONTENT_TYPE, "application/mygenerictype"); + encoder.encode(Collections.singletonList("hi"), stringListType.getType(), + request); + + Collection contentTypeHeader = request.headers().get("Content-Type"); + assertThat(contentTypeHeader).as("missing content type header").isNotNull(); + assertThat(contentTypeHeader.isEmpty()).as("missing content type header") + .isFalse(); + + String header = contentTypeHeader.iterator().next(); + assertThat(header).as("content type header is wrong") + .isEqualTo("application/mygenerictype"); + + assertThat(request.requestCharset()).as("request charset is null").isNotNull(); + assertThat(request.requestCharset()).as("request charset is wrong") + .isEqualTo(StandardCharsets.UTF_8); } @Test @@ -178,6 +214,11 @@ public class SpringEncoderTests { return new MyHttpMessageConverter(); } + @Bean + GenericHttpMessageConverter myGenericHttpMessageConverter() { + return new MyGenericHttpMessageConverter(); + } + private static class MyHttpMessageConverter extends AbstractGenericHttpMessageConverter { @@ -203,20 +244,77 @@ public class SpringEncoderTests { @Override protected void writeInternal(Object o, Type type, HttpOutputMessage outputMessage) - throws IOException, HttpMessageNotWritableException { + throws HttpMessageNotWritableException { } @Override protected Object readInternal(Class clazz, HttpInputMessage inputMessage) - throws IOException, HttpMessageNotReadableException { + throws HttpMessageNotReadableException { return null; } @Override public Object read(Type type, Class contextClass, HttpInputMessage inputMessage) - throws IOException, HttpMessageNotReadableException { + throws HttpMessageNotReadableException { + return null; + } + + } + + private static class MyGenericHttpMessageConverter + extends AbstractGenericHttpMessageConverter { + + MyGenericHttpMessageConverter() { + super(new MediaType("application", "mygenerictype")); + } + + private boolean isStringList(Type type) { + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) type; + return parameterizedType.getRawType() == List.class + && parameterizedType + .getActualTypeArguments()[0] == String.class; + } + else { + return false; + } + } + + @Override + protected boolean supports(Class clazz) { + return clazz == List.class; + } + + @Override + public boolean canWrite(Type type, Class clazz, MediaType mediaType) { + return canWrite(mediaType) && isStringList(type); + } + + @Override + public boolean canRead(Type type, Class contextClass, + MediaType mediaType) { + return canRead(mediaType) && isStringList(type); + } + + @Override + protected void writeInternal(Object o, Type type, + HttpOutputMessage outputMessage) + throws HttpMessageNotWritableException { + + } + + @Override + public Object read(Type type, Class contextClass, + HttpInputMessage inputMessage) + throws HttpMessageNotReadableException { + return null; + } + + @Override + protected Object readInternal(Class clazz, HttpInputMessage inputMessage) + throws HttpMessageNotReadableException { return null; } @@ -224,27 +322,4 @@ public class SpringEncoderTests { } - class MediaTypeMatcher implements ArgumentMatcher { - - private MediaType mediaType; - - MediaTypeMatcher(String type, String subtype) { - this.mediaType = new MediaType(type, subtype); - } - - @Override - public boolean matches(MediaType argument) { - return this.mediaType.equals(argument); - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("MediaTypeMatcher{"); - sb.append("mediaType=").append(this.mediaType); - sb.append('}'); - return sb.toString(); - } - - } - }