Compare commits
114
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f09ae0824 | ||
|
|
c82b577d00 | ||
|
|
eca40256d8 | ||
|
|
a85294a835 | ||
|
|
db778b5c74 | ||
|
|
73a75fd8b2 | ||
|
|
892e65e303 | ||
|
|
422dda0a75 | ||
|
|
3eabb0237e | ||
|
|
ada2cb7913 | ||
|
|
05b58e087e | ||
|
|
80ecc9ac09 | ||
|
|
bee97b8611 | ||
|
|
01d05227c8 | ||
|
|
90400b9e43 | ||
|
|
b1e38db1e2 | ||
|
|
d77337bc79 | ||
|
|
80d2067134 | ||
|
|
887ceefa60 | ||
|
|
2b364367cb | ||
|
|
8aa4729537 | ||
|
|
41e9b55869 | ||
|
|
8a25b8bd63 | ||
|
|
774017db85 | ||
|
|
d1b50ec2ae | ||
|
|
bde804c6a4 | ||
|
|
0888d9ce8d | ||
|
|
1bc7542dc5 | ||
|
|
68689182be | ||
|
|
d5c176c5f4 | ||
|
|
38733043ae | ||
|
|
1b21e3b639 | ||
|
|
14e6806c1c | ||
|
|
dd95dae352 | ||
|
|
c1c211efdb | ||
|
|
ea69c30496 | ||
|
|
f71b419d8d | ||
|
|
35bbb32e03 | ||
|
|
f97cbb9a73 | ||
|
|
de39e67e18 | ||
|
|
78037a1161 | ||
|
|
1ce5ca1ba8 | ||
|
|
59b34b23e9 | ||
|
|
f01c46ab2e | ||
|
|
6dc78c99c2 | ||
|
|
3046af2b42 | ||
|
|
8973f4286b | ||
|
|
ef5f9d6858 | ||
|
|
f661105e63 | ||
|
|
bc10583bf3 | ||
|
|
cb1ea20f3f | ||
|
|
6bfc684967 | ||
|
|
63a9245f13 | ||
|
|
64d63cbb39 | ||
|
|
d963ebd0f0 | ||
|
|
1e1562b24a | ||
|
|
7eb7067752 | ||
|
|
bc4bfb5b7a | ||
|
|
94977691b8 | ||
|
|
b2791605b7 | ||
|
|
3e5d7f84aa | ||
|
|
eecc51e695 | ||
|
|
9dfc820306 | ||
|
|
c3fc93268c | ||
|
|
ecfd1b4cee | ||
|
|
5ce9fcf9f8 | ||
|
|
4e6c1b2d04 | ||
|
|
d8cdade30f | ||
|
|
b16904f15e | ||
|
|
21a2a59461 | ||
|
|
39dfa0ef7f | ||
|
|
96ae8479aa | ||
|
|
37fd2d4448 | ||
|
|
6493eab98a | ||
|
|
caacee575c | ||
|
|
8abbf0a343 | ||
|
|
c32b8568cf | ||
|
|
654479a696 | ||
|
|
35b9de7f6e | ||
|
|
2294dee616 | ||
|
|
2cdc1aceeb | ||
|
|
dabbfb7220 | ||
|
|
3e069b41af | ||
|
|
9cf06153a8 | ||
|
|
ead4c47fcb | ||
|
|
eda905684d | ||
|
|
2c73498398 | ||
|
|
ebd80b5115 | ||
|
|
866d20d976 | ||
|
|
0d891d284a | ||
|
|
27380898a8 | ||
|
|
d5031f8618 | ||
|
|
b5539198e6 | ||
|
|
9b8a3c6c1b | ||
|
|
2e8a5833a9 | ||
|
|
f76a81fe6b | ||
|
|
3a60921794 | ||
|
|
e531539e77 | ||
|
|
7afd62dd32 | ||
|
|
2e21175087 | ||
|
|
10dda1601e | ||
|
|
84b0d0ca40 | ||
|
|
50c799a4a0 | ||
|
|
aba2abba8a | ||
|
|
f6fee55411 | ||
|
|
4092cb10cc | ||
|
|
0169a3c3f3 | ||
|
|
fff4975c1e | ||
|
|
75faca6c17 | ||
|
|
a81c53a55c | ||
|
|
43c53739cf | ||
|
|
115e87b6ce | ||
|
|
33fa5b1b6b | ||
|
|
ca55e95c8f |
@@ -9,7 +9,6 @@ jobs:
|
|||||||
branches:
|
branches:
|
||||||
ignore:
|
ignore:
|
||||||
- gh-pages # list of branches to ignore
|
- gh-pages # list of branches to ignore
|
||||||
resource_class: large
|
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
@@ -36,4 +35,4 @@ jobs:
|
|||||||
destination: artifacts
|
destination: artifacts
|
||||||
- store_test_results:
|
- store_test_results:
|
||||||
path: /junit/
|
path: /junit/
|
||||||
destination: testartifacts
|
destination: testartifacts
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-build</artifactId>
|
||||||
|
<version>2.2.3.RELEASE</version>
|
||||||
|
<relativePath></relativePath>
|
||||||
|
</parent>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-openfeign</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>Spring Cloud OpenFeign</name>
|
||||||
|
<description>Spring Cloud OpenFeign</description>
|
||||||
|
<url>https://spring.io/spring-cloud/spring-cloud-openfeign</url>
|
||||||
|
<organization>
|
||||||
|
<name>Pivotal Software, Inc.</name>
|
||||||
|
<url>https://www.spring.io</url>
|
||||||
|
</organization>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||||
|
<comments>Copyright 2014-2015 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.</comments>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>dsyer</id>
|
||||||
|
<name>Dave Syer</name>
|
||||||
|
<email>dsyer at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>lead</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>sgibb</id>
|
||||||
|
<name>Spencer Gibb</name>
|
||||||
|
<email>sgibb at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>lead</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>mgrzejszczak</id>
|
||||||
|
<name>Marcin Grzejszczak</name>
|
||||||
|
<email>mgrzejszczak at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>rbaxter</id>
|
||||||
|
<name>Ryan Baxter</name>
|
||||||
|
<email>rbaxter at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>omaciaszeksharma</id>
|
||||||
|
<name>Olga Maciaszek-Sharma</name>
|
||||||
|
<email>omaciaszeksharma at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-openfeign.git</connection>
|
||||||
|
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-openfeign.git</developerConnection>
|
||||||
|
<url>https://github.com/spring-cloud/spring-cloud-openfeign</url>
|
||||||
|
</scm>
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>spring</id>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<releases>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/libs-snapshot-local</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/libs-milestone-local</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<id>spring-releases</id>
|
||||||
|
<name>Spring Releases</name>
|
||||||
|
<url>https://repo.spring.io/release</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
Please provide details of the problem, including the version of Spring Cloud that you
|
||||||
|
are using.
|
||||||
|
|
||||||
|
**Sample**
|
||||||
|
If possible, please provide a test case or sample application that reproduces
|
||||||
|
the problem. This makes it much easier for us to diagnose the problem and to verify that
|
||||||
|
we have fixed it.
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
@@ -18,3 +18,4 @@ _site/
|
|||||||
.shelf
|
.shelf
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
.vscode/
|
||||||
+19
-1
@@ -10,6 +10,23 @@ image:https://codecov.io/gh/spring-cloud/spring-cloud-openfeign/branch/master/gr
|
|||||||
|
|
||||||
image:https://api.codacy.com/project/badge/Grade/97b04c4e609c4b4f86b415e4437a6484["Codacy code quality", link="https://www.codacy.com/app/Spring-Cloud/spring-cloud-openfeign?utm_source=github.com&utm_medium=referral&utm_content=spring-cloud/spring-cloud-openfeign&utm_campaign=Badge_Grade"]
|
image:https://api.codacy.com/project/badge/Grade/97b04c4e609c4b4f86b415e4437a6484["Codacy code quality", link="https://www.codacy.com/app/Spring-Cloud/spring-cloud-openfeign?utm_source=github.com&utm_medium=referral&utm_content=spring-cloud/spring-cloud-openfeign&utm_campaign=Badge_Grade"]
|
||||||
|
|
||||||
|
: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 OpenFeign
|
||||||
|
:all: {asterisk}{asterisk}
|
||||||
|
|
||||||
This project provides OpenFeign integrations for Spring Boot apps through autoconfiguration
|
This project provides OpenFeign integrations for Spring Boot apps through autoconfiguration
|
||||||
and binding to the Spring Environment and other Spring programming model idioms.
|
and binding to the Spring Environment and other Spring programming model idioms.
|
||||||
|
|
||||||
@@ -245,6 +262,7 @@ $ touch .springformat
|
|||||||
==== Intellij IDEA
|
==== Intellij IDEA
|
||||||
|
|
||||||
In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.
|
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/
|
.spring-cloud-build-tools/
|
||||||
----
|
----
|
||||||
@@ -285,7 +303,7 @@ image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/{spring
|
|||||||
|
|
||||||
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:
|
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/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.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.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`.
|
- `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`.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
To report security vulnerabilities, please go to https://pivotal.io/security.
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-openfeign</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
</parent>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-openfeign-docs</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>Spring Cloud OpenFeign Docs</name>
|
||||||
|
<description>Spring Cloud Docs</description>
|
||||||
|
<url>https://spring.io/spring-cloud/spring-cloud-openfeign/spring-cloud-openfeign-docs</url>
|
||||||
|
<organization>
|
||||||
|
<name>Pivotal Software, Inc.</name>
|
||||||
|
<url>https://www.spring.io</url>
|
||||||
|
</organization>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||||
|
<comments>Copyright 2014-2015 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.</comments>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>dsyer</id>
|
||||||
|
<name>Dave Syer</name>
|
||||||
|
<email>dsyer at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>lead</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>sgibb</id>
|
||||||
|
<name>Spencer Gibb</name>
|
||||||
|
<email>sgibb at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>lead</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>mgrzejszczak</id>
|
||||||
|
<name>Marcin Grzejszczak</name>
|
||||||
|
<email>mgrzejszczak at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>rbaxter</id>
|
||||||
|
<name>Ryan Baxter</name>
|
||||||
|
<email>rbaxter at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>omaciaszeksharma</id>
|
||||||
|
<name>Olga Maciaszek-Sharma</name>
|
||||||
|
<email>omaciaszeksharma at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-openfeign.git/spring-cloud-openfeign-docs</connection>
|
||||||
|
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-openfeign.git/spring-cloud-openfeign-docs</developerConnection>
|
||||||
|
<url>https://github.com/spring-cloud/spring-cloud-openfeign/spring-cloud-openfeign-docs</url>
|
||||||
|
</scm>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+20
-12
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-openfeign</artifactId>
|
<artifactId>spring-cloud-openfeign</artifactId>
|
||||||
<version>2.1.2.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-cloud-openfeign-docs</artifactId>
|
<artifactId>spring-cloud-openfeign-docs</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
@@ -16,7 +16,14 @@
|
|||||||
<docs.main>spring-cloud-openfeign</docs.main>
|
<docs.main>spring-cloud-openfeign</docs.main>
|
||||||
<main.basedir>${basedir}/..</main.basedir>
|
<main.basedir>${basedir}/..</main.basedir>
|
||||||
<docs.whitelisted.branches>2.0.x,2.1.x</docs.whitelisted.branches>
|
<docs.whitelisted.branches>2.0.x,2.1.x</docs.whitelisted.branches>
|
||||||
|
<configprops.inclusionPattern>feign.*</configprops.inclusionPattern>
|
||||||
</properties>
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -32,28 +39,29 @@
|
|||||||
<id>docs</id>
|
<id>docs</id>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>pl.project13.maven</groupId>
|
||||||
|
<artifactId>git-commit-id-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.asciidoctor</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>asciidoctor-maven-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<inherited>false</inherited>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.agilejava.docbkx</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>docbkx-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.asciidoctor</groupId>
|
||||||
|
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-antrun-plugin</artifactId>
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
<inherited>false</inherited>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>build-helper-maven-plugin</artifactId>
|
|
||||||
<inherited>false</inherited>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ image:https://codecov.io/gh/spring-cloud/spring-cloud-openfeign/branch/master/gr
|
|||||||
|
|
||||||
image:https://api.codacy.com/project/badge/Grade/97b04c4e609c4b4f86b415e4437a6484["Codacy code quality", link="https://www.codacy.com/app/Spring-Cloud/spring-cloud-openfeign?utm_source=github.com&utm_medium=referral&utm_content=spring-cloud/spring-cloud-openfeign&utm_campaign=Badge_Grade"]
|
image:https://api.codacy.com/project/badge/Grade/97b04c4e609c4b4f86b415e4437a6484["Codacy code quality", link="https://www.codacy.com/app/Spring-Cloud/spring-cloud-openfeign?utm_source=github.com&utm_medium=referral&utm_content=spring-cloud/spring-cloud-openfeign&utm_campaign=Badge_Grade"]
|
||||||
|
|
||||||
|
include::_attributes.adoc[]
|
||||||
|
|
||||||
include::intro.adoc[]
|
include::intro.adoc[]
|
||||||
|
|
||||||
== Features
|
== Features
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
: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 OpenFeign
|
||||||
|
:all: {asterisk}{asterisk}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|===
|
||||||
|
|Name | Default | Description
|
||||||
|
|
||||||
|
|feign.client.config | |
|
||||||
|
|feign.client.default-config | default |
|
||||||
|
|feign.client.default-to-properties | true |
|
||||||
|
|feign.compression.request.enabled | false | Enables the request sent by Feign to be compressed.
|
||||||
|
|feign.compression.request.mime-types | [text/xml, application/xml, application/json] | The list of supported mime types.
|
||||||
|
|feign.compression.request.min-request-size | 2048 | The minimum threshold content size.
|
||||||
|
|feign.compression.response.enabled | false | Enables the response from Feign to be compressed.
|
||||||
|
|feign.compression.response.useGzipDecoder | false | Enables the default gzip decoder to be used.
|
||||||
|
|feign.httpclient.connection-timeout | 2000 |
|
||||||
|
|feign.httpclient.connection-timer-repeat | 3000 |
|
||||||
|
|feign.httpclient.disable-ssl-validation | false |
|
||||||
|
|feign.httpclient.enabled | true | Enables the use of the Apache HTTP Client by Feign.
|
||||||
|
|feign.httpclient.follow-redirects | true |
|
||||||
|
|feign.httpclient.max-connections | 200 |
|
||||||
|
|feign.httpclient.max-connections-per-route | 50 |
|
||||||
|
|feign.httpclient.time-to-live | 900 |
|
||||||
|
|feign.httpclient.time-to-live-unit | |
|
||||||
|
|feign.hystrix.enabled | false | If true, an OpenFeign client will be wrapped with a Hystrix circuit breaker.
|
||||||
|
|feign.okhttp.enabled | false | Enables the use of the OK HTTP Client by Feign.
|
||||||
|
|
||||||
|
|===
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
:numbered!:
|
||||||
|
[appendix]
|
||||||
|
[[common-application-properties]]
|
||||||
|
== Common application properties
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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[]
|
||||||
@@ -40,7 +40,7 @@ function check_if_anything_to_sync() {
|
|||||||
|
|
||||||
function retrieve_current_branch() {
|
function retrieve_current_branch() {
|
||||||
# Code getting the name of the current branch. For master we want to publish as we did until now
|
# Code getting the name of the current branch. For master we want to publish as we did until now
|
||||||
# http://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch
|
# https://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch
|
||||||
# If there is a branch already passed will reuse it - otherwise will try to find it
|
# If there is a branch already passed will reuse it - otherwise will try to find it
|
||||||
CURRENT_BRANCH=${BRANCH}
|
CURRENT_BRANCH=${BRANCH}
|
||||||
if [[ -z "${CURRENT_BRANCH}" ]] ; then
|
if [[ -z "${CURRENT_BRANCH}" ]] ; then
|
||||||
@@ -147,7 +147,7 @@ function copy_docs_for_current_version() {
|
|||||||
COMMIT_CHANGES="yes"
|
COMMIT_CHANGES="yes"
|
||||||
else
|
else
|
||||||
echo -e "Current branch is [${CURRENT_BRANCH}]"
|
echo -e "Current branch is [${CURRENT_BRANCH}]"
|
||||||
# http://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin
|
# https://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin
|
||||||
if [[ ",${WHITELISTED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then
|
if [[ ",${WHITELISTED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then
|
||||||
mkdir -p ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
mkdir -p ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
||||||
echo -e "Branch [${CURRENT_BRANCH}] is whitelisted! Will copy the current docs to the [${CURRENT_BRANCH}] folder"
|
echo -e "Branch [${CURRENT_BRANCH}] is whitelisted! Will copy the current docs to the [${CURRENT_BRANCH}] folder"
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
spring-cloud-openfeign.adoc
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
This project provides https://github.com/OpenFeign/feign[OpenFeign] integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
|
||||||
|
```java
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableFeignClients
|
||||||
|
public class WebApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(WebApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FeignClient("name")
|
||||||
|
static interface NameService {
|
||||||
|
@RequestMapping("/")
|
||||||
|
public String getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
:github-tag: master
|
|
||||||
:github-repo: spring-cloud/spring-cloud-openfeign
|
|
||||||
: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: master
|
|
||||||
= Spring Cloud OpenFeign
|
= Spring Cloud OpenFeign
|
||||||
|
include::_attributes.adoc[]
|
||||||
|
|
||||||
*{spring-cloud-version}*
|
*{spring-cloud-version}*
|
||||||
|
|
||||||
@@ -15,7 +9,13 @@ include::intro.adoc[]
|
|||||||
[[spring-cloud-feign]]
|
[[spring-cloud-feign]]
|
||||||
== Declarative REST Client: Feign
|
== Declarative REST Client: Feign
|
||||||
|
|
||||||
https://github.com/Netflix/feign[Feign] is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations. Feign also supports pluggable encoders and decoders. Spring Cloud adds support for Spring MVC annotations and for using the same `HttpMessageConverters` used by default in Spring Web. Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.
|
https://github.com/OpenFeign/feign[Feign] is a declarative web service client.
|
||||||
|
It makes writing web service clients easier.
|
||||||
|
To use Feign create an interface and annotate it.
|
||||||
|
It has pluggable annotation support including Feign annotations and JAX-RS annotations.
|
||||||
|
Feign also supports pluggable encoders and decoders.
|
||||||
|
Spring Cloud adds support for Spring MVC annotations and for using the same `HttpMessageConverters` used by default in Spring Web.
|
||||||
|
Spring Cloud integrates Ribbon and Eureka, as well as Spring Cloud LoadBalancer to provide a load-balanced http client when using Feign.
|
||||||
|
|
||||||
[[netflix-feign-starter]]
|
[[netflix-feign-starter]]
|
||||||
=== How to Include Feign
|
=== How to Include Feign
|
||||||
@@ -52,22 +52,24 @@ public interface StoreClient {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
In the `@FeignClient` annotation the String value ("stores" above) is
|
In the `@FeignClient` annotation the String value ("stores" above) is an arbitrary client name, which is used to create either a https://github.com/Netflix/ribbon[Ribbon] load-balancer (see <<spring-cloud-ribbon,below for details of Ribbon support>>) or https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-commons/src/main/java/org/springframework/cloud/client/loadbalancer/reactive/ReactiveLoadBalancer.java[Spring Cloud LoadBalancer].
|
||||||
an arbitrary client name, which is used to create a Ribbon load
|
You can also specify a URL using the `url` attribute
|
||||||
balancer (see <<spring-cloud-ribbon,below for details of Ribbon
|
|
||||||
support>>). You can also specify a URL using the `url` attribute
|
|
||||||
(absolute value or just a hostname). The name of the bean in the
|
(absolute value or just a hostname). The name of the bean in the
|
||||||
application context is the fully qualified name of the interface.
|
application context is the fully qualified name of the interface.
|
||||||
To specify your own alias value you can use the `qualifier` value
|
To specify your own alias value you can use the `qualifier` value
|
||||||
of the `@FeignClient` annotation.
|
of the `@FeignClient` annotation.
|
||||||
|
|
||||||
The Ribbon client above will want to discover the physical addresses
|
The load-balancer client above will want to discover the physical addresses
|
||||||
for the "stores" service. If your application is a Eureka client then
|
for the "stores" service. If your application is a Eureka client then
|
||||||
it will resolve the service in the Eureka service registry. If you
|
it will resolve the service in the Eureka service registry. If you
|
||||||
don't want to use Eureka, you can simply configure a list of servers
|
don't want to use Eureka, you can simply configure a list of servers
|
||||||
in your external configuration (see
|
in your external configuration (see
|
||||||
<<spring-cloud-ribbon-without-eureka,above for example>>).
|
<<spring-cloud-ribbon-without-eureka,above for example>>).
|
||||||
|
|
||||||
|
WARNING: In order to maintain backward compatibility, is used as the default load-balancer implementation.
|
||||||
|
However, Spring Cloud Netflix Ribbon is now in maintenance mode, so we recommend using Spring Cloud LoadBalancer instead.
|
||||||
|
To do this, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false`.
|
||||||
|
|
||||||
[[spring-cloud-feign-overriding-defaults]]
|
[[spring-cloud-feign-overriding-defaults]]
|
||||||
=== Overriding Feign Defaults
|
=== Overriding Feign Defaults
|
||||||
|
|
||||||
@@ -115,10 +117,13 @@ Spring Cloud Netflix provides the following beans by default for feign (`BeanTyp
|
|||||||
* `Logger` feignLogger: `Slf4jLogger`
|
* `Logger` feignLogger: `Slf4jLogger`
|
||||||
* `Contract` feignContract: `SpringMvcContract`
|
* `Contract` feignContract: `SpringMvcContract`
|
||||||
* `Feign.Builder` feignBuilder: `HystrixFeign.Builder`
|
* `Feign.Builder` feignBuilder: `HystrixFeign.Builder`
|
||||||
* `Client` feignClient: if Ribbon is enabled it is a `LoadBalancerFeignClient`, otherwise the default feign client is used.
|
* `Client` feignClient: if Ribbon is in the classpath and is enabled it is a `LoadBalancerFeignClient`, otherwise if Spring Cloud LoadBalancer is in the classpath, `FeignBlockingLoadBalancerClient` is used.
|
||||||
|
If none of them is in the classpath, the default feign client is used.
|
||||||
|
|
||||||
|
NOTE: `spring-cloud-starter-openfeign` contains both `spring-cloud-starter-netflix-ribbon` and `spring-cloud-starter-loadbalancer`.
|
||||||
|
|
||||||
The OkHttpClient and ApacheHttpClient feign clients can be used by setting `feign.okhttp.enabled` or `feign.httpclient.enabled` to `true`, respectively, and having them on the classpath.
|
The OkHttpClient and ApacheHttpClient feign clients can be used by setting `feign.okhttp.enabled` or `feign.httpclient.enabled` to `true`, respectively, and having them on the classpath.
|
||||||
You can customize the HTTP client used by providing a bean of either `ClosableHttpClient` when using Apache or `OkHttpClient` when using OK HTTP.
|
You can customize the HTTP client used by providing a bean of either `org.apache.http.impl.client.CloseableHttpClient` when using Apache or `okhttp3.OkHttpClient` when using OK HTTP.
|
||||||
|
|
||||||
Spring Cloud Netflix _does not_ provide the following beans by default for feign, but still looks up beans of these types from the application context to create the feign client:
|
Spring Cloud Netflix _does not_ provide the following beans by default for feign, but still looks up beans of these types from the application context to create the feign client:
|
||||||
|
|
||||||
@@ -128,6 +133,7 @@ Spring Cloud Netflix _does not_ provide the following beans by default for feign
|
|||||||
* `Request.Options`
|
* `Request.Options`
|
||||||
* `Collection<RequestInterceptor>`
|
* `Collection<RequestInterceptor>`
|
||||||
* `SetterFactory`
|
* `SetterFactory`
|
||||||
|
* `QueryMapEncoder`
|
||||||
|
|
||||||
Creating a bean of one of those type and placing it in a `@FeignClient` configuration (such as `FooConfiguration` above) allows you to override each one of the beans described. Example:
|
Creating a bean of one of those type and placing it in a `@FeignClient` configuration (such as `FooConfiguration` above) allows you to override each one of the beans described. Example:
|
||||||
|
|
||||||
@@ -257,14 +263,14 @@ class FooController {
|
|||||||
.decoder(decoder)
|
.decoder(decoder)
|
||||||
.contract(contract)
|
.contract(contract)
|
||||||
.requestInterceptor(new BasicAuthRequestInterceptor("user", "user"))
|
.requestInterceptor(new BasicAuthRequestInterceptor("user", "user"))
|
||||||
.target(FooClient.class, "http://PROD-SVC");
|
.target(FooClient.class, "https://PROD-SVC");
|
||||||
|
|
||||||
this.adminClient = Feign.builder().client(client)
|
this.adminClient = Feign.builder().client(client)
|
||||||
.encoder(encoder)
|
.encoder(encoder)
|
||||||
.decoder(decoder)
|
.decoder(decoder)
|
||||||
.contract(contract)
|
.contract(contract)
|
||||||
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
|
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
|
||||||
.target(FooClient.class, "http://PROD-SVC");
|
.target(FooClient.class, "https://PROD-SVC");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
@@ -423,6 +429,14 @@ feign.compression.request.min-request-size=2048
|
|||||||
|
|
||||||
These properties allow you to be selective about the compressed media types and minimum request threshold length.
|
These properties allow you to be selective about the compressed media types and minimum request threshold length.
|
||||||
|
|
||||||
|
For http clients except OkHttpClient, default gzip decoder can be enabled to decode gzip response in UTF-8 encoding:
|
||||||
|
|
||||||
|
[source,java]
|
||||||
|
----
|
||||||
|
feign.compression.response.enabled=true
|
||||||
|
feign.compression.response.useGzipDecoder=true
|
||||||
|
----
|
||||||
|
|
||||||
=== Feign logging
|
=== Feign logging
|
||||||
|
|
||||||
A logger is created for each Feign client created. By default the name of the logger is the full class name of the interface used to create the Feign client. Feign logging only responds to the `DEBUG` level.
|
A logger is created for each Feign client created. By default the name of the logger is the full class name of the interface used to create the Feign client. Feign logging only responds to the `DEBUG` level.
|
||||||
@@ -481,9 +495,48 @@ The following feign client uses the `Params` class by using the `@SpringQueryMap
|
|||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
@FeignClient("demo")
|
@FeignClient("demo")
|
||||||
public class DemoTemplate {
|
public interface DemoTemplate {
|
||||||
|
|
||||||
@GetMapping(path = "/demo")
|
@GetMapping(path = "/demo")
|
||||||
String demoEndpoint(@SpringQueryMap Params params);
|
String demoEndpoint(@SpringQueryMap Params params);
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
If you need more control over the generated query parameter map, you can implement a custom `QueryMapEncoder` bean.
|
||||||
|
|
||||||
|
=== HATEOAS support
|
||||||
|
|
||||||
|
Spring provides some APIs to create REST representations that follow the https://en.wikipedia.org/wiki/HATEOAS[HATEOAS] principle, https://spring.io/projects/spring-hateoas[Spring Hateoas] and https://spring.io/projects/spring-data-rest[Spring Data REST].
|
||||||
|
|
||||||
|
If your project use the `org.springframework.boot:spring-boot-starter-hateoas` starter
|
||||||
|
or the `org.springframework.boot:spring-boot-starter-data-rest` starter, Feign HATEOAS support is enabled by default.
|
||||||
|
|
||||||
|
When HATEOAS support is enabled, Feign clients are allowed to serialize
|
||||||
|
and deserialize HATEOAS representation models: https://docs.spring.io/spring-hateoas/docs/1.0.0.M1/apidocs/org/springframework/hateoas/EntityModel.html[EntityModel], https://docs.spring.io/spring-hateoas/docs/1.0.0.M1/apidocs/org/springframework/hateoas/CollectionModel.html[CollectionModel] and https://docs.spring.io/spring-hateoas/docs/1.0.0.M1/apidocs/org/springframework/hateoas/PagedModel.html[PagedModel].
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
@FeignClient("demo")
|
||||||
|
public interface DemoTemplate {
|
||||||
|
|
||||||
|
@GetMapping(path = "/stores")
|
||||||
|
CollectionModel<Store> getStores();
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
=== Troubleshooting
|
||||||
|
|
||||||
|
==== Early Initialization Errors
|
||||||
|
|
||||||
|
Depending on how you are using your Feign clients you may see initialization errors when starting your application.
|
||||||
|
To work around this problem you can use an `ObjectProvider` when autowiring your client.
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
@Autowired
|
||||||
|
ObjectProvider<TestFeginClient> testFeginClient;
|
||||||
|
----
|
||||||
|
|
||||||
|
== Configuration properties
|
||||||
|
|
||||||
|
To see the list of all Sleuth related configuration properties please check link:appendix.html[the Appendix page].
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
# "License"); you may not use this file except in compliance
|
# "License"); you may not use this file except in compliance
|
||||||
# with the License. You may obtain a copy of the License at
|
# with the License. You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing,
|
# Unless required by applicable law or agreed to in writing,
|
||||||
# software distributed under the License is distributed on an
|
# software distributed under the License is distributed on an
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
@REM "License"); you may not use this file except in compliance
|
@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 with the License. You may obtain a copy of the License at
|
||||||
@REM
|
@REM
|
||||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
@REM https://www.apache.org/licenses/LICENSE-2.0
|
||||||
@REM
|
@REM
|
||||||
@REM Unless required by applicable law or agreed to in writing,
|
@REM Unless required by applicable law or agreed to in writing,
|
||||||
@REM software distributed under the License is distributed on an
|
@REM software distributed under the License is distributed on an
|
||||||
|
|||||||
@@ -4,14 +4,14 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>spring-cloud-openfeign</artifactId>
|
<artifactId>spring-cloud-openfeign</artifactId>
|
||||||
<version>2.1.2.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>Spring Cloud OpenFeign</name>
|
<name>Spring Cloud OpenFeign</name>
|
||||||
<description>Spring Cloud OpenFeign</description>
|
<description>Spring Cloud OpenFeign</description>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-build</artifactId>
|
<artifactId>spring-cloud-build</artifactId>
|
||||||
<version>2.1.5.RELEASE</version>
|
<version>2.2.3.RELEASE</version>
|
||||||
<relativePath/>
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
<scm>
|
<scm>
|
||||||
@@ -26,8 +26,8 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<main.basedir>${basedir}</main.basedir>
|
<main.basedir>${basedir}</main.basedir>
|
||||||
<jackson.version>2.7.3</jackson.version>
|
<jackson.version>2.7.3</jackson.version>
|
||||||
<spring-cloud-commons.version>2.1.2.RELEASE</spring-cloud-commons.version>
|
<spring-cloud-commons.version>2.2.2.RELEASE</spring-cloud-commons.version>
|
||||||
<spring-cloud-netflix.version>2.1.2.RELEASE</spring-cloud-netflix.version>
|
<spring-cloud-netflix.version>2.2.2.RELEASE</spring-cloud-netflix.version>
|
||||||
|
|
||||||
<!-- Plugin versions -->
|
<!-- Plugin versions -->
|
||||||
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>
|
||||||
@@ -39,15 +39,13 @@
|
|||||||
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec
|
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec
|
||||||
</sonar.jacoco.reportPath>
|
</sonar.jacoco.reportPath>
|
||||||
<sonar.language>java</sonar.language>
|
<sonar.language>java</sonar.language>
|
||||||
|
|
||||||
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
|
|
||||||
<maven-checkstyle-plugin.failsOnViolation>true
|
|
||||||
</maven-checkstyle-plugin.failsOnViolation>
|
|
||||||
<maven-checkstyle-plugin.includeTestSourceDirectory>true
|
|
||||||
</maven-checkstyle-plugin.includeTestSourceDirectory>
|
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>flatten-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-eclipse-plugin</artifactId>
|
<artifactId>maven-eclipse-plugin</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,385 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-openfeign</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<relativePath>..</relativePath>
|
||||||
|
</parent>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<name>Spring Cloud OpenFeign Core</name>
|
||||||
|
<description>Spring Cloud OpenFeign Core</description>
|
||||||
|
<url>https://spring.io/spring-cloud/spring-cloud-openfeign/spring-cloud-openfeign-core</url>
|
||||||
|
<organization>
|
||||||
|
<name>Pivotal Software, Inc.</name>
|
||||||
|
<url>https://www.spring.io</url>
|
||||||
|
</organization>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>Apache License, Version 2.0</name>
|
||||||
|
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
|
||||||
|
<comments>Copyright 2014-2015 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.</comments>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>dsyer</id>
|
||||||
|
<name>Dave Syer</name>
|
||||||
|
<email>dsyer at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>lead</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>sgibb</id>
|
||||||
|
<name>Spencer Gibb</name>
|
||||||
|
<email>sgibb at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>lead</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>mgrzejszczak</id>
|
||||||
|
<name>Marcin Grzejszczak</name>
|
||||||
|
<email>mgrzejszczak at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>rbaxter</id>
|
||||||
|
<name>Ryan Baxter</name>
|
||||||
|
<email>rbaxter at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
<developer>
|
||||||
|
<id>omaciaszeksharma</id>
|
||||||
|
<name>Olga Maciaszek-Sharma</name>
|
||||||
|
<email>omaciaszeksharma at pivotal.io</email>
|
||||||
|
<organization>Pivotal Software, Inc.</organization>
|
||||||
|
<organizationUrl>https://www.spring.io</organizationUrl>
|
||||||
|
<roles>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:git://github.com/spring-cloud/spring-cloud-openfeign.git/spring-cloud-openfeign-core</connection>
|
||||||
|
<developerConnection>scm:git:ssh://git@github.com/spring-cloud/spring-cloud-openfeign.git/spring-cloud-openfeign-core</developerConnection>
|
||||||
|
<url>https://github.com/spring-cloud/spring-cloud-openfeign/spring-cloud-openfeign-core</url>
|
||||||
|
</scm>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-netflix-ribbon</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-reactor-netty</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-hateoas</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec-http</artifactId>
|
||||||
|
<version>4.1.45.Final</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.projectreactor</groupId>
|
||||||
|
<artifactId>reactor-core</artifactId>
|
||||||
|
<version>3.3.3.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.reactivex</groupId>
|
||||||
|
<artifactId>rxjava-reactive-streams</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.retry</groupId>
|
||||||
|
<artifactId>spring-retry</artifactId>
|
||||||
|
<version>1.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-commons</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-context</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netflix.ribbon</groupId>
|
||||||
|
<artifactId>ribbon-loadbalancer</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-core</artifactId>
|
||||||
|
<version>10.7.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign.form</groupId>
|
||||||
|
<artifactId>feign-form-spring</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-slf4j</artifactId>
|
||||||
|
<version>10.7.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-httpclient</artifactId>
|
||||||
|
<version>10.7.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-hystrix</artifactId>
|
||||||
|
<version>10.7.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-okhttp</artifactId>
|
||||||
|
<version>10.7.4</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netflix.hystrix</groupId>
|
||||||
|
<artifactId>hystrix-core</artifactId>
|
||||||
|
<version>1.5.18</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netflix.hystrix</groupId>
|
||||||
|
<artifactId>hystrix-serialization</artifactId>
|
||||||
|
<version>1.5.18</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netflix.hystrix</groupId>
|
||||||
|
<artifactId>hystrix-metrics-event-stream</artifactId>
|
||||||
|
<version>1.5.18</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netflix.hystrix</groupId>
|
||||||
|
<artifactId>hystrix-javanica</artifactId>
|
||||||
|
<version>1.5.18</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>jsr305</artifactId>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>aspectjrt</artifactId>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netflix.ribbon</groupId>
|
||||||
|
<artifactId>ribbon-core</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.netflix.ribbon</groupId>
|
||||||
|
<artifactId>ribbon-httpclient</artifactId>
|
||||||
|
<version>2.3.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.reactivex</groupId>
|
||||||
|
<artifactId>rxjava</artifactId>
|
||||||
|
<version>1.3.8</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>3.14.7</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-autoconfigure-processor</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-commons</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-loadbalancer</artifactId>
|
||||||
|
<version>2.2.2.RELEASE</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-openfeign</artifactId>
|
<artifactId>spring-cloud-openfeign</artifactId>
|
||||||
<version>2.1.2.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
<relativePath>..</relativePath> <!-- lookup parent from repository -->
|
<relativePath>..</relativePath> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-cloud-openfeign-core</artifactId>
|
<artifactId>spring-cloud-openfeign-core</artifactId>
|
||||||
@@ -50,6 +50,11 @@
|
|||||||
<artifactId>spring-boot-starter-reactor-netty</artifactId>
|
<artifactId>spring-boot-starter-reactor-netty</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-hateoas</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-codec-http</artifactId>
|
<artifactId>netty-codec-http</artifactId>
|
||||||
@@ -118,11 +123,6 @@
|
|||||||
<artifactId>feign-okhttp</artifactId>
|
<artifactId>feign-okhttp</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.openfeign</groupId>
|
|
||||||
<artifactId>feign-java8</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.netflix.hystrix</groupId>
|
<groupId>com.netflix.hystrix</groupId>
|
||||||
<artifactId>hystrix-core</artifactId>
|
<artifactId>hystrix-core</artifactId>
|
||||||
@@ -158,11 +158,6 @@
|
|||||||
<artifactId>rxjava</artifactId>
|
<artifactId>rxjava</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.jersey.contribs</groupId>
|
|
||||||
<artifactId>jersey-apache-client4</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp</artifactId>
|
||||||
@@ -208,6 +203,11 @@
|
|||||||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
|
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.googlecode.protobuf-java-format</groupId>
|
<groupId>com.googlecode.protobuf-java-format</groupId>
|
||||||
<artifactId>protobuf-java-format</artifactId>
|
<artifactId>protobuf-java-format</artifactId>
|
||||||
@@ -226,6 +226,11 @@
|
|||||||
<version>0.10.0</version>
|
<version>0.10.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-loadbalancer</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
|
|||||||
+8
-5
@@ -46,18 +46,21 @@ import org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionMa
|
|||||||
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
|
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
|
||||||
import org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory;
|
import org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory;
|
||||||
import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
|
import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
|
||||||
|
import org.springframework.cloud.openfeign.support.DefaultGzipDecoderConfiguration;
|
||||||
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
* @author Julien Roy
|
* @author Julien Roy
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(Feign.class)
|
@ConditionalOnClass(Feign.class)
|
||||||
@EnableConfigurationProperties({ FeignClientProperties.class,
|
@EnableConfigurationProperties({ FeignClientProperties.class,
|
||||||
FeignHttpClientProperties.class })
|
FeignHttpClientProperties.class })
|
||||||
|
@Import(DefaultGzipDecoderConfiguration.class)
|
||||||
public class FeignAutoConfiguration {
|
public class FeignAutoConfiguration {
|
||||||
|
|
||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
@@ -75,7 +78,7 @@ public class FeignAutoConfiguration {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(name = "feign.hystrix.HystrixFeign")
|
@ConditionalOnClass(name = "feign.hystrix.HystrixFeign")
|
||||||
protected static class HystrixFeignTargeterConfiguration {
|
protected static class HystrixFeignTargeterConfiguration {
|
||||||
|
|
||||||
@@ -87,7 +90,7 @@ public class FeignAutoConfiguration {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnMissingClass("feign.hystrix.HystrixFeign")
|
@ConditionalOnMissingClass("feign.hystrix.HystrixFeign")
|
||||||
protected static class DefaultFeignTargeterConfiguration {
|
protected static class DefaultFeignTargeterConfiguration {
|
||||||
|
|
||||||
@@ -103,7 +106,7 @@ public class FeignAutoConfiguration {
|
|||||||
// ribbon is not on the class path.
|
// ribbon is not on the class path.
|
||||||
// see corresponding configurations in FeignRibbonClientAutoConfiguration
|
// see corresponding configurations in FeignRibbonClientAutoConfiguration
|
||||||
// for load balanced ribbon clients.
|
// for load balanced ribbon clients.
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(ApacheHttpClient.class)
|
@ConditionalOnClass(ApacheHttpClient.class)
|
||||||
@ConditionalOnMissingClass("com.netflix.loadbalancer.ILoadBalancer")
|
@ConditionalOnMissingClass("com.netflix.loadbalancer.ILoadBalancer")
|
||||||
@ConditionalOnMissingBean(CloseableHttpClient.class)
|
@ConditionalOnMissingBean(CloseableHttpClient.class)
|
||||||
@@ -169,7 +172,7 @@ public class FeignAutoConfiguration {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(OkHttpClient.class)
|
@ConditionalOnClass(OkHttpClient.class)
|
||||||
@ConditionalOnMissingClass("com.netflix.loadbalancer.ILoadBalancer")
|
@ConditionalOnMissingClass("com.netflix.loadbalancer.ILoadBalancer")
|
||||||
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
|
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
|
||||||
|
|||||||
+1
-1
@@ -85,7 +85,7 @@ public @interface FeignClient {
|
|||||||
boolean decode404() default false;
|
boolean decode404() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom <code>@Configuration</code> for the feign client. Can contain override
|
* A custom configuration class for the feign client. Can contain override
|
||||||
* <code>@Bean</code> definition for the pieces that make up the client, for instance
|
* <code>@Bean</code> definition for the pieces that make up the client, for instance
|
||||||
* {@link feign.codec.Decoder}, {@link feign.codec.Encoder}, {@link feign.Contract}.
|
* {@link feign.codec.Decoder}, {@link feign.codec.Encoder}, {@link feign.Contract}.
|
||||||
*
|
*
|
||||||
|
|||||||
+11
-10
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign;
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
|
import feign.hystrix.FallbackFactory;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,47 +59,46 @@ public class FeignClientBuilder {
|
|||||||
this.feignClientFactoryBean.setContextId(FeignClientsRegistrar.getName(name));
|
this.feignClientFactoryBean.setContextId(FeignClientsRegistrar.getName(name));
|
||||||
// preset default values - these values resemble the default values on the
|
// preset default values - these values resemble the default values on the
|
||||||
// FeignClient annotation
|
// FeignClient annotation
|
||||||
this.url("").path("").decode404(false).fallback(void.class)
|
this.url("").path("").decode404(false);
|
||||||
.fallbackFactory(void.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder url(final String url) {
|
public Builder<T> url(final String url) {
|
||||||
this.feignClientFactoryBean.setUrl(FeignClientsRegistrar.getUrl(url));
|
this.feignClientFactoryBean.setUrl(FeignClientsRegistrar.getUrl(url));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder contextId(final String contextId) {
|
public Builder<T> contextId(final String contextId) {
|
||||||
this.feignClientFactoryBean.setContextId(contextId);
|
this.feignClientFactoryBean.setContextId(contextId);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder path(final String path) {
|
public Builder<T> path(final String path) {
|
||||||
this.feignClientFactoryBean.setPath(FeignClientsRegistrar.getPath(path));
|
this.feignClientFactoryBean.setPath(FeignClientsRegistrar.getPath(path));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder decode404(final boolean decode404) {
|
public Builder<T> decode404(final boolean decode404) {
|
||||||
this.feignClientFactoryBean.setDecode404(decode404);
|
this.feignClientFactoryBean.setDecode404(decode404);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fallback(final Class<T> fallback) {
|
public Builder<T> fallback(final Class<? extends T> fallback) {
|
||||||
FeignClientsRegistrar.validateFallback(fallback);
|
FeignClientsRegistrar.validateFallback(fallback);
|
||||||
this.feignClientFactoryBean.setFallback(fallback);
|
this.feignClientFactoryBean.setFallback(fallback);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder fallbackFactory(final Class<T> fallbackFactory) {
|
public Builder<T> fallbackFactory(
|
||||||
|
final Class<? extends FallbackFactory<? extends T>> fallbackFactory) {
|
||||||
FeignClientsRegistrar.validateFallbackFactory(fallbackFactory);
|
FeignClientsRegistrar.validateFallbackFactory(fallbackFactory);
|
||||||
this.feignClientFactoryBean.setFallbackFactory(fallbackFactory);
|
this.feignClientFactoryBean.setFallbackFactory(fallbackFactory);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <T> the target type of the Feign client to be created
|
|
||||||
* @return the created Feign client
|
* @return the created Feign client
|
||||||
*/
|
*/
|
||||||
public <T> T build() {
|
public T build() {
|
||||||
return this.feignClientFactoryBean.getTarget();
|
return this.feignClientFactoryBean.getTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-1
@@ -21,8 +21,10 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.Contract;
|
import feign.Contract;
|
||||||
|
import feign.ExceptionPropagationPolicy;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
|
import feign.QueryMapEncoder;
|
||||||
import feign.Request;
|
import feign.Request;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.Retryer;
|
import feign.Retryer;
|
||||||
@@ -36,6 +38,7 @@ import org.springframework.beans.BeansException;
|
|||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
|
import org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient;
|
||||||
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
|
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
@@ -147,10 +150,18 @@ class FeignClientFactoryBean
|
|||||||
if (requestInterceptors != null) {
|
if (requestInterceptors != null) {
|
||||||
builder.requestInterceptors(requestInterceptors.values());
|
builder.requestInterceptors(requestInterceptors.values());
|
||||||
}
|
}
|
||||||
|
QueryMapEncoder queryMapEncoder = getOptional(context, QueryMapEncoder.class);
|
||||||
|
if (queryMapEncoder != null) {
|
||||||
|
builder.queryMapEncoder(queryMapEncoder);
|
||||||
|
}
|
||||||
if (this.decode404) {
|
if (this.decode404) {
|
||||||
builder.decode404();
|
builder.decode404();
|
||||||
}
|
}
|
||||||
|
ExceptionPropagationPolicy exceptionPropagationPolicy = getOptional(context,
|
||||||
|
ExceptionPropagationPolicy.class);
|
||||||
|
if (exceptionPropagationPolicy != null) {
|
||||||
|
builder.exceptionPropagationPolicy(exceptionPropagationPolicy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void configureUsingProperties(
|
protected void configureUsingProperties(
|
||||||
@@ -205,6 +216,10 @@ class FeignClientFactoryBean
|
|||||||
if (Objects.nonNull(config.getContract())) {
|
if (Objects.nonNull(config.getContract())) {
|
||||||
builder.contract(getOrInstantiate(config.getContract()));
|
builder.contract(getOrInstantiate(config.getContract()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Objects.nonNull(config.getExceptionPropagationPolicy())) {
|
||||||
|
builder.exceptionPropagationPolicy(config.getExceptionPropagationPolicy());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> T getOrInstantiate(Class<T> tClass) {
|
private <T> T getOrInstantiate(Class<T> tClass) {
|
||||||
@@ -278,6 +293,11 @@ class FeignClientFactoryBean
|
|||||||
// but ribbon is on the classpath, so unwrap
|
// but ribbon is on the classpath, so unwrap
|
||||||
client = ((LoadBalancerFeignClient) client).getDelegate();
|
client = ((LoadBalancerFeignClient) client).getDelegate();
|
||||||
}
|
}
|
||||||
|
if (client instanceof FeignBlockingLoadBalancerClient) {
|
||||||
|
// not load balancing because we have a url,
|
||||||
|
// but Spring Cloud LoadBalancer is on the classpath, so unwrap
|
||||||
|
client = ((FeignBlockingLoadBalancerClient) client).getDelegate();
|
||||||
|
}
|
||||||
builder.client(client);
|
builder.client(client);
|
||||||
}
|
}
|
||||||
Targeter targeter = get(context, Targeter.class);
|
Targeter targeter = get(context, Targeter.class);
|
||||||
|
|||||||
+17
-2
@@ -22,6 +22,7 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import feign.Contract;
|
import feign.Contract;
|
||||||
|
import feign.ExceptionPropagationPolicy;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.Retryer;
|
import feign.Retryer;
|
||||||
@@ -111,6 +112,8 @@ public class FeignClientProperties {
|
|||||||
|
|
||||||
private Class<Contract> contract;
|
private Class<Contract> contract;
|
||||||
|
|
||||||
|
private ExceptionPropagationPolicy exceptionPropagationPolicy;
|
||||||
|
|
||||||
public Logger.Level getLoggerLevel() {
|
public Logger.Level getLoggerLevel() {
|
||||||
return this.loggerLevel;
|
return this.loggerLevel;
|
||||||
}
|
}
|
||||||
@@ -192,6 +195,15 @@ public class FeignClientProperties {
|
|||||||
this.contract = contract;
|
this.contract = contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExceptionPropagationPolicy getExceptionPropagationPolicy() {
|
||||||
|
return exceptionPropagationPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExceptionPropagationPolicy(
|
||||||
|
ExceptionPropagationPolicy exceptionPropagationPolicy) {
|
||||||
|
this.exceptionPropagationPolicy = exceptionPropagationPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
@@ -210,14 +222,17 @@ public class FeignClientProperties {
|
|||||||
&& Objects.equals(this.decode404, that.decode404)
|
&& Objects.equals(this.decode404, that.decode404)
|
||||||
&& Objects.equals(this.encoder, that.encoder)
|
&& Objects.equals(this.encoder, that.encoder)
|
||||||
&& Objects.equals(this.decoder, that.decoder)
|
&& Objects.equals(this.decoder, that.decoder)
|
||||||
&& Objects.equals(this.contract, that.contract);
|
&& Objects.equals(this.contract, that.contract)
|
||||||
|
&& Objects.equals(this.exceptionPropagationPolicy,
|
||||||
|
that.exceptionPropagationPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(this.loggerLevel, this.connectTimeout, this.readTimeout,
|
return Objects.hash(this.loggerLevel, this.connectTimeout, this.readTimeout,
|
||||||
this.retryer, this.errorDecoder, this.requestInterceptors,
|
this.retryer, this.errorDecoder, this.requestInterceptors,
|
||||||
this.decode404, this.encoder, this.decoder, this.contract);
|
this.decode404, this.encoder, this.decoder, this.contract,
|
||||||
|
this.exceptionPropagationPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-3
@@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
import org.springframework.cloud.openfeign.support.PageJacksonModule;
|
import org.springframework.cloud.openfeign.support.PageJacksonModule;
|
||||||
import org.springframework.cloud.openfeign.support.PageableSpringEncoder;
|
import org.springframework.cloud.openfeign.support.PageableSpringEncoder;
|
||||||
@@ -54,7 +55,7 @@ import org.springframework.format.support.FormattingConversionService;
|
|||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Venil Noronha
|
* @author Venil Noronha
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class FeignClientsConfiguration {
|
public class FeignClientsConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -69,6 +70,9 @@ public class FeignClientsConfiguration {
|
|||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private SpringDataWebProperties springDataWebProperties;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public Decoder feignDecoder() {
|
public Decoder feignDecoder() {
|
||||||
@@ -87,7 +91,17 @@ public class FeignClientsConfiguration {
|
|||||||
@ConditionalOnClass(name = "org.springframework.data.domain.Pageable")
|
@ConditionalOnClass(name = "org.springframework.data.domain.Pageable")
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public Encoder feignEncoderPageable() {
|
public Encoder feignEncoderPageable() {
|
||||||
return new PageableSpringEncoder(new SpringEncoder(this.messageConverters));
|
PageableSpringEncoder encoder = new PageableSpringEncoder(
|
||||||
|
new SpringEncoder(this.messageConverters));
|
||||||
|
if (springDataWebProperties != null) {
|
||||||
|
encoder.setPageParameter(
|
||||||
|
springDataWebProperties.getPageable().getPageParameter());
|
||||||
|
encoder.setSizeParameter(
|
||||||
|
springDataWebProperties.getPageable().getSizeParameter());
|
||||||
|
encoder.setSortParameter(
|
||||||
|
springDataWebProperties.getSort().getSortParameter());
|
||||||
|
}
|
||||||
|
return encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -130,7 +144,7 @@ public class FeignClientsConfiguration {
|
|||||||
return new PageJacksonModule();
|
return new PageJacksonModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({ HystrixCommand.class, HystrixFeign.class })
|
@ConditionalOnClass({ HystrixCommand.class, HystrixFeign.class })
|
||||||
protected static class HystrixFeignConfiguration {
|
protected static class HystrixFeignConfiguration {
|
||||||
|
|
||||||
|
|||||||
+7
-5
@@ -22,6 +22,8 @@ import feign.hystrix.FallbackFactory;
|
|||||||
import feign.hystrix.HystrixFeign;
|
import feign.hystrix.HystrixFeign;
|
||||||
import feign.hystrix.SetterFactory;
|
import feign.hystrix.SetterFactory;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
* @author Erik Kringen
|
* @author Erik Kringen
|
||||||
@@ -36,19 +38,19 @@ class HystrixTargeter implements Targeter {
|
|||||||
return feign.target(target);
|
return feign.target(target);
|
||||||
}
|
}
|
||||||
feign.hystrix.HystrixFeign.Builder builder = (feign.hystrix.HystrixFeign.Builder) feign;
|
feign.hystrix.HystrixFeign.Builder builder = (feign.hystrix.HystrixFeign.Builder) feign;
|
||||||
SetterFactory setterFactory = getOptional(factory.getName(), context,
|
String name = StringUtils.isEmpty(factory.getContextId()) ? factory.getName()
|
||||||
SetterFactory.class);
|
: factory.getContextId();
|
||||||
|
SetterFactory setterFactory = getOptional(name, context, SetterFactory.class);
|
||||||
if (setterFactory != null) {
|
if (setterFactory != null) {
|
||||||
builder.setterFactory(setterFactory);
|
builder.setterFactory(setterFactory);
|
||||||
}
|
}
|
||||||
Class<?> fallback = factory.getFallback();
|
Class<?> fallback = factory.getFallback();
|
||||||
if (fallback != void.class) {
|
if (fallback != void.class) {
|
||||||
return targetWithFallback(factory.getName(), context, target, builder,
|
return targetWithFallback(name, context, target, builder, fallback);
|
||||||
fallback);
|
|
||||||
}
|
}
|
||||||
Class<?> fallbackFactory = factory.getFallbackFactory();
|
Class<?> fallbackFactory = factory.getFallbackFactory();
|
||||||
if (fallbackFactory != void.class) {
|
if (fallbackFactory != void.class) {
|
||||||
return targetWithFallbackFactory(factory.getName(), context, target, builder,
|
return targetWithFallbackFactory(name, context, target, builder,
|
||||||
fallbackFactory);
|
fallbackFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import feign.MethodMetadata;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
|
||||||
|
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||||
|
|
||||||
|
import static feign.Util.checkState;
|
||||||
|
import static feign.Util.emptyToNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link MatrixVariable} annotation processor.
|
||||||
|
*
|
||||||
|
* Can expand maps or single objects. Values are assigned from the objects
|
||||||
|
* {@code toString()} method.
|
||||||
|
*
|
||||||
|
* @author Matt King
|
||||||
|
* @see AnnotatedParameterProcessor
|
||||||
|
*/
|
||||||
|
public class MatrixVariableParameterProcessor implements AnnotatedParameterProcessor {
|
||||||
|
|
||||||
|
private static final Class<MatrixVariable> ANNOTATION = MatrixVariable.class;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> getAnnotationType() {
|
||||||
|
return ANNOTATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean processArgument(AnnotatedParameterContext context,
|
||||||
|
Annotation annotation, Method method) {
|
||||||
|
int parameterIndex = context.getParameterIndex();
|
||||||
|
Class<?> parameterType = method.getParameterTypes()[parameterIndex];
|
||||||
|
MethodMetadata data = context.getMethodMetadata();
|
||||||
|
String name = ANNOTATION.cast(annotation).value();
|
||||||
|
|
||||||
|
checkState(emptyToNull(name) != null,
|
||||||
|
"MatrixVariable annotation was empty on param %s.",
|
||||||
|
context.getParameterIndex());
|
||||||
|
|
||||||
|
context.setParameterName(name);
|
||||||
|
|
||||||
|
if (Map.class.isAssignableFrom(parameterType)) {
|
||||||
|
data.indexToExpander().put(parameterIndex, this::expandMap);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data.indexToExpander().put(parameterIndex,
|
||||||
|
object -> ";" + name + "=" + object.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String expandMap(Object object) {
|
||||||
|
Map<String, Object> paramMap = (Map) object;
|
||||||
|
|
||||||
|
return paramMap.keySet().stream()
|
||||||
|
.map(key -> ";" + key + "=" + paramMap.get(key).toString())
|
||||||
|
.collect(Collectors.joining());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import feign.MethodMetadata;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
|
||||||
|
import org.springframework.web.bind.annotation.RequestPart;
|
||||||
|
|
||||||
|
import static feign.Util.checkState;
|
||||||
|
import static feign.Util.emptyToNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link RequestPart} parameter processor.
|
||||||
|
*
|
||||||
|
* @author Aaron Whiteside
|
||||||
|
* @see AnnotatedParameterProcessor
|
||||||
|
*/
|
||||||
|
public class RequestPartParameterProcessor implements AnnotatedParameterProcessor {
|
||||||
|
|
||||||
|
private static final Class<RequestPart> ANNOTATION = RequestPart.class;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Annotation> getAnnotationType() {
|
||||||
|
return ANNOTATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean processArgument(AnnotatedParameterContext context,
|
||||||
|
Annotation annotation, Method method) {
|
||||||
|
int parameterIndex = context.getParameterIndex();
|
||||||
|
MethodMetadata data = context.getMethodMetadata();
|
||||||
|
|
||||||
|
String name = ANNOTATION.cast(annotation).value();
|
||||||
|
checkState(emptyToNull(name) != null,
|
||||||
|
"RequestPart.value() was empty on parameter %s", parameterIndex);
|
||||||
|
context.setParameterName(name);
|
||||||
|
|
||||||
|
data.formParams().add(name);
|
||||||
|
Collection<String> names = context.setTemplateParameter(name,
|
||||||
|
data.indexToName().get(parameterIndex));
|
||||||
|
data.indexToName().put(parameterIndex, names);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+123
@@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.clientconfig;
|
||||||
|
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.config.RegistryBuilder;
|
||||||
|
import org.apache.http.conn.HttpClientConnectionManager;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory;
|
||||||
|
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
|
||||||
|
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default configuration for {@link CloseableHttpClient}.
|
||||||
|
*
|
||||||
|
* @author Ryan Baxter
|
||||||
|
* @author Marcin Grzejszczak
|
||||||
|
* @author Spencer Gibb
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnMissingBean(CloseableHttpClient.class)
|
||||||
|
public class HttpClientFeignConfiguration {
|
||||||
|
|
||||||
|
private final Timer connectionManagerTimer = new Timer(
|
||||||
|
"FeignApacheHttpClientConfiguration.connectionManagerTimer", true);
|
||||||
|
|
||||||
|
private CloseableHttpClient httpClient;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private RegistryBuilder registryBuilder;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(HttpClientConnectionManager.class)
|
||||||
|
public HttpClientConnectionManager connectionManager(
|
||||||
|
ApacheHttpClientConnectionManagerFactory connectionManagerFactory,
|
||||||
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
|
final HttpClientConnectionManager connectionManager = connectionManagerFactory
|
||||||
|
.newConnectionManager(httpClientProperties.isDisableSslValidation(),
|
||||||
|
httpClientProperties.getMaxConnections(),
|
||||||
|
httpClientProperties.getMaxConnectionsPerRoute(),
|
||||||
|
httpClientProperties.getTimeToLive(),
|
||||||
|
httpClientProperties.getTimeToLiveUnit(), this.registryBuilder);
|
||||||
|
this.connectionManagerTimer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
connectionManager.closeExpiredConnections();
|
||||||
|
}
|
||||||
|
}, 30000, httpClientProperties.getConnectionTimerRepeat());
|
||||||
|
return connectionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(value = "feign.compression.response.enabled",
|
||||||
|
havingValue = "true")
|
||||||
|
public CloseableHttpClient customHttpClient(
|
||||||
|
HttpClientConnectionManager httpClientConnectionManager,
|
||||||
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
|
HttpClientBuilder builder = HttpClientBuilder.create().disableCookieManagement()
|
||||||
|
.useSystemProperties();
|
||||||
|
this.httpClient = createClient(builder, httpClientConnectionManager,
|
||||||
|
httpClientProperties);
|
||||||
|
return this.httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(value = "feign.compression.response.enabled",
|
||||||
|
havingValue = "false", matchIfMissing = true)
|
||||||
|
public CloseableHttpClient httpClient(ApacheHttpClientFactory httpClientFactory,
|
||||||
|
HttpClientConnectionManager httpClientConnectionManager,
|
||||||
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
|
this.httpClient = createClient(httpClientFactory.createBuilder(),
|
||||||
|
httpClientConnectionManager, httpClientProperties);
|
||||||
|
return this.httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CloseableHttpClient createClient(HttpClientBuilder builder,
|
||||||
|
HttpClientConnectionManager httpClientConnectionManager,
|
||||||
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
|
RequestConfig defaultRequestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(httpClientProperties.getConnectionTimeout())
|
||||||
|
.setRedirectsEnabled(httpClientProperties.isFollowRedirects()).build();
|
||||||
|
CloseableHttpClient httpClient = builder
|
||||||
|
.setDefaultRequestConfig(defaultRequestConfig)
|
||||||
|
.setConnectionManager(httpClientConnectionManager).build();
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() throws Exception {
|
||||||
|
this.connectionManagerTimer.cancel();
|
||||||
|
if (this.httpClient != null) {
|
||||||
|
this.httpClient.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.clientconfig;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import okhttp3.ConnectionPool;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory;
|
||||||
|
import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
|
||||||
|
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defualt configuration for {@link OkHttpClient}.
|
||||||
|
*
|
||||||
|
* @author Ryan Baxter
|
||||||
|
* @author Marcin Grzejszczak
|
||||||
|
* @author Spencer Gibb
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
|
||||||
|
public class OkHttpFeignConfiguration {
|
||||||
|
|
||||||
|
private okhttp3.OkHttpClient okHttpClient;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(ConnectionPool.class)
|
||||||
|
public ConnectionPool httpClientConnectionPool(
|
||||||
|
FeignHttpClientProperties httpClientProperties,
|
||||||
|
OkHttpClientConnectionPoolFactory connectionPoolFactory) {
|
||||||
|
Integer maxTotalConnections = httpClientProperties.getMaxConnections();
|
||||||
|
Long timeToLive = httpClientProperties.getTimeToLive();
|
||||||
|
TimeUnit ttlUnit = httpClientProperties.getTimeToLiveUnit();
|
||||||
|
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public okhttp3.OkHttpClient client(OkHttpClientFactory httpClientFactory,
|
||||||
|
ConnectionPool connectionPool,
|
||||||
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
|
Boolean followRedirects = httpClientProperties.isFollowRedirects();
|
||||||
|
Integer connectTimeout = httpClientProperties.getConnectionTimeout();
|
||||||
|
this.okHttpClient = httpClientFactory
|
||||||
|
.createBuilder(httpClientProperties.isDisableSslValidation())
|
||||||
|
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
||||||
|
.followRedirects(followRedirects).connectionPool(connectionPool).build();
|
||||||
|
return this.okHttpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void destroy() {
|
||||||
|
if (this.okHttpClient != null) {
|
||||||
|
this.okHttpClient.dispatcher().executorService().shutdown();
|
||||||
|
this.okHttpClient.connectionPool().evictAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+3
-2
@@ -35,11 +35,12 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
* @see FeignAcceptGzipEncodingInterceptor
|
* @see FeignAcceptGzipEncodingInterceptor
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
|
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
|
||||||
@ConditionalOnClass(Feign.class)
|
@ConditionalOnClass(Feign.class)
|
||||||
@ConditionalOnBean(Client.class)
|
@ConditionalOnBean(Client.class)
|
||||||
@ConditionalOnProperty(value = "feign.compression.response.enabled", matchIfMissing = false)
|
@ConditionalOnProperty(value = "feign.compression.response.enabled",
|
||||||
|
matchIfMissing = false)
|
||||||
// The OK HTTP client uses "transparent" compression.
|
// The OK HTTP client uses "transparent" compression.
|
||||||
// If the accept-encoding header is present it disable transparent compression
|
// If the accept-encoding header is present it disable transparent compression
|
||||||
@ConditionalOnMissingBean(type = "okhttp3.OkHttpClient")
|
@ConditionalOnMissingBean(type = "okhttp3.OkHttpClient")
|
||||||
|
|||||||
+3
-2
@@ -35,14 +35,15 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
* @see FeignContentGzipEncodingInterceptor
|
* @see FeignContentGzipEncodingInterceptor
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
|
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
|
||||||
@ConditionalOnClass(Feign.class)
|
@ConditionalOnClass(Feign.class)
|
||||||
@ConditionalOnBean(Client.class)
|
@ConditionalOnBean(Client.class)
|
||||||
// The OK HTTP client uses "transparent" compression.
|
// The OK HTTP client uses "transparent" compression.
|
||||||
// If the content-encoding header is present it disable transparent compression
|
// If the content-encoding header is present it disable transparent compression
|
||||||
@ConditionalOnMissingBean(type = "okhttp3.OkHttpClient")
|
@ConditionalOnMissingBean(type = "okhttp3.OkHttpClient")
|
||||||
@ConditionalOnProperty(value = "feign.compression.request.enabled", matchIfMissing = false)
|
@ConditionalOnProperty(value = "feign.compression.request.enabled",
|
||||||
|
matchIfMissing = false)
|
||||||
@AutoConfigureAfter(FeignAutoConfiguration.class)
|
@AutoConfigureAfter(FeignAutoConfiguration.class)
|
||||||
public class FeignContentGzipEncodingAutoConfiguration {
|
public class FeignContentGzipEncodingAutoConfiguration {
|
||||||
|
|
||||||
|
|||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
import org.springframework.hateoas.mediatype.MessageResolver;
|
||||||
|
import org.springframework.hateoas.mediatype.hal.CurieProvider;
|
||||||
|
import org.springframework.hateoas.mediatype.hal.DefaultCurieProvider;
|
||||||
|
import org.springframework.hateoas.mediatype.hal.HalConfiguration;
|
||||||
|
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
|
||||||
|
import org.springframework.hateoas.server.LinkRelationProvider;
|
||||||
|
import org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
||||||
|
|
||||||
|
import static org.springframework.hateoas.MediaTypes.HAL_JSON;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnWebApplication
|
||||||
|
@ConditionalOnClass(RepresentationModel.class)
|
||||||
|
@AutoConfigureAfter({ JacksonAutoConfiguration.class,
|
||||||
|
HttpMessageConvertersAutoConfiguration.class,
|
||||||
|
RepositoryRestMvcAutoConfiguration.class })
|
||||||
|
@AutoConfigureBefore(HypermediaAutoConfiguration.class)
|
||||||
|
public class FeignHalAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public TypeConstrainedMappingJackson2HttpMessageConverter halJacksonHttpMessageConverter(
|
||||||
|
ObjectProvider<ObjectMapper> objectMapper,
|
||||||
|
ObjectProvider<HalConfiguration> halConfiguration,
|
||||||
|
ObjectProvider<MessageResolver> messageResolver,
|
||||||
|
ObjectProvider<CurieProvider> curieProvider,
|
||||||
|
ObjectProvider<LinkRelationProvider> linkRelationProvider) {
|
||||||
|
|
||||||
|
ObjectMapper mapper = objectMapper.getIfAvailable(ObjectMapper::new).copy();
|
||||||
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
|
|
||||||
|
HalConfiguration configuration = halConfiguration
|
||||||
|
.getIfAvailable(HalConfiguration::new);
|
||||||
|
|
||||||
|
CurieProvider curieProviderInstance = curieProvider
|
||||||
|
.getIfAvailable(() -> new DefaultCurieProvider(Collections.emptyMap()));
|
||||||
|
|
||||||
|
Jackson2HalModule.HalHandlerInstantiator halHandlerInstantiator = new Jackson2HalModule.HalHandlerInstantiator(
|
||||||
|
linkRelationProvider.getIfAvailable(), curieProviderInstance,
|
||||||
|
messageResolver.getIfAvailable(), configuration);
|
||||||
|
|
||||||
|
mapper.setHandlerInstantiator(halHandlerInstantiator);
|
||||||
|
|
||||||
|
if (!Jackson2HalModule.isAlreadyRegisteredIn(mapper)) {
|
||||||
|
Jackson2HalModule halModule = new Jackson2HalModule();
|
||||||
|
mapper.registerModule(halModule);
|
||||||
|
}
|
||||||
|
|
||||||
|
TypeConstrainedMappingJackson2HttpMessageConverter converter = new TypeConstrainedMappingJackson2HttpMessageConverter(
|
||||||
|
RepresentationModel.class);
|
||||||
|
converter.setSupportedMediaTypes(Arrays.asList(HAL_JSON));
|
||||||
|
converter.setObjectMapper(mapper);
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration instantiating a {@link BlockingLoadBalancerClient}-based {@link Client}
|
||||||
|
* object that uses {@link Client.Default} under the hood.
|
||||||
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @since 2.2.0
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
class DefaultFeignLoadBalancerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public Client feignClient(BlockingLoadBalancerClient loadBalancerClient) {
|
||||||
|
return new FeignBlockingLoadBalancerClient(new Client.Default(null, null),
|
||||||
|
loadBalancerClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import feign.Request;
|
||||||
|
import feign.Response;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
|
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link Client} implementation that uses {@link BlockingLoadBalancerClient} to select
|
||||||
|
* a {@link ServiceInstance} to use while resolving the request host.
|
||||||
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @since 2.2.0
|
||||||
|
*/
|
||||||
|
public class FeignBlockingLoadBalancerClient implements Client {
|
||||||
|
|
||||||
|
private static final Log LOG = LogFactory
|
||||||
|
.getLog(FeignBlockingLoadBalancerClient.class);
|
||||||
|
|
||||||
|
private final Client delegate;
|
||||||
|
|
||||||
|
private final BlockingLoadBalancerClient loadBalancerClient;
|
||||||
|
|
||||||
|
public FeignBlockingLoadBalancerClient(Client delegate,
|
||||||
|
BlockingLoadBalancerClient loadBalancerClient) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Response execute(Request request, Request.Options options) throws IOException {
|
||||||
|
final URI originalUri = URI.create(request.url());
|
||||||
|
String serviceId = originalUri.getHost();
|
||||||
|
Assert.state(serviceId != null,
|
||||||
|
"Request URI does not contain a valid hostname: " + originalUri);
|
||||||
|
ServiceInstance instance = loadBalancerClient.choose(serviceId);
|
||||||
|
if (instance == null) {
|
||||||
|
String message = "Load balancer does not contain an instance for the service "
|
||||||
|
+ serviceId;
|
||||||
|
if (LOG.isWarnEnabled()) {
|
||||||
|
LOG.warn(message);
|
||||||
|
}
|
||||||
|
return Response.builder().request(request)
|
||||||
|
.status(HttpStatus.SERVICE_UNAVAILABLE.value())
|
||||||
|
.body(message, StandardCharsets.UTF_8).build();
|
||||||
|
}
|
||||||
|
String reconstructedUrl = loadBalancerClient.reconstructURI(instance, originalUri)
|
||||||
|
.toString();
|
||||||
|
Request newRequest = Request.create(request.httpMethod(), reconstructedUrl,
|
||||||
|
request.headers(), request.body(), request.charset(),
|
||||||
|
request.requestTemplate());
|
||||||
|
return delegate.execute(newRequest, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Visible for Sleuth instrumentation
|
||||||
|
public Client getDelegate() {
|
||||||
|
return delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import feign.Feign;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
|
||||||
|
import org.springframework.cloud.openfeign.ribbon.FeignRibbonClientAutoConfiguration;
|
||||||
|
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An autoconfiguration that instantiates {@link BlockingLoadBalancerClient}-based
|
||||||
|
* implementations of {@link Client}. In order to use this load-balancing mechanism, the
|
||||||
|
* Ribbon-based implementation has to be disabled by setting
|
||||||
|
* <code>spring.cloud.loadbalancer.ribbon.enabled</code> to <code>true</code>.
|
||||||
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @since 2.2.0
|
||||||
|
*/
|
||||||
|
@ConditionalOnClass(Feign.class)
|
||||||
|
@ConditionalOnBean(BlockingLoadBalancerClient.class)
|
||||||
|
@AutoConfigureBefore(FeignAutoConfiguration.class)
|
||||||
|
@AutoConfigureAfter(FeignRibbonClientAutoConfiguration.class)
|
||||||
|
@EnableConfigurationProperties(FeignHttpClientProperties.class)
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
// Order is important here, last should be the default, first should be optional
|
||||||
|
// see
|
||||||
|
// https://github.com/spring-cloud/spring-cloud-netflix/issues/2086#issuecomment-316281653
|
||||||
|
@Import({ HttpClientFeignLoadBalancerConfiguration.class,
|
||||||
|
OkHttpFeignLoadBalancerConfiguration.class,
|
||||||
|
DefaultFeignLoadBalancerConfiguration.class })
|
||||||
|
public class FeignLoadBalancerAutoConfiguration {
|
||||||
|
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import feign.httpclient.ApacheHttpClient;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
|
||||||
|
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.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.cloud.openfeign.clientconfig.HttpClientFeignConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration instantiating a {@link BlockingLoadBalancerClient}-based {@link Client}
|
||||||
|
* object that uses {@link ApacheHttpClient} under the hood.
|
||||||
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @since 2.2.0
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnClass(ApacheHttpClient.class)
|
||||||
|
@ConditionalOnBean(BlockingLoadBalancerClient.class)
|
||||||
|
@ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true)
|
||||||
|
@Import(HttpClientFeignConfiguration.class)
|
||||||
|
class HttpClientFeignLoadBalancerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public Client feignClient(BlockingLoadBalancerClient loadBalancerClient,
|
||||||
|
HttpClient httpClient) {
|
||||||
|
ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
|
||||||
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import feign.okhttp.OkHttpClient;
|
||||||
|
|
||||||
|
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.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.cloud.openfeign.clientconfig.OkHttpFeignConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration instantiating a {@link BlockingLoadBalancerClient}-based {@link Client}
|
||||||
|
* object that uses {@link OkHttpClient} under the hood.
|
||||||
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @since 2.2.0
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnClass(OkHttpClient.class)
|
||||||
|
@ConditionalOnProperty("feign.okhttp.enabled")
|
||||||
|
@ConditionalOnBean(BlockingLoadBalancerClient.class)
|
||||||
|
@Import(OkHttpFeignConfiguration.class)
|
||||||
|
class OkHttpFeignLoadBalancerConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public Client feignClient(okhttp3.OkHttpClient okHttpClient,
|
||||||
|
BlockingLoadBalancerClient loadBalancerClient) {
|
||||||
|
OkHttpClient delegate = new OkHttpClient(okHttpClient);
|
||||||
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -26,7 +26,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
class DefaultFeignLoadBalancedConfiguration {
|
class DefaultFeignLoadBalancedConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
+1
-1
@@ -134,7 +134,7 @@ public class FeignLoadBalancer extends
|
|||||||
Map<String, Collection<String>> headers = new LinkedHashMap<>(
|
Map<String, Collection<String>> headers = new LinkedHashMap<>(
|
||||||
request.headers());
|
request.headers());
|
||||||
return Request.create(request.httpMethod(), getUri().toASCIIString(), headers,
|
return Request.create(request.httpMethod(), getUri().toASCIIString(), headers,
|
||||||
request.requestBody());
|
request.body(), request.charset(), request.requestTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
Request toRequest() {
|
Request toRequest() {
|
||||||
|
|||||||
+5
-1
@@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
|||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
|
||||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||||
@@ -39,9 +40,12 @@ import org.springframework.context.annotation.Primary;
|
|||||||
* load balancer.
|
* load balancer.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
@ConditionalOnClass({ ILoadBalancer.class, Feign.class })
|
@ConditionalOnClass({ ILoadBalancer.class, Feign.class })
|
||||||
@Configuration
|
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.ribbon.enabled",
|
||||||
|
matchIfMissing = true)
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
@AutoConfigureBefore(FeignAutoConfiguration.class)
|
@AutoConfigureBefore(FeignAutoConfiguration.class)
|
||||||
@EnableConfigurationProperties({ FeignHttpClientProperties.class })
|
@EnableConfigurationProperties({ FeignHttpClientProperties.class })
|
||||||
// Order is important here, last should be the default, first should be optional
|
// Order is important here, last should be the default, first should be optional
|
||||||
|
|||||||
+5
-93
@@ -16,37 +16,27 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.ribbon;
|
package org.springframework.cloud.openfeign.ribbon;
|
||||||
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
|
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.httpclient.ApacheHttpClient;
|
import feign.httpclient.ApacheHttpClient;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
|
||||||
import org.apache.http.config.RegistryBuilder;
|
|
||||||
import org.apache.http.conn.HttpClientConnectionManager;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory;
|
|
||||||
import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
|
|
||||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||||
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
import org.springframework.cloud.openfeign.clientconfig.HttpClientFeignConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(ApacheHttpClient.class)
|
@ConditionalOnClass(ApacheHttpClient.class)
|
||||||
@ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true)
|
@ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true)
|
||||||
|
@Import(HttpClientFeignConfiguration.class)
|
||||||
class HttpClientFeignLoadBalancedConfiguration {
|
class HttpClientFeignLoadBalancedConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -57,82 +47,4 @@ class HttpClientFeignLoadBalancedConfiguration {
|
|||||||
return new LoadBalancerFeignClient(delegate, cachingFactory, clientFactory);
|
return new LoadBalancerFeignClient(delegate, cachingFactory, clientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnMissingBean(CloseableHttpClient.class)
|
|
||||||
protected static class HttpClientFeignConfiguration {
|
|
||||||
|
|
||||||
private final Timer connectionManagerTimer = new Timer(
|
|
||||||
"FeignApacheHttpClientConfiguration.connectionManagerTimer", true);
|
|
||||||
|
|
||||||
private CloseableHttpClient httpClient;
|
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private RegistryBuilder registryBuilder;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(HttpClientConnectionManager.class)
|
|
||||||
public HttpClientConnectionManager connectionManager(
|
|
||||||
ApacheHttpClientConnectionManagerFactory connectionManagerFactory,
|
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
|
||||||
final HttpClientConnectionManager connectionManager = connectionManagerFactory
|
|
||||||
.newConnectionManager(httpClientProperties.isDisableSslValidation(),
|
|
||||||
httpClientProperties.getMaxConnections(),
|
|
||||||
httpClientProperties.getMaxConnectionsPerRoute(),
|
|
||||||
httpClientProperties.getTimeToLive(),
|
|
||||||
httpClientProperties.getTimeToLiveUnit(),
|
|
||||||
this.registryBuilder);
|
|
||||||
this.connectionManagerTimer.schedule(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
connectionManager.closeExpiredConnections();
|
|
||||||
}
|
|
||||||
}, 30000, httpClientProperties.getConnectionTimerRepeat());
|
|
||||||
return connectionManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnProperty(value = "feign.compression.response.enabled", havingValue = "true")
|
|
||||||
public CloseableHttpClient customHttpClient(
|
|
||||||
HttpClientConnectionManager httpClientConnectionManager,
|
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
|
||||||
HttpClientBuilder builder = HttpClientBuilder.create()
|
|
||||||
.disableCookieManagement().useSystemProperties();
|
|
||||||
this.httpClient = createClient(builder, httpClientConnectionManager,
|
|
||||||
httpClientProperties);
|
|
||||||
return this.httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnProperty(value = "feign.compression.response.enabled", havingValue = "false", matchIfMissing = true)
|
|
||||||
public CloseableHttpClient httpClient(ApacheHttpClientFactory httpClientFactory,
|
|
||||||
HttpClientConnectionManager httpClientConnectionManager,
|
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
|
||||||
this.httpClient = createClient(httpClientFactory.createBuilder(),
|
|
||||||
httpClientConnectionManager, httpClientProperties);
|
|
||||||
return this.httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CloseableHttpClient createClient(HttpClientBuilder builder,
|
|
||||||
HttpClientConnectionManager httpClientConnectionManager,
|
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
|
||||||
RequestConfig defaultRequestConfig = RequestConfig.custom()
|
|
||||||
.setConnectTimeout(httpClientProperties.getConnectionTimeout())
|
|
||||||
.setRedirectsEnabled(httpClientProperties.isFollowRedirects())
|
|
||||||
.build();
|
|
||||||
CloseableHttpClient httpClient = builder
|
|
||||||
.setDefaultRequestConfig(defaultRequestConfig)
|
|
||||||
.setConnectionManager(httpClientConnectionManager).build();
|
|
||||||
return httpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
public void destroy() throws Exception {
|
|
||||||
this.connectionManagerTimer.cancel();
|
|
||||||
if (this.httpClient != null) {
|
|
||||||
this.httpClient.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-50
@@ -16,30 +16,26 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.ribbon;
|
package org.springframework.cloud.openfeign.ribbon;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
|
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.okhttp.OkHttpClient;
|
import feign.okhttp.OkHttpClient;
|
||||||
import okhttp3.ConnectionPool;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory;
|
|
||||||
import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
|
|
||||||
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
|
||||||
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
import org.springframework.cloud.openfeign.clientconfig.OkHttpFeignConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(OkHttpClient.class)
|
@ConditionalOnClass(OkHttpClient.class)
|
||||||
@ConditionalOnProperty("feign.okhttp.enabled")
|
@ConditionalOnProperty("feign.okhttp.enabled")
|
||||||
|
@Import(OkHttpFeignConfiguration.class)
|
||||||
class OkHttpFeignLoadBalancedConfiguration {
|
class OkHttpFeignLoadBalancedConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -50,45 +46,4 @@ class OkHttpFeignLoadBalancedConfiguration {
|
|||||||
return new LoadBalancerFeignClient(delegate, cachingFactory, clientFactory);
|
return new LoadBalancerFeignClient(delegate, cachingFactory, clientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
|
|
||||||
protected static class OkHttpFeignConfiguration {
|
|
||||||
|
|
||||||
private okhttp3.OkHttpClient okHttpClient;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(ConnectionPool.class)
|
|
||||||
public ConnectionPool httpClientConnectionPool(
|
|
||||||
FeignHttpClientProperties httpClientProperties,
|
|
||||||
OkHttpClientConnectionPoolFactory connectionPoolFactory) {
|
|
||||||
Integer maxTotalConnections = httpClientProperties.getMaxConnections();
|
|
||||||
Long timeToLive = httpClientProperties.getTimeToLive();
|
|
||||||
TimeUnit ttlUnit = httpClientProperties.getTimeToLiveUnit();
|
|
||||||
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public okhttp3.OkHttpClient client(OkHttpClientFactory httpClientFactory,
|
|
||||||
ConnectionPool connectionPool,
|
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
|
||||||
Boolean followRedirects = httpClientProperties.isFollowRedirects();
|
|
||||||
Integer connectTimeout = httpClientProperties.getConnectionTimeout();
|
|
||||||
this.okHttpClient = httpClientFactory
|
|
||||||
.createBuilder(httpClientProperties.isDisableSslValidation())
|
|
||||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
|
|
||||||
.followRedirects(followRedirects).connectionPool(connectionPool)
|
|
||||||
.build();
|
|
||||||
return this.okHttpClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
public void destroy() {
|
|
||||||
if (this.okHttpClient != null) {
|
|
||||||
this.okHttpClient.dispatcher().executorService().shutdown();
|
|
||||||
this.okHttpClient.connectionPool().evictAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.support;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
import feign.FeignException;
|
||||||
|
import feign.Response;
|
||||||
|
import feign.codec.Decoder;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.encoding.HttpEncoding;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When response is compressed as gzip, this decompresses and uses {@link SpringDecoder}
|
||||||
|
* to decode.
|
||||||
|
*
|
||||||
|
* @author Jaesik Kim
|
||||||
|
*/
|
||||||
|
public class DefaultGzipDecoder implements Decoder {
|
||||||
|
|
||||||
|
private Decoder decoder;
|
||||||
|
|
||||||
|
public DefaultGzipDecoder(Decoder decoder) {
|
||||||
|
this.decoder = decoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object decode(final Response response, Type type)
|
||||||
|
throws IOException, FeignException {
|
||||||
|
Collection<String> encoding = response.headers()
|
||||||
|
.containsKey(HttpEncoding.CONTENT_ENCODING_HEADER)
|
||||||
|
? response.headers().get(HttpEncoding.CONTENT_ENCODING_HEADER)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (encoding != null) {
|
||||||
|
if (encoding.contains(HttpEncoding.GZIP_ENCODING)) {
|
||||||
|
String decompressedBody = decompress(response);
|
||||||
|
if (decompressedBody != null) {
|
||||||
|
Response decompressedResponse = response.toBuilder()
|
||||||
|
.body(decompressedBody.getBytes()).build();
|
||||||
|
return decoder.decode(decompressedResponse, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return decoder.decode(response, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decompress(Response response) throws IOException {
|
||||||
|
if (response.body() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try (GZIPInputStream gzipInputStream = new GZIPInputStream(
|
||||||
|
response.body().asInputStream());
|
||||||
|
BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(gzipInputStream, StandardCharsets.UTF_8))) {
|
||||||
|
String outputString = "";
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
outputString += line;
|
||||||
|
}
|
||||||
|
return outputString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.support;
|
||||||
|
|
||||||
|
import feign.codec.Decoder;
|
||||||
|
import feign.optionals.OptionalDecoder;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectFactory;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
|
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures Default Gzip Decoder.
|
||||||
|
*
|
||||||
|
* @author Jaesik Kim
|
||||||
|
*/
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ConditionalOnProperty("feign.compression.response.enabled")
|
||||||
|
// The OK HTTP client uses "transparent" compression.
|
||||||
|
// If the accept-encoding header is present, it disables transparent compression
|
||||||
|
@ConditionalOnMissingBean(type = "okhttp3.OkHttpClient")
|
||||||
|
@AutoConfigureAfter(FeignAutoConfiguration.class)
|
||||||
|
public class DefaultGzipDecoderConfiguration {
|
||||||
|
|
||||||
|
private ObjectFactory<HttpMessageConverters> messageConverters;
|
||||||
|
|
||||||
|
public DefaultGzipDecoderConfiguration(
|
||||||
|
ObjectFactory<HttpMessageConverters> messageConverters) {
|
||||||
|
this.messageConverters = messageConverters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
@ConditionalOnProperty("feign.compression.response.useGzipDecoder")
|
||||||
|
public Decoder defaultGzipDecoder() {
|
||||||
|
return new OptionalDecoder(new ResponseEntityDecoder(
|
||||||
|
new DefaultGzipDecoder(new SpringDecoder(messageConverters))));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+40
-3
@@ -37,6 +37,21 @@ public class PageableSpringEncoder implements Encoder {
|
|||||||
|
|
||||||
private final Encoder delegate;
|
private final Encoder delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page index parameter name.
|
||||||
|
*/
|
||||||
|
private String pageParameter = "page";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page size parameter name.
|
||||||
|
*/
|
||||||
|
private String sizeParameter = "size";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort parameter name.
|
||||||
|
*/
|
||||||
|
private String sortParameter = "sort";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new PageableSpringEncoder with the given delegate for fallback. If no
|
* Creates a new PageableSpringEncoder with the given delegate for fallback. If no
|
||||||
* delegate is provided and this encoder cant handle the request, an EncodeException
|
* delegate is provided and this encoder cant handle the request, an EncodeException
|
||||||
@@ -47,6 +62,18 @@ public class PageableSpringEncoder implements Encoder {
|
|||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPageParameter(String pageParameter) {
|
||||||
|
this.pageParameter = pageParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSizeParameter(String sizeParameter) {
|
||||||
|
this.sizeParameter = sizeParameter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSortParameter(String sortParameter) {
|
||||||
|
this.sortParameter = sortParameter;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(Object object, Type bodyType, RequestTemplate template)
|
public void encode(Object object, Type bodyType, RequestTemplate template)
|
||||||
throws EncodeException {
|
throws EncodeException {
|
||||||
@@ -54,8 +81,12 @@ public class PageableSpringEncoder implements Encoder {
|
|||||||
if (supports(object)) {
|
if (supports(object)) {
|
||||||
if (object instanceof Pageable) {
|
if (object instanceof Pageable) {
|
||||||
Pageable pageable = (Pageable) object;
|
Pageable pageable = (Pageable) object;
|
||||||
template.query("page", pageable.getPageNumber() + "");
|
|
||||||
template.query("size", pageable.getPageSize() + "");
|
if (pageable.isPaged()) {
|
||||||
|
template.query(pageParameter, pageable.getPageNumber() + "");
|
||||||
|
template.query(sizeParameter, pageable.getPageSize() + "");
|
||||||
|
}
|
||||||
|
|
||||||
if (pageable.getSort() != null) {
|
if (pageable.getSort() != null) {
|
||||||
applySort(template, pageable.getSort());
|
applySort(template, pageable.getSort());
|
||||||
}
|
}
|
||||||
@@ -82,11 +113,17 @@ public class PageableSpringEncoder implements Encoder {
|
|||||||
Collection<String> existingSorts = template.queries().get("sort");
|
Collection<String> existingSorts = template.queries().get("sort");
|
||||||
List<String> sortQueries = existingSorts != null ? new ArrayList<>(existingSorts)
|
List<String> sortQueries = existingSorts != null ? new ArrayList<>(existingSorts)
|
||||||
: new ArrayList<>();
|
: new ArrayList<>();
|
||||||
|
if (!sortParameter.equals("sort")) {
|
||||||
|
existingSorts = template.queries().get(sortParameter);
|
||||||
|
if (existingSorts != null) {
|
||||||
|
sortQueries.addAll(existingSorts);
|
||||||
|
}
|
||||||
|
}
|
||||||
for (Sort.Order order : sort) {
|
for (Sort.Order order : sort) {
|
||||||
sortQueries.add(order.getProperty() + "," + order.getDirection());
|
sortQueries.add(order.getProperty() + "," + order.getDirection());
|
||||||
}
|
}
|
||||||
if (!sortQueries.isEmpty()) {
|
if (!sortQueries.isEmpty()) {
|
||||||
template.query("sort", sortQueries);
|
template.query(sortParameter, sortQueries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -59,7 +59,8 @@ public class SpringDecoder implements Decoder {
|
|||||||
return extractor.extractData(new FeignResponseAdapter(response));
|
return extractor.extractData(new FeignResponseAdapter(response));
|
||||||
}
|
}
|
||||||
throw new DecodeException(response.status(),
|
throw new DecodeException(response.status(),
|
||||||
"type is not an instance of Class or ParameterizedType: " + type);
|
"type is not an instance of Class or ParameterizedType: " + type,
|
||||||
|
response.request());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class FeignResponseAdapter implements ClientHttpResponse {
|
private final class FeignResponseAdapter implements ClientHttpResponse {
|
||||||
|
|||||||
+76
-36
@@ -35,10 +35,13 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.ObjectFactory;
|
import org.springframework.beans.factory.ObjectFactory;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
|
import org.springframework.cloud.openfeign.encoding.HttpEncoding;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpOutputMessage;
|
import org.springframework.http.HttpOutputMessage;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.GenericHttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.HttpMessageConversionException;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter;
|
import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -49,6 +52,8 @@ import static org.springframework.cloud.openfeign.support.FeignUtils.getHttpHead
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
* @author Scien Jus
|
* @author Scien Jus
|
||||||
|
* @author Ahmad Mozafarnia
|
||||||
|
* @author Aaron Whiteside
|
||||||
*/
|
*/
|
||||||
public class SpringEncoder implements Encoder {
|
public class SpringEncoder implements Encoder {
|
||||||
|
|
||||||
@@ -56,7 +61,7 @@ public class SpringEncoder implements Encoder {
|
|||||||
|
|
||||||
private final SpringFormEncoder springFormEncoder = new SpringFormEncoder();
|
private final SpringFormEncoder springFormEncoder = new SpringFormEncoder();
|
||||||
|
|
||||||
private ObjectFactory<HttpMessageConverters> messageConverters;
|
private final ObjectFactory<HttpMessageConverters> messageConverters;
|
||||||
|
|
||||||
public SpringEncoder(ObjectFactory<HttpMessageConverters> messageConverters) {
|
public SpringEncoder(ObjectFactory<HttpMessageConverters> messageConverters) {
|
||||||
this.messageConverters = messageConverters;
|
this.messageConverters = messageConverters;
|
||||||
@@ -67,8 +72,8 @@ public class SpringEncoder implements Encoder {
|
|||||||
throws EncodeException {
|
throws EncodeException {
|
||||||
// template.body(conversionService.convert(object, String.class));
|
// template.body(conversionService.convert(object, String.class));
|
||||||
if (requestBody != null) {
|
if (requestBody != null) {
|
||||||
Class<?> requestType = requestBody.getClass();
|
Collection<String> contentTypes = request.headers()
|
||||||
Collection<String> contentTypes = request.headers().get("Content-Type");
|
.get(HttpEncoding.CONTENT_TYPE);
|
||||||
|
|
||||||
MediaType requestContentType = null;
|
MediaType requestContentType = null;
|
||||||
if (contentTypes != null && !contentTypes.isEmpty()) {
|
if (contentTypes != null && !contentTypes.isEmpty()) {
|
||||||
@@ -76,44 +81,36 @@ public class SpringEncoder implements Encoder {
|
|||||||
requestContentType = MediaType.valueOf(type);
|
requestContentType = MediaType.valueOf(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bodyType != null && bodyType.equals(MultipartFile.class)) {
|
if (Objects.equals(requestContentType, MediaType.MULTIPART_FORM_DATA)) {
|
||||||
if (Objects.equals(requestContentType, MediaType.MULTIPART_FORM_DATA)) {
|
this.springFormEncoder.encode(requestBody, bodyType, request);
|
||||||
this.springFormEncoder.encode(requestBody, bodyType, request);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
else {
|
||||||
else {
|
if (bodyType == MultipartFile.class) {
|
||||||
String message = "Content-Type \"" + MediaType.MULTIPART_FORM_DATA
|
log.warn(
|
||||||
+ "\" not set for request body of type "
|
"For MultipartFile to be handled correctly, the 'consumes' parameter of @RequestMapping "
|
||||||
+ requestBody.getClass().getSimpleName();
|
+ "should be specified as MediaType.MULTIPART_FORM_DATA_VALUE");
|
||||||
throw new EncodeException(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (HttpMessageConverter<?> messageConverter : this.messageConverters
|
for (HttpMessageConverter messageConverter : this.messageConverters
|
||||||
.getObject().getConverters()) {
|
.getObject().getConverters()) {
|
||||||
if (messageConverter.canWrite(requestType, requestContentType)) {
|
FeignOutputMessage outputMessage;
|
||||||
if (log.isDebugEnabled()) {
|
try {
|
||||||
if (requestContentType != null) {
|
if (messageConverter instanceof GenericHttpMessageConverter) {
|
||||||
log.debug("Writing [" + requestBody + "] as \""
|
outputMessage = checkAndWrite(requestBody, bodyType,
|
||||||
+ requestContentType + "\" using [" + messageConverter
|
requestContentType,
|
||||||
+ "]");
|
(GenericHttpMessageConverter) messageConverter, request);
|
||||||
}
|
|
||||||
else {
|
|
||||||
log.debug("Writing [" + requestBody + "] using ["
|
|
||||||
+ messageConverter + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
FeignOutputMessage outputMessage = new FeignOutputMessage(request);
|
outputMessage = checkAndWrite(requestBody, requestContentType,
|
||||||
try {
|
messageConverter, request);
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
HttpMessageConverter<Object> copy = (HttpMessageConverter<Object>) messageConverter;
|
|
||||||
copy.write(requestBody, requestContentType, outputMessage);
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
throw new EncodeException("Error converting request body", ex);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (IOException | HttpMessageConversionException ex) {
|
||||||
|
throw new EncodeException("Error converting request body", ex);
|
||||||
|
}
|
||||||
|
if (outputMessage != null) {
|
||||||
// clear headers
|
// clear headers
|
||||||
request.headers(null);
|
request.headers(null);
|
||||||
// converters can modify headers, so update the request
|
// converters can modify headers, so update the request
|
||||||
@@ -139,7 +136,7 @@ public class SpringEncoder implements Encoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String message = "Could not write request: no suitable HttpMessageConverter "
|
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) {
|
if (requestContentType != null) {
|
||||||
message += " and content type [" + requestContentType + "]";
|
message += " and content type [" + requestContentType + "]";
|
||||||
}
|
}
|
||||||
@@ -147,6 +144,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 class FeignOutputMessage implements HttpOutputMessage {
|
||||||
|
|
||||||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|||||||
+8
-7
@@ -36,10 +36,12 @@ import feign.Param;
|
|||||||
import feign.Request;
|
import feign.Request;
|
||||||
|
|
||||||
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
|
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
|
||||||
|
import org.springframework.cloud.openfeign.annotation.MatrixVariableParameterProcessor;
|
||||||
import org.springframework.cloud.openfeign.annotation.PathVariableParameterProcessor;
|
import org.springframework.cloud.openfeign.annotation.PathVariableParameterProcessor;
|
||||||
import org.springframework.cloud.openfeign.annotation.QueryMapParameterProcessor;
|
import org.springframework.cloud.openfeign.annotation.QueryMapParameterProcessor;
|
||||||
import org.springframework.cloud.openfeign.annotation.RequestHeaderParameterProcessor;
|
import org.springframework.cloud.openfeign.annotation.RequestHeaderParameterProcessor;
|
||||||
import org.springframework.cloud.openfeign.annotation.RequestParamParameterProcessor;
|
import org.springframework.cloud.openfeign.annotation.RequestParamParameterProcessor;
|
||||||
|
import org.springframework.cloud.openfeign.annotation.RequestPartParameterProcessor;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.ResourceLoaderAware;
|
import org.springframework.context.ResourceLoaderAware;
|
||||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||||
@@ -68,6 +70,7 @@ import static org.springframework.core.annotation.AnnotatedElementUtils.findMerg
|
|||||||
* @author Halvdan Hoem Grelland
|
* @author Halvdan Hoem Grelland
|
||||||
* @author Aram Peres
|
* @author Aram Peres
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author Aaron Whiteside
|
||||||
*/
|
*/
|
||||||
public class SpringMvcContract extends Contract.BaseContract
|
public class SpringMvcContract extends Contract.BaseContract
|
||||||
implements ResourceLoaderAware {
|
implements ResourceLoaderAware {
|
||||||
@@ -110,13 +113,9 @@ public class SpringMvcContract extends Contract.BaseContract
|
|||||||
"Parameter processors can not be null.");
|
"Parameter processors can not be null.");
|
||||||
Assert.notNull(conversionService, "ConversionService can not be null.");
|
Assert.notNull(conversionService, "ConversionService can not be null.");
|
||||||
|
|
||||||
List<AnnotatedParameterProcessor> processors;
|
List<AnnotatedParameterProcessor> processors = getDefaultAnnotatedArgumentsProcessors();
|
||||||
if (!annotatedParameterProcessors.isEmpty()) {
|
processors.addAll(annotatedParameterProcessors);
|
||||||
processors = new ArrayList<>(annotatedParameterProcessors);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
processors = getDefaultAnnotatedArgumentsProcessors();
|
|
||||||
}
|
|
||||||
this.annotatedArgumentProcessors = toAnnotatedArgumentProcessorMap(processors);
|
this.annotatedArgumentProcessors = toAnnotatedArgumentProcessorMap(processors);
|
||||||
this.conversionService = conversionService;
|
this.conversionService = conversionService;
|
||||||
this.convertingExpanderFactory = new ConvertingExpanderFactory(conversionService);
|
this.convertingExpanderFactory = new ConvertingExpanderFactory(conversionService);
|
||||||
@@ -355,10 +354,12 @@ public class SpringMvcContract extends Contract.BaseContract
|
|||||||
|
|
||||||
List<AnnotatedParameterProcessor> annotatedArgumentResolvers = new ArrayList<>();
|
List<AnnotatedParameterProcessor> annotatedArgumentResolvers = new ArrayList<>();
|
||||||
|
|
||||||
|
annotatedArgumentResolvers.add(new MatrixVariableParameterProcessor());
|
||||||
annotatedArgumentResolvers.add(new PathVariableParameterProcessor());
|
annotatedArgumentResolvers.add(new PathVariableParameterProcessor());
|
||||||
annotatedArgumentResolvers.add(new RequestParamParameterProcessor());
|
annotatedArgumentResolvers.add(new RequestParamParameterProcessor());
|
||||||
annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());
|
annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());
|
||||||
annotatedArgumentResolvers.add(new QueryMapParameterProcessor());
|
annotatedArgumentResolvers.add(new QueryMapParameterProcessor());
|
||||||
|
annotatedArgumentResolvers.add(new RequestPartParameterProcessor());
|
||||||
|
|
||||||
return annotatedArgumentResolvers;
|
return annotatedArgumentResolvers;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -26,6 +26,12 @@
|
|||||||
"description": "Enables the response from Feign to be compressed.",
|
"description": "Enables the response from Feign to be compressed.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "feign.compression.response.useGzipDecoder",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "Enables the default gzip decoder to be used.",
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.compression.request.enabled",
|
"name": "feign.compression.request.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
org.springframework.cloud.openfeign.ribbon.FeignRibbonClientAutoConfiguration,\
|
org.springframework.cloud.openfeign.ribbon.FeignRibbonClientAutoConfiguration,\
|
||||||
|
org.springframework.cloud.openfeign.hateoas.FeignHalAutoConfiguration,\
|
||||||
org.springframework.cloud.openfeign.FeignAutoConfiguration,\
|
org.springframework.cloud.openfeign.FeignAutoConfiguration,\
|
||||||
org.springframework.cloud.openfeign.encoding.FeignAcceptGzipEncodingAutoConfiguration,\
|
org.springframework.cloud.openfeign.encoding.FeignAcceptGzipEncodingAutoConfiguration,\
|
||||||
org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingAutoConfiguration
|
org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingAutoConfiguration,\
|
||||||
|
org.springframework.cloud.openfeign.loadbalancer.FeignLoadBalancerAutoConfiguration
|
||||||
|
|||||||
+179
@@ -0,0 +1,179 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jaesik Kim
|
||||||
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@SpringBootTest(classes = DefaultGzipDecoderTests.Application.class,
|
||||||
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
|
value = { "spring.application.name=defaultGzipDecoderTests",
|
||||||
|
"feign.compression.response.enabled=true",
|
||||||
|
"feign.compression.response.useGzipDecoder=true",
|
||||||
|
"feign.client.config.default.loggerLevel=full",
|
||||||
|
"logging.level.org.springframework.cloud.openfeign=DEBUG" })
|
||||||
|
@DirtiesContext
|
||||||
|
public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
FeignContext context;
|
||||||
|
|
||||||
|
@Value("${local.server.port}")
|
||||||
|
private int port = 0;
|
||||||
|
|
||||||
|
public DefaultGzipDecoderTests() {
|
||||||
|
setName("tests");
|
||||||
|
setContextId("test");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestClient testClient() {
|
||||||
|
setType(this.getClass());
|
||||||
|
return feign(context).target(TestClient.class, "http://localhost:" + this.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBodyDecompress() {
|
||||||
|
ResponseEntity<Hello> response = testClient().getGzipResponse();
|
||||||
|
assertThat(response).as("response was null").isNotNull();
|
||||||
|
assertThat(response.getStatusCode()).as("wrong status code")
|
||||||
|
.isEqualTo(HttpStatus.OK);
|
||||||
|
Hello hello = response.getBody();
|
||||||
|
assertThat(hello).as("hello was null").isNotNull();
|
||||||
|
assertThat(hello).as("first hello didn't match")
|
||||||
|
.isEqualTo(new Hello("hello world via response"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullBodyDecompress() {
|
||||||
|
ResponseEntity<Hello> response = testClient().getNullResponse();
|
||||||
|
assertThat(response).as("response was null").isNotNull();
|
||||||
|
assertThat(response.getStatusCode()).as("wrong status code")
|
||||||
|
.isEqualTo(HttpStatus.OK);
|
||||||
|
Hello hello = response.getBody();
|
||||||
|
assertThat(hello).as("hello was not null").isNull();
|
||||||
|
assertThat(hello).as("null hello didn't match").isEqualTo(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCharsetDecompress() {
|
||||||
|
ResponseEntity<Hello> response = testClient().getUtf8Response();
|
||||||
|
assertThat(response).as("response was null").isNotNull();
|
||||||
|
assertThat(response.getStatusCode()).as("wrong status code")
|
||||||
|
.isEqualTo(HttpStatus.OK);
|
||||||
|
Hello hello = response.getBody();
|
||||||
|
assertThat(hello).as("hello was null").isNotNull();
|
||||||
|
assertThat(hello).as("utf8 hello didn't match")
|
||||||
|
.isEqualTo(new Hello("안녕하세요 means Hello in Korean"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Hello {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
Hello() {
|
||||||
|
}
|
||||||
|
|
||||||
|
Hello(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Hello that = (Hello) o;
|
||||||
|
return Objects.equals(message, that.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected interface TestClient {
|
||||||
|
|
||||||
|
@GetMapping("/helloGzipResponse")
|
||||||
|
ResponseEntity<Hello> getGzipResponse();
|
||||||
|
|
||||||
|
@GetMapping("/nullGzipResponse")
|
||||||
|
ResponseEntity<Hello> getNullResponse();
|
||||||
|
|
||||||
|
@GetMapping("/utf8Response")
|
||||||
|
ResponseEntity<Hello> getUtf8Response();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@RestController
|
||||||
|
@Import(NoSecurityConfiguration.class)
|
||||||
|
protected static class Application implements TestClient {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Hello> getGzipResponse() {
|
||||||
|
return ResponseEntity.ok(new Hello("hello world via response"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Hello> getNullResponse() {
|
||||||
|
return ResponseEntity.ok(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Hello> getUtf8Response() {
|
||||||
|
return ResponseEntity.ok(new Hello("안녕하세요 means Hello in Korean"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -48,7 +48,7 @@ public class EnableFeignClientsSpringDataTests {
|
|||||||
.cast(this.feignContext.getInstance("foo", Encoder.class));
|
.cast(this.feignContext.getInstance("foo", Encoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import({ PropertyPlaceholderAutoConfiguration.class, ArchaiusAutoConfiguration.class,
|
@Import({ PropertyPlaceholderAutoConfiguration.class, ArchaiusAutoConfiguration.class,
|
||||||
FeignAutoConfiguration.class })
|
FeignAutoConfiguration.class })
|
||||||
protected static class PlainConfiguration {
|
protected static class PlainConfiguration {
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ public class EnableFeignClientsTests {
|
|||||||
Feign.Builder.class.cast(this.context.getBeansOfType(Feign.Builder.class).get(0));
|
Feign.Builder.class.cast(this.context.getBeansOfType(Feign.Builder.class).get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import({ ArchaiusAutoConfiguration.class, FeignAutoConfiguration.class })
|
@Import({ ArchaiusAutoConfiguration.class, FeignAutoConfiguration.class })
|
||||||
protected static class PlainConfiguration {
|
protected static class PlainConfiguration {
|
||||||
|
|
||||||
|
|||||||
+30
-8
@@ -24,6 +24,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import feign.hystrix.FallbackFactory;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@@ -101,11 +102,11 @@ public class FeignClientBuilderTests {
|
|||||||
public void forType_preinitializedBuilder() {
|
public void forType_preinitializedBuilder() {
|
||||||
// when:
|
// when:
|
||||||
final FeignClientBuilder.Builder builder = this.feignClientBuilder
|
final FeignClientBuilder.Builder builder = this.feignClientBuilder
|
||||||
.forType(FeignClientBuilderTests.class, "TestClient");
|
.forType(TestFeignClient.class, "TestClient");
|
||||||
|
|
||||||
// then:
|
// then:
|
||||||
assertFactoryBeanField(builder, "applicationContext", this.applicationContext);
|
assertFactoryBeanField(builder, "applicationContext", this.applicationContext);
|
||||||
assertFactoryBeanField(builder, "type", FeignClientBuilderTests.class);
|
assertFactoryBeanField(builder, "type", TestFeignClient.class);
|
||||||
assertFactoryBeanField(builder, "name", "TestClient");
|
assertFactoryBeanField(builder, "name", "TestClient");
|
||||||
assertFactoryBeanField(builder, "contextId", "TestClient");
|
assertFactoryBeanField(builder, "contextId", "TestClient");
|
||||||
|
|
||||||
@@ -126,21 +127,24 @@ public class FeignClientBuilderTests {
|
|||||||
public void forType_allFieldsSetOnBuilder() {
|
public void forType_allFieldsSetOnBuilder() {
|
||||||
// when:
|
// when:
|
||||||
final FeignClientBuilder.Builder builder = this.feignClientBuilder
|
final FeignClientBuilder.Builder builder = this.feignClientBuilder
|
||||||
.forType(FeignClientBuilderTests.class, "TestClient").decode404(true)
|
.forType(TestFeignClient.class, "TestClient").decode404(true)
|
||||||
.fallback(Object.class).fallbackFactory(Object.class).path("Path/")
|
.fallback(TestFeignClientFallback.class)
|
||||||
.url("Url/");
|
.fallbackFactory(TestFeignClientFallbackFactory.class).path("Path/")
|
||||||
|
.url("Url/").contextId("TestContext");
|
||||||
|
|
||||||
// then:
|
// then:
|
||||||
assertFactoryBeanField(builder, "applicationContext", this.applicationContext);
|
assertFactoryBeanField(builder, "applicationContext", this.applicationContext);
|
||||||
assertFactoryBeanField(builder, "type", FeignClientBuilderTests.class);
|
assertFactoryBeanField(builder, "type", TestFeignClient.class);
|
||||||
assertFactoryBeanField(builder, "name", "TestClient");
|
assertFactoryBeanField(builder, "name", "TestClient");
|
||||||
|
assertFactoryBeanField(builder, "contextId", "TestContext");
|
||||||
|
|
||||||
// and:
|
// and:
|
||||||
assertFactoryBeanField(builder, "url", "http://Url/");
|
assertFactoryBeanField(builder, "url", "http://Url/");
|
||||||
assertFactoryBeanField(builder, "path", "/Path");
|
assertFactoryBeanField(builder, "path", "/Path");
|
||||||
assertFactoryBeanField(builder, "decode404", true);
|
assertFactoryBeanField(builder, "decode404", true);
|
||||||
assertFactoryBeanField(builder, "fallback", Object.class);
|
assertFactoryBeanField(builder, "fallback", TestFeignClientFallback.class);
|
||||||
assertFactoryBeanField(builder, "fallbackFactory", Object.class);
|
assertFactoryBeanField(builder, "fallbackFactory",
|
||||||
|
TestFeignClientFallbackFactory.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -159,4 +163,22 @@ public class FeignClientBuilderTests {
|
|||||||
builder.build();
|
builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface TestFeignClient {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestFeignClientFallback implements TestFeignClient {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestFeignClientFallbackFactory
|
||||||
|
implements FallbackFactory<TestFeignClient> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestFeignClientFallback create(Throwable throwable) {
|
||||||
|
return new TestFeignClientFallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+80
@@ -16,14 +16,30 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign;
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import feign.InvocationHandlerFactory;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||||
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
|
||||||
|
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.springframework.web.bind.annotation.RequestMethod.GET;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
@@ -49,10 +65,74 @@ public class FeignClientFactoryTests {
|
|||||||
assertThat(foobar).as("bar was not null").isNull();
|
assertThat(foobar).as("bar was not null").isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRedirectToDelegateWhenUrlSet() {
|
||||||
|
new ApplicationContextRunner().withUserConfiguration(TestConfig.class)
|
||||||
|
.run(this::defaultClientUsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unchecked", "ConstantConditions" })
|
||||||
|
private void defaultClientUsed(AssertableApplicationContext context) {
|
||||||
|
Proxy target = context.getBean(FeignClientFactoryBean.class).getTarget();
|
||||||
|
Object invocationHandler = ReflectionTestUtils.getField(target, "h");
|
||||||
|
Map<Method, InvocationHandlerFactory.MethodHandler> dispatch = (Map<Method, InvocationHandlerFactory.MethodHandler>) ReflectionTestUtils
|
||||||
|
.getField(invocationHandler, "dispatch");
|
||||||
|
Method key = new ArrayList<>(dispatch.keySet()).get(0);
|
||||||
|
Object client = ReflectionTestUtils.getField(dispatch.get(key), "client");
|
||||||
|
assertThat(client).isInstanceOf(Client.Default.class);
|
||||||
|
}
|
||||||
|
|
||||||
private FeignClientSpecification getSpec(String name, Class<?> configClass) {
|
private FeignClientSpecification getSpec(String name, Class<?> configClass) {
|
||||||
return new FeignClientSpecification(name, new Class[] { configClass });
|
return new FeignClientSpecification(name, new Class[] { configClass });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TestType {
|
||||||
|
|
||||||
|
@RequestMapping(value = "/", method = GET)
|
||||||
|
String hello();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class TestConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
BlockingLoadBalancerClient loadBalancerClient() {
|
||||||
|
return new BlockingLoadBalancerClient(new LoadBalancerClientFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
FeignContext feignContext() {
|
||||||
|
FeignContext feignContext = new FeignContext();
|
||||||
|
feignContext.setConfigurations(
|
||||||
|
Collections.singletonList(new FeignClientSpecification("test",
|
||||||
|
new Class[] { LoadBalancerAutoConfiguration.class })));
|
||||||
|
return feignContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
FeignClientProperties feignClientProperties() {
|
||||||
|
return new FeignClientProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Targeter targeter() {
|
||||||
|
return new DefaultTargeter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
FeignClientFactoryBean feignClientFactoryBean() {
|
||||||
|
FeignClientFactoryBean feignClientFactoryBean = new FeignClientFactoryBean();
|
||||||
|
feignClientFactoryBean.setContextId("test");
|
||||||
|
feignClientFactoryBean.setName("test");
|
||||||
|
feignClientFactoryBean.setType(TestType.class);
|
||||||
|
feignClientFactoryBean.setPath("");
|
||||||
|
feignClientFactoryBean.setUrl("http://some.absolute.url");
|
||||||
|
return feignClientFactoryBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static class FooConfig {
|
static class FooConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
+39
-3
@@ -17,8 +17,10 @@
|
|||||||
package org.springframework.cloud.openfeign;
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
import feign.Contract;
|
import feign.Contract;
|
||||||
|
import feign.ExceptionPropagationPolicy;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
|
import feign.QueryMapEncoder;
|
||||||
import feign.Request;
|
import feign.Request;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestLine;
|
import feign.RequestLine;
|
||||||
@@ -30,6 +32,7 @@ import feign.codec.Encoder;
|
|||||||
import feign.codec.ErrorDecoder;
|
import feign.codec.ErrorDecoder;
|
||||||
import feign.hystrix.HystrixFeign;
|
import feign.hystrix.HystrixFeign;
|
||||||
import feign.optionals.OptionalDecoder;
|
import feign.optionals.OptionalDecoder;
|
||||||
|
import feign.querymap.BeanQueryMapEncoder;
|
||||||
import feign.slf4j.Slf4jLogger;
|
import feign.slf4j.Slf4jLogger;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -133,6 +136,14 @@ public class FeignClientOverrideDefaultsTests {
|
|||||||
assertThat(options.readTimeoutMillis()).isEqualTo(1);
|
assertThat(options.readTimeoutMillis()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void overrideQueryMapEncoder() {
|
||||||
|
QueryMapEncoder.Default.class
|
||||||
|
.cast(this.context.getInstance("foo", QueryMapEncoder.class));
|
||||||
|
BeanQueryMapEncoder.class
|
||||||
|
.cast(this.context.getInstance("bar", QueryMapEncoder.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addRequestInterceptor() {
|
public void addRequestInterceptor() {
|
||||||
assertThat(this.context.getInstances("foo", RequestInterceptor.class).size())
|
assertThat(this.context.getInstances("foo", RequestInterceptor.class).size())
|
||||||
@@ -141,7 +152,16 @@ public class FeignClientOverrideDefaultsTests {
|
|||||||
.isEqualTo(2);
|
.isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeignClient(name = "foo", url = "http://foo", configuration = FooConfiguration.class)
|
@Test
|
||||||
|
public void exceptionPropagationPolicy() {
|
||||||
|
assertThat(this.context.getInstances("foo", ExceptionPropagationPolicy.class))
|
||||||
|
.isNull();
|
||||||
|
assertThat(this.context.getInstances("bar", ExceptionPropagationPolicy.class))
|
||||||
|
.containsValues(ExceptionPropagationPolicy.UNWRAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FeignClient(name = "foo", url = "https://foo",
|
||||||
|
configuration = FooConfiguration.class)
|
||||||
interface FooClient {
|
interface FooClient {
|
||||||
|
|
||||||
@RequestLine("GET /")
|
@RequestLine("GET /")
|
||||||
@@ -149,7 +169,8 @@ public class FeignClientOverrideDefaultsTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeignClient(name = "bar", url = "http://bar", configuration = BarConfiguration.class)
|
@FeignClient(name = "bar", url = "https://bar",
|
||||||
|
configuration = BarConfiguration.class)
|
||||||
interface BarClient {
|
interface BarClient {
|
||||||
|
|
||||||
@RequestMapping(value = "/", method = RequestMethod.GET)
|
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||||
@@ -157,7 +178,7 @@ public class FeignClientOverrideDefaultsTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableFeignClients(clients = { FooClient.class, BarClient.class })
|
@EnableFeignClients(clients = { FooClient.class, BarClient.class })
|
||||||
@Import({ PropertyPlaceholderAutoConfiguration.class, ArchaiusAutoConfiguration.class,
|
@Import({ PropertyPlaceholderAutoConfiguration.class, ArchaiusAutoConfiguration.class,
|
||||||
FeignAutoConfiguration.class })
|
FeignAutoConfiguration.class })
|
||||||
@@ -201,6 +222,11 @@ public class FeignClientOverrideDefaultsTests {
|
|||||||
return HystrixFeign.builder();
|
return HystrixFeign.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public QueryMapEncoder queryMapEncoder() {
|
||||||
|
return new feign.QueryMapEncoder.Default();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BarConfiguration {
|
public static class BarConfiguration {
|
||||||
@@ -230,6 +256,16 @@ public class FeignClientOverrideDefaultsTests {
|
|||||||
return new BasicAuthRequestInterceptor("user", "pass");
|
return new BasicAuthRequestInterceptor("user", "pass");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public QueryMapEncoder queryMapEncoder() {
|
||||||
|
return new BeanQueryMapEncoder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ExceptionPropagationPolicy exceptionPropagationPolicy() {
|
||||||
|
return ExceptionPropagationPolicy.UNWRAP;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-7
@@ -16,13 +16,14 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign;
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import feign.Request;
|
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
import feign.RetryableException;
|
import feign.RetryableException;
|
||||||
@@ -50,7 +51,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.fail;
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
@@ -59,7 +59,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Eko Kurniawan Khannedy
|
* @author Eko Kurniawan Khannedy
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = FeignClientUsingPropertiesTests.Application.class, webEnvironment = RANDOM_PORT)
|
@SpringBootTest(classes = FeignClientUsingPropertiesTests.Application.class,
|
||||||
|
webEnvironment = RANDOM_PORT)
|
||||||
@TestPropertySource("classpath:feign-properties.properties")
|
@TestPropertySource("classpath:feign-properties.properties")
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignClientUsingPropertiesTests {
|
public class FeignClientUsingPropertiesTests {
|
||||||
@@ -77,6 +78,8 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
|
|
||||||
private FeignClientFactoryBean barFactoryBean;
|
private FeignClientFactoryBean barFactoryBean;
|
||||||
|
|
||||||
|
private FeignClientFactoryBean unwrapFactoryBean;
|
||||||
|
|
||||||
private FeignClientFactoryBean formFactoryBean;
|
private FeignClientFactoryBean formFactoryBean;
|
||||||
|
|
||||||
public FeignClientUsingPropertiesTests() {
|
public FeignClientUsingPropertiesTests() {
|
||||||
@@ -88,6 +91,10 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
this.barFactoryBean.setContextId("bar");
|
this.barFactoryBean.setContextId("bar");
|
||||||
this.barFactoryBean.setType(FeignClientFactoryBean.class);
|
this.barFactoryBean.setType(FeignClientFactoryBean.class);
|
||||||
|
|
||||||
|
this.unwrapFactoryBean = new FeignClientFactoryBean();
|
||||||
|
this.unwrapFactoryBean.setContextId("unwrap");
|
||||||
|
this.unwrapFactoryBean.setType(FeignClientFactoryBean.class);
|
||||||
|
|
||||||
this.formFactoryBean = new FeignClientFactoryBean();
|
this.formFactoryBean = new FeignClientFactoryBean();
|
||||||
this.formFactoryBean.setContextId("form");
|
this.formFactoryBean.setContextId("form");
|
||||||
this.formFactoryBean.setType(FeignClientFactoryBean.class);
|
this.formFactoryBean.setType(FeignClientFactoryBean.class);
|
||||||
@@ -105,6 +112,12 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
"http://localhost:" + this.port);
|
"http://localhost:" + this.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UnwrapClient unwrapClient() {
|
||||||
|
this.unwrapFactoryBean.setApplicationContext(this.applicationContext);
|
||||||
|
return this.unwrapFactoryBean.feign(this.context).target(UnwrapClient.class,
|
||||||
|
"http://localhost:" + this.port);
|
||||||
|
}
|
||||||
|
|
||||||
public FormClient formClient() {
|
public FormClient formClient() {
|
||||||
this.formFactoryBean.setApplicationContext(this.applicationContext);
|
this.formFactoryBean.setApplicationContext(this.applicationContext);
|
||||||
return this.formFactoryBean.feign(this.context).target(FormClient.class,
|
return this.formFactoryBean.feign(this.context).target(FormClient.class,
|
||||||
@@ -123,6 +136,12 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
fail("it should timeout");
|
fail("it should timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = SocketTimeoutException.class)
|
||||||
|
public void testUnwrap() throws Exception {
|
||||||
|
unwrapClient().unwrap();
|
||||||
|
fail("it should timeout");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testForm() {
|
public void testForm() {
|
||||||
Map<String, String> request = Collections.singletonMap("form", "Data");
|
Map<String, String> request = Collections.singletonMap("form", "Data");
|
||||||
@@ -144,14 +163,22 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected interface UnwrapClient {
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = "/bar") // intentionally /bar
|
||||||
|
String unwrap() throws IOException;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected interface FormClient {
|
protected interface FormClient {
|
||||||
|
|
||||||
@RequestMapping(value = "/form", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@RequestMapping(value = "/form", method = RequestMethod.POST,
|
||||||
|
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
String form(Map<String, String> form);
|
String form(Map<String, String> form);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@RestController
|
@RestController
|
||||||
@Import(NoSecurityConfiguration.class)
|
@Import(NoSecurityConfiguration.class)
|
||||||
@@ -174,7 +201,8 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/form", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@RequestMapping(value = "/form", method = RequestMethod.POST,
|
||||||
|
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
public String form(HttpServletRequest request) {
|
public String form(HttpServletRequest request) {
|
||||||
return request.getParameter("form");
|
return request.getParameter("form");
|
||||||
}
|
}
|
||||||
@@ -230,7 +258,7 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
|
|
||||||
requestTemplate.header(HttpHeaders.CONTENT_TYPE,
|
requestTemplate.header(HttpHeaders.CONTENT_TYPE,
|
||||||
MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
||||||
requestTemplate.body(Request.Body.bodyTemplate(builder.toString(), UTF_8));
|
requestTemplate.body(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-9
@@ -37,7 +37,7 @@ public class FeignClientsRegistrarTests {
|
|||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void badNameHttpPrefix() {
|
public void badNameHttpPrefix() {
|
||||||
testGetName("http://bad_hostname");
|
testGetName("https://bad_hostname");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
@@ -63,8 +63,8 @@ public class FeignClientsRegistrarTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void goodNameHttpPrefix() {
|
public void goodNameHttpPrefix() {
|
||||||
String name = testGetName("http://good-name");
|
String name = testGetName("https://good-name");
|
||||||
assertThat(name).as("name was wrong").isEqualTo("http://good-name");
|
assertThat(name).as("name was wrong").isEqualTo("https://good-name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -89,7 +89,8 @@ public class FeignClientsRegistrarTests {
|
|||||||
new AnnotationConfigApplicationContext(FallbackFactoryTestConfig.class);
|
new AnnotationConfigApplicationContext(FallbackFactoryTestConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeignClient(name = "fallbackTestClient", url = "http://localhost:8080/", fallback = FallbackClient.class)
|
@FeignClient(name = "fallbackTestClient", url = "http://localhost:8080/",
|
||||||
|
fallback = FallbackClient.class)
|
||||||
protected interface FallbackClient {
|
protected interface FallbackClient {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/hello")
|
@RequestMapping(method = RequestMethod.GET, value = "/hello")
|
||||||
@@ -97,7 +98,8 @@ public class FeignClientsRegistrarTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeignClient(name = "fallbackFactoryTestClient", url = "http://localhost:8081/", fallbackFactory = FallbackFactoryClient.class)
|
@FeignClient(name = "fallbackFactoryTestClient", url = "http://localhost:8081/",
|
||||||
|
fallbackFactory = FallbackFactoryClient.class)
|
||||||
protected interface FallbackFactoryClient {
|
protected interface FallbackFactoryClient {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/hello")
|
@RequestMapping(method = RequestMethod.GET, value = "/hello")
|
||||||
@@ -105,17 +107,17 @@ public class FeignClientsRegistrarTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@EnableFeignClients(clients = { FeignClientsRegistrarTests.FallbackClient.class })
|
@EnableFeignClients(clients = { FeignClientsRegistrarTests.FallbackClient.class })
|
||||||
protected static class FallbackTestConfig {
|
protected static class FallbackTestConfig {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@EnableFeignClients(clients = {
|
@EnableFeignClients(
|
||||||
FeignClientsRegistrarTests.FallbackFactoryClient.class })
|
clients = { FeignClientsRegistrarTests.FallbackFactoryClient.class })
|
||||||
protected static class FallbackFactoryTestConfig {
|
protected static class FallbackFactoryTestConfig {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -71,7 +71,7 @@ public class FeignCompressionTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
protected static class PlainConfig {
|
protected static class PlainConfig {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
+5
-4
@@ -50,9 +50,10 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = FeignHttpClientUrlTests.TestConfig.class, webEnvironment = DEFINED_PORT, value = {
|
@SpringBootTest(classes = FeignHttpClientUrlTests.TestConfig.class,
|
||||||
"spring.application.name=feignclienturltest", "feign.hystrix.enabled=false",
|
webEnvironment = DEFINED_PORT,
|
||||||
"feign.okhttp.enabled=false" })
|
value = { "spring.application.name=feignclienturltest",
|
||||||
|
"feign.hystrix.enabled=false", "feign.okhttp.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignHttpClientUrlTests {
|
public class FeignHttpClientUrlTests {
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ public class FeignHttpClientUrlTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@RestController
|
@RestController
|
||||||
@EnableFeignClients(clients = { UrlClient.class, BeanUrlClient.class,
|
@EnableFeignClients(clients = { UrlClient.class, BeanUrlClient.class,
|
||||||
|
|||||||
+3
-3
@@ -69,13 +69,13 @@ public class FeignLoggerFactoryTests {
|
|||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignClientsConfiguration.class)
|
@Import(FeignClientsConfiguration.class)
|
||||||
protected static class SampleConfiguration1 {
|
protected static class SampleConfiguration1 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignClientsConfiguration.class)
|
@Import(FeignClientsConfiguration.class)
|
||||||
protected static class SampleConfiguration2 {
|
protected static class SampleConfiguration2 {
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ public class FeignLoggerFactoryTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignClientsConfiguration.class)
|
@Import(FeignClientsConfiguration.class)
|
||||||
protected static class SampleConfiguration3 {
|
protected static class SampleConfiguration3 {
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -47,8 +47,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = SpringDecoderTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
|
@SpringBootTest(classes = SpringDecoderTests.Application.class,
|
||||||
"spring.application.name=springdecodertest", "spring.jmx.enabled=false" })
|
webEnvironment = WebEnvironment.RANDOM_PORT, value = {
|
||||||
|
"spring.application.name=springdecodertest", "spring.jmx.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class SpringDecoderTests extends FeignClientFactoryBean {
|
public class SpringDecoderTests extends FeignClientFactoryBean {
|
||||||
|
|
||||||
@@ -214,7 +215,7 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@RestController
|
@RestController
|
||||||
@Import(NoSecurityConfiguration.class)
|
@Import(NoSecurityConfiguration.class)
|
||||||
|
|||||||
+7
-6
@@ -49,10 +49,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = FeignClientTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
|
@SpringBootTest(classes = FeignClientTests.Application.class,
|
||||||
"spring.application.name=feignclienttest",
|
webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||||
"logging.level.org.springframework.cloud.openfeign.valid=DEBUG",
|
value = { "spring.application.name=feignclienttest",
|
||||||
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false" })
|
"logging.level.org.springframework.cloud.openfeign.valid=DEBUG",
|
||||||
|
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignClientTests {
|
public class FeignClientTests {
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ public class FeignClientTests {
|
|||||||
assertThat(invocationHandler).as("invocationHandler was null").isNotNull();
|
assertThat(invocationHandler).as("invocationHandler was null").isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@RestController
|
@RestController
|
||||||
@EnableFeignClients
|
@EnableFeignClients
|
||||||
@@ -169,7 +170,7 @@ public class FeignClientTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public static class TestDefaultFeignConfig {
|
public static class TestDefaultFeignConfig {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-4
@@ -50,8 +50,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
*
|
*
|
||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignAcceptEncodingTests.Application.class, webEnvironment = RANDOM_PORT, value = {
|
@SpringBootTest(classes = FeignAcceptEncodingTests.Application.class,
|
||||||
"feign.compression.response.enabled=true" })
|
webEnvironment = RANDOM_PORT,
|
||||||
|
value = { "feign.compression.response.enabled=true" })
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignAcceptEncodingTests {
|
public class FeignAcceptEncodingTests {
|
||||||
@@ -75,13 +76,14 @@ public class FeignAcceptEncodingTests {
|
|||||||
|
|
||||||
@EnableFeignClients(clients = InvoiceClient.class)
|
@EnableFeignClients(clients = InvoiceClient.class)
|
||||||
@RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class)
|
@RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class)
|
||||||
@SpringBootApplication(scanBasePackages = "org.springframework.cloud.openfeign.encoding.app")
|
@SpringBootApplication(
|
||||||
|
scanBasePackages = "org.springframework.cloud.openfeign.encoding.app")
|
||||||
@Import(NoSecurityConfiguration.class)
|
@Import(NoSecurityConfiguration.class)
|
||||||
public static class Application {
|
public static class Application {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class LocalRibbonClientConfiguration {
|
static class LocalRibbonClientConfiguration {
|
||||||
|
|
||||||
@Value("${local.server.port}")
|
@Value("${local.server.port}")
|
||||||
|
|||||||
+8
-6
@@ -49,10 +49,11 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
*
|
*
|
||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignContentEncodingTests.Application.class, webEnvironment = RANDOM_PORT, value = {
|
@SpringBootTest(classes = FeignContentEncodingTests.Application.class,
|
||||||
"feign.compression.request.enabled=true",
|
webEnvironment = RANDOM_PORT,
|
||||||
"hystrix.command.default.execution.isolation.strategy=SEMAPHORE",
|
value = { "feign.compression.request.enabled=true",
|
||||||
"ribbon.OkToRetryOnAllOperations=false" })
|
"hystrix.command.default.execution.isolation.strategy=SEMAPHORE",
|
||||||
|
"ribbon.OkToRetryOnAllOperations=false" })
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
public class FeignContentEncodingTests {
|
public class FeignContentEncodingTests {
|
||||||
|
|
||||||
@@ -79,13 +80,14 @@ public class FeignContentEncodingTests {
|
|||||||
|
|
||||||
@EnableFeignClients(clients = InvoiceClient.class)
|
@EnableFeignClients(clients = InvoiceClient.class)
|
||||||
@RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class)
|
@RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class)
|
||||||
@SpringBootApplication(scanBasePackages = "org.springframework.cloud.openfeign.encoding.app")
|
@SpringBootApplication(
|
||||||
|
scanBasePackages = "org.springframework.cloud.openfeign.encoding.app")
|
||||||
@Import(NoSecurityConfiguration.class)
|
@Import(NoSecurityConfiguration.class)
|
||||||
public static class Application {
|
public static class Application {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class LocalRibbonClientConfiguration {
|
static class LocalRibbonClientConfiguration {
|
||||||
|
|
||||||
@Value("${local.server.port}")
|
@Value("${local.server.port}")
|
||||||
|
|||||||
+10
-6
@@ -27,6 +27,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
@@ -54,10 +55,11 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
*
|
*
|
||||||
* @author Charlie Mordant.
|
* @author Charlie Mordant.
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignPageableEncodingTests.Application.class, webEnvironment = RANDOM_PORT, value = {
|
@SpringBootTest(classes = FeignPageableEncodingTests.Application.class,
|
||||||
"feign.compression.request.enabled=true",
|
webEnvironment = RANDOM_PORT,
|
||||||
"hystrix.command.default.execution.isolation.strategy=SEMAPHORE",
|
value = { "feign.compression.request.enabled=true",
|
||||||
"ribbon.OkToRetryOnAllOperations=false" })
|
"hystrix.command.default.execution.isolation.strategy=SEMAPHORE",
|
||||||
|
"ribbon.OkToRetryOnAllOperations=false" })
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
public class FeignPageableEncodingTests {
|
public class FeignPageableEncodingTests {
|
||||||
|
|
||||||
@@ -84,14 +86,16 @@ public class FeignPageableEncodingTests {
|
|||||||
|
|
||||||
@EnableFeignClients(clients = InvoiceClient.class)
|
@EnableFeignClients(clients = InvoiceClient.class)
|
||||||
@RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class)
|
@RibbonClient(name = "local", configuration = LocalRibbonClientConfiguration.class)
|
||||||
@SpringBootApplication(scanBasePackages = "org.springframework.cloud.openfeign.encoding.app")
|
@SpringBootApplication(
|
||||||
|
scanBasePackages = "org.springframework.cloud.openfeign.encoding.app",
|
||||||
|
exclude = { RepositoryRestMvcAutoConfiguration.class })
|
||||||
@EnableSpringDataWebSupport
|
@EnableSpringDataWebSupport
|
||||||
@Import({ NoSecurityConfiguration.class, FeignClientsConfiguration.class })
|
@Import({ NoSecurityConfiguration.class, FeignClientsConfiguration.class })
|
||||||
public static class Application {
|
public static class Application {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class LocalRibbonClientConfiguration {
|
static class LocalRibbonClientConfiguration {
|
||||||
|
|
||||||
@Value("${local.server.port}")
|
@Value("${local.server.port}")
|
||||||
|
|||||||
+7
-3
@@ -34,14 +34,18 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
@FeignClient("local")
|
@FeignClient("local")
|
||||||
public interface InvoiceClient {
|
public interface InvoiceClient {
|
||||||
|
|
||||||
@RequestMapping(value = "invoicesPaged", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "invoicesPaged", method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<Page<Invoice>> getInvoicesPaged(
|
ResponseEntity<Page<Invoice>> getInvoicesPaged(
|
||||||
org.springframework.data.domain.Pageable pageable);
|
org.springframework.data.domain.Pageable pageable);
|
||||||
|
|
||||||
@RequestMapping(value = "invoices", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "invoices", method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<List<Invoice>> getInvoices();
|
ResponseEntity<List<Invoice>> getInvoices();
|
||||||
|
|
||||||
@RequestMapping(value = "invoices", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "invoices", method = RequestMethod.POST,
|
||||||
|
consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<List<Invoice>> saveInvoices(List<Invoice> invoices);
|
ResponseEntity<List<Invoice>> saveInvoices(List<Invoice> invoices);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -39,19 +39,23 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RestController
|
@RestController
|
||||||
public class InvoiceResource {
|
public class InvoiceResource {
|
||||||
|
|
||||||
@RequestMapping(value = "invoices", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "invoices", method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public ResponseEntity<List<Invoice>> getInvoices() {
|
public ResponseEntity<List<Invoice>> getInvoices() {
|
||||||
|
|
||||||
return ResponseEntity.ok(createInvoiceList(100));
|
return ResponseEntity.ok(createInvoiceList(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "invoices", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "invoices", method = RequestMethod.POST,
|
||||||
|
consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<List<Invoice>> saveInvoices(@RequestBody List<Invoice> invoices) {
|
ResponseEntity<List<Invoice>> saveInvoices(@RequestBody List<Invoice> invoices) {
|
||||||
|
|
||||||
return ResponseEntity.ok(invoices);
|
return ResponseEntity.ok(invoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "invoicesPaged", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "invoicesPaged", method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public ResponseEntity<Page<Invoice>> getInvoicesPaged(
|
public ResponseEntity<Page<Invoice>> getInvoicesPaged(
|
||||||
org.springframework.data.domain.Pageable pageable) {
|
org.springframework.data.domain.Pageable pageable) {
|
||||||
Page<Invoice> page = new PageImpl<>(createInvoiceList(pageable.getPageSize()),
|
Page<Invoice> page = new PageImpl<>(createInvoiceList(pageable.getPageSize()),
|
||||||
|
|||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||||
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||||
|
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
public class FeignHalAutoConfigurationContextTests {
|
||||||
|
|
||||||
|
private WebApplicationContextRunner contextRunner;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
contextRunner = new WebApplicationContextRunner()
|
||||||
|
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class,
|
||||||
|
HttpMessageConvertersAutoConfiguration.class,
|
||||||
|
HypermediaAutoConfiguration.class,
|
||||||
|
RepositoryRestMvcAutoConfiguration.class,
|
||||||
|
FeignHalAutoConfiguration.class))
|
||||||
|
.withPropertyValues("debug=true");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHalJacksonHttpMessageConverterIsNotLoaded() {
|
||||||
|
FilteredClassLoader filteredClassLoader = new FilteredClassLoader(
|
||||||
|
RepositoryRestMvcConfiguration.class, RepresentationModel.class);
|
||||||
|
contextRunner.withClassLoader(filteredClassLoader)
|
||||||
|
.run(context -> assertThat(context)
|
||||||
|
.doesNotHaveBean("halJacksonHttpMessageConverter"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHalJacksonHttpMessageConverterIsLoaded() {
|
||||||
|
FilteredClassLoader filteredClassLoader = new FilteredClassLoader(
|
||||||
|
RepositoryRestMvcConfiguration.class);
|
||||||
|
contextRunner.withClassLoader(filteredClassLoader).run(
|
||||||
|
context -> assertThat(context).hasBean("halJacksonHttpMessageConverter"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHalJacksonHttpMessageConverterIsNotLoadedUseRestDataMessageConverterInstead() {
|
||||||
|
contextRunner.run(
|
||||||
|
context -> assertThat(context).hasBean("halJacksonHttpMessageConverter"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+89
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
import org.springframework.hateoas.mediatype.MessageResolver;
|
||||||
|
import org.springframework.hateoas.mediatype.hal.CurieProvider;
|
||||||
|
import org.springframework.hateoas.mediatype.hal.HalConfiguration;
|
||||||
|
import org.springframework.hateoas.mediatype.hal.Jackson2HalModule;
|
||||||
|
import org.springframework.hateoas.server.LinkRelationProvider;
|
||||||
|
import org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.hateoas.MediaTypes.HAL_JSON;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
|
public class FeignHalAutoConfigurationTests {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ObjectProvider<ObjectMapper> objectMapper;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ObjectProvider<HalConfiguration> halConfiguration;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ObjectProvider<LinkRelationProvider> relProvider;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ObjectProvider<CurieProvider> curieProvider;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ObjectProvider<MessageResolver> messageResolver;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private FeignHalAutoConfiguration feignHalAutoConfiguration;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void halJacksonHttpMessageConverter() {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
when(objectMapper.getIfAvailable(any())).thenReturn(mapper);
|
||||||
|
|
||||||
|
when(halConfiguration.getIfAvailable(any()))
|
||||||
|
.thenReturn(mock(HalConfiguration.class));
|
||||||
|
when(relProvider.getIfAvailable()).thenReturn(mock(LinkRelationProvider.class));
|
||||||
|
when(curieProvider.getIfAvailable(any())).thenReturn(mock(CurieProvider.class));
|
||||||
|
when(messageResolver.getIfAvailable()).thenReturn(mock(MessageResolver.class));
|
||||||
|
|
||||||
|
TypeConstrainedMappingJackson2HttpMessageConverter converter = feignHalAutoConfiguration
|
||||||
|
.halJacksonHttpMessageConverter(objectMapper, halConfiguration,
|
||||||
|
messageResolver, curieProvider, relProvider);
|
||||||
|
|
||||||
|
assertThat(converter).isNotNull();
|
||||||
|
assertThat(converter.getObjectMapper()).isNotNull();
|
||||||
|
assertThat(converter.getSupportedMediaTypes()).isEqualTo(Arrays.asList(HAL_JSON));
|
||||||
|
|
||||||
|
assertThat(Jackson2HalModule.isAlreadyRegisteredIn(converter.getObjectMapper()))
|
||||||
|
.isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.cloud.openfeign.hateoas.app.FeignHalApplication;
|
||||||
|
import org.springframework.cloud.openfeign.hateoas.app.FeignHalClient;
|
||||||
|
import org.springframework.cloud.openfeign.hateoas.app.MarsRover;
|
||||||
|
import org.springframework.hateoas.CollectionModel;
|
||||||
|
import org.springframework.hateoas.EntityModel;
|
||||||
|
import org.springframework.hateoas.Link;
|
||||||
|
import org.springframework.hateoas.PagedModel;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test HATEOAS support.
|
||||||
|
*
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = FeignHalApplication.class, webEnvironment = RANDOM_PORT,
|
||||||
|
value = "debug=true")
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@DirtiesContext
|
||||||
|
public class FeignHalTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FeignHalClient feignHalClient;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEntityModel() {
|
||||||
|
EntityModel<MarsRover> entity = feignHalClient.entity();
|
||||||
|
assertThat(entity).isNotNull();
|
||||||
|
|
||||||
|
assertThat(entity.hasLinks()).isTrue();
|
||||||
|
assertThat(entity.hasLink("self")).isTrue();
|
||||||
|
|
||||||
|
assertThat(entity.getLink("self")).map(Link::getHref).contains("/entity");
|
||||||
|
|
||||||
|
MarsRover marsRover = entity.getContent();
|
||||||
|
assertThat(marsRover).isNotNull();
|
||||||
|
assertThat(marsRover.getName()).isEqualTo("Sojourner");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCollectionModel() {
|
||||||
|
CollectionModel<MarsRover> collectionModel = feignHalClient.collection();
|
||||||
|
assertThat(collectionModel).isNotNull();
|
||||||
|
assertThat(collectionModel).isNotEmpty();
|
||||||
|
|
||||||
|
assertThat(collectionModel.hasLinks()).isTrue();
|
||||||
|
assertThat(collectionModel.hasLink("self")).isTrue();
|
||||||
|
|
||||||
|
assertThat(collectionModel.getLink("self")).map(Link::getHref)
|
||||||
|
.contains("/collection");
|
||||||
|
|
||||||
|
Collection<MarsRover> collection = collectionModel.getContent();
|
||||||
|
assertThat(collection).isNotEmpty();
|
||||||
|
|
||||||
|
MarsRover marsRover = collection.stream().findAny().orElse(null);
|
||||||
|
assertThat(marsRover).isNotNull();
|
||||||
|
assertThat(marsRover.getName()).isEqualTo("Opportunity");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPagedModel() {
|
||||||
|
PagedModel<MarsRover> paged = feignHalClient.paged();
|
||||||
|
assertThat(paged).isNotNull();
|
||||||
|
assertThat(paged).isNotEmpty();
|
||||||
|
|
||||||
|
assertThat(paged.hasLinks()).isTrue();
|
||||||
|
assertThat(paged.hasLink("self")).isTrue();
|
||||||
|
|
||||||
|
assertThat(paged.getLink("self")).map(Link::getHref).contains("/paged");
|
||||||
|
|
||||||
|
Collection<MarsRover> collection = paged.getContent();
|
||||||
|
assertThat(collection).isNotEmpty();
|
||||||
|
|
||||||
|
MarsRover marsRover = collection.stream().findAny().orElse(null);
|
||||||
|
assertThat(marsRover).isNotNull();
|
||||||
|
assertThat(marsRover.getName()).isEqualTo("Curiosity");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas.app;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
|
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test HATEOAS application.
|
||||||
|
*
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
@EnableFeignClients(clients = FeignHalClient.class)
|
||||||
|
@RibbonClient(name = "local", configuration = FeignHalRibbonConfiguration.class)
|
||||||
|
@SpringBootApplication(
|
||||||
|
scanBasePackages = "org.springframework.cloud.openfeign.hateoas.app",
|
||||||
|
exclude = RepositoryRestMvcAutoConfiguration.class)
|
||||||
|
@Import(NoSecurityConfiguration.class)
|
||||||
|
public class FeignHalApplication {
|
||||||
|
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas.app;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.hateoas.CollectionModel;
|
||||||
|
import org.springframework.hateoas.EntityModel;
|
||||||
|
import org.springframework.hateoas.PagedModel;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
@FeignClient("local")
|
||||||
|
public interface FeignHalClient {
|
||||||
|
|
||||||
|
@GetMapping("entity")
|
||||||
|
EntityModel<MarsRover> entity();
|
||||||
|
|
||||||
|
@GetMapping("collection")
|
||||||
|
CollectionModel<MarsRover> collection();
|
||||||
|
|
||||||
|
@GetMapping("paged")
|
||||||
|
PagedModel<MarsRover> paged();
|
||||||
|
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas.app;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.springframework.hateoas.CollectionModel;
|
||||||
|
import org.springframework.hateoas.EntityModel;
|
||||||
|
import org.springframework.hateoas.Link;
|
||||||
|
import org.springframework.hateoas.PagedModel;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class FeignHalController {
|
||||||
|
|
||||||
|
@GetMapping("/entity")
|
||||||
|
public EntityModel<MarsRover> getEntity() {
|
||||||
|
MarsRover marsRover = new MarsRover();
|
||||||
|
marsRover.setName("Sojourner");
|
||||||
|
Link link = new Link("/entity", "self");
|
||||||
|
return new EntityModel<>(marsRover, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/collection")
|
||||||
|
public CollectionModel<MarsRover> getCollection() {
|
||||||
|
MarsRover marsRover = new MarsRover();
|
||||||
|
marsRover.setName("Opportunity");
|
||||||
|
Link link = new Link("/collection", "self");
|
||||||
|
return new CollectionModel<>(Collections.singleton(marsRover), link);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/paged")
|
||||||
|
public CollectionModel<MarsRover> getPaged() {
|
||||||
|
MarsRover marsRover = new MarsRover();
|
||||||
|
marsRover.setName("Curiosity");
|
||||||
|
Link link = new Link("/paged", "self");
|
||||||
|
PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(1, 1, 1);
|
||||||
|
return new PagedModel<>(Collections.singleton(marsRover), metadata, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas.app;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import com.netflix.loadbalancer.BaseLoadBalancer;
|
||||||
|
import com.netflix.loadbalancer.ILoadBalancer;
|
||||||
|
import com.netflix.loadbalancer.Server;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
public class FeignHalRibbonConfiguration {
|
||||||
|
|
||||||
|
@Value("${local.server.port}")
|
||||||
|
private int serverPort = 0;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ILoadBalancer ribbonLoadBalancer() {
|
||||||
|
Server server = new Server("localhost", serverPort);
|
||||||
|
BaseLoadBalancer balancer = new BaseLoadBalancer();
|
||||||
|
balancer.setServersList(Collections.singletonList(server));
|
||||||
|
return balancer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2019 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.openfeign.hateoas.app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hector Espert
|
||||||
|
*/
|
||||||
|
public class MarsRover {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -31,7 +31,7 @@ import org.springframework.context.annotation.Import;
|
|||||||
/**
|
/**
|
||||||
* @author Daniel Lavoie
|
* @author Daniel Lavoie
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@EnableFeignClients(clients = UsernameClient.class)
|
@EnableFeignClients(clients = UsernameClient.class)
|
||||||
@Import(NoSecurityConfiguration.class)
|
@Import(NoSecurityConfiguration.class)
|
||||||
|
|||||||
+2
-2
@@ -56,8 +56,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||||
"feign.hystrix.enabled=true" })
|
properties = { "feign.hystrix.enabled=true" })
|
||||||
@ActiveProfiles("proxysecurity")
|
@ActiveProfiles("proxysecurity")
|
||||||
public class HystrixSecurityTests {
|
public class HystrixSecurityTests {
|
||||||
|
|
||||||
|
|||||||
+16
-35
@@ -47,12 +47,6 @@ public class FeignClientValidationTests {
|
|||||||
@Rule
|
@Rule
|
||||||
public ExpectedException expected = ExpectedException.none();
|
public ExpectedException expected = ExpectedException.none();
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNameAndValue() {
|
|
||||||
this.expected.expectMessage("only one is permitted");
|
|
||||||
new AnnotationConfigApplicationContext(NameAndValueConfiguration.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServiceIdAndValue() {
|
public void testServiceIdAndValue() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
@@ -128,22 +122,7 @@ public class FeignClientValidationTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignAutoConfiguration.class)
|
|
||||||
@EnableFeignClients(clients = NameAndValueConfiguration.Client.class)
|
|
||||||
protected static class NameAndValueConfiguration {
|
|
||||||
|
|
||||||
@FeignClient(value = "foo", name = "bar")
|
|
||||||
interface Client {
|
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/")
|
|
||||||
String get();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@Import({ FeignAutoConfiguration.class, HttpClientConfiguration.class })
|
@Import({ FeignAutoConfiguration.class, HttpClientConfiguration.class })
|
||||||
@EnableFeignClients(clients = NameAndServiceIdConfiguration.Client.class)
|
@EnableFeignClients(clients = NameAndServiceIdConfiguration.Client.class)
|
||||||
protected static class NameAndServiceIdConfiguration {
|
protected static class NameAndServiceIdConfiguration {
|
||||||
@@ -158,12 +137,11 @@ public class FeignClientValidationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
|
||||||
@Import({ FeignAutoConfiguration.class, HttpClientConfiguration.class })
|
@Import({ FeignAutoConfiguration.class, HttpClientConfiguration.class })
|
||||||
@EnableFeignClients(clients = {
|
@EnableFeignClients(
|
||||||
DuplicatedFeignClientNamesConfiguration.FooClient.class,
|
clients = { DuplicatedFeignClientNamesConfiguration.FooClient.class,
|
||||||
DuplicatedFeignClientNamesConfiguration.BarClient.class })
|
DuplicatedFeignClientNamesConfiguration.BarClient.class })
|
||||||
protected static class DuplicatedFeignClientNamesConfiguration {
|
protected static class DuplicatedFeignClientNamesConfiguration {
|
||||||
|
|
||||||
@FeignClient(contextId = "foo", name = "bar")
|
@FeignClient(contextId = "foo", name = "bar")
|
||||||
@@ -184,7 +162,7 @@ public class FeignClientValidationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignAutoConfiguration.class)
|
@Import(FeignAutoConfiguration.class)
|
||||||
@EnableFeignClients(clients = BadHostnameConfiguration.Client.class)
|
@EnableFeignClients(clients = BadHostnameConfiguration.Client.class)
|
||||||
protected static class BadHostnameConfiguration {
|
protected static class BadHostnameConfiguration {
|
||||||
@@ -199,7 +177,7 @@ public class FeignClientValidationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignAutoConfiguration.class)
|
@Import(FeignAutoConfiguration.class)
|
||||||
@EnableFeignClients(clients = MissingFallbackConfiguration.Client.class)
|
@EnableFeignClients(clients = MissingFallbackConfiguration.Client.class)
|
||||||
protected static class MissingFallbackConfiguration {
|
protected static class MissingFallbackConfiguration {
|
||||||
@@ -209,7 +187,8 @@ public class FeignClientValidationTests {
|
|||||||
return HystrixFeign.builder();
|
return HystrixFeign.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeignClient(name = "foobar", url = "http://localhost", fallback = ClientFallback.class)
|
@FeignClient(name = "foobar", url = "http://localhost",
|
||||||
|
fallback = ClientFallback.class)
|
||||||
interface Client {
|
interface Client {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/")
|
@RequestMapping(method = RequestMethod.GET, value = "/")
|
||||||
@@ -228,7 +207,7 @@ public class FeignClientValidationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignAutoConfiguration.class)
|
@Import(FeignAutoConfiguration.class)
|
||||||
@EnableFeignClients(clients = WrongFallbackTypeConfiguration.Client.class)
|
@EnableFeignClients(clients = WrongFallbackTypeConfiguration.Client.class)
|
||||||
protected static class WrongFallbackTypeConfiguration {
|
protected static class WrongFallbackTypeConfiguration {
|
||||||
@@ -257,7 +236,7 @@ public class FeignClientValidationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignAutoConfiguration.class)
|
@Import(FeignAutoConfiguration.class)
|
||||||
@EnableFeignClients(clients = MissingFallbackFactoryConfiguration.Client.class)
|
@EnableFeignClients(clients = MissingFallbackFactoryConfiguration.Client.class)
|
||||||
protected static class MissingFallbackFactoryConfiguration {
|
protected static class MissingFallbackFactoryConfiguration {
|
||||||
@@ -267,7 +246,8 @@ public class FeignClientValidationTests {
|
|||||||
return HystrixFeign.builder();
|
return HystrixFeign.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeignClient(name = "foobar", url = "http://localhost", fallbackFactory = ClientFallback.class)
|
@FeignClient(name = "foobar", url = "http://localhost",
|
||||||
|
fallbackFactory = ClientFallback.class)
|
||||||
interface Client {
|
interface Client {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/")
|
@RequestMapping(method = RequestMethod.GET, value = "/")
|
||||||
@@ -286,7 +266,7 @@ public class FeignClientValidationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignAutoConfiguration.class)
|
@Import(FeignAutoConfiguration.class)
|
||||||
@EnableFeignClients(clients = WrongFallbackFactoryTypeConfiguration.Client.class)
|
@EnableFeignClients(clients = WrongFallbackFactoryTypeConfiguration.Client.class)
|
||||||
protected static class WrongFallbackFactoryTypeConfiguration {
|
protected static class WrongFallbackFactoryTypeConfiguration {
|
||||||
@@ -301,7 +281,8 @@ public class FeignClientValidationTests {
|
|||||||
return HystrixFeign.builder();
|
return HystrixFeign.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FeignClient(name = "foobar", url = "http://localhost", fallbackFactory = Dummy.class)
|
@FeignClient(name = "foobar", url = "http://localhost",
|
||||||
|
fallbackFactory = Dummy.class)
|
||||||
interface Client {
|
interface Client {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/")
|
@RequestMapping(method = RequestMethod.GET, value = "/")
|
||||||
|
|||||||
+144
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import feign.Request;
|
||||||
|
import feign.Response;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||||
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
|
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link FeignBlockingLoadBalancerClient}. Note: the underlying
|
||||||
|
* {@link BlockingLoadBalancerClient} is already extensively tested in the Spring Cloud
|
||||||
|
* Commons project, so here we are only testing the interactions between
|
||||||
|
* {@link FeignBlockingLoadBalancerClient} and its delegates.
|
||||||
|
*
|
||||||
|
* @see <a href=
|
||||||
|
* "https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClientTests.java">BlockingLoadBalancerClientTests</a>
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
*/
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class FeignBlockingLoadBalancerClientTests {
|
||||||
|
|
||||||
|
private Client delegate = mock(Client.class);
|
||||||
|
|
||||||
|
private BlockingLoadBalancerClient loadBalancerClient = mock(
|
||||||
|
BlockingLoadBalancerClient.class);
|
||||||
|
|
||||||
|
private FeignBlockingLoadBalancerClient feignBlockingLoadBalancerClient = new FeignBlockingLoadBalancerClient(
|
||||||
|
delegate, loadBalancerClient);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldExtractServiceIdFromRequestUrl() throws IOException {
|
||||||
|
Request request = testRequest();
|
||||||
|
|
||||||
|
feignBlockingLoadBalancerClient.execute(request, new Request.Options());
|
||||||
|
|
||||||
|
verify(loadBalancerClient).choose("test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldThrowExceptionIfNoServiceId() {
|
||||||
|
Request request = testRequest("");
|
||||||
|
|
||||||
|
assertThatIllegalStateException()
|
||||||
|
.isThrownBy(() -> feignBlockingLoadBalancerClient.execute(request,
|
||||||
|
new Request.Options()))
|
||||||
|
.withMessage(
|
||||||
|
"Request URI does not contain a valid hostname: http:///path");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldRespondWithServiceUnavailableIfInstanceNotFound() throws IOException {
|
||||||
|
Request request = testRequest();
|
||||||
|
|
||||||
|
Response response = feignBlockingLoadBalancerClient.execute(request,
|
||||||
|
new Request.Options());
|
||||||
|
|
||||||
|
assertThat(response.status()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||||
|
assertThat(response.body().toString()).isEqualTo(
|
||||||
|
"Load balancer does not contain an instance for the service test");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldPassCorrectRequestToDelegate() throws IOException {
|
||||||
|
Request request = testRequest();
|
||||||
|
Request.Options options = new Request.Options();
|
||||||
|
String url = "http://127.0.0.1/path";
|
||||||
|
ServiceInstance serviceInstance = new DefaultServiceInstance("test-1", "test",
|
||||||
|
"test-host", 8888, false);
|
||||||
|
when(loadBalancerClient.choose("test")).thenReturn(serviceInstance);
|
||||||
|
when(loadBalancerClient.reconstructURI(serviceInstance,
|
||||||
|
URI.create("http://test/path"))).thenReturn(URI.create(url));
|
||||||
|
|
||||||
|
feignBlockingLoadBalancerClient.execute(request, options);
|
||||||
|
|
||||||
|
ArgumentCaptor<Request> captor = ArgumentCaptor.forClass(Request.class);
|
||||||
|
verify(delegate, times(1)).execute(captor.capture(), eq(options));
|
||||||
|
Request actualRequest = captor.getValue();
|
||||||
|
assertThat(actualRequest.httpMethod()).isEqualTo(Request.HttpMethod.GET);
|
||||||
|
assertThat(actualRequest.url()).isEqualTo(url);
|
||||||
|
assertThat(actualRequest.headers()).hasSize(1);
|
||||||
|
assertThat(actualRequest.headers()).containsEntry(HttpHeaders.CONTENT_TYPE,
|
||||||
|
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
||||||
|
assertThat(new String(actualRequest.body())).isEqualTo("hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request testRequest() {
|
||||||
|
return testRequest("test");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Request testRequest(String host) {
|
||||||
|
return Request.create(Request.HttpMethod.GET, "http://" + host + "/path",
|
||||||
|
testHeaders(), "hello".getBytes(), StandardCharsets.UTF_8, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Collection<String>> testHeaders() {
|
||||||
|
Map<String, Collection<String>> feignHeaders = new HashMap<>();
|
||||||
|
feignHeaders.put(HttpHeaders.CONTENT_TYPE,
|
||||||
|
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
||||||
|
return feignHeaders;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2019 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.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
|
import feign.httpclient.ApacheHttpClient;
|
||||||
|
import feign.okhttp.OkHttpClient;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.WebApplicationType;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
||||||
|
import org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient;
|
||||||
|
import org.springframework.cloud.loadbalancer.config.BlockingLoadBalancerClientAutoConfiguration;
|
||||||
|
import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfiguration;
|
||||||
|
import org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration;
|
||||||
|
import org.springframework.cloud.openfeign.ribbon.FeignRibbonClientAutoConfiguration;
|
||||||
|
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
*/
|
||||||
|
class FeignLoadBalancerAutoConfigurationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateDefaultFeignBlockingLoadBalancerClientWhenHttpClientDisabled() {
|
||||||
|
ConfigurableApplicationContext context = initContext(
|
||||||
|
"spring.cloud.loadbalancer.ribbon.enabled=false",
|
||||||
|
"feign.httpclient.enabled=false");
|
||||||
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
|
assertLoadBalanced(context, Client.Default.class);
|
||||||
|
assertThatBeanNotPresent(context, LoadBalancerFeignClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateHttpFeignClientWhenEnabled() {
|
||||||
|
ConfigurableApplicationContext context = initContext(
|
||||||
|
"spring.cloud.loadbalancer.ribbon.enabled=false");
|
||||||
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
|
assertLoadBalanced(context, ApacheHttpClient.class);
|
||||||
|
assertThatBeanNotPresent(context, LoadBalancerFeignClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateOkHttpFeignClientWhenEnabled() {
|
||||||
|
ConfigurableApplicationContext context = initContext(
|
||||||
|
"spring.cloud.loadbalancer.ribbon.enabled=false",
|
||||||
|
"feign.httpclient.enabled=false", "feign.okhttp.enabled=true");
|
||||||
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
|
assertLoadBalanced(context, OkHttpClient.class);
|
||||||
|
assertThatBeanNotPresent(context, LoadBalancerFeignClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldNotProcessLoadBalancerConfigurationWhenRibbonEnabled() {
|
||||||
|
ConfigurableApplicationContext context = initContext(
|
||||||
|
"spring.cloud.loadbalancer.ribbon.enabled=true");
|
||||||
|
assertThatOneBeanPresent(context, LoadBalancerFeignClient.class);
|
||||||
|
assertThatBeanNotPresent(context, BlockingLoadBalancerClient.class);
|
||||||
|
assertThatBeanNotPresent(context, FeignBlockingLoadBalancerClient.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConfigurableApplicationContext initContext(String... properties) {
|
||||||
|
return new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||||
|
.properties(properties)
|
||||||
|
.sources(HttpClientConfiguration.class, RibbonAutoConfiguration.class,
|
||||||
|
LoadBalancerAutoConfiguration.class,
|
||||||
|
BlockingLoadBalancerClientAutoConfiguration.class,
|
||||||
|
FeignRibbonClientAutoConfiguration.class,
|
||||||
|
FeignLoadBalancerAutoConfiguration.class)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertThatOneBeanPresent(ConfigurableApplicationContext context,
|
||||||
|
Class<?> beanClass) {
|
||||||
|
Map<String, ?> beans = context.getBeansOfType(beanClass);
|
||||||
|
assertThat(beans).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertLoadBalanced(ConfigurableApplicationContext context,
|
||||||
|
Class delegateClass) {
|
||||||
|
Map<String, FeignBlockingLoadBalancerClient> beans = context
|
||||||
|
.getBeansOfType(FeignBlockingLoadBalancerClient.class);
|
||||||
|
assertThat(beans).hasSize(1);
|
||||||
|
assertThat(beans.get("feignClient").getDelegate()).isInstanceOf(delegateClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertThatBeanNotPresent(ConfigurableApplicationContext context,
|
||||||
|
Class<?> beanClass) {
|
||||||
|
Map<String, ?> beans = context.getBeansOfType(beanClass);
|
||||||
|
assertThat(beans).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+8
-8
@@ -96,7 +96,7 @@ public class FeignLoadBalancerTests {
|
|||||||
|
|
||||||
this.feignLoadBalancer = new FeignLoadBalancer(this.lb, this.config,
|
this.feignLoadBalancer = new FeignLoadBalancer(this.lb, this.config,
|
||||||
this.inspector);
|
this.inspector);
|
||||||
Request request = new RequestTemplate().method(GET).target("http://foo/")
|
Request request = new RequestTemplate().method(GET).target("https://foo/")
|
||||||
.resolve(new HashMap<>()).request();
|
.resolve(new HashMap<>()).request();
|
||||||
RibbonRequest ribbonRequest = new RibbonRequest(this.delegate, request,
|
RibbonRequest ribbonRequest = new RibbonRequest(this.delegate, request,
|
||||||
new URI(request.url()));
|
new URI(request.url()));
|
||||||
@@ -108,7 +108,7 @@ public class FeignLoadBalancerTests {
|
|||||||
|
|
||||||
RibbonResponse resp = this.feignLoadBalancer.execute(ribbonRequest, null);
|
RibbonResponse resp = this.feignLoadBalancer.execute(ribbonRequest, null);
|
||||||
|
|
||||||
assertThat(resp.getRequestedURI()).isEqualTo(new URI("http://foo"));
|
assertThat(resp.getRequestedURI()).isEqualTo(new URI("https://foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -118,7 +118,7 @@ public class FeignLoadBalancerTests {
|
|||||||
this.inspector);
|
this.inspector);
|
||||||
Server server = new Server("foo", 7777);
|
Server server = new Server("foo", 7777);
|
||||||
URI uri = this.feignLoadBalancer.reconstructURIWithServer(server,
|
URI uri = this.feignLoadBalancer.reconstructURIWithServer(server,
|
||||||
new URI("http://foo/"));
|
new URI("https://foo/"));
|
||||||
assertThat(uri).isEqualTo(new URI("https://foo:7777/"));
|
assertThat(uri).isEqualTo(new URI("https://foo:7777/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +140,8 @@ public class FeignLoadBalancerTests {
|
|||||||
});
|
});
|
||||||
Server server = new Server("foo", 7777);
|
Server server = new Server("foo", 7777);
|
||||||
URI uri = this.feignLoadBalancer.reconstructURIWithServer(server,
|
URI uri = this.feignLoadBalancer.reconstructURIWithServer(server,
|
||||||
new URI("http://foo/"));
|
new URI("https://foo/"));
|
||||||
assertThat(uri).isEqualTo(new URI("http://foo:7777/"));
|
assertThat(uri).isEqualTo(new URI("https://foo:7777/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -152,14 +152,14 @@ public class FeignLoadBalancerTests {
|
|||||||
when(server.getPort()).thenReturn(443);
|
when(server.getPort()).thenReturn(443);
|
||||||
when(server.getHost()).thenReturn("foo");
|
when(server.getHost()).thenReturn("foo");
|
||||||
URI uri = this.feignLoadBalancer.reconstructURIWithServer(server,
|
URI uri = this.feignLoadBalancer.reconstructURIWithServer(server,
|
||||||
new URI("http://bar/"));
|
new URI("https://bar/"));
|
||||||
assertThat(uri).isEqualTo(new URI("https://foo:443/"));
|
assertThat(uri).isEqualTo(new URI("https://foo:443/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRibbonRequestURLEncode() throws Exception {
|
public void testRibbonRequestURLEncode() throws Exception {
|
||||||
String url = "http://foo/?name=%7bcookie"; // name={cookie
|
String url = "https://foo/?name=%7bcookie"; // name={cookie
|
||||||
Request request = Request.create(GET, url, new HashMap<>(), null, null);
|
Request request = Request.create(GET, url, new HashMap<>(), null, null, null);
|
||||||
|
|
||||||
assertThat(request.url()).isEqualTo(url);
|
assertThat(request.url()).isEqualTo(url);
|
||||||
|
|
||||||
|
|||||||
+10
-7
@@ -46,11 +46,14 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Venil Noronha
|
* @author Venil Noronha
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = FeignRibbonClientPathTests.Application.class, webEnvironment = RANDOM_PORT, value = {
|
@SpringBootTest(classes = FeignRibbonClientPathTests.Application.class,
|
||||||
"spring.application.name=feignribbonclientpathtest", "feign.okhttp.enabled=false",
|
webEnvironment = RANDOM_PORT,
|
||||||
"feign.httpclient.enabled=false", "feign.hystrix.enabled=false",
|
value = { "spring.application.name=feignribbonclientpathtest",
|
||||||
"test.path.prefix=/base/path" // For pathWithPlaceholder test
|
"feign.okhttp.enabled=false", "feign.httpclient.enabled=false",
|
||||||
})
|
"feign.hystrix.enabled=false", "test.path.prefix=/base/path" // For
|
||||||
|
// pathWithPlaceholder
|
||||||
|
// test
|
||||||
|
})
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignRibbonClientPathTests {
|
public class FeignRibbonClientPathTests {
|
||||||
|
|
||||||
@@ -136,7 +139,7 @@ public class FeignRibbonClientPathTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/base/path")
|
@RequestMapping("/base/path")
|
||||||
@@ -174,7 +177,7 @@ public class FeignRibbonClientPathTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public static class LocalRibbonClientConfiguration {
|
public static class LocalRibbonClientConfiguration {
|
||||||
|
|
||||||
@Value("${local.server.port}")
|
@Value("${local.server.port}")
|
||||||
|
|||||||
+8
-7
@@ -52,11 +52,12 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = FeignRibbonClientRetryTests.Application.class, webEnvironment = RANDOM_PORT, value = {
|
@SpringBootTest(classes = FeignRibbonClientRetryTests.Application.class,
|
||||||
"spring.application.name=feignclientretrytest", "feign.okhttp.enabled=false",
|
webEnvironment = RANDOM_PORT,
|
||||||
"feign.httpclient.enabled=false", "feign.hystrix.enabled=false",
|
value = { "spring.application.name=feignclientretrytest",
|
||||||
"localapp.ribbon.MaxAutoRetries=2",
|
"feign.okhttp.enabled=false", "feign.httpclient.enabled=false",
|
||||||
"localapp.ribbon.MaxAutoRetriesNextServer=3" })
|
"feign.hystrix.enabled=false", "localapp.ribbon.MaxAutoRetries=2",
|
||||||
|
"localapp.ribbon.MaxAutoRetriesNextServer=3" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignRibbonClientRetryTests {
|
public class FeignRibbonClientRetryTests {
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ public class FeignRibbonClientRetryTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@RestController
|
@RestController
|
||||||
@EnableFeignClients(clients = TestClient.class)
|
@EnableFeignClients(clients = TestClient.class)
|
||||||
@@ -141,7 +142,7 @@ public class FeignRibbonClientRetryTests {
|
|||||||
|
|
||||||
// Load balancer with fixed server list for "local" pointing to localhost
|
// Load balancer with fixed server list for "local" pointing to localhost
|
||||||
// some bogus servers are thrown in to test retry
|
// some bogus servers are thrown in to test retry
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
class LocalRibbonClientConfiguration {
|
class LocalRibbonClientConfiguration {
|
||||||
|
|
||||||
@Value("${local.server.port}")
|
@Value("${local.server.port}")
|
||||||
|
|||||||
+5
-3
@@ -44,8 +44,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = FeignRibbonHttpClientConfigurationTests.FeignRibbonHttpClientConfigurationTestsApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
|
@SpringBootTest(
|
||||||
"debug=true", "feign.httpclient.disableSslValidation=true" })
|
classes = FeignRibbonHttpClientConfigurationTests.FeignRibbonHttpClientConfigurationTestsApplication.class,
|
||||||
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
|
properties = { "debug=true", "feign.httpclient.disableSslValidation=true" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignRibbonHttpClientConfigurationTests {
|
public class FeignRibbonHttpClientConfigurationTests {
|
||||||
|
|
||||||
@@ -86,7 +88,7 @@ public class FeignRibbonHttpClientConfigurationTests {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
static class FeignRibbonHttpClientConfigurationTestsApplication {
|
static class FeignRibbonHttpClientConfigurationTestsApplication {
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -40,9 +40,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = FeignRibbonOkHttpClientConfigurationTests.FeignRibbonOkHttpClientConfigurationTestsApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = {
|
@SpringBootTest(
|
||||||
"debug=true", "feign.httpclient.disableSslValidation=true",
|
classes = FeignRibbonOkHttpClientConfigurationTests.FeignRibbonOkHttpClientConfigurationTestsApplication.class,
|
||||||
"feign.okhttp.enabled=true", "feign.httpclient.enabled=false" })
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
|
properties = { "debug=true", "feign.httpclient.disableSslValidation=true",
|
||||||
|
"feign.okhttp.enabled=true", "feign.httpclient.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignRibbonOkHttpClientConfigurationTests {
|
public class FeignRibbonOkHttpClientConfigurationTests {
|
||||||
|
|
||||||
@@ -65,7 +67,7 @@ public class FeignRibbonOkHttpClientConfigurationTests {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
static class FeignRibbonOkHttpClientConfigurationTestsApplication {
|
static class FeignRibbonOkHttpClientConfigurationTestsApplication {
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -41,9 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = LoadBalancerFeignClientOverrideTests.TestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
|
@SpringBootTest(classes = LoadBalancerFeignClientOverrideTests.TestConfiguration.class,
|
||||||
"spring.application.name=loadBalancerFeignClientTests",
|
webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||||
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false" })
|
value = { "spring.application.name=loadBalancerFeignClientTests",
|
||||||
|
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class LoadBalancerFeignClientOverrideTests {
|
public class LoadBalancerFeignClientOverrideTests {
|
||||||
|
|
||||||
@@ -107,7 +108,7 @@ public class LoadBalancerFeignClientOverrideTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableFeignClients(clients = { FooClient.class, BarClient.class, BazClient.class })
|
@EnableFeignClients(clients = { FooClient.class, BarClient.class, BazClient.class })
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
protected static class TestConfiguration {
|
protected static class TestConfiguration {
|
||||||
|
|||||||
+33
-33
@@ -132,11 +132,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
doReturn(config).when(clientFactory).getClientConfig(eq("default"));
|
doReturn(config).when(clientFactory).getClientConfig(eq("default"));
|
||||||
RibbonLoadBalancedRetryFactory loadBalancedRetryFactory = new RibbonLoadBalancedRetryFactory(
|
RibbonLoadBalancedRetryFactory loadBalancedRetryFactory = new RibbonLoadBalancedRetryFactory(
|
||||||
clientFactory);
|
clientFactory);
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
Response response = Response.builder().status(200).request(feignRequest)
|
Response response = Response.builder().status(200).request(feignRequest)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
doReturn(response).when(client).execute(any(Request.class),
|
doReturn(response).when(client).execute(any(Request.class),
|
||||||
@@ -150,11 +150,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void executeNeverRetry() throws Exception {
|
public void executeNeverRetry() throws Exception {
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
doThrow(new IOException("boom")).when(client).execute(any(Request.class),
|
doThrow(new IOException("boom")).when(client).execute(any(Request.class),
|
||||||
any(Request.Options.class));
|
any(Request.Options.class));
|
||||||
RetryableFeignLoadBalancer feignLb = new RetryableFeignLoadBalancer(this.lb,
|
RetryableFeignLoadBalancer feignLb = new RetryableFeignLoadBalancer(this.lb,
|
||||||
@@ -214,11 +214,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
return backOffPolicy;
|
return backOffPolicy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
Response response = Response.builder().status(200).request(feignRequest)
|
Response response = Response.builder().status(200).request(feignRequest)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
doThrow(new IOException("boom")).doReturn(response).when(client)
|
doThrow(new IOException("boom")).doReturn(response).when(client)
|
||||||
@@ -259,11 +259,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
return backOffPolicy;
|
return backOffPolicy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
Response response = Response.builder().request(feignRequest).status(200)
|
Response response = Response.builder().request(feignRequest).status(200)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
Response fourOFourResponse = Response.builder().request(feignRequest).status(404)
|
Response fourOFourResponse = Response.builder().request(feignRequest).status(404)
|
||||||
@@ -309,11 +309,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
return backOffPolicy;
|
return backOffPolicy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
Response response = Response.builder().request(feignRequest).status(404)
|
Response response = Response.builder().request(feignRequest).status(404)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
Response fourOFourResponse = Response.builder().request(feignRequest).status(404)
|
Response fourOFourResponse = Response.builder().request(feignRequest).status(404)
|
||||||
@@ -338,11 +338,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
doReturn(lbContext).when(clientFactory).getLoadBalancerContext(any(String.class));
|
doReturn(lbContext).when(clientFactory).getLoadBalancerContext(any(String.class));
|
||||||
RibbonLoadBalancedRetryFactory loadBalancedRetryFactory = new RibbonLoadBalancedRetryFactory(
|
RibbonLoadBalancedRetryFactory loadBalancedRetryFactory = new RibbonLoadBalancedRetryFactory(
|
||||||
clientFactory);
|
clientFactory);
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
Response response = Response.builder().request(feignRequest).status(200)
|
Response response = Response.builder().request(feignRequest).status(200)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
doReturn(response).when(client).execute(any(Request.class),
|
doReturn(response).when(client).execute(any(Request.class),
|
||||||
@@ -364,11 +364,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
doReturn(lbContext).when(clientFactory).getLoadBalancerContext(any(String.class));
|
doReturn(lbContext).when(clientFactory).getLoadBalancerContext(any(String.class));
|
||||||
RibbonLoadBalancedRetryFactory loadBalancedRetryFactory = new RibbonLoadBalancedRetryFactory(
|
RibbonLoadBalancedRetryFactory loadBalancedRetryFactory = new RibbonLoadBalancedRetryFactory(
|
||||||
clientFactory);
|
clientFactory);
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
Response response = Response.builder().request(feignRequest).status(200)
|
Response response = Response.builder().request(feignRequest).status(200)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
doReturn(response).when(client).execute(any(Request.class),
|
doReturn(response).when(client).execute(any(Request.class),
|
||||||
@@ -445,11 +445,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
return backOffPolicy;
|
return backOffPolicy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Request feignRequest = Request.create(GET, "http://listener", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://listener", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://listener"));
|
client, feignRequest, new URI("https://listener"));
|
||||||
Response response = Response.builder().request(feignRequest).status(200)
|
Response response = Response.builder().request(feignRequest).status(200)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
doThrow(new IOException("boom")).doReturn(response).when(client)
|
doThrow(new IOException("boom")).doReturn(response).when(client)
|
||||||
@@ -497,11 +497,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
return backOffPolicy;
|
return backOffPolicy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Request feignRequest = Request.create(GET, "http://listener", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://listener", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://listener"));
|
client, feignRequest, new URI("https://listener"));
|
||||||
RetryableFeignLoadBalancer feignLb = new RetryableFeignLoadBalancer(this.lb,
|
RetryableFeignLoadBalancer feignLb = new RetryableFeignLoadBalancer(this.lb,
|
||||||
config, this.inspector, loadBalancedRetryFactory);
|
config, this.inspector, loadBalancedRetryFactory);
|
||||||
FeignLoadBalancer.RibbonResponse ribbonResponse = feignLb.execute(request, null);
|
FeignLoadBalancer.RibbonResponse ribbonResponse = feignLb.execute(request, null);
|
||||||
@@ -534,11 +534,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
return backOffPolicy;
|
return backOffPolicy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Request feignRequest = Request.create(GET, "http://listener", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://listener", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://listener"));
|
client, feignRequest, new URI("https://listener"));
|
||||||
Response response = Response.builder().request(feignRequest).status(200)
|
Response response = Response.builder().request(feignRequest).status(200)
|
||||||
.headers(new HashMap<>()).build();
|
.headers(new HashMap<>()).build();
|
||||||
doThrow(new IOException("boom")).doReturn(response).when(client)
|
doThrow(new IOException("boom")).doReturn(response).when(client)
|
||||||
@@ -579,11 +579,11 @@ public class RetryableFeignLoadBalancerTests {
|
|||||||
return backOffPolicy;
|
return backOffPolicy;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Request feignRequest = Request.create(GET, "http://foo", new HashMap<>(),
|
Request feignRequest = Request.create(GET, "https://foo", new HashMap<>(),
|
||||||
new byte[] {}, UTF_8);
|
new byte[] {}, UTF_8, null);
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(
|
||||||
client, feignRequest, new URI("http://foo"));
|
client, feignRequest, new URI("https://foo"));
|
||||||
Response fourOFourResponse = Response.builder().request(feignRequest).status(404)
|
Response fourOFourResponse = Response.builder().request(feignRequest).status(404)
|
||||||
.headers(new HashMap<>()).body(new Response.Body() { // set content into
|
.headers(new HashMap<>()).body(new Response.Body() { // set content into
|
||||||
// response
|
// response
|
||||||
|
|||||||
+4
-5
@@ -44,13 +44,12 @@ public class RibbonResponseStatusCodeExceptionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getResponse() throws Exception {
|
public void getResponse() throws Exception {
|
||||||
Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
|
Map<String, Collection<String>> headers = new HashMap<>();
|
||||||
List<String> fooValues = new ArrayList<String>();
|
List<String> fooValues = new ArrayList<>();
|
||||||
fooValues.add("bar");
|
fooValues.add("bar");
|
||||||
headers.put("foo", fooValues);
|
headers.put("foo", fooValues);
|
||||||
Request request = Request.create(GET, "https://service.com",
|
Request request = Request.create(GET, "https://service.com", new HashMap<>(),
|
||||||
new HashMap<String, Collection<String>>(), new byte[] {},
|
new byte[] {}, Charset.defaultCharset(), null);
|
||||||
Charset.defaultCharset());
|
|
||||||
byte[] body = "foo".getBytes();
|
byte[] body = "foo".getBytes();
|
||||||
ByteArrayInputStream is = new ByteArrayInputStream(body);
|
ByteArrayInputStream is = new ByteArrayInputStream(body);
|
||||||
Response response = Response.builder().status(200).reason("Success")
|
Response response = Response.builder().status(200).reason("Success")
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ public class FeignHttpClientPropertiesTests {
|
|||||||
return this.context.getBean(FeignHttpClientProperties.class);
|
return this.context.getBean(FeignHttpClientProperties.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableConfigurationProperties
|
@EnableConfigurationProperties
|
||||||
protected static class TestConfiguration {
|
protected static class TestConfiguration {
|
||||||
|
|
||||||
|
|||||||
+32
-10
@@ -39,8 +39,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Charlie Mordant.
|
* @author Charlie Mordant.
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = SpringEncoderTests.Application.class, webEnvironment = RANDOM_PORT, value = {
|
@SpringBootTest(classes = SpringEncoderTests.Application.class,
|
||||||
"spring.application.name=springencodertest", "spring.jmx.enabled=false" })
|
webEnvironment = RANDOM_PORT, value = {
|
||||||
|
"spring.application.name=springencodertest", "spring.jmx.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class PageableEncoderTests {
|
public class PageableEncoderTests {
|
||||||
|
|
||||||
@@ -63,13 +64,18 @@ public class PageableEncoderTests {
|
|||||||
encoder.encode(createPageAndSortRequest(), null, request);
|
encoder.encode(createPageAndSortRequest(), null, request);
|
||||||
|
|
||||||
// Request queries shall contain three entries
|
// Request queries shall contain three entries
|
||||||
assertThat(request.queries().size()).isEqualTo(3);
|
assertThat(request.queries()).hasSize(3);
|
||||||
// Request page shall contain page
|
// Request page shall contain page
|
||||||
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
|
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
|
||||||
// Request size shall contain size
|
// Request size shall contain size
|
||||||
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE));
|
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE)); // Request
|
||||||
// Request sort size shall contain sort entries
|
// sort
|
||||||
assertThat(request.queries().get("sort").size()).isEqualTo(2);
|
// size
|
||||||
|
// shall
|
||||||
|
// contain
|
||||||
|
// sort
|
||||||
|
// entries
|
||||||
|
assertThat(request.queries().get("sort")).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pageable createPageAndSortRequest() {
|
private Pageable createPageAndSortRequest() {
|
||||||
@@ -86,9 +92,14 @@ public class PageableEncoderTests {
|
|||||||
// Request page shall contain page
|
// Request page shall contain page
|
||||||
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
|
assertThat(request.queries().get("page")).contains(String.valueOf(PAGE));
|
||||||
// Request size shall contain size
|
// Request size shall contain size
|
||||||
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE));
|
assertThat(request.queries().get("size")).contains(String.valueOf(SIZE)); // Request
|
||||||
// Request sort size shall contain sort entries
|
// sort
|
||||||
assertThat(request.queries().containsKey("sort")).isEqualTo(false);
|
// size
|
||||||
|
// shall
|
||||||
|
// contain
|
||||||
|
// sort
|
||||||
|
// entries
|
||||||
|
assertThat(request.queries()).doesNotContainKey("sort");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pageable createPageAndRequest() {
|
private Pageable createPageAndRequest() {
|
||||||
@@ -105,11 +116,22 @@ public class PageableEncoderTests {
|
|||||||
// Request queries shall contain three entries
|
// Request queries shall contain three entries
|
||||||
assertThat(request.queries().size()).isEqualTo(1);
|
assertThat(request.queries().size()).isEqualTo(1);
|
||||||
// Request sort size shall contain sort entries
|
// Request sort size shall contain sort entries
|
||||||
assertThat(request.queries().get("sort").size()).isEqualTo(2);
|
assertThat(request.queries().get("sort")).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Sort createSort() {
|
private Sort createSort() {
|
||||||
return Sort.by(SORT_1, SORT_2).ascending();
|
return Sort.by(SORT_1, SORT_2).ascending();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnpagedRequest() {
|
||||||
|
Encoder encoder = this.context.getInstance("foo", Encoder.class);
|
||||||
|
assertThat(encoder).isNotNull();
|
||||||
|
RequestTemplate request = new RequestTemplate();
|
||||||
|
|
||||||
|
encoder.encode(Pageable.unpaged(), null, request);
|
||||||
|
// Request queries shall contain three entries
|
||||||
|
assertThat(request.queries()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+109
-35
@@ -16,10 +16,11 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.support;
|
package org.springframework.cloud.openfeign.support;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
@@ -27,7 +28,6 @@ import feign.codec.EncodeException;
|
|||||||
import feign.codec.Encoder;
|
import feign.codec.Encoder;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentMatcher;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
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;
|
||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
import org.springframework.cloud.openfeign.FeignContext;
|
import org.springframework.cloud.openfeign.FeignContext;
|
||||||
|
import org.springframework.cloud.openfeign.encoding.HttpEncoding;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.http.HttpInputMessage;
|
import org.springframework.http.HttpInputMessage;
|
||||||
import org.springframework.http.HttpOutputMessage;
|
import org.springframework.http.HttpOutputMessage;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.converter.AbstractGenericHttpMessageConverter;
|
import org.springframework.http.converter.AbstractGenericHttpMessageConverter;
|
||||||
|
import org.springframework.http.converter.GenericHttpMessageConverter;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||||
@@ -60,10 +63,12 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author Ahmad Mozafarnia
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(classes = SpringEncoderTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT, value = {
|
@SpringBootTest(classes = SpringEncoderTests.Application.class,
|
||||||
"spring.application.name=springencodertest", "spring.jmx.enabled=false" })
|
webEnvironment = WebEnvironment.RANDOM_PORT, value = {
|
||||||
|
"spring.application.name=springencodertest", "spring.jmx.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class SpringEncoderTests {
|
public class SpringEncoderTests {
|
||||||
|
|
||||||
@@ -74,6 +79,10 @@ public class SpringEncoderTests {
|
|||||||
@Qualifier("myHttpMessageConverter")
|
@Qualifier("myHttpMessageConverter")
|
||||||
private HttpMessageConverter<?> myConverter;
|
private HttpMessageConverter<?> myConverter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("myGenericHttpMessageConverter")
|
||||||
|
private GenericHttpMessageConverter<?> myGenericConverter;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomHttpMessageConverter() {
|
public void testCustomHttpMessageConverter() {
|
||||||
Encoder encoder = this.context.getInstance("foo", Encoder.class);
|
Encoder encoder = this.context.getInstance("foo", Encoder.class);
|
||||||
@@ -93,7 +102,35 @@ public class SpringEncoderTests {
|
|||||||
|
|
||||||
assertThat(request.requestCharset()).as("request charset is null").isNotNull();
|
assertThat(request.requestCharset()).as("request charset is null").isNotNull();
|
||||||
assertThat(request.requestCharset()).as("request charset is wrong")
|
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<List<String>> stringListType = new ParameterizedTypeReference<List<String>>() {
|
||||||
|
};
|
||||||
|
|
||||||
|
request.header(HttpEncoding.CONTENT_TYPE, "application/mygenerictype");
|
||||||
|
encoder.encode(Collections.singletonList("hi"), stringListType.getType(),
|
||||||
|
request);
|
||||||
|
|
||||||
|
Collection<String> 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
|
@Test
|
||||||
@@ -119,8 +156,6 @@ public class SpringEncoderTests {
|
|||||||
MultipartFile multipartFile = new MockMultipartFile("test_multipart_file",
|
MultipartFile multipartFile = new MockMultipartFile("test_multipart_file",
|
||||||
"hi".getBytes());
|
"hi".getBytes());
|
||||||
encoder.encode(multipartFile, MultipartFile.class, request);
|
encoder.encode(multipartFile, MultipartFile.class, request);
|
||||||
|
|
||||||
assertThat(request.requestCharset()).as("request charset is not null").isNull();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// gh-105, gh-107
|
// gh-105, gh-107
|
||||||
@@ -168,7 +203,7 @@ public class SpringEncoderTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@RestController
|
@RestController
|
||||||
protected static class Application implements TestClient {
|
protected static class Application implements TestClient {
|
||||||
@@ -178,6 +213,11 @@ public class SpringEncoderTests {
|
|||||||
return new MyHttpMessageConverter();
|
return new MyHttpMessageConverter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
GenericHttpMessageConverter<?> myGenericHttpMessageConverter() {
|
||||||
|
return new MyGenericHttpMessageConverter();
|
||||||
|
}
|
||||||
|
|
||||||
private static class MyHttpMessageConverter
|
private static class MyHttpMessageConverter
|
||||||
extends AbstractGenericHttpMessageConverter<Object> {
|
extends AbstractGenericHttpMessageConverter<Object> {
|
||||||
|
|
||||||
@@ -203,20 +243,77 @@ public class SpringEncoderTests {
|
|||||||
@Override
|
@Override
|
||||||
protected void writeInternal(Object o, Type type,
|
protected void writeInternal(Object o, Type type,
|
||||||
HttpOutputMessage outputMessage)
|
HttpOutputMessage outputMessage)
|
||||||
throws IOException, HttpMessageNotWritableException {
|
throws HttpMessageNotWritableException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
|
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage)
|
||||||
throws IOException, HttpMessageNotReadableException {
|
throws HttpMessageNotReadableException {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object read(Type type, Class<?> contextClass,
|
public Object read(Type type, Class<?> contextClass,
|
||||||
HttpInputMessage inputMessage)
|
HttpInputMessage inputMessage)
|
||||||
throws IOException, HttpMessageNotReadableException {
|
throws HttpMessageNotReadableException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MyGenericHttpMessageConverter
|
||||||
|
extends AbstractGenericHttpMessageConverter<Object> {
|
||||||
|
|
||||||
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,27 +321,4 @@ public class SpringEncoderTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MediaTypeMatcher implements ArgumentMatcher<MediaType> {
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+96
-27
@@ -23,6 +23,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -45,6 +46,7 @@ import org.springframework.util.MultiValueMap;
|
|||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.MatrixVariable;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@@ -52,18 +54,19 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RequestPart;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
|
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY;
|
||||||
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
|
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
import static org.springframework.web.util.UriUtils.encode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author chadjaros
|
* @author chadjaros
|
||||||
* @author Halvdan Hoem Grelland
|
* @author Halvdan Hoem Grelland
|
||||||
* @author Aram Peres
|
* @author Aram Peres
|
||||||
|
* @author Aaron Whiteside
|
||||||
*/
|
*/
|
||||||
public class SpringMvcContractTests {
|
public class SpringMvcContractTests {
|
||||||
|
|
||||||
@@ -244,7 +247,7 @@ public class SpringMvcContractTests {
|
|||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url())
|
assertThat(data.template().url())
|
||||||
.isEqualTo("/advanced/test/{id}?amount=" + encode("{amount}", UTF_8));
|
.isEqualTo("/advanced/test/{id}?amount=" + "{amount}");
|
||||||
assertThat(data.template().method()).isEqualTo("PUT");
|
assertThat(data.template().method()).isEqualTo("PUT");
|
||||||
assertThat(data.template().headers().get("Accept").iterator().next())
|
assertThat(data.template().headers().get("Accept").iterator().next())
|
||||||
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||||
@@ -268,7 +271,7 @@ public class SpringMvcContractTests {
|
|||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url())
|
assertThat(data.template().url())
|
||||||
.isEqualTo("/advanced/test/{id}?amount=" + encode("{amount}", UTF_8));
|
.isEqualTo("/advanced/test/{id}?amount=" + "{amount}");
|
||||||
assertThat(data.template().method()).isEqualTo("PUT");
|
assertThat(data.template().method()).isEqualTo("PUT");
|
||||||
assertThat(data.template().headers().get("Accept").iterator().next())
|
assertThat(data.template().headers().get("Accept").iterator().next())
|
||||||
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||||
@@ -293,7 +296,7 @@ public class SpringMvcContractTests {
|
|||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url())
|
assertThat(data.template().url())
|
||||||
.isEqualTo("/advanced/test2?amount=" + encode("{amount}", UTF_8));
|
.isEqualTo("/advanced/test2?amount=" + "{amount}");
|
||||||
assertThat(data.template().method()).isEqualTo("PUT");
|
assertThat(data.template().method()).isEqualTo("PUT");
|
||||||
assertThat(data.template().headers().get("Accept").iterator().next())
|
assertThat(data.template().headers().get("Accept").iterator().next())
|
||||||
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||||
@@ -380,7 +383,7 @@ public class SpringMvcContractTests {
|
|||||||
MethodMetadata data = this.contract
|
MethodMetadata data = this.contract
|
||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url()).isEqualTo("/test?id=" + encode("{id}", UTF_8));
|
assertThat(data.template().url()).isEqualTo("/test?id=" + "{id}");
|
||||||
assertThat(data.template().method()).isEqualTo("GET");
|
assertThat(data.template().method()).isEqualTo("GET");
|
||||||
assertThat(data.template().queries().get("id").toString()).isEqualTo("[{id}]");
|
assertThat(data.template().queries().get("id").toString()).isEqualTo("[{id}]");
|
||||||
assertThat(data.indexToExpander().get(0)).isNotNull();
|
assertThat(data.indexToExpander().get(0)).isNotNull();
|
||||||
@@ -393,7 +396,7 @@ public class SpringMvcContractTests {
|
|||||||
MethodMetadata data = this.contract
|
MethodMetadata data = this.contract
|
||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url()).isEqualTo("/test?id=" + encode("{id}", UTF_8));
|
assertThat(data.template().url()).isEqualTo("/test?id=" + "{id}");
|
||||||
assertThat(data.template().method()).isEqualTo("GET");
|
assertThat(data.template().method()).isEqualTo("GET");
|
||||||
assertThat(data.template().queries().get("id").toString()).isEqualTo("[{id}]");
|
assertThat(data.template().queries().get("id").toString()).isEqualTo("[{id}]");
|
||||||
assertThat(data.indexToExpander().get(0)).isNotNull();
|
assertThat(data.indexToExpander().get(0)).isNotNull();
|
||||||
@@ -448,8 +451,8 @@ public class SpringMvcContractTests {
|
|||||||
MethodMetadata data = this.contract
|
MethodMetadata data = this.contract
|
||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url()).isEqualTo(
|
assertThat(data.template().url())
|
||||||
"/advanced/testfallback/{id}?amount=" + encode("{amount}", UTF_8));
|
.isEqualTo("/advanced/testfallback/{id}?amount=" + "{amount}");
|
||||||
assertThat(data.template().method()).isEqualTo("PUT");
|
assertThat(data.template().method()).isEqualTo("PUT");
|
||||||
assertThat(data.template().headers().get("Accept").iterator().next())
|
assertThat(data.template().headers().get("Accept").iterator().next())
|
||||||
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
|
||||||
@@ -493,8 +496,7 @@ public class SpringMvcContractTests {
|
|||||||
MethodMetadata data = this.contract
|
MethodMetadata data = this.contract
|
||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url())
|
assertThat(data.template().url()).isEqualTo("/queryMap?aParam=" + "{aParam}");
|
||||||
.isEqualTo("/queryMap?aParam=" + encode("{aParam}", UTF_8));
|
|
||||||
assertThat(data.template().method()).isEqualTo("GET");
|
assertThat(data.template().method()).isEqualTo("GET");
|
||||||
assertThat(data.queryMapIndex().intValue()).isEqualTo(0);
|
assertThat(data.queryMapIndex().intValue()).isEqualTo(0);
|
||||||
Map<String, Collection<String>> params = data.template().queries();
|
Map<String, Collection<String>> params = data.template().queries();
|
||||||
@@ -509,7 +511,7 @@ public class SpringMvcContractTests {
|
|||||||
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
assertThat(data.template().url())
|
assertThat(data.template().url())
|
||||||
.isEqualTo("/queryMapObject?aParam=" + encode("{aParam}", UTF_8));
|
.isEqualTo("/queryMapObject?aParam=" + "{aParam}");
|
||||||
assertThat(data.template().method()).isEqualTo("GET");
|
assertThat(data.template().method()).isEqualTo("GET");
|
||||||
assertThat(data.queryMapIndex().intValue()).isEqualTo(0);
|
assertThat(data.queryMapIndex().intValue()).isEqualTo(0);
|
||||||
Map<String, Collection<String>> params = data.template().queries();
|
Map<String, Collection<String>> params = data.template().queries();
|
||||||
@@ -523,6 +525,35 @@ public class SpringMvcContractTests {
|
|||||||
this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatrixVariable_MapParam() throws Exception {
|
||||||
|
Method method = TestTemplate_MatrixVariable.class
|
||||||
|
.getDeclaredMethod("matrixVariable", Map.class);
|
||||||
|
MethodMetadata data = this.contract
|
||||||
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
|
Map<String, String> testMap = new HashMap<>();
|
||||||
|
testMap.put("param", "value");
|
||||||
|
|
||||||
|
assertThat(data.template().method()).isEqualTo("GET");
|
||||||
|
assertThat(data.template().url()).isEqualTo("/matrixVariable/{params}");
|
||||||
|
assertThat(";param=value")
|
||||||
|
.isEqualTo(data.indexToExpander().get(0).expand(testMap));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatrixVariable_ObjectParam() throws Exception {
|
||||||
|
Method method = TestTemplate_MatrixVariable.class
|
||||||
|
.getDeclaredMethod("matrixVariableObject", Object.class);
|
||||||
|
MethodMetadata data = this.contract
|
||||||
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
|
||||||
|
assertThat(data.template().method()).isEqualTo("GET");
|
||||||
|
assertThat(data.template().url()).isEqualTo("/matrixVariableObject/{param}");
|
||||||
|
assertThat(";param=value")
|
||||||
|
.isEqualTo(data.indexToExpander().get(0).expand("value"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddingTemplatedParameterWithTheSameKey()
|
public void testAddingTemplatedParameterWithTheSameKey()
|
||||||
throws NoSuchMethodException {
|
throws NoSuchMethodException {
|
||||||
@@ -535,18 +566,31 @@ public class SpringMvcContractTests {
|
|||||||
"{Accept}");
|
"{Accept}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMultipleRequestPartAnnotations() throws NoSuchMethodException {
|
||||||
|
Method method = TestTemplate_RequestPart.class.getDeclaredMethod(
|
||||||
|
"requestWithMultipleParts", MultipartFile.class, String.class);
|
||||||
|
|
||||||
|
MethodMetadata data = contract
|
||||||
|
.parseAndValidateMetadata(method.getDeclaringClass(), method);
|
||||||
|
assertThat(data.formParams()).contains("file", "id");
|
||||||
|
}
|
||||||
|
|
||||||
public interface TestTemplate_Simple {
|
public interface TestTemplate_Simple {
|
||||||
|
|
||||||
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
|
ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
TestObject getTest();
|
TestObject getTest();
|
||||||
|
|
||||||
@GetMapping(value = "/test/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
@GetMapping(value = "/test/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<TestObject> getMappingTest(@PathVariable("id") String id);
|
ResponseEntity<TestObject> getMappingTest(@PathVariable("id") String id);
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(method = RequestMethod.POST,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
TestObject postTest(@RequestBody TestObject object);
|
TestObject postTest(@RequestBody TestObject object);
|
||||||
|
|
||||||
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
@@ -572,15 +616,16 @@ public class SpringMvcContractTests {
|
|||||||
|
|
||||||
public interface TestTemplate_Headers {
|
public interface TestTemplate_Headers {
|
||||||
|
|
||||||
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET, headers = "X-Foo=bar")
|
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET,
|
||||||
|
headers = "X-Foo=bar")
|
||||||
ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
|
ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface TestTemplate_HeadersWithoutValues {
|
public interface TestTemplate_HeadersWithoutValues {
|
||||||
|
|
||||||
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET, headers = {
|
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET,
|
||||||
"X-Foo", "!X-Bar", "X-Baz!=fooBar" })
|
headers = { "X-Foo", "!X-Bar", "X-Baz!=fooBar" })
|
||||||
ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
|
ResponseEntity<TestObject> getTest(@PathVariable("id") String id);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -635,26 +680,49 @@ public class SpringMvcContractTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface TestTemplate_RequestPart {
|
||||||
|
|
||||||
|
@RequestMapping(path = "/requestPart", method = RequestMethod.POST,
|
||||||
|
consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
void requestWithMultipleParts(@RequestPart("file") MultipartFile file,
|
||||||
|
@RequestPart("id") String identifier);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface TestTemplate_MatrixVariable {
|
||||||
|
|
||||||
|
@RequestMapping(path = "/matrixVariable/{params}")
|
||||||
|
String matrixVariable(@MatrixVariable("params") Map<String, Object> params);
|
||||||
|
|
||||||
|
@RequestMapping(path = "/matrixVariableObject/{param}")
|
||||||
|
String matrixVariableObject(@MatrixVariable("param") Object object);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@JsonAutoDetect
|
@JsonAutoDetect
|
||||||
@RequestMapping("/advanced")
|
@RequestMapping("/advanced")
|
||||||
public interface TestTemplate_Advanced {
|
public interface TestTemplate_Advanced {
|
||||||
|
|
||||||
@ExceptionHandler
|
@ExceptionHandler
|
||||||
@RequestMapping(path = "/test/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(path = "/test/{id}", method = RequestMethod.PUT,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<TestObject> getTest(@RequestHeader("Authorization") String auth,
|
ResponseEntity<TestObject> getTest(@RequestHeader("Authorization") String auth,
|
||||||
@PathVariable("id") String id, @RequestParam("amount") Integer amount);
|
@PathVariable("id") String id, @RequestParam("amount") Integer amount);
|
||||||
|
|
||||||
@RequestMapping(path = "/test2", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(path = "/test2", method = RequestMethod.PUT,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<TestObject> getTest2(
|
ResponseEntity<TestObject> getTest2(
|
||||||
@RequestHeader(name = "Authorization") String auth,
|
@RequestHeader(name = "Authorization") String auth,
|
||||||
@RequestParam(name = "amount") Integer amount);
|
@RequestParam(name = "amount") Integer amount);
|
||||||
|
|
||||||
@ExceptionHandler
|
@ExceptionHandler
|
||||||
@RequestMapping(path = "/testfallback/{id}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(path = "/testfallback/{id}", method = RequestMethod.PUT,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
ResponseEntity<TestObject> getTestFallback(@RequestHeader String Authorization,
|
ResponseEntity<TestObject> getTestFallback(@RequestHeader String Authorization,
|
||||||
@PathVariable String id, @RequestParam Integer amount);
|
@PathVariable String id, @RequestParam Integer amount);
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(method = RequestMethod.GET,
|
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
TestObject getTest();
|
TestObject getTest();
|
||||||
|
|
||||||
@GetMapping(produces = "application/json")
|
@GetMapping(produces = "application/json")
|
||||||
@@ -668,8 +736,8 @@ public class SpringMvcContractTests {
|
|||||||
String CUSTOM_PATTERN = "dd-MM-yyyy HH:mm";
|
String CUSTOM_PATTERN = "dd-MM-yyyy HH:mm";
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET)
|
@RequestMapping(method = RequestMethod.GET)
|
||||||
String getTest(
|
String getTest(@RequestParam(name = "localDateTime") @DateTimeFormat(
|
||||||
@RequestParam(name = "localDateTime") @DateTimeFormat(pattern = CUSTOM_PATTERN) LocalDateTime localDateTime);
|
pattern = CUSTOM_PATTERN) LocalDateTime localDateTime);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,12 +746,13 @@ public class SpringMvcContractTests {
|
|||||||
String CUSTOM_PATTERN = "$###,###.###";
|
String CUSTOM_PATTERN = "$###,###.###";
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET)
|
@RequestMapping(method = RequestMethod.GET)
|
||||||
String getTest(
|
String getTest(@RequestParam("amount") @NumberFormat(
|
||||||
@RequestParam("amount") @NumberFormat(pattern = CUSTOM_PATTERN) BigDecimal amount);
|
pattern = CUSTOM_PATTERN) BigDecimal amount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
|
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE,
|
||||||
|
setterVisibility = NONE)
|
||||||
public class TestObject {
|
public class TestObject {
|
||||||
|
|
||||||
public String something;
|
public String something;
|
||||||
|
|||||||
+5
-5
@@ -65,8 +65,8 @@ import static org.mockito.Mockito.mockingDetails;
|
|||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@SpringBootTest(properties = { "feign.okhttp.enabled: false",
|
@SpringBootTest(
|
||||||
"ribbon.eureka.enabled = false" })
|
properties = { "feign.okhttp.enabled: false", "ribbon.eureka.enabled = false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class ApacheHttpClientConfigurationTests {
|
public class ApacheHttpClientConfigurationTests {
|
||||||
|
|
||||||
@@ -109,8 +109,8 @@ public class ApacheHttpClientConfigurationTests {
|
|||||||
|
|
||||||
@SpringBootConfiguration
|
@SpringBootConfiguration
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@EnableFeignClients(clients = {
|
@EnableFeignClients(
|
||||||
ApacheHttpClientConfigurationTestApp.FooClient.class })
|
clients = { ApacheHttpClientConfigurationTestApp.FooClient.class })
|
||||||
static class ApacheHttpClientConfigurationTestApp {
|
static class ApacheHttpClientConfigurationTestApp {
|
||||||
|
|
||||||
@FeignClient(name = "foo", serviceId = "foo")
|
@FeignClient(name = "foo", serviceId = "foo")
|
||||||
@@ -160,7 +160,7 @@ public class ApacheHttpClientConfigurationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class MyConfig {
|
static class MyConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
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.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
|
||||||
@Configuration
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class NoSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
public class NoSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user