Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
245b106a76 | ||
|
|
666a59df6b | ||
|
|
5a21e22002 | ||
|
|
bdcbaa7f3b | ||
|
|
375241803d | ||
|
|
0213d4be21 | ||
|
|
73cde28fcf | ||
|
|
5bddccf720 | ||
|
|
5f40f245af | ||
|
|
e4bdc13c51 | ||
|
|
f344125527 | ||
|
|
26e157fd46 | ||
|
|
efbf71294d | ||
|
|
9529e43c01 | ||
|
|
a26095bb6c | ||
|
|
540ec0410d | ||
|
|
8989036e93 | ||
|
|
1c8e8056e4 | ||
|
|
a29f28506f | ||
|
|
926f1151c1 | ||
|
|
1e70aec75c | ||
|
|
3f55dbecba | ||
|
|
1a72f2502e | ||
|
|
f8b3ed971e | ||
|
|
bc7d39fa04 | ||
|
|
4cba1de153 | ||
|
|
8493de9aa6 | ||
|
|
1bed516e03 | ||
|
|
a142f6f2c0 | ||
|
|
434ce22328 | ||
|
|
9f160e7688 | ||
|
|
a3f270d3b4 | ||
|
|
1ff643f4c1 | ||
|
|
6704982bcd | ||
|
|
909da0afdf | ||
|
|
4cd0c363be | ||
|
|
86a2f28a9e | ||
|
|
001b7388a7 | ||
|
|
0c5c3befbc | ||
|
|
952a7b0ff0 | ||
|
|
2b1ac9caa8 | ||
|
|
573d933b3d | ||
|
|
2a008d12c8 | ||
|
|
d76869f214 | ||
|
|
12efc629a3 | ||
|
|
965c168c2c | ||
|
|
295b5e4861 | ||
|
|
efbb0b8224 | ||
|
|
4e1859eea6 | ||
|
|
f2386e365d | ||
|
|
0972d4211f | ||
|
|
2f8f114667 | ||
|
|
0d0ff50842 | ||
|
|
088221b9fb | ||
|
|
765431dce1 | ||
|
|
8998eb3423 | ||
|
|
75fc0f6b2e | ||
|
|
f662c0547d | ||
|
|
aa4b8a280d | ||
|
|
973c048be5 | ||
|
|
5a19a0a128 | ||
|
|
ddc1b94555 | ||
|
|
cef268947f | ||
|
|
e99dac2af1 | ||
|
|
8d802a3fee | ||
|
|
e674f488d2 | ||
|
|
2eea81f93b | ||
|
|
83b6f043dd | ||
|
|
ee8a42e401 | ||
|
|
53428758ad | ||
|
|
59ac5c1b3c | ||
|
|
4f7892f34d | ||
|
|
261fc58a5e | ||
|
|
67e8c9072d | ||
|
|
813ff7c8b0 | ||
|
|
7b08279aae | ||
|
|
b8519c01a0 | ||
|
|
f60859120d | ||
|
|
c665d2c029 | ||
|
|
d626518dc5 | ||
|
|
7f425704e4 | ||
|
|
8b1c1dbf4c | ||
|
|
eb11b51ee7 | ||
|
|
5dff9cfc49 | ||
|
|
6c130af613 | ||
|
|
468d18b8f7 | ||
|
|
98b2511d1f | ||
|
|
234361e0fc | ||
|
|
10ad8a0c6e | ||
|
|
505894315d | ||
|
|
d706e071f3 | ||
|
|
e2048b3719 | ||
|
|
653a35270d | ||
|
|
c195a9a1db | ||
|
|
e389726ba2 | ||
|
|
2cf8adf482 | ||
|
|
6a1d9fe074 | ||
|
|
b6b16a034a | ||
|
|
cabf06e2fd | ||
|
|
60b55c7b06 | ||
|
|
7f91d7ec5a | ||
|
|
bf1aa72fad | ||
|
|
9629f15491 | ||
|
|
26a11826ab | ||
|
|
098ecb9dd7 | ||
|
|
1b0626a345 | ||
|
|
fe8bbbb6da | ||
|
|
b4f6f4ee30 | ||
|
|
ffbcf788bf | ||
|
|
85886c0cbb | ||
|
|
f7e4281002 | ||
|
|
bd46a10a7d | ||
|
|
65efa29da5 | ||
|
|
4e23e0cf58 | ||
|
|
d11e0d9dd4 | ||
|
|
e5deb642a2 | ||
|
|
ba7346573e | ||
|
|
38ccf1be95 | ||
|
|
5fee522f4c | ||
|
|
ce04947d92 | ||
|
|
61f71e6ac7 | ||
|
|
939f279a38 | ||
|
|
0cd57b2ce7 | ||
|
|
1752dd9815 | ||
|
|
b78eacd714 | ||
|
|
876778935c | ||
|
|
ae97365b6c | ||
|
|
fd6c1290fe | ||
|
|
7f03521b0d | ||
|
|
21adacbc43 | ||
|
|
3de4b98b3d | ||
|
|
a5e66077d6 | ||
|
|
02c0a1e0f6 | ||
|
|
98229d5ece | ||
|
|
9c0dda896f | ||
|
|
f018193b9f | ||
|
|
3432b7a965 | ||
|
|
8d8d948f08 | ||
|
|
c6ea224501 | ||
|
|
f5be046f90 | ||
|
|
9018acfc40 | ||
|
|
6533389e16 | ||
|
|
1ff68c11d2 | ||
|
|
abdb699f1d | ||
|
|
8b9254a008 | ||
|
|
95a93dcc5c | ||
|
|
685b42e85f | ||
|
|
8dd2c82968 | ||
|
|
f4615d198e | ||
|
|
fae18f2039 | ||
|
|
ff30485b40 | ||
|
|
a3704f0614 | ||
|
|
3322f95fe4 | ||
|
|
626d0a739b | ||
|
|
8f403f85f2 | ||
|
|
7581b2c27f | ||
|
|
a3ea61a586 | ||
|
|
1b063edf7e | ||
|
|
f3f9525081 | ||
|
|
a08fd801c2 | ||
|
|
183e6ff30a | ||
|
|
fe91a99984 | ||
|
|
c2539ac6a5 | ||
|
|
948aa13cc1 | ||
|
|
d8cbd16b76 | ||
|
|
1187c3e5b8 | ||
|
|
ebe30c8d3c | ||
|
|
4ffc61e186 | ||
|
|
5f9a827a40 | ||
|
|
80a7102b14 | ||
|
|
26a0319095 | ||
|
|
7b6a0c2838 | ||
|
|
05365b79f9 |
@@ -5,9 +5,9 @@ name: Build
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ 3.0.x ]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ 3.0.x ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java: ["8", "11", "16"]
|
java: ["17"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|||||||
@@ -20,5 +20,4 @@ _site/
|
|||||||
*.swo
|
*.swo
|
||||||
.vscode/
|
.vscode/
|
||||||
.flattened-pom.xml
|
.flattened-pom.xml
|
||||||
.sdkmanrc
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Enable auto-env through the sdkman_auto_env config
|
||||||
|
# Add key=value pairs of SDKs to use below
|
||||||
|
java=17.0.1-tem
|
||||||
+3
-1
@@ -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>3.0.8-SNAPSHOT</version>
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-cloud-openfeign-docs</artifactId>
|
<artifactId>spring-cloud-openfeign-docs</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
<main.basedir>${basedir}/..</main.basedir>
|
<main.basedir>${basedir}/..</main.basedir>
|
||||||
<configprops.inclusionPattern>feign.*</configprops.inclusionPattern>
|
<configprops.inclusionPattern>feign.*</configprops.inclusionPattern>
|
||||||
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
|
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
|
||||||
|
<!-- Don't upload docs jar to central / repo.spring.io -->
|
||||||
|
<maven-deploy-plugin-default.phase>none</maven-deploy-plugin-default.phase>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,35 +1,37 @@
|
|||||||
|===
|
|===
|
||||||
|Name | Default | Description
|
|Name | Default | Description
|
||||||
|
|
||||||
|feign.autoconfiguration.jackson.enabled | `false` | If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding.
|
|spring.cloud.openfeign.autoconfiguration.jackson.enabled | `false` | If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding.
|
||||||
|feign.circuitbreaker.enabled | `false` | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker.
|
|spring.cloud.openfeign.circuitbreaker.enabled | `false` | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker.
|
||||||
|feign.circuitbreaker.group.enabled | `false` | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker with with group.
|
|spring.cloud.openfeign.circuitbreaker.group.enabled | `false` | If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker with with group.
|
||||||
|feign.client.config | |
|
|spring.cloud.openfeign.client.config | |
|
||||||
|feign.client.decode-slash | `true` | Feign clients do not encode slash `/` characters by default. To change this behavior, set the `decodeSlash` to `false`.
|
|spring.cloud.openfeign.client.decode-slash | `true` | Feign clients do not encode slash `/` characters by default. To change this behavior, set the `decodeSlash` to `false`.
|
||||||
|feign.client.default-config | `default` |
|
|spring.cloud.openfeign.client.default-config | `default` |
|
||||||
|feign.client.default-to-properties | `true` |
|
|spring.cloud.openfeign.client.default-to-properties | `true` |
|
||||||
|feign.client.refresh-enabled | `false` | Enables options value refresh capability for Feign.
|
|spring.cloud.openfeign.client.refresh-enabled | `false` | Enables options value refresh capability for Feign.
|
||||||
|feign.compression.request.enabled | `false` | Enables the request sent by Feign to be compressed.
|
|spring.cloud.openfeign.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.
|
|spring.cloud.openfeign.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.
|
|spring.cloud.openfeign.compression.request.min-request-size | `2048` | The minimum threshold content size.
|
||||||
|feign.compression.response.enabled | `false` | Enables the response from Feign to be compressed.
|
|spring.cloud.openfeign.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.
|
|spring.cloud.openfeign.encoder.charset-from-content-type | `false` | Indicates whether the charset should be derived from the {@code Content-Type} header.
|
||||||
|feign.encoder.charset-from-content-type | `false` | Indicates whether the charset should be derived from the {@code Content-Type} header.
|
|spring.cloud.openfeign.httpclient.connection-timeout | `2000` |
|
||||||
|feign.httpclient.connection-timeout | `2000` |
|
|spring.cloud.openfeign.httpclient.connection-timer-repeat | `3000` |
|
||||||
|feign.httpclient.connection-timer-repeat | `3000` |
|
|spring.cloud.openfeign.httpclient.disable-ssl-validation | `false` |
|
||||||
|feign.httpclient.disable-ssl-validation | `false` |
|
|spring.cloud.openfeign.httpclient.enabled | `true` | Enables the use of the Apache HTTP Client by Feign.
|
||||||
|feign.httpclient.enabled | `true` | Enables the use of the Apache HTTP Client by Feign.
|
|spring.cloud.openfeign.httpclient.follow-redirects | `true` |
|
||||||
|feign.httpclient.follow-redirects | `true` |
|
|spring.cloud.openfeign.httpclient.hc5.enabled | `false` | Enables the use of the Apache HTTP Client 5 by Feign.
|
||||||
|feign.httpclient.hc5.enabled | `false` | Enables the use of the Apache HTTP Client 5 by Feign.
|
|spring.cloud.openfeign.httpclient.hc5.pool-concurrency-policy | | Pool concurrency policies.
|
||||||
|feign.httpclient.hc5.pool-concurrency-policy | | Pool concurrency policies.
|
|spring.cloud.openfeign.httpclient.hc5.pool-reuse-policy | | Pool connection re-use policies.
|
||||||
|feign.httpclient.hc5.pool-reuse-policy | | Pool connection re-use policies.
|
|spring.cloud.openfeign.httpclient.hc5.socket-timeout | `5` | Default value for socket timeout.
|
||||||
|feign.httpclient.hc5.socket-timeout | `5` | Default value for socket timeout.
|
|spring.cloud.openfeign.httpclient.hc5.socket-timeout-unit | | Default value for socket timeout unit.
|
||||||
|feign.httpclient.hc5.socket-timeout-unit | | Default value for socket timeout unit.
|
|spring.cloud.openfeign.httpclient.max-connections | `200` |
|
||||||
|feign.httpclient.max-connections | `200` |
|
|spring.cloud.openfeign.httpclient.max-connections-per-route | `50` |
|
||||||
|feign.httpclient.max-connections-per-route | `50` |
|
|spring.cloud.openfeign.httpclient.ok-http.read-timeout | `60s` | {@link OkHttpClient} read timeout; defaults to 60 seconds.
|
||||||
|feign.httpclient.time-to-live | `900` |
|
|spring.cloud.openfeign.httpclient.time-to-live | `900` |
|
||||||
|feign.httpclient.time-to-live-unit | |
|
|spring.cloud.openfeign.httpclient.time-to-live-unit | |
|
||||||
|feign.metrics.enabled | `true` | Enables metrics capability for Feign.
|
|spring.cloud.openfeign.metrics.enabled | `true` | Enables metrics capability for Feign.
|
||||||
|feign.okhttp.enabled | `false` | Enables the use of the OK HTTP Client by Feign.
|
|spring.cloud.openfeign.oauth2.enabled | `false` | Enables feign interceptor for managing oauth2 access token.
|
||||||
|
|spring.cloud.openfeign.oauth2.load-balanced | `false` | Enables load balancing for oauth2 access token provider.
|
||||||
|
|spring.cloud.openfeign.okhttp.enabled | `false` | Enables the use of the OK HTTP Client by Feign.
|
||||||
|
|
||||||
|===
|
|===
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
spring-cloud-openfeign.adoc
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
include::spring-cloud-openfeign.adoc[]
|
||||||
@@ -52,6 +52,9 @@ public interface StoreClient {
|
|||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
|
||||||
Store update(@PathVariable("storeId") Long storeId, Store store);
|
Store update(@PathVariable("storeId") Long storeId, Store store);
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.DELETE, value = "/stores/{storeId:\\d+}")
|
||||||
|
void delete(@PathVariable Long storeId);
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
@@ -119,6 +122,7 @@ Spring Cloud OpenFeign provides the following beans by default for feign (`BeanT
|
|||||||
* `Encoder` feignEncoder: `SpringEncoder`
|
* `Encoder` feignEncoder: `SpringEncoder`
|
||||||
* `Logger` feignLogger: `Slf4jLogger`
|
* `Logger` feignLogger: `Slf4jLogger`
|
||||||
* `MicrometerCapability` micrometerCapability: If `feign-micrometer` is on the classpath and `MeterRegistry` is available
|
* `MicrometerCapability` micrometerCapability: If `feign-micrometer` is on the classpath and `MeterRegistry` is available
|
||||||
|
* `CachingCapability` cachingCapability: If `@EnableCaching` annotation is used. Can be disabled via `spring.cloud.openfeign.cache.enabled`.
|
||||||
* `Contract` feignContract: `SpringMvcContract`
|
* `Contract` feignContract: `SpringMvcContract`
|
||||||
* `Feign.Builder` feignBuilder: `FeignCircuitBreaker.Builder`
|
* `Feign.Builder` feignBuilder: `FeignCircuitBreaker.Builder`
|
||||||
* `Client` feignClient: If Spring Cloud LoadBalancer is on the classpath, `FeignBlockingLoadBalancerClient` is used.
|
* `Client` feignClient: If Spring Cloud LoadBalancer is on the classpath, `FeignBlockingLoadBalancerClient` is used.
|
||||||
@@ -126,7 +130,7 @@ If none of them is on the classpath, the default feign client is used.
|
|||||||
|
|
||||||
NOTE: `spring-cloud-starter-openfeign` supports `spring-cloud-starter-loadbalancer`. However, as is an optional dependency, you need to make sure it been added to your project if you want to use it.
|
NOTE: `spring-cloud-starter-openfeign` supports `spring-cloud-starter-loadbalancer`. However, as is an optional dependency, you need to make sure it been added to your project if you want to use it.
|
||||||
|
|
||||||
The OkHttpClient and ApacheHttpClient and ApacheHC5 feign clients can be used by setting `feign.okhttp.enabled` or `feign.httpclient.enabled` or `feign.httpclient.hc5.enabled` to `true`, respectively, and having them on the classpath.
|
The OkHttpClient and ApacheHttpClient and ApacheHC5 feign clients can be used by setting `spring.cloud.openfeign.okhttp.enabled` or `spring.cloud.openfeign.httpclient.enabled` or `spring.cloud.openfeign.httpclient.hc5.enabled` to `true`, respectively, and having them on the classpath.
|
||||||
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 or `org.apache.hc.client5.http.impl.classic.CloseableHttpClient` when using Apache HC5.
|
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 or `org.apache.hc.client5.http.impl.classic.CloseableHttpClient` when using Apache HC5.
|
||||||
|
|
||||||
Spring Cloud OpenFeign _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 OpenFeign _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:
|
||||||
@@ -138,7 +142,7 @@ Spring Cloud OpenFeign _does not_ provide the following beans by default for fei
|
|||||||
* `Collection<RequestInterceptor>`
|
* `Collection<RequestInterceptor>`
|
||||||
* `SetterFactory`
|
* `SetterFactory`
|
||||||
* `QueryMapEncoder`
|
* `QueryMapEncoder`
|
||||||
* `Capability` (`MicrometerCapability` is provided by default)
|
* `Capability` (`MicrometerCapability` and `CachingCapability` are provided by default)
|
||||||
|
|
||||||
A bean of `Retryer.NEVER_RETRY` with the type `Retryer` is created by default, which will disable retrying.
|
A bean of `Retryer.NEVER_RETRY` with the type `Retryer` is created by default, which will disable retrying.
|
||||||
Notice this retrying behavior is different from the Feign default one, where it will automatically retry IOExceptions,
|
Notice this retrying behavior is different from the Feign default one, where it will automatically retry IOExceptions,
|
||||||
@@ -169,53 +173,58 @@ This replaces the `SpringMvcContract` with `feign.Contract.Default` and adds a `
|
|||||||
application.yml
|
application.yml
|
||||||
[source,yaml]
|
[source,yaml]
|
||||||
----
|
----
|
||||||
feign:
|
spring:
|
||||||
client:
|
cloud:
|
||||||
config:
|
openfeign:
|
||||||
feignName:
|
client:
|
||||||
connectTimeout: 5000
|
config:
|
||||||
readTimeout: 5000
|
feignName:
|
||||||
loggerLevel: full
|
connectTimeout: 5000
|
||||||
errorDecoder: com.example.SimpleErrorDecoder
|
readTimeout: 5000
|
||||||
retryer: com.example.SimpleRetryer
|
loggerLevel: full
|
||||||
defaultQueryParameters:
|
errorDecoder: com.example.SimpleErrorDecoder
|
||||||
query: queryValue
|
retryer: com.example.SimpleRetryer
|
||||||
defaultRequestHeaders:
|
defaultQueryParameters:
|
||||||
header: headerValue
|
query: queryValue
|
||||||
requestInterceptors:
|
defaultRequestHeaders:
|
||||||
- com.example.FooRequestInterceptor
|
header: headerValue
|
||||||
- com.example.BarRequestInterceptor
|
requestInterceptors:
|
||||||
decode404: false
|
- com.example.FooRequestInterceptor
|
||||||
encoder: com.example.SimpleEncoder
|
- com.example.BarRequestInterceptor
|
||||||
decoder: com.example.SimpleDecoder
|
decode404: false
|
||||||
contract: com.example.SimpleContract
|
encoder: com.example.SimpleEncoder
|
||||||
capabilities:
|
decoder: com.example.SimpleDecoder
|
||||||
- com.example.FooCapability
|
contract: com.example.SimpleContract
|
||||||
- com.example.BarCapability
|
capabilities:
|
||||||
metrics.enabled: false
|
- com.example.FooCapability
|
||||||
|
- com.example.BarCapability
|
||||||
|
queryMapEncoder: com.example.SimpleQueryMapEncoder
|
||||||
|
metrics.enabled: false
|
||||||
----
|
----
|
||||||
|
|
||||||
Default configurations can be specified in the `@EnableFeignClients` attribute `defaultConfiguration` in a similar manner as described above. The difference is that this configuration will apply to _all_ feign clients.
|
Default configurations can be specified in the `@EnableFeignClients` attribute `defaultConfiguration` in a similar manner as described above. The difference is that this configuration will apply to _all_ feign clients.
|
||||||
|
|
||||||
If you prefer using configuration properties to configure all `@FeignClient`, you can create configuration properties with `default` feign name.
|
If you prefer using configuration properties to configure all `@FeignClient`, you can create configuration properties with `default` feign name.
|
||||||
|
|
||||||
You can use `feign.client.config.feignName.defaultQueryParameters` and `feign.client.config.feignName.defaultRequestHeaders` to specify query parameters and headers that will be sent with every request of the client named `feignName`.
|
You can use `spring.cloud.openfeign.client.config.feignName.defaultQueryParameters` and `spring.cloud.openfeign.client.config.feignName.defaultRequestHeaders` to specify query parameters and headers that will be sent with every request of the client named `feignName`.
|
||||||
|
|
||||||
application.yml
|
application.yml
|
||||||
[source,yaml]
|
[source,yaml]
|
||||||
----
|
----
|
||||||
feign:
|
spring:
|
||||||
client:
|
cloud:
|
||||||
config:
|
openfeign:
|
||||||
default:
|
client:
|
||||||
connectTimeout: 5000
|
config:
|
||||||
readTimeout: 5000
|
default:
|
||||||
loggerLevel: basic
|
connectTimeout: 5000
|
||||||
|
readTimeout: 5000
|
||||||
|
loggerLevel: basic
|
||||||
----
|
----
|
||||||
|
|
||||||
If we create both `@Configuration` bean and configuration properties, configuration properties will win.
|
If we create both `@Configuration` bean and configuration properties, configuration properties will win.
|
||||||
It will override `@Configuration` values. But if you want to change the priority to `@Configuration`,
|
It will override `@Configuration` values. But if you want to change the priority to `@Configuration`,
|
||||||
you can change `feign.client.default-to-properties` to `false`.
|
you can change `spring.cloud.openfeign.client.default-to-properties` to `false`.
|
||||||
|
|
||||||
If we want to create multiple feign clients with the same name or url
|
If we want to create multiple feign clients with the same name or url
|
||||||
so that they would point to the same server but each with a different custom configuration then
|
so that they would point to the same server but each with a different custom configuration then
|
||||||
@@ -261,13 +270,13 @@ public FeignClientConfigurer feignClientConfigurer() {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
TIP: By default, Feign clients do not encode slash `/` characters. You can change this behaviour, by setting the value of `feign.client.decodeSlash` to `false`.
|
TIP: By default, Feign clients do not encode slash `/` characters. You can change this behaviour, by setting the value of `spring.cloud.openfeign.client.decodeSlash` to `false`.
|
||||||
|
|
||||||
==== `SpringEncoder` configuration
|
==== `SpringEncoder` configuration
|
||||||
|
|
||||||
In the `SpringEncoder` that we provide, we set `null` charset for binary content types and `UTF-8` for all the other ones.
|
In the `SpringEncoder` that we provide, we set `null` charset for binary content types and `UTF-8` for all the other ones.
|
||||||
|
|
||||||
You can modify this behaviour to derive the charset from the `Content-Type` header charset instead by setting the value of `feign.encoder.charset-from-content-type` to `true`.
|
You can modify this behaviour to derive the charset from the `Content-Type` header charset instead by setting the value of `spring.cloud.openfeign.encoder.charset-from-content-type` to `true`.
|
||||||
|
|
||||||
[[timeout-handling]]
|
[[timeout-handling]]
|
||||||
=== Timeout Handling
|
=== Timeout Handling
|
||||||
@@ -332,7 +341,7 @@ You can do this by overriding calling `inheritParentContext(false)` on the `Buil
|
|||||||
[[spring-cloud-feign-circuitbreaker]]
|
[[spring-cloud-feign-circuitbreaker]]
|
||||||
=== Feign Spring Cloud CircuitBreaker Support
|
=== Feign Spring Cloud CircuitBreaker Support
|
||||||
|
|
||||||
If Spring Cloud CircuitBreaker is on the classpath and `feign.circuitbreaker.enabled=true`, Feign will wrap all methods with a circuit breaker.
|
If Spring Cloud CircuitBreaker is on the classpath and `spring.cloud.openfeign.circuitbreaker.enabled=true`, Feign will wrap all methods with a circuit breaker.
|
||||||
|
|
||||||
To disable Spring Cloud CircuitBreaker support on a per-client basis create a vanilla `Feign.Builder` with the "prototype" scope, e.g.:
|
To disable Spring Cloud CircuitBreaker support on a per-client basis create a vanilla `Feign.Builder` with the "prototype" scope, e.g.:
|
||||||
|
|
||||||
@@ -365,8 +374,47 @@ public class FooConfiguration {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
To enable Spring Cloud CircuitBreaker group set the `feign.circuitbreaker.group.enabled` property to `true` (by default `false`).
|
To enable Spring Cloud CircuitBreaker group set the `spring.cloud.openfeign.circuitbreaker.group.enabled` property to `true` (by default `false`).
|
||||||
|
|
||||||
|
[[spring-clou-feign-circuitbreaker-configurationproperties]]
|
||||||
|
=== Configuring CircuitBreakers With Configuration Properties
|
||||||
|
|
||||||
|
You can configure CircuitBreakers via configuration properties.
|
||||||
|
|
||||||
|
For example, if you had this Feign client
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
@FeignClient(url = "http://localhost:8080")
|
||||||
|
public interface DemoClient {
|
||||||
|
|
||||||
|
@GetMapping("demo")
|
||||||
|
String getDemo();
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
You could configure it using configuration properties by doing the following
|
||||||
|
|
||||||
|
[source,yaml,indent=0]
|
||||||
|
----
|
||||||
|
feign:
|
||||||
|
circuitbreaker:
|
||||||
|
enabled: true
|
||||||
|
alphanumeric-ids:
|
||||||
|
enabled: true
|
||||||
|
resilience4j:
|
||||||
|
circuitbreaker:
|
||||||
|
instances:
|
||||||
|
DemoClientgetDemo:
|
||||||
|
minimumNumberOfCalls: 69
|
||||||
|
timelimiter:
|
||||||
|
instances:
|
||||||
|
DemoClientgetDemo:
|
||||||
|
timeoutDuration: 10s
|
||||||
|
----
|
||||||
|
|
||||||
|
NOTE: If you want to switch back to the circuit breaker names used prior to Spring Cloud
|
||||||
|
2022.0.0 you can set `spring.cloud.openfeign.circuitbreaker.alphanumeric-ids.enabled` to `false`.
|
||||||
|
|
||||||
[[spring-cloud-feign-circuitbreaker-fallback]]
|
[[spring-cloud-feign-circuitbreaker-fallback]]
|
||||||
=== Feign Spring Cloud CircuitBreaker Fallbacks
|
=== Feign Spring Cloud CircuitBreaker Fallbacks
|
||||||
@@ -500,29 +548,21 @@ Feign requests. You can do this by enabling one of the properties:
|
|||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
feign.compression.request.enabled=true
|
spring.cloud.openfeign.compression.request.enabled=true
|
||||||
feign.compression.response.enabled=true
|
spring.cloud.openfeign.compression.response.enabled=true
|
||||||
----
|
----
|
||||||
|
|
||||||
Feign request compression gives you settings similar to what you may set for your web server:
|
Feign request compression gives you settings similar to what you may set for your web server:
|
||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
feign.compression.request.enabled=true
|
spring.cloud.openfeign.compression.request.enabled=true
|
||||||
feign.compression.request.mime-types=text/xml,application/xml,application/json
|
spring.cloud.openfeign.compression.request.mime-types=text/xml,application/xml,application/json
|
||||||
feign.compression.request.min-request-size=2048
|
spring.cloud.openfeign.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.
|
||||||
@@ -579,8 +619,8 @@ If all of the following conditions are true, a `MicrometerCapability` bean is cr
|
|||||||
* `feign-micrometer` is on the classpath
|
* `feign-micrometer` is on the classpath
|
||||||
* A `MeterRegistry` bean is available
|
* A `MeterRegistry` bean is available
|
||||||
* feign metrics properties are set to `true` (by default)
|
* feign metrics properties are set to `true` (by default)
|
||||||
- `feign.metrics.enabled=true` (for all clients)
|
- `spring.cloud.openfeign.metrics.enabled=true` (for all clients)
|
||||||
- `feign.client.config.feignName.metrics.enabled=true` (for a single client)
|
- `spring.cloud.openfeign.client.config.feignName.metrics.enabled=true` (for a single client)
|
||||||
|
|
||||||
NOTE: If your application already uses Micrometer, enabling metrics is as simple as putting `feign-micrometer` onto your classpath.
|
NOTE: If your application already uses Micrometer, enabling metrics is as simple as putting `feign-micrometer` onto your classpath.
|
||||||
|
|
||||||
@@ -588,11 +628,11 @@ You can also disable the feature by either:
|
|||||||
|
|
||||||
* excluding `feign-micrometer` from your classpath
|
* excluding `feign-micrometer` from your classpath
|
||||||
* setting one of the feign metrics properties to `false`
|
* setting one of the feign metrics properties to `false`
|
||||||
- `feign.metrics.enabled=false`
|
- `spring.cloud.openfeign.metrics.enabled=false`
|
||||||
- `feign.client.config.feignName.metrics.enabled=false`
|
- `spring.cloud.openfeign.client.config.feignName.metrics.enabled=false`
|
||||||
|
|
||||||
NOTE: `feign.metrics.enabled=false` disables metrics support for *all* Feign clients regardless of the value of the client-level flags: `feign.client.config.feignName.metrics.enabled`.
|
NOTE: `spring.cloud.openfeign.metrics.enabled=false` disables metrics support for *all* Feign clients regardless of the value of the client-level flags: `spring.cloud.openfeign.client.config.feignName.metrics.enabled`.
|
||||||
If you want to enable or disable merics per client, don't set `feign.metrics.enabled` and use `feign.client.config.feignName.metrics.enabled`.
|
If you want to enable or disable merics per client, don't set `spring.cloud.openfeign.metrics.enabled` and use `spring.cloud.openfeign.client.config.feignName.metrics.enabled`.
|
||||||
|
|
||||||
You can also customize the `MicrometerCapability` by registering your own bean:
|
You can also customize the `MicrometerCapability` by registering your own bean:
|
||||||
|
|
||||||
@@ -607,6 +647,22 @@ public class FooConfiguration {
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
|
=== Feign Caching
|
||||||
|
|
||||||
|
If `@EnableCaching` annotation is used, a `CachingCapability` bean is created and registered so that your Feign client recognizes `@Cache*` annotations on its interface:
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
public interface DemoClient {
|
||||||
|
|
||||||
|
@GetMapping("/demo/{filterParam}")
|
||||||
|
@Cacheable(cacheNames = "demo-cache", key = "#keyParam")
|
||||||
|
String demoEndpoint(String keyParam, @PathVariable String filterParam);
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
You can also disable the feature via property `spring.cloud.openfeign.cache.enabled=false`.
|
||||||
|
|
||||||
=== Feign @QueryMap support
|
=== Feign @QueryMap support
|
||||||
|
|
||||||
The OpenFeign `@QueryMap` annotation provides support for POJOs to be used as
|
The OpenFeign `@QueryMap` annotation provides support for POJOs to be used as
|
||||||
@@ -694,20 +750,21 @@ public interface DemoTemplate {
|
|||||||
----
|
----
|
||||||
|
|
||||||
=== Feign `CollectionFormat` support
|
=== Feign `CollectionFormat` support
|
||||||
We support `feign.CollectionFormat` by providing the `@CollectionFormat` annotation.You can annotate a Feign client method with it by passing the desired `feign.CollectionFormat` as annotation value.
|
We support `feign.CollectionFormat` by providing the `@CollectionFormat` annotation.
|
||||||
|
You can annotate a Feign client method (or the whole class to affect all methods) with it by passing the desired `feign.CollectionFormat` as annotation value.
|
||||||
|
|
||||||
In the following example, the `CSV` format is used instead of the default `EXPLODED` to process the method.
|
In the following example, the `CSV` format is used instead of the default `EXPLODED` to process the method.
|
||||||
|
|
||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
@FeignClient(name = "demo")
|
@FeignClient(name = "demo")
|
||||||
protected interface PageableFeignClient {
|
protected interface PageableFeignClient {
|
||||||
|
|
||||||
@CollectionFormat(feign.CollectionFormat.CSV)
|
@CollectionFormat(feign.CollectionFormat.CSV)
|
||||||
@GetMapping(path = "/page")
|
@GetMapping(path = "/page")
|
||||||
ResponseEntity performRequest(Pageable page);
|
ResponseEntity performRequest(Pageable page);
|
||||||
|
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
TIP: Set the `CSV` format while sending `Pageable` as a query parameter in order for it to be encoded correctly.
|
TIP: Set the `CSV` format while sending `Pageable` as a query parameter in order for it to be encoded correctly.
|
||||||
@@ -725,7 +782,7 @@ To work around this problem you can use an `ObjectProvider` when autowiring your
|
|||||||
[source,java,indent=0]
|
[source,java,indent=0]
|
||||||
----
|
----
|
||||||
@Autowired
|
@Autowired
|
||||||
ObjectProvider<TestFeginClient> testFeginClient;
|
ObjectProvider<TestFeignClient> testFeignClient;
|
||||||
----
|
----
|
||||||
|
|
||||||
=== Spring Data Support
|
=== Spring Data Support
|
||||||
@@ -734,7 +791,7 @@ You may consider enabling Jackson Modules for the support `org.springframework.d
|
|||||||
|
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
feign.autoconfiguration.jackson.enabled=true
|
spring.cloud.openfeign.autoconfiguration.jackson.enabled=true
|
||||||
----
|
----
|
||||||
|
|
||||||
=== Spring `@RefreshScope` Support
|
=== Spring `@RefreshScope` Support
|
||||||
@@ -743,10 +800,47 @@ If Feign client refresh is enabled, each feign client is created with `feign.Req
|
|||||||
By default, refresh behavior in Feign clients is disabled. Use the following property to enable refresh behavior:
|
By default, refresh behavior in Feign clients is disabled. Use the following property to enable refresh behavior:
|
||||||
[source,java]
|
[source,java]
|
||||||
----
|
----
|
||||||
feign.client.refresh-enabled=true
|
spring.cloud.openfeign.client.refresh-enabled=true
|
||||||
----
|
----
|
||||||
TIP: DO NOT annotate the `@FeignClient` interface with the `@RefreshScope` annotation.
|
TIP: DO NOT annotate the `@FeignClient` interface with the `@RefreshScope` annotation.
|
||||||
|
|
||||||
|
=== OAuth2 Support
|
||||||
|
OAuth2 support can be enabled by setting following flag:
|
||||||
|
----
|
||||||
|
spring.cloud.openfeign.oauth2.enabled=true
|
||||||
|
----
|
||||||
|
When the flag is set to true, and the oauth2 client context resource details are present, a bean of class `OAuth2FeignRequestInterceptor` is created. Before each request, the interceptor resolves the required access token and includes it as a header.
|
||||||
|
Sometimes, when load balancing is enabled for Feign clients, you may want to use load balancing for fetching access tokens, too. To do so, you should ensure that the load balancer is on the classpath (spring-cloud-starter-loadbalancer) and explicitly enable load balancing for OAuth2FeignRequestInterceptor by setting the following flag:
|
||||||
|
----
|
||||||
|
spring.cloud.openfeign.oauth2.load-balanced=true
|
||||||
|
----
|
||||||
|
|
||||||
|
=== Transform the load-balanced HTTP request
|
||||||
|
|
||||||
|
You can use the selected `ServiceInstance` to transform the load-balanced HTTP Request.
|
||||||
|
|
||||||
|
For `Request`, you need to implement and define `LoadBalancerFeignRequestTransformer`, as follows:
|
||||||
|
|
||||||
|
[source,java,indent=0]
|
||||||
|
----
|
||||||
|
@Bean
|
||||||
|
public LoadBalancerFeignRequestTransformer transformer() {
|
||||||
|
return new LoadBalancerFeignRequestTransformer() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Request transformRequest(Request request, ServiceInstance instance) {
|
||||||
|
Map<String, Collection<String>> headers = new HashMap<>(request.headers());
|
||||||
|
headers.put("X-ServiceId", Collections.singletonList(instance.getServiceId()));
|
||||||
|
headers.put("X-InstanceId", Collections.singletonList(instance.getInstanceId()));
|
||||||
|
return Request.create(request.httpMethod(), request.url(), headers, request.body(), request.charset(),
|
||||||
|
request.requestTemplate());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
If multiple transformers are defined, they are applied in the order in which beans are defined.
|
||||||
|
Alternatively, you can use `LoadBalancerFeignRequestTransformer.DEFAULT_ORDER` to specify the order.
|
||||||
|
|
||||||
== Configuration properties
|
== Configuration properties
|
||||||
|
|
||||||
|
|||||||
@@ -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>3.0.8-SNAPSHOT</version>
|
<version>4.0.0-SNAPSHOT</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>3.0.5</version>
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
<relativePath/>
|
<relativePath/>
|
||||||
</parent>
|
</parent>
|
||||||
<scm>
|
<scm>
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<main.basedir>${basedir}</main.basedir>
|
<main.basedir>${basedir}</main.basedir>
|
||||||
<jackson.version>2.11.3</jackson.version>
|
<jackson.version>2.11.3</jackson.version>
|
||||||
<spring-cloud-commons.version>3.0.7-SNAPSHOT</spring-cloud-commons.version>
|
<spring-cloud-commons.version>4.0.0-SNAPSHOT</spring-cloud-commons.version>
|
||||||
|
|
||||||
<!-- Plugin versions -->
|
<!-- Plugin versions -->
|
||||||
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
<maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version>
|
||||||
@@ -64,13 +64,6 @@
|
|||||||
</additionalConfig>
|
</additionalConfig>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
@@ -79,6 +72,15 @@
|
|||||||
<groupId>io.spring.javaformat</groupId>
|
<groupId>io.spring.javaformat</groupId>
|
||||||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.basepom.maven</groupId>
|
||||||
|
<artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<ignoredResourcePatterns>
|
||||||
|
<ignoredResourcePattern>mozilla/public-suffix-list.txt</ignoredResourcePattern>
|
||||||
|
</ignoredResourcePatterns>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@@ -133,7 +135,7 @@
|
|||||||
<repository>
|
<repository>
|
||||||
<id>spring-snapshots</id>
|
<id>spring-snapshots</id>
|
||||||
<name>Spring Snapshots</name>
|
<name>Spring Snapshots</name>
|
||||||
<url>https://repo.spring.io/libs-snapshot-local</url>
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
@@ -144,7 +146,7 @@
|
|||||||
<repository>
|
<repository>
|
||||||
<id>spring-milestones</id>
|
<id>spring-milestones</id>
|
||||||
<name>Spring Milestones</name>
|
<name>Spring Milestones</name>
|
||||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
<url>https://repo.spring.io/milestone</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>false</enabled>
|
<enabled>false</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
@@ -162,7 +164,7 @@
|
|||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>spring-snapshots</id>
|
<id>spring-snapshots</id>
|
||||||
<name>Spring Snapshots</name>
|
<name>Spring Snapshots</name>
|
||||||
<url>https://repo.spring.io/libs-snapshot-local</url>
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
@@ -173,7 +175,7 @@
|
|||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>spring-milestones</id>
|
<id>spring-milestones</id>
|
||||||
<name>Spring Milestones</name>
|
<name>Spring Milestones</name>
|
||||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
<url>https://repo.spring.io/milestone</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>false</enabled>
|
<enabled>false</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
@@ -181,7 +183,7 @@
|
|||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>spring-releases</id>
|
<id>spring-releases</id>
|
||||||
<name>Spring Releases</name>
|
<name>Spring Releases</name>
|
||||||
<url>https://repo.spring.io/libs-release-local</url>
|
<url>https://repo.spring.io/release</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>false</enabled>
|
<enabled>false</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
|
|||||||
@@ -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>3.0.8-SNAPSHOT</version>
|
<version>4.0.0-SNAPSHOT</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>
|
||||||
@@ -61,15 +61,16 @@
|
|||||||
<artifactId>reactor-core</artifactId>
|
<artifactId>reactor-core</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.reactivex</groupId>
|
|
||||||
<artifactId>rxjava-reactive-streams</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.retry</groupId>
|
<groupId>org.springframework.retry</groupId>
|
||||||
<artifactId>spring-retry</artifactId>
|
<artifactId>spring-retry</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>javax.annotation</groupId>
|
||||||
|
<artifactId>javax.annotation-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -93,6 +94,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.openfeign.form</groupId>
|
<groupId>io.github.openfeign.form</groupId>
|
||||||
<artifactId>feign-form-spring</artifactId>
|
<artifactId>feign-form-spring</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<!-- Vulnerable in 3.8.0-->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.openfeign</groupId>
|
<groupId>io.github.openfeign</groupId>
|
||||||
@@ -119,11 +127,6 @@
|
|||||||
<artifactId>feign-okhttp</artifactId>
|
<artifactId>feign-okhttp</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.reactivex</groupId>
|
|
||||||
<artifactId>rxjava</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp</artifactId>
|
||||||
@@ -133,6 +136,20 @@
|
|||||||
<groupId>org.springframework.security.oauth.boot</groupId>
|
<groupId>org.springframework.security.oauth.boot</groupId>
|
||||||
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>javax.activation</groupId>
|
||||||
|
<artifactId>javax.activation-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.sun.activation</groupId>
|
||||||
|
<artifactId>jakarta.activation</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -149,11 +166,6 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-test-support</artifactId>
|
<artifactId>spring-cloud-test-support</artifactId>
|
||||||
@@ -183,7 +195,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.protobuf</groupId>
|
<groupId>com.google.protobuf</groupId>
|
||||||
<artifactId>protobuf-java</artifactId>
|
<artifactId>protobuf-java</artifactId>
|
||||||
<version>3.19.1</version>
|
<version>3.19.3</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -197,6 +209,12 @@
|
|||||||
<artifactId>spring-cloud-loadbalancer</artifactId>
|
<artifactId>spring-cloud-loadbalancer</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.11.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
|
import feign.Capability;
|
||||||
|
import feign.InvocationHandlerFactory;
|
||||||
|
|
||||||
|
import org.springframework.cache.interceptor.CacheInterceptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows Spring's @Cache* annotations to be declared on the feign client's methods.
|
||||||
|
*
|
||||||
|
* @author Sam Kruglov
|
||||||
|
*/
|
||||||
|
public class CachingCapability implements Capability {
|
||||||
|
|
||||||
|
private final CacheInterceptor cacheInterceptor;
|
||||||
|
|
||||||
|
public CachingCapability(CacheInterceptor cacheInterceptor) {
|
||||||
|
this.cacheInterceptor = cacheInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
|
||||||
|
return new FeignCachingInvocationHandlerFactory(invocationHandlerFactory, cacheInterceptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-1
@@ -25,9 +25,10 @@ import java.lang.annotation.Target;
|
|||||||
* Indicates which collection format should be used while processing the annotated method.
|
* Indicates which collection format should be used while processing the annotated method.
|
||||||
*
|
*
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author Sam Kruglov
|
||||||
* @see feign.CollectionFormat
|
* @see feign.CollectionFormat
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CollectionFormat {
|
public @interface CollectionFormat {
|
||||||
|
|
||||||
|
|||||||
+71
-19
@@ -18,15 +18,15 @@ package org.springframework.cloud.openfeign;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.Module;
|
import com.fasterxml.jackson.databind.Module;
|
||||||
|
import feign.Capability;
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
@@ -34,6 +34,7 @@ import feign.Target;
|
|||||||
import feign.hc5.ApacheHttp5Client;
|
import feign.hc5.ApacheHttp5Client;
|
||||||
import feign.httpclient.ApacheHttpClient;
|
import feign.httpclient.ApacheHttpClient;
|
||||||
import feign.okhttp.OkHttpClient;
|
import feign.okhttp.OkHttpClient;
|
||||||
|
import jakarta.annotation.PreDestroy;
|
||||||
import okhttp3.ConnectionPool;
|
import okhttp3.ConnectionPool;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -50,15 +51,18 @@ 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.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.cache.interceptor.CacheInterceptor;
|
||||||
import org.springframework.cloud.client.actuator.HasFeatures;
|
import org.springframework.cloud.client.actuator.HasFeatures;
|
||||||
import org.springframework.cloud.client.circuitbreaker.CircuitBreaker;
|
import org.springframework.cloud.client.circuitbreaker.CircuitBreaker;
|
||||||
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
|
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
|
||||||
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
|
||||||
|
import org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor;
|
||||||
import org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory;
|
import org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory;
|
||||||
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.security.OAuth2FeignRequestInterceptor;
|
import org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptor;
|
||||||
import org.springframework.cloud.openfeign.support.DefaultGzipDecoderConfiguration;
|
import org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptorConfigurer;
|
||||||
import org.springframework.cloud.openfeign.support.FeignEncoderProperties;
|
import org.springframework.cloud.openfeign.support.FeignEncoderProperties;
|
||||||
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
import org.springframework.cloud.openfeign.support.FeignHttpClientProperties;
|
||||||
import org.springframework.cloud.openfeign.support.PageJacksonModule;
|
import org.springframework.cloud.openfeign.support.PageJacksonModule;
|
||||||
@@ -72,6 +76,8 @@ import org.springframework.data.domain.Sort;
|
|||||||
import org.springframework.security.oauth2.client.OAuth2ClientContext;
|
import org.springframework.security.oauth2.client.OAuth2ClientContext;
|
||||||
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
|
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
|
||||||
|
|
||||||
|
import static org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptorBuilder.buildWithConfigurers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
* @author Julien Roy
|
* @author Julien Roy
|
||||||
@@ -82,12 +88,13 @@ import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResour
|
|||||||
* @author Nguyen Ky Thanh
|
* @author Nguyen Ky Thanh
|
||||||
* @author Andrii Bohutskyi
|
* @author Andrii Bohutskyi
|
||||||
* @author Kwangyong Kim
|
* @author Kwangyong Kim
|
||||||
|
* @author Sam Kruglov
|
||||||
|
* @author Wojciech Mąka
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(Feign.class)
|
@ConditionalOnClass(Feign.class)
|
||||||
@EnableConfigurationProperties({ FeignClientProperties.class, FeignHttpClientProperties.class,
|
@EnableConfigurationProperties({ FeignClientProperties.class, FeignHttpClientProperties.class,
|
||||||
FeignEncoderProperties.class })
|
FeignEncoderProperties.class })
|
||||||
@Import(DefaultGzipDecoderConfiguration.class)
|
|
||||||
public class FeignAutoConfiguration {
|
public class FeignAutoConfiguration {
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(FeignAutoConfiguration.class);
|
private static final Log LOG = LogFactory.getLog(FeignAutoConfiguration.class);
|
||||||
@@ -107,9 +114,16 @@ public class FeignAutoConfiguration {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.cache.enabled", matchIfMissing = true)
|
||||||
|
@ConditionalOnBean(CacheInterceptor.class)
|
||||||
|
public Capability cachingCapability(CacheInterceptor cacheInterceptor) {
|
||||||
|
return new CachingCapability(cacheInterceptor);
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({ Module.class, Page.class, Sort.class })
|
@ConditionalOnClass({ Module.class, Page.class, Sort.class })
|
||||||
@ConditionalOnProperty(value = "feign.autoconfiguration.jackson.enabled", havingValue = "true")
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.autoconfiguration.jackson.enabled", havingValue = "true")
|
||||||
protected static class FeignJacksonConfiguration {
|
protected static class FeignJacksonConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -140,7 +154,7 @@ public class FeignAutoConfiguration {
|
|||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(CircuitBreaker.class)
|
@ConditionalOnClass(CircuitBreaker.class)
|
||||||
@ConditionalOnProperty(value = "feign.circuitbreaker.enabled", havingValue = "true")
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.circuitbreaker.enabled", havingValue = "true")
|
||||||
protected static class CircuitBreakerPresentFeignTargeterConfiguration {
|
protected static class CircuitBreakerPresentFeignTargeterConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -151,15 +165,25 @@ public class FeignAutoConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(CircuitBreakerNameResolver.class)
|
@ConditionalOnMissingBean(CircuitBreakerNameResolver.class)
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.circuitbreaker.alphanumeric-ids.enabled",
|
||||||
|
havingValue = "false")
|
||||||
public CircuitBreakerNameResolver circuitBreakerNameResolver() {
|
public CircuitBreakerNameResolver circuitBreakerNameResolver() {
|
||||||
return new DefaultCircuitBreakerNameResolver();
|
return new DefaultCircuitBreakerNameResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(CircuitBreakerNameResolver.class)
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.circuitbreaker.alphanumeric-ids.enabled",
|
||||||
|
havingValue = "true", matchIfMissing = true)
|
||||||
|
public CircuitBreakerNameResolver alphanumericCircuitBreakerNameResolver() {
|
||||||
|
return new AlphanumericCircuitBreakerNameResolver();
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@ConditionalOnBean(CircuitBreakerFactory.class)
|
@ConditionalOnBean(CircuitBreakerFactory.class)
|
||||||
public Targeter circuitBreakerFeignTargeter(CircuitBreakerFactory circuitBreakerFactory,
|
public Targeter circuitBreakerFeignTargeter(CircuitBreakerFactory circuitBreakerFactory,
|
||||||
@Value("${feign.circuitbreaker.group.enabled:false}") boolean circuitBreakerGroupEnabled,
|
@Value("${spring.cloud.openfeign.circuitbreaker.group.enabled:false}") boolean circuitBreakerGroupEnabled,
|
||||||
CircuitBreakerNameResolver circuitBreakerNameResolver) {
|
CircuitBreakerNameResolver circuitBreakerNameResolver) {
|
||||||
return new FeignCircuitBreakerTargeter(circuitBreakerFactory, circuitBreakerGroupEnabled,
|
return new FeignCircuitBreakerTargeter(circuitBreakerFactory, circuitBreakerGroupEnabled,
|
||||||
circuitBreakerNameResolver);
|
circuitBreakerNameResolver);
|
||||||
@@ -174,6 +198,15 @@ public class FeignAutoConfiguration {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class AlphanumericCircuitBreakerNameResolver extends DefaultCircuitBreakerNameResolver {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resolveCircuitBreakerName(String feignClientName, Target<?> target, Method method) {
|
||||||
|
return super.resolveCircuitBreakerName(feignClientName, target, method).replaceAll("[^a-zA-Z0-9]", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the following configuration is for alternate feign clients if
|
// the following configuration is for alternate feign clients if
|
||||||
@@ -183,7 +216,7 @@ public class FeignAutoConfiguration {
|
|||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(ApacheHttpClient.class)
|
@ConditionalOnClass(ApacheHttpClient.class)
|
||||||
@ConditionalOnMissingBean(CloseableHttpClient.class)
|
@ConditionalOnMissingBean(CloseableHttpClient.class)
|
||||||
@ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true)
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.httpclient.enabled", matchIfMissing = true)
|
||||||
@Conditional(HttpClient5DisabledConditions.class)
|
@Conditional(HttpClient5DisabledConditions.class)
|
||||||
protected static class HttpClientFeignConfiguration {
|
protected static class HttpClientFeignConfiguration {
|
||||||
|
|
||||||
@@ -251,7 +284,7 @@ public class FeignAutoConfiguration {
|
|||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(OkHttpClient.class)
|
@ConditionalOnClass(OkHttpClient.class)
|
||||||
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
|
@ConditionalOnMissingBean(okhttp3.OkHttpClient.class)
|
||||||
@ConditionalOnProperty("feign.okhttp.enabled")
|
@ConditionalOnProperty("spring.cloud.openfeign.okhttp.enabled")
|
||||||
protected static class OkHttpFeignConfiguration {
|
protected static class OkHttpFeignConfiguration {
|
||||||
|
|
||||||
private okhttp3.OkHttpClient okHttpClient;
|
private okhttp3.OkHttpClient okHttpClient;
|
||||||
@@ -260,8 +293,8 @@ public class FeignAutoConfiguration {
|
|||||||
@ConditionalOnMissingBean(ConnectionPool.class)
|
@ConditionalOnMissingBean(ConnectionPool.class)
|
||||||
public ConnectionPool httpClientConnectionPool(FeignHttpClientProperties httpClientProperties,
|
public ConnectionPool httpClientConnectionPool(FeignHttpClientProperties httpClientProperties,
|
||||||
OkHttpClientConnectionPoolFactory connectionPoolFactory) {
|
OkHttpClientConnectionPoolFactory connectionPoolFactory) {
|
||||||
Integer maxTotalConnections = httpClientProperties.getMaxConnections();
|
int maxTotalConnections = httpClientProperties.getMaxConnections();
|
||||||
Long timeToLive = httpClientProperties.getTimeToLive();
|
long timeToLive = httpClientProperties.getTimeToLive();
|
||||||
TimeUnit ttlUnit = httpClientProperties.getTimeToLiveUnit();
|
TimeUnit ttlUnit = httpClientProperties.getTimeToLiveUnit();
|
||||||
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
|
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
|
||||||
}
|
}
|
||||||
@@ -269,12 +302,13 @@ public class FeignAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
public okhttp3.OkHttpClient client(OkHttpClientFactory httpClientFactory, ConnectionPool connectionPool,
|
public okhttp3.OkHttpClient client(OkHttpClientFactory httpClientFactory, ConnectionPool connectionPool,
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
Boolean followRedirects = httpClientProperties.isFollowRedirects();
|
boolean followRedirects = httpClientProperties.isFollowRedirects();
|
||||||
Integer connectTimeout = httpClientProperties.getConnectionTimeout();
|
int connectTimeout = httpClientProperties.getConnectionTimeout();
|
||||||
Boolean disableSslValidation = httpClientProperties.isDisableSslValidation();
|
boolean disableSslValidation = httpClientProperties.isDisableSslValidation();
|
||||||
|
Duration readTimeout = httpClientProperties.getOkHttp().getReadTimeout();
|
||||||
this.okHttpClient = httpClientFactory.createBuilder(disableSslValidation)
|
this.okHttpClient = httpClientFactory.createBuilder(disableSslValidation)
|
||||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS).followRedirects(followRedirects)
|
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS).followRedirects(followRedirects)
|
||||||
.connectionPool(connectionPool).build();
|
.readTimeout(readTimeout).connectionPool(connectionPool).build();
|
||||||
return this.okHttpClient;
|
return this.okHttpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +331,7 @@ public class FeignAutoConfiguration {
|
|||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(ApacheHttp5Client.class)
|
@ConditionalOnClass(ApacheHttp5Client.class)
|
||||||
@ConditionalOnMissingBean(org.apache.hc.client5.http.impl.classic.CloseableHttpClient.class)
|
@ConditionalOnMissingBean(org.apache.hc.client5.http.impl.classic.CloseableHttpClient.class)
|
||||||
@ConditionalOnProperty(value = "feign.httpclient.hc5.enabled", havingValue = "true")
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.httpclient.hc5.enabled", havingValue = "true")
|
||||||
@Import(org.springframework.cloud.openfeign.clientconfig.HttpClient5FeignConfiguration.class)
|
@Import(org.springframework.cloud.openfeign.clientconfig.HttpClient5FeignConfiguration.class)
|
||||||
protected static class HttpClient5FeignConfiguration {
|
protected static class HttpClient5FeignConfiguration {
|
||||||
|
|
||||||
@@ -311,16 +345,34 @@ public class FeignAutoConfiguration {
|
|||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(OAuth2ClientContext.class)
|
@ConditionalOnClass(OAuth2ClientContext.class)
|
||||||
@ConditionalOnProperty("feign.oauth2.enabled")
|
@ConditionalOnProperty("spring.cloud.openfeign.oauth2.enabled")
|
||||||
@Deprecated // spring-security-oauth2 reached EOL
|
@Deprecated // spring-security-oauth2 reached EOL
|
||||||
protected static class Oauth2FeignConfiguration {
|
protected static class Oauth2FeignConfiguration {
|
||||||
|
|
||||||
|
@ConditionalOnBean({ RetryLoadBalancerInterceptor.class, OAuth2ClientContext.class,
|
||||||
|
OAuth2ProtectedResourceDetails.class })
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.oauth2.load-balanced", havingValue = "true")
|
||||||
|
@Bean
|
||||||
|
public OAuth2FeignRequestInterceptorConfigurer retryLoadBalancerInterceptorInjectingConfigurer(
|
||||||
|
final RetryLoadBalancerInterceptor loadBalancerInterceptor) {
|
||||||
|
return builder -> builder.withAccessTokenProviderInterceptors(loadBalancerInterceptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConditionalOnBean({ LoadBalancerInterceptor.class, OAuth2ClientContext.class,
|
||||||
|
OAuth2ProtectedResourceDetails.class })
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.oauth2.load-balanced", havingValue = "true")
|
||||||
|
@Bean
|
||||||
|
public OAuth2FeignRequestInterceptorConfigurer loadBalancerInterceptorInjectingConfigurer(
|
||||||
|
final LoadBalancerInterceptor loadBalancerInterceptor) {
|
||||||
|
return builder -> builder.withAccessTokenProviderInterceptors(loadBalancerInterceptor);
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(OAuth2FeignRequestInterceptor.class)
|
@ConditionalOnMissingBean(OAuth2FeignRequestInterceptor.class)
|
||||||
@ConditionalOnBean({ OAuth2ClientContext.class, OAuth2ProtectedResourceDetails.class })
|
@ConditionalOnBean({ OAuth2ClientContext.class, OAuth2ProtectedResourceDetails.class })
|
||||||
public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext,
|
public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext,
|
||||||
OAuth2ProtectedResourceDetails resource) {
|
OAuth2ProtectedResourceDetails resource, List<OAuth2FeignRequestInterceptorConfigurer> configurers) {
|
||||||
return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, resource);
|
return buildWithConfigurers(oAuth2ClientContext, resource, configurers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+82
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
|
import java.lang.reflect.AccessibleObject;
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import feign.InvocationHandlerFactory;
|
||||||
|
import feign.Target;
|
||||||
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
import org.springframework.cache.interceptor.CacheInterceptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows Spring's @Cache* annotations to be declared on the feign client's methods.
|
||||||
|
*
|
||||||
|
* @author Sam Kruglov
|
||||||
|
*/
|
||||||
|
public class FeignCachingInvocationHandlerFactory implements InvocationHandlerFactory {
|
||||||
|
|
||||||
|
private final InvocationHandlerFactory delegateFactory;
|
||||||
|
|
||||||
|
private final CacheInterceptor cacheInterceptor;
|
||||||
|
|
||||||
|
public FeignCachingInvocationHandlerFactory(InvocationHandlerFactory delegateFactory,
|
||||||
|
CacheInterceptor cacheInterceptor) {
|
||||||
|
this.delegateFactory = delegateFactory;
|
||||||
|
this.cacheInterceptor = cacheInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InvocationHandler create(Target target, Map<Method, MethodHandler> dispatch) {
|
||||||
|
final InvocationHandler delegateHandler = delegateFactory.create(target, dispatch);
|
||||||
|
return (proxy, method, argsNullable) -> {
|
||||||
|
Object[] args = Optional.ofNullable(argsNullable).orElseGet(() -> new Object[0]);
|
||||||
|
return cacheInterceptor.invoke(new MethodInvocation() {
|
||||||
|
@Override
|
||||||
|
public Method getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] getArguments() {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object proceed() throws Throwable {
|
||||||
|
return delegateHandler.invoke(proxy, method, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getThis() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AccessibleObject getStaticPart() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-1
@@ -31,7 +31,8 @@ class FeignCircuitBreakerDisabledConditions extends AnyNestedCondition {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConditionalOnProperty(value = "feign.circuitbreaker.enabled", havingValue = "false", matchIfMissing = true)
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.circuitbreaker.enabled", havingValue = "false",
|
||||||
|
matchIfMissing = true)
|
||||||
static class CircuitBreakerDisabled {
|
static class CircuitBreakerDisabled {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -68,6 +68,8 @@ import org.springframework.util.StringUtils;
|
|||||||
* @author Jonatan Ivanov
|
* @author Jonatan Ivanov
|
||||||
* @author Sam Kruglov
|
* @author Sam Kruglov
|
||||||
* @author Jasbir Singh
|
* @author Jasbir Singh
|
||||||
|
* @author Hyeonmin Park
|
||||||
|
* @author Felix Dittrich
|
||||||
*/
|
*/
|
||||||
public class FeignClientFactoryBean
|
public class FeignClientFactoryBean
|
||||||
implements FactoryBean<Object>, InitializingBean, ApplicationContextAware, BeanFactoryAware {
|
implements FactoryBean<Object>, InitializingBean, ApplicationContextAware, BeanFactoryAware {
|
||||||
@@ -131,7 +133,6 @@ public class FeignClientFactoryBean
|
|||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
configureFeign(context, builder);
|
configureFeign(context, builder);
|
||||||
applyBuildCustomizers(context, builder);
|
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
@@ -295,6 +296,10 @@ public class FeignClientFactoryBean
|
|||||||
if (config.getCapabilities() != null) {
|
if (config.getCapabilities() != null) {
|
||||||
config.getCapabilities().stream().map(this::getOrInstantiate).forEach(builder::addCapability);
|
config.getCapabilities().stream().map(this::getOrInstantiate).forEach(builder::addCapability);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.getQueryMapEncoder() != null) {
|
||||||
|
builder.queryMapEncoder(getOrInstantiate(config.getQueryMapEncoder()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDefaultQueryParams(FeignClientProperties.FeignClientConfiguration config, Feign.Builder builder) {
|
private void addDefaultQueryParams(FeignClientProperties.FeignClientConfiguration config, Feign.Builder builder) {
|
||||||
@@ -369,6 +374,7 @@ public class FeignClientFactoryBean
|
|||||||
Client client = getOptional(context, Client.class);
|
Client client = getOptional(context, Client.class);
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
builder.client(client);
|
builder.client(client);
|
||||||
|
applyBuildCustomizers(context, builder);
|
||||||
Targeter targeter = get(context, Targeter.class);
|
Targeter targeter = get(context, Targeter.class);
|
||||||
return targeter.target(this, builder, context, target);
|
return targeter.target(this, builder, context, target);
|
||||||
}
|
}
|
||||||
@@ -438,6 +444,9 @@ public class FeignClientFactoryBean
|
|||||||
}
|
}
|
||||||
builder.client(client);
|
builder.client(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyBuildCustomizers(context, builder);
|
||||||
|
|
||||||
Targeter targeter = get(context, Targeter.class);
|
Targeter targeter = get(context, Targeter.class);
|
||||||
return (T) targeter.target(this, builder, context, new HardCodedTarget<>(type, name, url));
|
return (T) targeter.target(this, builder, context, new HardCodedTarget<>(type, name, url));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ class FeignClientMetricsEnabledCondition implements Condition {
|
|||||||
.getConfig();
|
.getConfig();
|
||||||
if (feignClientConfigMap != null) {
|
if (feignClientConfigMap != null) {
|
||||||
FeignClientProperties.FeignClientConfiguration feignClientConfig = feignClientConfigMap
|
FeignClientProperties.FeignClientConfiguration feignClientConfig = feignClientConfigMap
|
||||||
.get(context.getEnvironment().getProperty("feign.client.name"));
|
.get(context.getEnvironment().getProperty("spring.cloud.openfeign.client.name"));
|
||||||
if (feignClientConfig != null) {
|
if (feignClientConfig != null) {
|
||||||
FeignClientProperties.MetricsProperties metrics = feignClientConfig.getMetrics();
|
FeignClientProperties.MetricsProperties metrics = feignClientConfig.getMetrics();
|
||||||
if (metrics != null && metrics.getEnabled() != null) {
|
if (metrics != null && metrics.getEnabled() != null) {
|
||||||
|
|||||||
+16
-3
@@ -26,6 +26,7 @@ import feign.Capability;
|
|||||||
import feign.Contract;
|
import feign.Contract;
|
||||||
import feign.ExceptionPropagationPolicy;
|
import feign.ExceptionPropagationPolicy;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
|
import feign.QueryMapEncoder;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.Retryer;
|
import feign.Retryer;
|
||||||
import feign.codec.Decoder;
|
import feign.codec.Decoder;
|
||||||
@@ -40,8 +41,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
* @author Ram Anaswara
|
* @author Ram Anaswara
|
||||||
* @author Jonatan Ivanov
|
* @author Jonatan Ivanov
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author Hyeonmin Park
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties("feign.client")
|
@ConfigurationProperties("spring.cloud.openfeign.client")
|
||||||
public class FeignClientProperties {
|
public class FeignClientProperties {
|
||||||
|
|
||||||
private boolean defaultToProperties = true;
|
private boolean defaultToProperties = true;
|
||||||
@@ -139,6 +141,8 @@ public class FeignClientProperties {
|
|||||||
|
|
||||||
private List<Class<Capability>> capabilities;
|
private List<Class<Capability>> capabilities;
|
||||||
|
|
||||||
|
private Class<QueryMapEncoder> queryMapEncoder;
|
||||||
|
|
||||||
private MetricsProperties metrics;
|
private MetricsProperties metrics;
|
||||||
|
|
||||||
private Boolean followRedirects;
|
private Boolean followRedirects;
|
||||||
@@ -255,6 +259,14 @@ public class FeignClientProperties {
|
|||||||
this.capabilities = capabilities;
|
this.capabilities = capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Class<QueryMapEncoder> getQueryMapEncoder() {
|
||||||
|
return queryMapEncoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueryMapEncoder(Class<QueryMapEncoder> queryMapEncoder) {
|
||||||
|
this.queryMapEncoder = queryMapEncoder;
|
||||||
|
}
|
||||||
|
|
||||||
public MetricsProperties getMetrics() {
|
public MetricsProperties getMetrics() {
|
||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
@@ -289,7 +301,8 @@ public class FeignClientProperties {
|
|||||||
&& Objects.equals(exceptionPropagationPolicy, that.exceptionPropagationPolicy)
|
&& Objects.equals(exceptionPropagationPolicy, that.exceptionPropagationPolicy)
|
||||||
&& Objects.equals(defaultRequestHeaders, that.defaultRequestHeaders)
|
&& Objects.equals(defaultRequestHeaders, that.defaultRequestHeaders)
|
||||||
&& Objects.equals(defaultQueryParameters, that.defaultQueryParameters)
|
&& Objects.equals(defaultQueryParameters, that.defaultQueryParameters)
|
||||||
&& Objects.equals(capabilities, that.capabilities) && Objects.equals(metrics, that.metrics)
|
&& Objects.equals(capabilities, that.capabilities)
|
||||||
|
&& Objects.equals(queryMapEncoder, that.queryMapEncoder) && Objects.equals(metrics, that.metrics)
|
||||||
&& Objects.equals(followRedirects, that.followRedirects);
|
&& Objects.equals(followRedirects, that.followRedirects);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +310,7 @@ public class FeignClientProperties {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(loggerLevel, connectTimeout, readTimeout, retryer, errorDecoder, requestInterceptors,
|
return Objects.hash(loggerLevel, connectTimeout, readTimeout, retryer, errorDecoder, requestInterceptors,
|
||||||
decode404, encoder, decoder, contract, exceptionPropagationPolicy, defaultQueryParameters,
|
decode404, encoder, decoder, contract, exceptionPropagationPolicy, defaultQueryParameters,
|
||||||
defaultRequestHeaders, capabilities, metrics, followRedirects);
|
defaultRequestHeaders, capabilities, queryMapEncoder, metrics, followRedirects);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -25,7 +25,7 @@ import org.springframework.cloud.context.named.NamedContextFactory;
|
|||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
* @author Gregor Zurowski
|
* @author Gregor Zurowski
|
||||||
*/
|
*/
|
||||||
class FeignClientSpecification implements NamedContextFactory.Specification {
|
public class FeignClientSpecification implements NamedContextFactory.Specification {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ class FeignClientSpecification implements NamedContextFactory.Specification {
|
|||||||
FeignClientSpecification() {
|
FeignClientSpecification() {
|
||||||
}
|
}
|
||||||
|
|
||||||
FeignClientSpecification(String name, Class<?>[] configuration) {
|
public FeignClientSpecification(String name, Class<?>[] configuration) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-15
@@ -47,6 +47,7 @@ import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
|
|||||||
import org.springframework.cloud.openfeign.clientconfig.FeignClientConfigurer;
|
import org.springframework.cloud.openfeign.clientconfig.FeignClientConfigurer;
|
||||||
import org.springframework.cloud.openfeign.support.AbstractFormWriter;
|
import org.springframework.cloud.openfeign.support.AbstractFormWriter;
|
||||||
import org.springframework.cloud.openfeign.support.FeignEncoderProperties;
|
import org.springframework.cloud.openfeign.support.FeignEncoderProperties;
|
||||||
|
import org.springframework.cloud.openfeign.support.HttpMessageConverterCustomizer;
|
||||||
import org.springframework.cloud.openfeign.support.PageableSpringEncoder;
|
import org.springframework.cloud.openfeign.support.PageableSpringEncoder;
|
||||||
import org.springframework.cloud.openfeign.support.PageableSpringQueryMapEncoder;
|
import org.springframework.cloud.openfeign.support.PageableSpringQueryMapEncoder;
|
||||||
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
|
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
|
||||||
@@ -70,6 +71,7 @@ import static feign.form.ContentType.MULTIPART;
|
|||||||
* @author Jonatan Ivanov
|
* @author Jonatan Ivanov
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
* @author Hyeonmin Park
|
* @author Hyeonmin Park
|
||||||
|
* @author Yanming Zhou
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
public class FeignClientsConfiguration {
|
public class FeignClientsConfiguration {
|
||||||
@@ -97,22 +99,25 @@ public class FeignClientsConfiguration {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public Decoder feignDecoder() {
|
public Decoder feignDecoder(ObjectProvider<HttpMessageConverterCustomizer> customizers) {
|
||||||
return new OptionalDecoder(new ResponseEntityDecoder(new SpringDecoder(this.messageConverters)));
|
return new OptionalDecoder(new ResponseEntityDecoder(new SpringDecoder(messageConverters, customizers)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@ConditionalOnMissingClass("org.springframework.data.domain.Pageable")
|
@ConditionalOnMissingClass("org.springframework.data.domain.Pageable")
|
||||||
public Encoder feignEncoder(ObjectProvider<AbstractFormWriter> formWriterProvider) {
|
public Encoder feignEncoder(ObjectProvider<AbstractFormWriter> formWriterProvider,
|
||||||
return springEncoder(formWriterProvider, encoderProperties);
|
ObjectProvider<HttpMessageConverterCustomizer> customizers) {
|
||||||
|
return springEncoder(formWriterProvider, encoderProperties, customizers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnClass(name = "org.springframework.data.domain.Pageable")
|
@ConditionalOnClass(name = "org.springframework.data.domain.Pageable")
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public Encoder feignEncoderPageable(ObjectProvider<AbstractFormWriter> formWriterProvider) {
|
public Encoder feignEncoderPageable(ObjectProvider<AbstractFormWriter> formWriterProvider,
|
||||||
PageableSpringEncoder encoder = new PageableSpringEncoder(springEncoder(formWriterProvider, encoderProperties));
|
ObjectProvider<HttpMessageConverterCustomizer> customizers) {
|
||||||
|
PageableSpringEncoder encoder = new PageableSpringEncoder(
|
||||||
|
springEncoder(formWriterProvider, encoderProperties, customizers));
|
||||||
|
|
||||||
if (springDataWebProperties != null) {
|
if (springDataWebProperties != null) {
|
||||||
encoder.setPageParameter(springDataWebProperties.getPageable().getPageParameter());
|
encoder.setPageParameter(springDataWebProperties.getPageable().getPageParameter());
|
||||||
@@ -126,20 +131,26 @@ public class FeignClientsConfiguration {
|
|||||||
@ConditionalOnClass(name = "org.springframework.data.domain.Pageable")
|
@ConditionalOnClass(name = "org.springframework.data.domain.Pageable")
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public QueryMapEncoder feignQueryMapEncoderPageable() {
|
public QueryMapEncoder feignQueryMapEncoderPageable() {
|
||||||
return new PageableSpringQueryMapEncoder();
|
PageableSpringQueryMapEncoder queryMapEncoder = new PageableSpringQueryMapEncoder();
|
||||||
|
if (springDataWebProperties != null) {
|
||||||
|
queryMapEncoder.setPageParameter(springDataWebProperties.getPageable().getPageParameter());
|
||||||
|
queryMapEncoder.setSizeParameter(springDataWebProperties.getPageable().getSizeParameter());
|
||||||
|
queryMapEncoder.setSortParameter(springDataWebProperties.getSort().getSortParameter());
|
||||||
|
}
|
||||||
|
return queryMapEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public Contract feignContract(ConversionService feignConversionService) {
|
public Contract feignContract(ConversionService feignConversionService) {
|
||||||
boolean decodeSlash = feignClientProperties == null || feignClientProperties.isDecodeSlash();
|
boolean decodeSlash = feignClientProperties == null || feignClientProperties.isDecodeSlash();
|
||||||
return new SpringMvcContract(this.parameterProcessors, feignConversionService, decodeSlash);
|
return new SpringMvcContract(parameterProcessors, feignConversionService, decodeSlash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public FormattingConversionService feignConversionService() {
|
public FormattingConversionService feignConversionService() {
|
||||||
FormattingConversionService conversionService = new DefaultFormattingConversionService();
|
FormattingConversionService conversionService = new DefaultFormattingConversionService();
|
||||||
for (FeignFormatterRegistrar feignFormatterRegistrar : this.feignFormatterRegistrars) {
|
for (FeignFormatterRegistrar feignFormatterRegistrar : feignFormatterRegistrars) {
|
||||||
feignFormatterRegistrar.registerFormatters(conversionService);
|
feignFormatterRegistrar.registerFormatters(conversionService);
|
||||||
}
|
}
|
||||||
return conversionService;
|
return conversionService;
|
||||||
@@ -154,7 +165,7 @@ public class FeignClientsConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(FeignLoggerFactory.class)
|
@ConditionalOnMissingBean(FeignLoggerFactory.class)
|
||||||
public FeignLoggerFactory feignLoggerFactory() {
|
public FeignLoggerFactory feignLoggerFactory() {
|
||||||
return new DefaultFeignLoggerFactory(this.logger);
|
return new DefaultFeignLoggerFactory(logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -165,14 +176,15 @@ public class FeignClientsConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Encoder springEncoder(ObjectProvider<AbstractFormWriter> formWriterProvider,
|
private Encoder springEncoder(ObjectProvider<AbstractFormWriter> formWriterProvider,
|
||||||
FeignEncoderProperties encoderProperties) {
|
FeignEncoderProperties encoderProperties, ObjectProvider<HttpMessageConverterCustomizer> customizers) {
|
||||||
AbstractFormWriter formWriter = formWriterProvider.getIfAvailable();
|
AbstractFormWriter formWriter = formWriterProvider.getIfAvailable();
|
||||||
|
|
||||||
if (formWriter != null) {
|
if (formWriter != null) {
|
||||||
return new SpringEncoder(new SpringPojoFormEncoder(formWriter), this.messageConverters, encoderProperties);
|
return new SpringEncoder(new SpringPojoFormEncoder(formWriter), messageConverters, encoderProperties,
|
||||||
|
customizers);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new SpringEncoder(new SpringFormEncoder(), this.messageConverters, encoderProperties);
|
return new SpringEncoder(new SpringFormEncoder(), messageConverters, encoderProperties, customizers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +214,7 @@ public class FeignClientsConfiguration {
|
|||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(CircuitBreaker.class)
|
@ConditionalOnClass(CircuitBreaker.class)
|
||||||
@ConditionalOnProperty("feign.circuitbreaker.enabled")
|
@ConditionalOnProperty("spring.cloud.openfeign.circuitbreaker.enabled")
|
||||||
protected static class CircuitBreakerPresentFeignBuilderConfiguration {
|
protected static class CircuitBreakerPresentFeignBuilderConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -225,7 +237,7 @@ public class FeignClientsConfiguration {
|
|||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnBean(type = "io.micrometer.core.instrument.MeterRegistry")
|
@ConditionalOnBean(type = "io.micrometer.core.instrument.MeterRegistry")
|
||||||
@ConditionalOnClass(name = "feign.micrometer.MicrometerCapability")
|
@ConditionalOnClass(name = "feign.micrometer.MicrometerCapability")
|
||||||
@ConditionalOnProperty(name = "feign.metrics.enabled", matchIfMissing = true)
|
@ConditionalOnProperty(name = "spring.cloud.openfeign.metrics.enabled", matchIfMissing = true)
|
||||||
@Conditional(FeignClientMetricsEnabledCondition.class)
|
@Conditional(FeignClientMetricsEnabledCondition.class)
|
||||||
protected static class MetricsConfiguration {
|
protected static class MetricsConfiguration {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -440,7 +440,7 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isClientRefreshEnabled() {
|
private boolean isClientRefreshEnabled() {
|
||||||
return environment.getProperty("feign.client.refresh-enabled", Boolean.class, false);
|
return environment.getProperty("spring.cloud.openfeign.client.refresh-enabled", Boolean.class, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ import org.springframework.lang.Nullable;
|
|||||||
public class FeignContext extends NamedContextFactory<FeignClientSpecification> {
|
public class FeignContext extends NamedContextFactory<FeignClientSpecification> {
|
||||||
|
|
||||||
public FeignContext() {
|
public FeignContext() {
|
||||||
super(FeignClientsConfiguration.class, "feign", "feign.client.name");
|
super(FeignClientsConfiguration.class, "spring.cloud.openfeign", "spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+2
-1
@@ -34,7 +34,8 @@ public class HttpClient5DisabledConditions extends AnyNestedCondition {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConditionalOnProperty(value = "feign.httpclient.hc5.enabled", havingValue = "false", matchIfMissing = true)
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.httpclient.hc5.enabled", havingValue = "false",
|
||||||
|
matchIfMissing = true)
|
||||||
static class HttpClient5Disabled {
|
static class HttpClient5Disabled {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import feign.MethodMetadata;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.web.bind.annotation.CookieValue;
|
||||||
|
|
||||||
|
import static feign.Util.checkState;
|
||||||
|
import static feign.Util.emptyToNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @{link CookieValue} annotation processor.
|
||||||
|
* @author Gong Yi
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CookieValueParameterProcessor implements AnnotatedParameterProcessor {
|
||||||
|
|
||||||
|
private static final Class<CookieValue> ANNOTATION = CookieValue.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();
|
||||||
|
CookieValue cookie = ANNOTATION.cast(annotation);
|
||||||
|
String name = cookie.value().trim();
|
||||||
|
checkState(emptyToNull(name) != null, "Cookie.name() was empty on parameter %s", parameterIndex);
|
||||||
|
context.setParameterName(name);
|
||||||
|
String cookieExpression = data.template().headers().getOrDefault(HttpHeaders.COOKIE, Arrays.asList("")).stream()
|
||||||
|
.findFirst().orElse("");
|
||||||
|
if (cookieExpression.length() == 0) {
|
||||||
|
cookieExpression = String.format("%s={%s}", name, name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cookieExpression += String.format("; %s={%s}", name, name);
|
||||||
|
}
|
||||||
|
data.template().removeHeader(HttpHeaders.COOKIE);
|
||||||
|
data.template().header(HttpHeaders.COOKIE, cookieExpression);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+3
-1
@@ -34,6 +34,7 @@ import static feign.Util.emptyToNull;
|
|||||||
*
|
*
|
||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
* @author Abhijit Sarkar
|
* @author Abhijit Sarkar
|
||||||
|
* @author Yanming Zhou
|
||||||
* @see AnnotatedParameterProcessor
|
* @see AnnotatedParameterProcessor
|
||||||
*/
|
*/
|
||||||
public class PathVariableParameterProcessor implements AnnotatedParameterProcessor {
|
public class PathVariableParameterProcessor implements AnnotatedParameterProcessor {
|
||||||
@@ -54,7 +55,8 @@ public class PathVariableParameterProcessor implements AnnotatedParameterProcess
|
|||||||
|
|
||||||
MethodMetadata data = context.getMethodMetadata();
|
MethodMetadata data = context.getMethodMetadata();
|
||||||
String varName = '{' + name + '}';
|
String varName = '{' + name + '}';
|
||||||
if (!data.template().url().contains(varName) && !searchMapValues(data.template().queries(), varName)
|
String varNameRegex = ".*\\{" + name + "(:[^}]+)?\\}.*";
|
||||||
|
if (!data.template().url().matches(varNameRegex) && !searchMapValues(data.template().queries(), varName)
|
||||||
&& !searchMapValues(data.template().headers(), varName)) {
|
&& !searchMapValues(data.template().headers(), varName)) {
|
||||||
data.formParams().add(name);
|
data.formParams().add(name);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -23,11 +23,11 @@ import java.security.cert.CertificateException;
|
|||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
import jakarta.annotation.PreDestroy;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hc.client5.http.config.RequestConfig;
|
import org.apache.hc.client5.http.config.RequestConfig;
|
||||||
|
|||||||
+4
-4
@@ -20,8 +20,7 @@ import java.io.IOException;
|
|||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
@@ -80,7 +79,7 @@ public class HttpClientFeignConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(value = "feign.compression.response.enabled", havingValue = "true")
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.compression.response.enabled", havingValue = "true")
|
||||||
public CloseableHttpClient customHttpClient(HttpClientConnectionManager httpClientConnectionManager,
|
public CloseableHttpClient customHttpClient(HttpClientConnectionManager httpClientConnectionManager,
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
HttpClientBuilder builder = HttpClientBuilder.create().disableCookieManagement().useSystemProperties();
|
HttpClientBuilder builder = HttpClientBuilder.create().disableCookieManagement().useSystemProperties();
|
||||||
@@ -89,7 +88,8 @@ public class HttpClientFeignConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(value = "feign.compression.response.enabled", havingValue = "false", matchIfMissing = true)
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.compression.response.enabled", havingValue = "false",
|
||||||
|
matchIfMissing = true)
|
||||||
public CloseableHttpClient httpClient(ApacheHttpClientFactory httpClientFactory,
|
public CloseableHttpClient httpClient(ApacheHttpClientFactory httpClientFactory,
|
||||||
HttpClientConnectionManager httpClientConnectionManager, FeignHttpClientProperties httpClientProperties) {
|
HttpClientConnectionManager httpClientConnectionManager, FeignHttpClientProperties httpClientProperties) {
|
||||||
this.httpClient = createClient(httpClientFactory.createBuilder(), httpClientConnectionManager,
|
this.httpClient = createClient(httpClientFactory.createBuilder(), httpClientConnectionManager,
|
||||||
|
|||||||
+8
-7
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.clientconfig;
|
package org.springframework.cloud.openfeign.clientconfig;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
|
|
||||||
import okhttp3.ConnectionPool;
|
import okhttp3.ConnectionPool;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ public class OkHttpFeignConfiguration {
|
|||||||
@ConditionalOnMissingBean(ConnectionPool.class)
|
@ConditionalOnMissingBean(ConnectionPool.class)
|
||||||
public ConnectionPool httpClientConnectionPool(FeignHttpClientProperties httpClientProperties,
|
public ConnectionPool httpClientConnectionPool(FeignHttpClientProperties httpClientProperties,
|
||||||
OkHttpClientConnectionPoolFactory connectionPoolFactory) {
|
OkHttpClientConnectionPoolFactory connectionPoolFactory) {
|
||||||
Integer maxTotalConnections = httpClientProperties.getMaxConnections();
|
int maxTotalConnections = httpClientProperties.getMaxConnections();
|
||||||
Long timeToLive = httpClientProperties.getTimeToLive();
|
long timeToLive = httpClientProperties.getTimeToLive();
|
||||||
TimeUnit ttlUnit = httpClientProperties.getTimeToLiveUnit();
|
TimeUnit ttlUnit = httpClientProperties.getTimeToLiveUnit();
|
||||||
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
|
return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
|
||||||
}
|
}
|
||||||
@@ -57,11 +57,12 @@ public class OkHttpFeignConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
public okhttp3.OkHttpClient client(OkHttpClientFactory httpClientFactory, ConnectionPool connectionPool,
|
public okhttp3.OkHttpClient client(OkHttpClientFactory httpClientFactory, ConnectionPool connectionPool,
|
||||||
FeignHttpClientProperties httpClientProperties) {
|
FeignHttpClientProperties httpClientProperties) {
|
||||||
Boolean followRedirects = httpClientProperties.isFollowRedirects();
|
boolean followRedirects = httpClientProperties.isFollowRedirects();
|
||||||
Integer connectTimeout = httpClientProperties.getConnectionTimeout();
|
int connectTimeout = httpClientProperties.getConnectionTimeout();
|
||||||
|
Duration reaTimeout = httpClientProperties.getOkHttp().getReadTimeout();
|
||||||
this.okHttpClient = httpClientFactory.createBuilder(httpClientProperties.isDisableSslValidation())
|
this.okHttpClient = httpClientFactory.createBuilder(httpClientProperties.isDisableSslValidation())
|
||||||
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS).followRedirects(followRedirects)
|
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS).followRedirects(followRedirects)
|
||||||
.connectionPool(connectionPool).build();
|
.readTimeout(reaTimeout).connectionPool(connectionPool).build();
|
||||||
return this.okHttpClient;
|
return this.okHttpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
@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 = "spring.cloud.openfeign.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")
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
*
|
*
|
||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties("feign.compression.request")
|
@ConfigurationProperties("spring.cloud.openfeign.compression.request")
|
||||||
public class FeignClientEncodingProperties {
|
public class FeignClientEncodingProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
// 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("feign.compression.request.enabled")
|
@ConditionalOnProperty("spring.cloud.openfeign.compression.request.enabled")
|
||||||
@AutoConfigureAfter(FeignAutoConfiguration.class)
|
@AutoConfigureAfter(FeignAutoConfiguration.class)
|
||||||
public class FeignContentGzipEncodingAutoConfiguration {
|
public class FeignContentGzipEncodingAutoConfiguration {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -83,7 +83,7 @@ public class FeignContentGzipEncodingInterceptor extends BaseRequestInterceptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the content mime types matches the configures mime types.
|
* Returns whether the content mime types matches the configured mime types.
|
||||||
* @param contentTypes the content types
|
* @param contentTypes the content types
|
||||||
* @return true if any specified content type matches the request content types
|
* @return true if any specified content type matches the request content types
|
||||||
*/
|
*/
|
||||||
|
|||||||
+8
-24
@@ -16,26 +16,18 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.hateoas;
|
package org.springframework.cloud.openfeign.hateoas;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
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.ConditionalOnWebApplication;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||||
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||||
|
import org.springframework.cloud.openfeign.support.HttpMessageConverterCustomizer;
|
||||||
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.hateoas.RepresentationModel;
|
import org.springframework.hateoas.config.HateoasConfiguration;
|
||||||
import org.springframework.hateoas.mediatype.hal.HalMediaTypeConfiguration;
|
import org.springframework.hateoas.config.WebConverters;
|
||||||
import org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
|
||||||
|
|
||||||
import static org.springframework.hateoas.MediaTypes.HAL_JSON;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hector Espert
|
* @author Hector Espert
|
||||||
@@ -43,23 +35,15 @@ import static org.springframework.hateoas.MediaTypes.HAL_JSON;
|
|||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnWebApplication
|
@ConditionalOnWebApplication
|
||||||
@ConditionalOnClass(RepresentationModel.class)
|
@ConditionalOnClass(WebConverters.class)
|
||||||
@AutoConfigureAfter({ JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
|
@AutoConfigureAfter({ JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
|
||||||
RepositoryRestMvcAutoConfiguration.class })
|
RepositoryRestMvcAutoConfiguration.class, HateoasConfiguration.class })
|
||||||
public class FeignHalAutoConfiguration {
|
public class FeignHalAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnBean(HalMediaTypeConfiguration.class)
|
@ConditionalOnBean(WebConverters.class)
|
||||||
@ConditionalOnMissingBean
|
HttpMessageConverterCustomizer webConvertersCustomizer(WebConverters webConverters) {
|
||||||
public TypeConstrainedMappingJackson2HttpMessageConverter halJacksonHttpMessageConverter(
|
return new WebConvertersCustomizer(webConverters);
|
||||||
ObjectProvider<ObjectMapper> objectMapper, HalMediaTypeConfiguration halConfiguration) {
|
|
||||||
ObjectMapper mapper = objectMapper.getIfAvailable(ObjectMapper::new).copy();
|
|
||||||
halConfiguration.configureObjectMapper(mapper);
|
|
||||||
TypeConstrainedMappingJackson2HttpMessageConverter converter = new TypeConstrainedMappingJackson2HttpMessageConverter(
|
|
||||||
RepresentationModel.class);
|
|
||||||
converter.setSupportedMediaTypes(Collections.singletonList(HAL_JSON));
|
|
||||||
converter.setObjectMapper(mapper);
|
|
||||||
return converter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.hateoas;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.cloud.openfeign.support.HttpMessageConverterCustomizer;
|
||||||
|
import org.springframework.hateoas.config.WebConverters;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
*/
|
||||||
|
public class WebConvertersCustomizer implements HttpMessageConverterCustomizer {
|
||||||
|
|
||||||
|
private final WebConverters webConverters;
|
||||||
|
|
||||||
|
public WebConvertersCustomizer(WebConverters webConverters) {
|
||||||
|
this.webConverters = webConverters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(List<HttpMessageConverter<?>> httpMessageConverters) {
|
||||||
|
webConverters.augmentClient(httpMessageConverters);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+13
-9
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.loadbalancer;
|
package org.springframework.cloud.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
@@ -25,7 +27,7 @@ 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.client.loadbalancer.LoadBalancerClient;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties;
|
||||||
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Conditional;
|
import org.springframework.context.annotation.Conditional;
|
||||||
@@ -36,19 +38,21 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* that uses {@link Client.Default} under the hood.
|
* that uses {@link Client.Default} under the hood.
|
||||||
*
|
*
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableConfigurationProperties(LoadBalancerProperties.class)
|
@EnableConfigurationProperties(LoadBalancerClientsProperties.class)
|
||||||
class DefaultFeignLoadBalancerConfiguration {
|
class DefaultFeignLoadBalancerConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@Conditional(OnRetryNotEnabledCondition.class)
|
@Conditional(OnRetryNotEnabledCondition.class)
|
||||||
public Client feignClient(LoadBalancerClient loadBalancerClient, LoadBalancerProperties properties,
|
public Client feignClient(LoadBalancerClient loadBalancerClient,
|
||||||
LoadBalancerClientFactory loadBalancerClientFactory) {
|
LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
return new FeignBlockingLoadBalancerClient(new Client.Default(null, null), loadBalancerClient, properties,
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
loadBalancerClientFactory);
|
return new FeignBlockingLoadBalancerClient(new Client.Default(null, null), loadBalancerClient,
|
||||||
|
loadBalancerClientFactory, transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -58,10 +62,10 @@ class DefaultFeignLoadBalancerConfiguration {
|
|||||||
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
public Client feignRetryClient(LoadBalancerClient loadBalancerClient,
|
public Client feignRetryClient(LoadBalancerClient loadBalancerClient,
|
||||||
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties,
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
LoadBalancerClientFactory loadBalancerClientFactory) {
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
return new RetryableFeignBlockingLoadBalancerClient(new Client.Default(null, null), loadBalancerClient,
|
return new RetryableFeignBlockingLoadBalancerClient(new Client.Default(null, null), loadBalancerClient,
|
||||||
loadBalancedRetryFactory, properties, loadBalancerClientFactory);
|
loadBalancedRetryFactory, loadBalancerClientFactory, transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+45
-4
@@ -19,6 +19,8 @@ package org.springframework.cloud.openfeign.loadbalancer;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
@@ -49,6 +51,7 @@ import static org.springframework.cloud.openfeign.loadbalancer.LoadBalancerUtils
|
|||||||
* {@link ServiceInstance} to use while resolving the request host.
|
* {@link ServiceInstance} to use while resolving the request host.
|
||||||
*
|
*
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@@ -60,16 +63,43 @@ public class FeignBlockingLoadBalancerClient implements Client {
|
|||||||
|
|
||||||
private final LoadBalancerClient loadBalancerClient;
|
private final LoadBalancerClient loadBalancerClient;
|
||||||
|
|
||||||
private final LoadBalancerProperties properties;
|
|
||||||
|
|
||||||
private final LoadBalancerClientFactory loadBalancerClientFactory;
|
private final LoadBalancerClientFactory loadBalancerClientFactory;
|
||||||
|
|
||||||
|
private final List<LoadBalancerFeignRequestTransformer> transformers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link FeignBlockingLoadBalancerClient#FeignBlockingLoadBalancerClient(Client, LoadBalancerClient, LoadBalancerClientFactory, List)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public FeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
public FeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) {
|
LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.loadBalancerClient = loadBalancerClient;
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
this.properties = properties;
|
|
||||||
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
|
this.transformers = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link FeignBlockingLoadBalancerClient#FeignBlockingLoadBalancerClient(Client, LoadBalancerClient, LoadBalancerClientFactory, List)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public FeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
|
LoadBalancerClientFactory loadBalancerClientFactory) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
|
this.transformers = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
|
LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
|
this.transformers = transformers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -100,7 +130,7 @@ public class FeignBlockingLoadBalancerClient implements Client {
|
|||||||
.body(message, StandardCharsets.UTF_8).build();
|
.body(message, StandardCharsets.UTF_8).build();
|
||||||
}
|
}
|
||||||
String reconstructedUrl = loadBalancerClient.reconstructURI(instance, originalUri).toString();
|
String reconstructedUrl = loadBalancerClient.reconstructURI(instance, originalUri).toString();
|
||||||
Request newRequest = buildRequest(request, reconstructedUrl);
|
Request newRequest = buildRequest(request, reconstructedUrl, instance);
|
||||||
return executeWithLoadBalancerLifecycleProcessing(delegate, options, newRequest, lbRequest, lbResponse,
|
return executeWithLoadBalancerLifecycleProcessing(delegate, options, newRequest, lbRequest, lbResponse,
|
||||||
supportedLifecycleProcessors);
|
supportedLifecycleProcessors);
|
||||||
}
|
}
|
||||||
@@ -110,12 +140,23 @@ public class FeignBlockingLoadBalancerClient implements Client {
|
|||||||
request.charset(), request.requestTemplate());
|
request.charset(), request.requestTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Request buildRequest(Request request, String reconstructedUrl, ServiceInstance instance) {
|
||||||
|
Request newRequest = buildRequest(request, reconstructedUrl);
|
||||||
|
if (transformers != null) {
|
||||||
|
for (LoadBalancerFeignRequestTransformer transformer : transformers) {
|
||||||
|
newRequest = transformer.transformRequest(newRequest, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newRequest;
|
||||||
|
}
|
||||||
|
|
||||||
// Visible for Sleuth instrumentation
|
// Visible for Sleuth instrumentation
|
||||||
public Client getDelegate() {
|
public Client getDelegate() {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHint(String serviceId) {
|
private String getHint(String serviceId) {
|
||||||
|
LoadBalancerProperties properties = loadBalancerClientFactory.getProperties(serviceId);
|
||||||
String defaultHint = properties.getHint().getOrDefault("default", "default");
|
String defaultHint = properties.getHint().getOrDefault("default", "default");
|
||||||
String hintPropertyValue = properties.getHint().get(serviceId);
|
String hintPropertyValue = properties.getHint().get(serviceId);
|
||||||
return hintPropertyValue != null ? hintPropertyValue : defaultHint;
|
return hintPropertyValue != null ? hintPropertyValue : defaultHint;
|
||||||
|
|||||||
+13
-8
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.loadbalancer;
|
package org.springframework.cloud.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.hc5.ApacheHttp5Client;
|
import feign.hc5.ApacheHttp5Client;
|
||||||
import org.apache.hc.client5.http.classic.HttpClient;
|
import org.apache.hc.client5.http.classic.HttpClient;
|
||||||
@@ -27,7 +29,7 @@ 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.client.loadbalancer.LoadBalancerClient;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties;
|
||||||
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
||||||
import org.springframework.cloud.openfeign.clientconfig.HttpClient5FeignConfiguration;
|
import org.springframework.cloud.openfeign.clientconfig.HttpClient5FeignConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -40,22 +42,25 @@ import org.springframework.context.annotation.Import;
|
|||||||
* that uses {@link ApacheHttp5Client} under the hood.
|
* that uses {@link ApacheHttp5Client} under the hood.
|
||||||
*
|
*
|
||||||
* @author Nguyen Ky Thanh
|
* @author Nguyen Ky Thanh
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(ApacheHttp5Client.class)
|
@ConditionalOnClass(ApacheHttp5Client.class)
|
||||||
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
||||||
@ConditionalOnProperty(value = "feign.httpclient.hc5.enabled", havingValue = "true")
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.httpclient.hc5.enabled", havingValue = "true")
|
||||||
@Import(HttpClient5FeignConfiguration.class)
|
@Import(HttpClient5FeignConfiguration.class)
|
||||||
@EnableConfigurationProperties(LoadBalancerProperties.class)
|
@EnableConfigurationProperties(LoadBalancerClientsProperties.class)
|
||||||
class HttpClient5FeignLoadBalancerConfiguration {
|
class HttpClient5FeignLoadBalancerConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@Conditional(OnRetryNotEnabledCondition.class)
|
@Conditional(OnRetryNotEnabledCondition.class)
|
||||||
public Client feignClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient5,
|
public Client feignClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient5,
|
||||||
LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) {
|
LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
Client delegate = new ApacheHttp5Client(httpClient5);
|
Client delegate = new ApacheHttp5Client(httpClient5);
|
||||||
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, properties, loadBalancerClientFactory);
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory,
|
||||||
|
transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -65,11 +70,11 @@ class HttpClient5FeignLoadBalancerConfiguration {
|
|||||||
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
public Client feignRetryClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient5,
|
public Client feignRetryClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient5,
|
||||||
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties,
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
LoadBalancerClientFactory loadBalancerClientFactory) {
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
Client delegate = new ApacheHttp5Client(httpClient5);
|
Client delegate = new ApacheHttp5Client(httpClient5);
|
||||||
return new RetryableFeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancedRetryFactory,
|
return new RetryableFeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancedRetryFactory,
|
||||||
properties, loadBalancerClientFactory);
|
loadBalancerClientFactory, transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-8
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.loadbalancer;
|
package org.springframework.cloud.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
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;
|
||||||
@@ -27,7 +29,7 @@ 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.client.loadbalancer.LoadBalancerClient;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties;
|
||||||
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
||||||
import org.springframework.cloud.openfeign.HttpClient5DisabledConditions;
|
import org.springframework.cloud.openfeign.HttpClient5DisabledConditions;
|
||||||
import org.springframework.cloud.openfeign.clientconfig.HttpClientFeignConfiguration;
|
import org.springframework.cloud.openfeign.clientconfig.HttpClientFeignConfiguration;
|
||||||
@@ -42,24 +44,27 @@ import org.springframework.context.annotation.Import;
|
|||||||
*
|
*
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
* @author Nguyen Ky Thanh
|
* @author Nguyen Ky Thanh
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(ApacheHttpClient.class)
|
@ConditionalOnClass(ApacheHttpClient.class)
|
||||||
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
||||||
@ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true)
|
@ConditionalOnProperty(value = "spring.cloud.openfeign.httpclient.enabled", matchIfMissing = true)
|
||||||
@Conditional(HttpClient5DisabledConditions.class)
|
@Conditional(HttpClient5DisabledConditions.class)
|
||||||
@Import(HttpClientFeignConfiguration.class)
|
@Import(HttpClientFeignConfiguration.class)
|
||||||
@EnableConfigurationProperties(LoadBalancerProperties.class)
|
@EnableConfigurationProperties(LoadBalancerClientsProperties.class)
|
||||||
class HttpClientFeignLoadBalancerConfiguration {
|
class HttpClientFeignLoadBalancerConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@Conditional(OnRetryNotEnabledCondition.class)
|
@Conditional(OnRetryNotEnabledCondition.class)
|
||||||
public Client feignClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient,
|
public Client feignClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient,
|
||||||
LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) {
|
LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
|
ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
|
||||||
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, properties, loadBalancerClientFactory);
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory,
|
||||||
|
transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -69,11 +74,11 @@ class HttpClientFeignLoadBalancerConfiguration {
|
|||||||
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
public Client feignRetryClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient,
|
public Client feignRetryClient(LoadBalancerClient loadBalancerClient, HttpClient httpClient,
|
||||||
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties,
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
LoadBalancerClientFactory loadBalancerClientFactory) {
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
|
ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
|
||||||
return new RetryableFeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancedRetryFactory,
|
return new RetryableFeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancedRetryFactory,
|
||||||
properties, loadBalancerClientFactory);
|
loadBalancerClientFactory, transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import feign.Request;
|
||||||
|
|
||||||
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows applications to transform the load-balanced {@link Request} given the chosen
|
||||||
|
* {@link org.springframework.cloud.client.ServiceInstance}.
|
||||||
|
*
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
|
*/
|
||||||
|
@Order(LoadBalancerFeignRequestTransformer.DEFAULT_ORDER)
|
||||||
|
public interface LoadBalancerFeignRequestTransformer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order for the {@link LoadBalancerFeignRequestTransformer}.
|
||||||
|
*/
|
||||||
|
int DEFAULT_ORDER = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows transforming load-balanced requests based on the provided
|
||||||
|
* {@link ServiceInstance}.
|
||||||
|
* @param request Original request.
|
||||||
|
* @param instance ServiceInstance returned from LoadBalancer.
|
||||||
|
* @return New request or original request
|
||||||
|
*/
|
||||||
|
Request transformRequest(Request request, ServiceInstance instance);
|
||||||
|
|
||||||
|
}
|
||||||
+2
-2
@@ -33,7 +33,7 @@ import org.springframework.cloud.client.loadbalancer.RequestData;
|
|||||||
import org.springframework.cloud.client.loadbalancer.ResponseData;
|
import org.springframework.cloud.client.loadbalancer.ResponseData;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatusCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
@@ -73,7 +73,7 @@ final class LoadBalancerUtils {
|
|||||||
static ResponseData buildResponseData(Response response) {
|
static ResponseData buildResponseData(Response response) {
|
||||||
HttpHeaders responseHeaders = new HttpHeaders();
|
HttpHeaders responseHeaders = new HttpHeaders();
|
||||||
response.headers().forEach((key, value) -> responseHeaders.put(key, new ArrayList<>(value)));
|
response.headers().forEach((key, value) -> responseHeaders.put(key, new ArrayList<>(value)));
|
||||||
return new ResponseData(HttpStatus.resolve(response.status()), responseHeaders, null,
|
return new ResponseData(HttpStatusCode.valueOf(response.status()), responseHeaders, null,
|
||||||
buildRequestData(response.request()));
|
buildRequestData(response.request()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-8
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.loadbalancer;
|
package org.springframework.cloud.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.okhttp.OkHttpClient;
|
import feign.okhttp.OkHttpClient;
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ 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.client.loadbalancer.LoadBalancerClient;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerClientsProperties;
|
||||||
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
|
||||||
import org.springframework.cloud.openfeign.clientconfig.OkHttpFeignConfiguration;
|
import org.springframework.cloud.openfeign.clientconfig.OkHttpFeignConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -39,23 +41,26 @@ import org.springframework.context.annotation.Import;
|
|||||||
* that uses {@link OkHttpClient} under the hood.
|
* that uses {@link OkHttpClient} under the hood.
|
||||||
*
|
*
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(OkHttpClient.class)
|
@ConditionalOnClass(OkHttpClient.class)
|
||||||
@ConditionalOnProperty("feign.okhttp.enabled")
|
@ConditionalOnProperty("spring.cloud.openfeign.okhttp.enabled")
|
||||||
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
||||||
@Import(OkHttpFeignConfiguration.class)
|
@Import(OkHttpFeignConfiguration.class)
|
||||||
@EnableConfigurationProperties(LoadBalancerProperties.class)
|
@EnableConfigurationProperties(LoadBalancerClientsProperties.class)
|
||||||
class OkHttpFeignLoadBalancerConfiguration {
|
class OkHttpFeignLoadBalancerConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@Conditional(OnRetryNotEnabledCondition.class)
|
@Conditional(OnRetryNotEnabledCondition.class)
|
||||||
public Client feignClient(okhttp3.OkHttpClient okHttpClient, LoadBalancerClient loadBalancerClient,
|
public Client feignClient(okhttp3.OkHttpClient okHttpClient, LoadBalancerClient loadBalancerClient,
|
||||||
LoadBalancerProperties properties, LoadBalancerClientFactory loadBalancerClientFactory) {
|
LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
OkHttpClient delegate = new OkHttpClient(okHttpClient);
|
OkHttpClient delegate = new OkHttpClient(okHttpClient);
|
||||||
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, properties, loadBalancerClientFactory);
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory,
|
||||||
|
transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -65,11 +70,11 @@ class OkHttpFeignLoadBalancerConfiguration {
|
|||||||
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.retry.enabled", havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
public Client feignRetryClient(LoadBalancerClient loadBalancerClient, okhttp3.OkHttpClient okHttpClient,
|
public Client feignRetryClient(LoadBalancerClient loadBalancerClient, okhttp3.OkHttpClient okHttpClient,
|
||||||
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties,
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
LoadBalancerClientFactory loadBalancerClientFactory) {
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
OkHttpClient delegate = new OkHttpClient(okHttpClient);
|
OkHttpClient delegate = new OkHttpClient(okHttpClient);
|
||||||
return new RetryableFeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancedRetryFactory,
|
return new RetryableFeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancedRetryFactory,
|
||||||
properties, loadBalancerClientFactory);
|
loadBalancerClientFactory, transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-4
@@ -20,6 +20,7 @@ import java.io.IOException;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -65,6 +66,7 @@ import static org.springframework.cloud.openfeign.loadbalancer.LoadBalancerUtils
|
|||||||
* load-balanced with Spring Cloud LoadBalancer.
|
* load-balanced with Spring Cloud LoadBalancer.
|
||||||
*
|
*
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
* @since 2.2.6
|
* @since 2.2.6
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
@@ -78,18 +80,47 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client {
|
|||||||
|
|
||||||
private final LoadBalancedRetryFactory loadBalancedRetryFactory;
|
private final LoadBalancedRetryFactory loadBalancedRetryFactory;
|
||||||
|
|
||||||
private final LoadBalancerProperties properties;
|
|
||||||
|
|
||||||
private final LoadBalancerClientFactory loadBalancerClientFactory;
|
private final LoadBalancerClientFactory loadBalancerClientFactory;
|
||||||
|
|
||||||
|
private final List<LoadBalancerFeignRequestTransformer> transformers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link RetryableFeignBlockingLoadBalancerClient#RetryableFeignBlockingLoadBalancerClient(Client, LoadBalancerClient, LoadBalancedRetryFactory, LoadBalancerClientFactory, List)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public RetryableFeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
public RetryableFeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties,
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerProperties properties,
|
||||||
LoadBalancerClientFactory loadBalancerClientFactory) {
|
LoadBalancerClientFactory loadBalancerClientFactory) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.loadBalancerClient = loadBalancerClient;
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
this.loadBalancedRetryFactory = loadBalancedRetryFactory;
|
this.loadBalancedRetryFactory = loadBalancedRetryFactory;
|
||||||
this.properties = properties;
|
|
||||||
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
|
this.transformers = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link RetryableFeignBlockingLoadBalancerClient#RetryableFeignBlockingLoadBalancerClient(Client, LoadBalancerClient, LoadBalancedRetryFactory, LoadBalancerClientFactory, List)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public RetryableFeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerClientFactory loadBalancerClientFactory) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
|
this.loadBalancedRetryFactory = loadBalancedRetryFactory;
|
||||||
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
|
this.transformers = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RetryableFeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerClientFactory loadBalancerClientFactory,
|
||||||
|
List<LoadBalancerFeignRequestTransformer> transformers) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
|
this.loadBalancedRetryFactory = loadBalancedRetryFactory;
|
||||||
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
|
this.transformers = transformers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -148,7 +179,7 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client {
|
|||||||
}
|
}
|
||||||
String reconstructedUrl = loadBalancerClient.reconstructURI(retrievedServiceInstance, originalUri)
|
String reconstructedUrl = loadBalancerClient.reconstructURI(retrievedServiceInstance, originalUri)
|
||||||
.toString();
|
.toString();
|
||||||
feignRequest = buildRequest(request, reconstructedUrl);
|
feignRequest = buildRequest(request, reconstructedUrl, retrievedServiceInstance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
org.springframework.cloud.client.loadbalancer.Response<ServiceInstance> lbResponse = new DefaultResponse(
|
org.springframework.cloud.client.loadbalancer.Response<ServiceInstance> lbResponse = new DefaultResponse(
|
||||||
@@ -181,6 +212,16 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client {
|
|||||||
request.charset(), request.requestTemplate());
|
request.charset(), request.requestTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Request buildRequest(Request request, String reconstructedUrl, ServiceInstance instance) {
|
||||||
|
Request newRequest = buildRequest(request, reconstructedUrl);
|
||||||
|
if (transformers != null) {
|
||||||
|
for (LoadBalancerFeignRequestTransformer transformer : transformers) {
|
||||||
|
newRequest = transformer.transformRequest(newRequest, instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newRequest;
|
||||||
|
}
|
||||||
|
|
||||||
private RetryTemplate buildRetryTemplate(String serviceId, Request request, LoadBalancedRetryPolicy retryPolicy) {
|
private RetryTemplate buildRetryTemplate(String serviceId, Request request, LoadBalancedRetryPolicy retryPolicy) {
|
||||||
RetryTemplate retryTemplate = new RetryTemplate();
|
RetryTemplate retryTemplate = new RetryTemplate();
|
||||||
BackOffPolicy backOffPolicy = this.loadBalancedRetryFactory.createBackOffPolicy(serviceId);
|
BackOffPolicy backOffPolicy = this.loadBalancedRetryFactory.createBackOffPolicy(serviceId);
|
||||||
@@ -232,6 +273,7 @@ public class RetryableFeignBlockingLoadBalancerClient implements Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getHint(String serviceId) {
|
private String getHint(String serviceId) {
|
||||||
|
LoadBalancerProperties properties = loadBalancerClientFactory.getProperties(serviceId);
|
||||||
String defaultHint = properties.getHint().getOrDefault("default", "default");
|
String defaultHint = properties.getHint().getOrDefault("default", "default");
|
||||||
String hintPropertyValue = properties.getHint().get(serviceId);
|
String hintPropertyValue = properties.getHint().get(serviceId);
|
||||||
return hintPropertyValue != null ? hintPropertyValue : defaultHint;
|
return hintPropertyValue != null ? hintPropertyValue : defaultHint;
|
||||||
|
|||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.security;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||||
|
import org.springframework.security.oauth2.client.OAuth2ClientContext;
|
||||||
|
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
|
||||||
|
import org.springframework.security.oauth2.client.token.AccessTokenProvider;
|
||||||
|
import org.springframework.security.oauth2.client.token.AccessTokenProviderChain;
|
||||||
|
import org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport;
|
||||||
|
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsAccessTokenProvider;
|
||||||
|
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider;
|
||||||
|
import org.springframework.security.oauth2.client.token.grant.implicit.ImplicitAccessTokenProvider;
|
||||||
|
import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordAccessTokenProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows to customize pre-defined {@link OAuth2FeignRequestInterceptor} using configurer
|
||||||
|
* beans of class {@link OAuth2FeignRequestInterceptorConfigurer}. Each configurer
|
||||||
|
* instance can add {@link AccessTokenProvider} new {@link ClientHttpRequestInterceptor}
|
||||||
|
* instances.
|
||||||
|
*
|
||||||
|
* @author Wojciech Mąka
|
||||||
|
* @since 3.1.1
|
||||||
|
*/
|
||||||
|
public class OAuth2FeignRequestInterceptorBuilder {
|
||||||
|
|
||||||
|
private AccessTokenProvider accessTokenProvider;
|
||||||
|
|
||||||
|
private final List<ClientHttpRequestInterceptor> accessTokenProviderInterceptors = new ArrayList<>();
|
||||||
|
|
||||||
|
public OAuth2FeignRequestInterceptorBuilder() {
|
||||||
|
accessTokenProvider = new AccessTokenProviderChain(Arrays.<AccessTokenProvider>asList(
|
||||||
|
new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(),
|
||||||
|
new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public OAuth2FeignRequestInterceptorBuilder withAccessTokenProviderInterceptors(
|
||||||
|
ClientHttpRequestInterceptor... interceptors) {
|
||||||
|
accessTokenProviderInterceptors.addAll(Arrays.asList(interceptors));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
OAuth2FeignRequestInterceptor build(OAuth2ClientContext oAuth2ClientContext,
|
||||||
|
OAuth2ProtectedResourceDetails resource) {
|
||||||
|
if (OAuth2AccessTokenSupport.class.isAssignableFrom(accessTokenProvider.getClass())) {
|
||||||
|
((OAuth2AccessTokenSupport) accessTokenProvider).setInterceptors(accessTokenProviderInterceptors);
|
||||||
|
}
|
||||||
|
final OAuth2FeignRequestInterceptor feignRequestInterceptor = new OAuth2FeignRequestInterceptor(
|
||||||
|
oAuth2ClientContext, resource);
|
||||||
|
feignRequestInterceptor.setAccessTokenProvider(accessTokenProvider);
|
||||||
|
return feignRequestInterceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OAuth2FeignRequestInterceptor buildWithConfigurers(OAuth2ClientContext oAuth2ClientContext,
|
||||||
|
OAuth2ProtectedResourceDetails resource, List<OAuth2FeignRequestInterceptorConfigurer> buildConfigurers) {
|
||||||
|
final OAuth2FeignRequestInterceptorBuilder builder = new OAuth2FeignRequestInterceptorBuilder();
|
||||||
|
for (OAuth2FeignRequestInterceptorConfigurer configurer : buildConfigurers) {
|
||||||
|
configurer.customize(builder);
|
||||||
|
}
|
||||||
|
return builder.build(oAuth2ClientContext, resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.security;
|
||||||
|
|
||||||
|
import org.springframework.security.oauth2.client.token.AccessTokenProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for configurer beans working with
|
||||||
|
* {@link OAuth2FeignRequestInterceptorBuilder} in order to provide custom interceptors
|
||||||
|
* for {@link AccessTokenProvider} managed internally by
|
||||||
|
* {@link OAuth2FeignRequestInterceptor}.
|
||||||
|
*
|
||||||
|
* @author Wojciech Mąka
|
||||||
|
* @since 3.1.1
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface OAuth2FeignRequestInterceptorConfigurer {
|
||||||
|
|
||||||
|
void customize(OAuth2FeignRequestInterceptorBuilder requestInterceptorBuilder);
|
||||||
|
|
||||||
|
}
|
||||||
-80
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013-2022 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.cloud.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-58
@@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013-2022 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.cloud.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))));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.support;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
*/
|
||||||
|
class EmptyObjectProvider<T> implements ObjectProvider<T> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getObject(Object... args) throws BeansException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getIfAvailable() throws BeansException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getIfUnique() throws BeansException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getObject() throws BeansException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEach(Consumer action) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
* @since 2.2.8
|
* @since 2.2.8
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties("feign.encoder")
|
@ConfigurationProperties("spring.cloud.openfeign.encoder")
|
||||||
public class FeignEncoderProperties {
|
public class FeignEncoderProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+47
-10
@@ -16,15 +16,19 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.support;
|
package org.springframework.cloud.openfeign.support;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import feign.okhttp.OkHttpClient;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
* @author Nguyen Ky Thanh
|
* @author Nguyen Ky Thanh
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "feign.httpclient")
|
@ConfigurationProperties(prefix = "spring.cloud.openfeign.httpclient")
|
||||||
public class FeignHttpClientProperties {
|
public class FeignHttpClientProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,8 +92,13 @@ public class FeignHttpClientProperties {
|
|||||||
*/
|
*/
|
||||||
private Hc5Properties hc5 = new Hc5Properties();
|
private Hc5Properties hc5 = new Hc5Properties();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional {@link OkHttpClient}-specific properties.
|
||||||
|
*/
|
||||||
|
private OkHttp okHttp = new OkHttp();
|
||||||
|
|
||||||
public int getConnectionTimerRepeat() {
|
public int getConnectionTimerRepeat() {
|
||||||
return this.connectionTimerRepeat;
|
return connectionTimerRepeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionTimerRepeat(int connectionTimerRepeat) {
|
public void setConnectionTimerRepeat(int connectionTimerRepeat) {
|
||||||
@@ -97,7 +106,7 @@ public class FeignHttpClientProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDisableSslValidation() {
|
public boolean isDisableSslValidation() {
|
||||||
return this.disableSslValidation;
|
return disableSslValidation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisableSslValidation(boolean disableSslValidation) {
|
public void setDisableSslValidation(boolean disableSslValidation) {
|
||||||
@@ -105,7 +114,7 @@ public class FeignHttpClientProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxConnections() {
|
public int getMaxConnections() {
|
||||||
return this.maxConnections;
|
return maxConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxConnections(int maxConnections) {
|
public void setMaxConnections(int maxConnections) {
|
||||||
@@ -113,7 +122,7 @@ public class FeignHttpClientProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxConnectionsPerRoute() {
|
public int getMaxConnectionsPerRoute() {
|
||||||
return this.maxConnectionsPerRoute;
|
return maxConnectionsPerRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxConnectionsPerRoute(int maxConnectionsPerRoute) {
|
public void setMaxConnectionsPerRoute(int maxConnectionsPerRoute) {
|
||||||
@@ -121,7 +130,7 @@ public class FeignHttpClientProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeToLive() {
|
public long getTimeToLive() {
|
||||||
return this.timeToLive;
|
return timeToLive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeToLive(long timeToLive) {
|
public void setTimeToLive(long timeToLive) {
|
||||||
@@ -129,7 +138,7 @@ public class FeignHttpClientProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TimeUnit getTimeToLiveUnit() {
|
public TimeUnit getTimeToLiveUnit() {
|
||||||
return this.timeToLiveUnit;
|
return timeToLiveUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeToLiveUnit(TimeUnit timeToLiveUnit) {
|
public void setTimeToLiveUnit(TimeUnit timeToLiveUnit) {
|
||||||
@@ -137,7 +146,7 @@ public class FeignHttpClientProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFollowRedirects() {
|
public boolean isFollowRedirects() {
|
||||||
return this.followRedirects;
|
return followRedirects;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFollowRedirects(boolean followRedirects) {
|
public void setFollowRedirects(boolean followRedirects) {
|
||||||
@@ -145,7 +154,7 @@ public class FeignHttpClientProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getConnectionTimeout() {
|
public int getConnectionTimeout() {
|
||||||
return this.connectionTimeout;
|
return connectionTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionTimeout(int connectionTimeout) {
|
public void setConnectionTimeout(int connectionTimeout) {
|
||||||
@@ -160,6 +169,14 @@ public class FeignHttpClientProperties {
|
|||||||
this.hc5 = hc5;
|
this.hc5 = hc5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OkHttp getOkHttp() {
|
||||||
|
return okHttp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOkHttp(OkHttp okHttp) {
|
||||||
|
this.okHttp = okHttp;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Hc5Properties {
|
public static class Hc5Properties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,7 +220,7 @@ public class FeignHttpClientProperties {
|
|||||||
private TimeUnit socketTimeoutUnit = DEFAULT_SOCKET_TIMEOUT_UNIT;
|
private TimeUnit socketTimeoutUnit = DEFAULT_SOCKET_TIMEOUT_UNIT;
|
||||||
|
|
||||||
public PoolConcurrencyPolicy getPoolConcurrencyPolicy() {
|
public PoolConcurrencyPolicy getPoolConcurrencyPolicy() {
|
||||||
return this.poolConcurrencyPolicy;
|
return poolConcurrencyPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPoolConcurrencyPolicy(PoolConcurrencyPolicy poolConcurrencyPolicy) {
|
public void setPoolConcurrencyPolicy(PoolConcurrencyPolicy poolConcurrencyPolicy) {
|
||||||
@@ -272,4 +289,24 @@ public class FeignHttpClientProperties {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link OkHttpClient}-specific properties.
|
||||||
|
*/
|
||||||
|
public static class OkHttp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link OkHttpClient} read timeout; defaults to 60 seconds.
|
||||||
|
*/
|
||||||
|
private Duration readTimeout = Duration.ofSeconds(60);
|
||||||
|
|
||||||
|
public Duration getReadTimeout() {
|
||||||
|
return readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadTimeout(Duration readTimeout) {
|
||||||
|
this.readTimeout = readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.support;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows customising {@link HttpMessageConverter} objects passed via {@link Consumer}
|
||||||
|
* parameter.
|
||||||
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @since 3.1.0
|
||||||
|
*/
|
||||||
|
public interface HttpMessageConverterCustomizer extends Consumer<List<HttpMessageConverter<?>>> {
|
||||||
|
|
||||||
|
}
|
||||||
+3
-2
@@ -32,6 +32,7 @@ import org.springframework.data.domain.Sort;
|
|||||||
* Provides support for encoding spring Pageable via composition.
|
* Provides support for encoding spring Pageable via composition.
|
||||||
*
|
*
|
||||||
* @author Pascal Büttiker
|
* @author Pascal Büttiker
|
||||||
|
* @author Yanming Zhou
|
||||||
*/
|
*/
|
||||||
public class PageableSpringEncoder implements Encoder {
|
public class PageableSpringEncoder implements Encoder {
|
||||||
|
|
||||||
@@ -82,8 +83,8 @@ public class PageableSpringEncoder implements Encoder {
|
|||||||
Pageable pageable = (Pageable) object;
|
Pageable pageable = (Pageable) object;
|
||||||
|
|
||||||
if (pageable.isPaged()) {
|
if (pageable.isPaged()) {
|
||||||
template.query(pageParameter, pageable.getPageNumber() + "");
|
template.query(pageParameter, String.valueOf(pageable.getPageNumber()));
|
||||||
template.query(sizeParameter, pageable.getPageSize() + "");
|
template.query(sizeParameter, String.valueOf(pageable.getPageSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageable.getSort() != null) {
|
if (pageable.getSort() != null) {
|
||||||
|
|||||||
+31
-3
@@ -31,10 +31,38 @@ import org.springframework.data.domain.Sort;
|
|||||||
* {@link org.springframework.cloud.openfeign.SpringQueryMap}.
|
* {@link org.springframework.cloud.openfeign.SpringQueryMap}.
|
||||||
*
|
*
|
||||||
* @author Hyeonmin Park
|
* @author Hyeonmin Park
|
||||||
|
* @author Yanming Zhou
|
||||||
* @since 2.2.8
|
* @since 2.2.8
|
||||||
*/
|
*/
|
||||||
public class PageableSpringQueryMapEncoder extends BeanQueryMapEncoder {
|
public class PageableSpringQueryMapEncoder extends BeanQueryMapEncoder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page index parameter name.
|
||||||
|
*/
|
||||||
|
private String pageParameter = "page";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Page size parameter name.
|
||||||
|
*/
|
||||||
|
private String sizeParameter = "size";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort parameter name.
|
||||||
|
*/
|
||||||
|
private String sortParameter = "sort";
|
||||||
|
|
||||||
|
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 Map<String, Object> encode(Object object) {
|
public Map<String, Object> encode(Object object) {
|
||||||
if (supports(object)) {
|
if (supports(object)) {
|
||||||
@@ -44,8 +72,8 @@ public class PageableSpringQueryMapEncoder extends BeanQueryMapEncoder {
|
|||||||
Pageable pageable = (Pageable) object;
|
Pageable pageable = (Pageable) object;
|
||||||
|
|
||||||
if (pageable.isPaged()) {
|
if (pageable.isPaged()) {
|
||||||
queryMap.put("page", pageable.getPageNumber());
|
queryMap.put(pageParameter, pageable.getPageNumber());
|
||||||
queryMap.put("size", pageable.getPageSize());
|
queryMap.put(sizeParameter, pageable.getPageSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageable.getSort() != null) {
|
if (pageable.getSort() != null) {
|
||||||
@@ -69,7 +97,7 @@ public class PageableSpringQueryMapEncoder extends BeanQueryMapEncoder {
|
|||||||
sortQueries.add(order.getProperty() + "%2C" + order.getDirection());
|
sortQueries.add(order.getProperty() + "%2C" + order.getDirection());
|
||||||
}
|
}
|
||||||
if (!sortQueries.isEmpty()) {
|
if (!sortQueries.isEmpty()) {
|
||||||
queryMap.put("sort", sortQueries);
|
queryMap.put(sortParameter, sortQueries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+27
-9
@@ -21,6 +21,7 @@ import java.io.InputStream;
|
|||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.lang.reflect.WildcardType;
|
import java.lang.reflect.WildcardType;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import feign.FeignException;
|
import feign.FeignException;
|
||||||
import feign.Response;
|
import feign.Response;
|
||||||
@@ -28,31 +29,48 @@ import feign.codec.DecodeException;
|
|||||||
import feign.codec.Decoder;
|
import feign.codec.Decoder;
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectFactory;
|
import org.springframework.beans.factory.ObjectFactory;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
import org.springframework.http.client.ClientHttpResponse;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.web.client.HttpMessageConverterExtractor;
|
import org.springframework.web.client.HttpMessageConverterExtractor;
|
||||||
|
|
||||||
import static org.springframework.cloud.openfeign.support.FeignUtils.getHttpHeaders;
|
import static org.springframework.cloud.openfeign.support.FeignUtils.getHttpHeaders;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
public class SpringDecoder implements Decoder {
|
public class SpringDecoder implements Decoder {
|
||||||
|
|
||||||
private ObjectFactory<HttpMessageConverters> messageConverters;
|
private final ObjectFactory<HttpMessageConverters> messageConverters;
|
||||||
|
|
||||||
|
private final ObjectProvider<HttpMessageConverterCustomizer> customizers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link SpringDecoder#SpringDecoder(ObjectFactory, ObjectProvider)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public SpringDecoder(ObjectFactory<HttpMessageConverters> messageConverters) {
|
public SpringDecoder(ObjectFactory<HttpMessageConverters> messageConverters) {
|
||||||
|
this(messageConverters, new EmptyObjectProvider<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpringDecoder(ObjectFactory<HttpMessageConverters> messageConverters,
|
||||||
|
ObjectProvider<HttpMessageConverterCustomizer> customizers) {
|
||||||
this.messageConverters = messageConverters;
|
this.messageConverters = messageConverters;
|
||||||
|
this.customizers = customizers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object decode(final Response response, Type type) throws IOException, FeignException {
|
public Object decode(final Response response, Type type) throws IOException, FeignException {
|
||||||
if (type instanceof Class || type instanceof ParameterizedType || type instanceof WildcardType) {
|
if (type instanceof Class || type instanceof ParameterizedType || type instanceof WildcardType) {
|
||||||
|
List<HttpMessageConverter<?>> converters = messageConverters.getObject().getConverters();
|
||||||
|
customizers.forEach(customizer -> customizer.accept(converters));
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
HttpMessageConverterExtractor<?> extractor = new HttpMessageConverterExtractor(type,
|
HttpMessageConverterExtractor<?> extractor = new HttpMessageConverterExtractor(type, converters);
|
||||||
this.messageConverters.getObject().getConverters());
|
|
||||||
|
|
||||||
return extractor.extractData(new FeignResponseAdapter(response));
|
return extractor.extractData(new FeignResponseAdapter(response));
|
||||||
}
|
}
|
||||||
@@ -70,23 +88,23 @@ public class SpringDecoder implements Decoder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpStatus getStatusCode() throws IOException {
|
public HttpStatus getStatusCode() throws IOException {
|
||||||
return HttpStatus.valueOf(this.response.status());
|
return HttpStatus.valueOf(response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRawStatusCode() throws IOException {
|
public int getRawStatusCode() throws IOException {
|
||||||
return this.response.status();
|
return response.status();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStatusText() throws IOException {
|
public String getStatusText() throws IOException {
|
||||||
return this.response.reason();
|
return response.reason();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
try {
|
try {
|
||||||
this.response.body().close();
|
response.body().close();
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
// Ignore exception on close...
|
// Ignore exception on close...
|
||||||
@@ -95,12 +113,12 @@ public class SpringDecoder implements Decoder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
return this.response.body().asInputStream();
|
return response.body().asInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpHeaders getHeaders() {
|
public HttpHeaders getHeaders() {
|
||||||
return getHttpHeaders(this.response.headers());
|
return getHttpHeaders(response.headers());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-2
@@ -24,6 +24,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectFactory;
|
import org.springframework.beans.factory.ObjectFactory;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||||
import org.springframework.cloud.openfeign.encoding.HttpEncoding;
|
import org.springframework.cloud.openfeign.encoding.HttpEncoding;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@@ -74,19 +76,37 @@ public class SpringEncoder implements Encoder {
|
|||||||
|
|
||||||
private final FeignEncoderProperties encoderProperties;
|
private final FeignEncoderProperties encoderProperties;
|
||||||
|
|
||||||
|
private final ObjectProvider<HttpMessageConverterCustomizer> customizers;
|
||||||
|
|
||||||
public SpringEncoder(ObjectFactory<HttpMessageConverters> messageConverters) {
|
public SpringEncoder(ObjectFactory<HttpMessageConverters> messageConverters) {
|
||||||
this(new SpringFormEncoder(), messageConverters);
|
this(new SpringFormEncoder(), messageConverters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link SpringEncoder#SpringEncoder(SpringFormEncoder, ObjectFactory, FeignEncoderProperties, ObjectProvider)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public SpringEncoder(SpringFormEncoder springFormEncoder, ObjectFactory<HttpMessageConverters> messageConverters) {
|
public SpringEncoder(SpringFormEncoder springFormEncoder, ObjectFactory<HttpMessageConverters> messageConverters) {
|
||||||
this(springFormEncoder, messageConverters, new FeignEncoderProperties());
|
this(springFormEncoder, messageConverters, new FeignEncoderProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link SpringEncoder#SpringEncoder(SpringFormEncoder, ObjectFactory, FeignEncoderProperties, ObjectProvider)}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public SpringEncoder(SpringFormEncoder springFormEncoder, ObjectFactory<HttpMessageConverters> messageConverters,
|
public SpringEncoder(SpringFormEncoder springFormEncoder, ObjectFactory<HttpMessageConverters> messageConverters,
|
||||||
FeignEncoderProperties encoderProperties) {
|
FeignEncoderProperties encoderProperties) {
|
||||||
|
this(springFormEncoder, messageConverters, encoderProperties, new EmptyObjectProvider<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public SpringEncoder(SpringFormEncoder springFormEncoder, ObjectFactory<HttpMessageConverters> messageConverters,
|
||||||
|
FeignEncoderProperties encoderProperties, ObjectProvider<HttpMessageConverterCustomizer> customizers) {
|
||||||
this.springFormEncoder = springFormEncoder;
|
this.springFormEncoder = springFormEncoder;
|
||||||
this.messageConverters = messageConverters;
|
this.messageConverters = messageConverters;
|
||||||
this.encoderProperties = encoderProperties;
|
this.encoderProperties = encoderProperties;
|
||||||
|
this.customizers = customizers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,7 +137,9 @@ public class SpringEncoder implements Encoder {
|
|||||||
|
|
||||||
private void encodeWithMessageConverter(Object requestBody, Type bodyType, RequestTemplate request,
|
private void encodeWithMessageConverter(Object requestBody, Type bodyType, RequestTemplate request,
|
||||||
MediaType requestContentType) {
|
MediaType requestContentType) {
|
||||||
for (HttpMessageConverter messageConverter : this.messageConverters.getObject().getConverters()) {
|
List<HttpMessageConverter<?>> converters = messageConverters.getObject().getConverters();
|
||||||
|
customizers.forEach(customizer -> customizer.accept(converters));
|
||||||
|
for (HttpMessageConverter messageConverter : converters) {
|
||||||
FeignOutputMessage outputMessage;
|
FeignOutputMessage outputMessage;
|
||||||
try {
|
try {
|
||||||
if (messageConverter instanceof GenericHttpMessageConverter) {
|
if (messageConverter instanceof GenericHttpMessageConverter) {
|
||||||
@@ -225,7 +247,7 @@ public class SpringEncoder implements Encoder {
|
|||||||
return Objects.equals(APPLICATION_FORM_URLENCODED, requestContentType);
|
return Objects.equals(APPLICATION_FORM_URLENCODED, requestContentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean binaryContentType(FeignOutputMessage outputMessage) {
|
protected boolean binaryContentType(FeignOutputMessage outputMessage) {
|
||||||
MediaType contentType = outputMessage.getHeaders().getContentType();
|
MediaType contentType = outputMessage.getHeaders().getContentType();
|
||||||
return contentType == null || Stream
|
return contentType == null || Stream
|
||||||
.of(MediaType.APPLICATION_CBOR, MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_PDF,
|
.of(MediaType.APPLICATION_CBOR, MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_PDF,
|
||||||
|
|||||||
+7
@@ -40,6 +40,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
|
|
||||||
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
|
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
|
||||||
import org.springframework.cloud.openfeign.CollectionFormat;
|
import org.springframework.cloud.openfeign.CollectionFormat;
|
||||||
|
import org.springframework.cloud.openfeign.annotation.CookieValueParameterProcessor;
|
||||||
import org.springframework.cloud.openfeign.annotation.MatrixVariableParameterProcessor;
|
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;
|
||||||
@@ -81,6 +82,7 @@ import static org.springframework.core.annotation.AnnotatedElementUtils.findMerg
|
|||||||
* @author Artyom Romanenko
|
* @author Artyom Romanenko
|
||||||
* @author Darren Foong
|
* @author Darren Foong
|
||||||
* @author Ram Anaswara
|
* @author Ram Anaswara
|
||||||
|
* @author Sam Kruglov
|
||||||
*/
|
*/
|
||||||
public class SpringMvcContract extends Contract.BaseContract implements ResourceLoaderAware {
|
public class SpringMvcContract extends Contract.BaseContract implements ResourceLoaderAware {
|
||||||
|
|
||||||
@@ -179,6 +181,10 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
|
|||||||
+ ". @RequestMapping annotation is not allowed on @FeignClient interfaces.");
|
+ ". @RequestMapping annotation is not allowed on @FeignClient interfaces.");
|
||||||
throw new IllegalArgumentException("@RequestMapping annotation not allowed on @FeignClient interfaces");
|
throw new IllegalArgumentException("@RequestMapping annotation not allowed on @FeignClient interfaces");
|
||||||
}
|
}
|
||||||
|
CollectionFormat collectionFormat = findMergedAnnotation(clz, CollectionFormat.class);
|
||||||
|
if (collectionFormat != null) {
|
||||||
|
data.template().collectionFormat(collectionFormat.value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -335,6 +341,7 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
|
|||||||
annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());
|
annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());
|
||||||
annotatedArgumentResolvers.add(new QueryMapParameterProcessor());
|
annotatedArgumentResolvers.add(new QueryMapParameterProcessor());
|
||||||
annotatedArgumentResolvers.add(new RequestPartParameterProcessor());
|
annotatedArgumentResolvers.add(new RequestPartParameterProcessor());
|
||||||
|
annotatedArgumentResolvers.add(new CookieValueParameterProcessor());
|
||||||
|
|
||||||
return annotatedArgumentResolvers;
|
return annotatedArgumentResolvers;
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-16
@@ -3,70 +3,82 @@
|
|||||||
],
|
],
|
||||||
"properties": [
|
"properties": [
|
||||||
{
|
{
|
||||||
"name": "feign.autoconfiguration.jackson.enabled",
|
"name": "spring.cloud.openfeign.autoconfiguration.jackson.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding.",
|
"description": "If true, PageJacksonModule and SortJacksonModule bean will be provided for Jackson page decoding.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.circuitbreaker.enabled",
|
"name": "spring.cloud.openfeign.circuitbreaker.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker.",
|
"description": "If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.circuitbreaker.group.enabled",
|
"name": "spring.cloud.openfeign.circuitbreaker.group.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker with with group.",
|
"description": "If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker with with group.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.httpclient.enabled",
|
"name": "spring.cloud.openfeign.circuitbreaker.alphanumeric-ids.enabled",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "If true, Circuit Breaker ids will only contain alphanumeric characters to allow for configuration via configuration properties.",
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.cloud.openfeign.httpclient.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "Enables the use of the Apache HTTP Client by Feign.",
|
"description": "Enables the use of the Apache HTTP Client by Feign.",
|
||||||
"defaultValue": "true"
|
"defaultValue": "true"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.httpclient.hc5.enabled",
|
"name": "spring.cloud.openfeign.httpclient.hc5.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "Enables the use of the Apache HTTP Client 5 by Feign.",
|
"description": "Enables the use of the Apache HTTP Client 5 by Feign.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.okhttp.enabled",
|
"name": "spring.cloud.openfeign.okhttp.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "Enables the use of the OK HTTP Client by Feign.",
|
"description": "Enables the use of the OK HTTP Client by Feign.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.compression.response.enabled",
|
"name": "spring.cloud.openfeign.compression.response.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"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",
|
"name": "spring.cloud.openfeign.compression.request.enabled",
|
||||||
"type": "java.lang.Boolean",
|
|
||||||
"description": "Enables the default gzip decoder to be used.",
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "feign.compression.request.enabled",
|
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "Enables the request sent by Feign to be compressed.",
|
"description": "Enables the request sent by Feign to be compressed.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.metrics.enabled",
|
"name": "spring.cloud.openfeign.metrics.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "Enables metrics capability for Feign.",
|
"description": "Enables metrics capability for Feign.",
|
||||||
"defaultValue": "true"
|
"defaultValue": "true"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "feign.client.refresh-enabled",
|
"name": "spring.cloud.openfeign.client.refresh-enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "Enables options value refresh capability for Feign.",
|
"description": "Enables options value refresh capability for Feign.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.cloud.openfeign.oauth2.enabled",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "Enables feign interceptor for managing oauth2 access token.",
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "spring.cloud.openfeign.oauth2.load-balanced",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "Enables load balancing for oauth2 access token provider.",
|
||||||
|
"defaultValue": "false"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-7
@@ -17,8 +17,7 @@
|
|||||||
package org.springframework.cloud.openfeign;
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
import feign.codec.Encoder;
|
import feign.codec.Encoder;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@@ -26,22 +25,19 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import org.springframework.cloud.openfeign.support.PageableSpringEncoder;
|
import org.springframework.cloud.openfeign.support.PageableSpringEncoder;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@SpringBootTest(classes = EnableFeignClientsSpringDataTests.PlainConfiguration.class)
|
@SpringBootTest(classes = EnableFeignClientsSpringDataTests.PlainConfiguration.class)
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class EnableFeignClientsSpringDataTests {
|
class EnableFeignClientsSpringDataTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FeignContext feignContext;
|
private FeignContext feignContext;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void encoderDefaultCorrect() {
|
void encoderDefaultCorrect() {
|
||||||
|
|
||||||
PageableSpringEncoder.class.cast(this.feignContext.getInstance("foo", Encoder.class));
|
PageableSpringEncoder.class.cast(this.feignContext.getInstance("foo", Encoder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-17
@@ -23,17 +23,15 @@ import feign.codec.Decoder;
|
|||||||
import feign.codec.Encoder;
|
import feign.codec.Encoder;
|
||||||
import feign.optionals.OptionalDecoder;
|
import feign.optionals.OptionalDecoder;
|
||||||
import feign.slf4j.Slf4jLogger;
|
import feign.slf4j.Slf4jLogger;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.WebApplicationType;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.cloud.openfeign.support.SpringEncoder;
|
import org.springframework.cloud.openfeign.support.SpringEncoder;
|
||||||
import org.springframework.cloud.openfeign.support.SpringMvcContract;
|
import org.springframework.cloud.openfeign.support.SpringMvcContract;
|
||||||
import org.springframework.cloud.test.ClassPathExclusions;
|
import org.springframework.cloud.test.ClassPathExclusions;
|
||||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
@@ -41,48 +39,47 @@ import org.springframework.context.annotation.Import;
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
|
||||||
@ClassPathExclusions({ "spring-data-commons-*.jar" })
|
@ClassPathExclusions({ "spring-data-commons-*.jar" })
|
||||||
public class EnableFeignClientsTests {
|
class EnableFeignClientsTests {
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||||
.properties("debug=true", "feign.httpclient.enabled=false")
|
.properties("debug=true", "spring.cloud.openfeign.httpclient.enabled=false")
|
||||||
.sources(EnableFeignClientsTests.PlainConfiguration.class).run();
|
.sources(EnableFeignClientsTests.PlainConfiguration.class).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
void tearDown() {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void decoderDefaultCorrect() {
|
void decoderDefaultCorrect() {
|
||||||
OptionalDecoder.class.cast(this.context.getBeansOfType(Decoder.class).get(0));
|
OptionalDecoder.class.cast(this.context.getBeansOfType(Decoder.class).get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void encoderDefaultCorrect() {
|
void encoderDefaultCorrect() {
|
||||||
SpringEncoder.class.cast(this.context.getBeansOfType(Encoder.class).get(0));
|
SpringEncoder.class.cast(this.context.getBeansOfType(Encoder.class).get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loggerDefaultCorrect() {
|
void loggerDefaultCorrect() {
|
||||||
Slf4jLogger.class.cast(this.context.getBeansOfType(Logger.class).get(0));
|
Slf4jLogger.class.cast(this.context.getBeansOfType(Logger.class).get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void contractDefaultCorrect() {
|
void contractDefaultCorrect() {
|
||||||
SpringMvcContract.class.cast(this.context.getBeansOfType(Contract.class).get(0));
|
SpringMvcContract.class.cast(this.context.getBeansOfType(Contract.class).get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void builderDefaultCorrect() {
|
void builderDefaultCorrect() {
|
||||||
Feign.Builder.class.cast(this.context.getBeansOfType(Feign.Builder.class).get(0));
|
Feign.Builder.class.cast(this.context.getBeansOfType(Feign.Builder.class).get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+89
-8
@@ -23,10 +23,19 @@ import org.assertj.core.api.Condition;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
|
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignAutoConfiguration.CircuitBreakerPresentFeignTargeterConfiguration.DefaultCircuitBreakerNameResolver;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
|
||||||
|
import org.springframework.cloud.openfeign.FeignAutoConfiguration.CircuitBreakerPresentFeignTargeterConfiguration.AlphanumericCircuitBreakerNameResolver;
|
||||||
|
import org.springframework.cloud.openfeign.security.MockOAuth2ClientContext;
|
||||||
|
import org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptor;
|
||||||
|
import org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptorBuilder;
|
||||||
|
import org.springframework.cloud.openfeign.security.OAuth2FeignRequestInterceptorConfigurer;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||||
|
import org.springframework.http.client.support.BasicAuthenticationInterceptor;
|
||||||
|
import org.springframework.security.oauth2.client.resource.BaseOAuth2ProtectedResourceDetails;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -36,35 +45,36 @@ import static org.mockito.Mockito.mock;
|
|||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
* @author Andrii Bohutskyi
|
* @author Andrii Bohutskyi
|
||||||
* @author Kwangyong Kim
|
* @author Kwangyong Kim
|
||||||
|
* @author Wojciech Mąka
|
||||||
*/
|
*/
|
||||||
class FeignAutoConfigurationTests {
|
class FeignAutoConfigurationTests {
|
||||||
|
|
||||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(FeignAutoConfiguration.class))
|
.withConfiguration(AutoConfigurations.of(FeignAutoConfiguration.class))
|
||||||
.withPropertyValues("feign.httpclient.enabled=false");
|
.withPropertyValues("spring.cloud.openfeign.httpclient.enabled=false");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateDefaultTargeterWhenFeignCircuitBreakerIsDisabled() {
|
void shouldInstantiateDefaultTargeterWhenFeignCircuitBreakerIsDisabled() {
|
||||||
runner.withPropertyValues("feign.circuitbreaker.enabled=false")
|
runner.withPropertyValues("spring.cloud.openfeign.circuitbreaker.enabled=false")
|
||||||
.run(ctx -> assertOnlyOneTargeterPresent(ctx, DefaultTargeter.class));
|
.run(ctx -> assertOnlyOneTargeterPresent(ctx, DefaultTargeter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateFeignCircuitBreakerTargeterWhenEnabled() {
|
void shouldInstantiateFeignCircuitBreakerTargeterWhenEnabled() {
|
||||||
runner.withBean(CircuitBreakerFactory.class, () -> mock(CircuitBreakerFactory.class))
|
runner.withBean(CircuitBreakerFactory.class, () -> mock(CircuitBreakerFactory.class))
|
||||||
.withPropertyValues("feign.circuitbreaker.enabled=true").run(ctx -> {
|
.withPropertyValues("spring.cloud.openfeign.circuitbreaker.enabled=true").run(ctx -> {
|
||||||
assertOnlyOneTargeterPresent(ctx, FeignCircuitBreakerTargeter.class);
|
assertOnlyOneTargeterPresent(ctx, FeignCircuitBreakerTargeter.class);
|
||||||
assertThatFeignCircuitBreakerTargeterHasGroupEnabledPropertyWithValue(ctx, false);
|
assertThatFeignCircuitBreakerTargeterHasGroupEnabledPropertyWithValue(ctx, false);
|
||||||
assertThatFeignCircuitBreakerTargeterHasSameCircuitBreakerNameResolver(ctx,
|
assertThatFeignCircuitBreakerTargeterHasSameCircuitBreakerNameResolver(ctx,
|
||||||
DefaultCircuitBreakerNameResolver.class);
|
AlphanumericCircuitBreakerNameResolver.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateFeignCircuitBreakerTargeterWithEnabledGroup() {
|
void shouldInstantiateFeignCircuitBreakerTargeterWithEnabledGroup() {
|
||||||
runner.withBean(CircuitBreakerFactory.class, () -> mock(CircuitBreakerFactory.class))
|
runner.withBean(CircuitBreakerFactory.class, () -> mock(CircuitBreakerFactory.class))
|
||||||
.withPropertyValues("feign.circuitbreaker.enabled=true")
|
.withPropertyValues("spring.cloud.openfeign.circuitbreaker.enabled=true")
|
||||||
.withPropertyValues("feign.circuitbreaker.group.enabled=true").run(ctx -> {
|
.withPropertyValues("spring.cloud.openfeign.circuitbreaker.group.enabled=true").run(ctx -> {
|
||||||
assertOnlyOneTargeterPresent(ctx, FeignCircuitBreakerTargeter.class);
|
assertOnlyOneTargeterPresent(ctx, FeignCircuitBreakerTargeter.class);
|
||||||
assertThatFeignCircuitBreakerTargeterHasGroupEnabledPropertyWithValue(ctx, true);
|
assertThatFeignCircuitBreakerTargeterHasGroupEnabledPropertyWithValue(ctx, true);
|
||||||
});
|
});
|
||||||
@@ -74,13 +84,74 @@ class FeignAutoConfigurationTests {
|
|||||||
void shouldInstantiateFeignCircuitBreakerTargeterWhenEnabledWithCustomCircuitBreakerNameResolver() {
|
void shouldInstantiateFeignCircuitBreakerTargeterWhenEnabledWithCustomCircuitBreakerNameResolver() {
|
||||||
runner.withBean(CircuitBreakerFactory.class, () -> mock(CircuitBreakerFactory.class))
|
runner.withBean(CircuitBreakerFactory.class, () -> mock(CircuitBreakerFactory.class))
|
||||||
.withBean(CircuitBreakerNameResolver.class, CustomCircuitBreakerNameResolver::new)
|
.withBean(CircuitBreakerNameResolver.class, CustomCircuitBreakerNameResolver::new)
|
||||||
.withPropertyValues("feign.circuitbreaker.enabled=true").run(ctx -> {
|
.withPropertyValues("spring.cloud.openfeign.circuitbreaker.enabled=true").run(ctx -> {
|
||||||
assertOnlyOneTargeterPresent(ctx, FeignCircuitBreakerTargeter.class);
|
assertOnlyOneTargeterPresent(ctx, FeignCircuitBreakerTargeter.class);
|
||||||
assertThatFeignCircuitBreakerTargeterHasSameCircuitBreakerNameResolver(ctx,
|
assertThatFeignCircuitBreakerTargeterHasSameCircuitBreakerNameResolver(ctx,
|
||||||
CustomCircuitBreakerNameResolver.class);
|
CustomCircuitBreakerNameResolver.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateFeignOAuth2FeignRequestInterceptorWithoutInterceptors() {
|
||||||
|
runner.withPropertyValues("spring.cloud.openfeign.oauth2.enabled=true")
|
||||||
|
.withBean(MockOAuth2ClientContext.class, "token").withBean(BaseOAuth2ProtectedResourceDetails.class)
|
||||||
|
.withBean(LoadBalancerInterceptor.class, () -> mock(LoadBalancerInterceptor.class)).run(ctx -> {
|
||||||
|
assertOauth2FeignRequestInterceptorExists(ctx);
|
||||||
|
assertAccessTokenProviderInterceptorNotExists(ctx, LoadBalancerInterceptor.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateFeignOAuth2FeignRequestInterceptorWithLoadBalancedInterceptor() {
|
||||||
|
runner.withPropertyValues("spring.cloud.openfeign.oauth2.enabled=true",
|
||||||
|
"spring.cloud.openfeign.oauth2.load-balanced=true").withBean(MockOAuth2ClientContext.class, "token")
|
||||||
|
.withBean(BaseOAuth2ProtectedResourceDetails.class)
|
||||||
|
.withBean(LoadBalancerInterceptor.class, () -> mock(LoadBalancerInterceptor.class)).run(ctx -> {
|
||||||
|
assertOauth2FeignRequestInterceptorExists(ctx);
|
||||||
|
assertAccessTokenProviderInterceptorExists(ctx, LoadBalancerInterceptor.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateFeignOAuth2FeignRequestInterceptorWithoutLoadBalancedInterceptorIfNoBeanPresent() {
|
||||||
|
runner.withPropertyValues("spring.cloud.openfeign.oauth2.enabled=true",
|
||||||
|
"spring.cloud.openfeign.oauth2.load-balanced=true").withBean(MockOAuth2ClientContext.class, "token")
|
||||||
|
.withBean(BaseOAuth2ProtectedResourceDetails.class).run(ctx -> {
|
||||||
|
assertOauth2FeignRequestInterceptorExists(ctx);
|
||||||
|
assertAccessTokenProviderInterceptorNotExists(ctx, LoadBalancerInterceptor.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateFeignOAuth2FeignRequestInterceptorWithCustomAccessTokenProviderInterceptor() {
|
||||||
|
runner.withPropertyValues("spring.cloud.openfeign.oauth2.enabled=true")
|
||||||
|
.withBean(MockOAuth2ClientContext.class, "token").withBean(BaseOAuth2ProtectedResourceDetails.class)
|
||||||
|
.withBean(CustomOAuth2FeignRequestInterceptorConfigurer.class).run(ctx -> {
|
||||||
|
assertOauth2FeignRequestInterceptorExists(ctx);
|
||||||
|
assertAccessTokenProviderInterceptorExists(ctx, BasicAuthenticationInterceptor.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertOauth2FeignRequestInterceptorExists(ConfigurableApplicationContext ctx) {
|
||||||
|
AssertableApplicationContext context = AssertableApplicationContext.get(() -> ctx);
|
||||||
|
assertThat(context).hasSingleBean(OAuth2FeignRequestInterceptor.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertAccessTokenProviderInterceptorExists(ConfigurableApplicationContext ctx,
|
||||||
|
Class<? extends ClientHttpRequestInterceptor> clazz) {
|
||||||
|
AssertableApplicationContext context = AssertableApplicationContext.get(() -> ctx);
|
||||||
|
assertThat(context).getBean(OAuth2FeignRequestInterceptor.class).extracting("accessTokenProvider")
|
||||||
|
.extracting("interceptors").asList().first().isInstanceOf(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertAccessTokenProviderInterceptorNotExists(ConfigurableApplicationContext ctx,
|
||||||
|
Class<? extends ClientHttpRequestInterceptor> clazz) {
|
||||||
|
AssertableApplicationContext context = AssertableApplicationContext.get(() -> ctx);
|
||||||
|
assertThat(context).getBean(OAuth2FeignRequestInterceptor.class).extracting("accessTokenProvider")
|
||||||
|
.extracting("interceptors").asList().filteredOn(obj -> clazz.isAssignableFrom(obj.getClass()))
|
||||||
|
.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private void assertOnlyOneTargeterPresent(ConfigurableApplicationContext ctx, Class<?> beanClass) {
|
private void assertOnlyOneTargeterPresent(ConfigurableApplicationContext ctx, Class<?> beanClass) {
|
||||||
assertThat(ctx.getBeansOfType(Targeter.class)).hasSize(1).hasValueSatisfying(new Condition<>(
|
assertThat(ctx.getBeansOfType(Targeter.class)).hasSize(1).hasValueSatisfying(new Condition<>(
|
||||||
beanClass::isInstance, String.format("Targeter should be an instance of %s", beanClass)));
|
beanClass::isInstance, String.format("Targeter should be an instance of %s", beanClass)));
|
||||||
@@ -108,4 +179,14 @@ class FeignAutoConfigurationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class CustomOAuth2FeignRequestInterceptorConfigurer implements OAuth2FeignRequestInterceptorConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void customize(OAuth2FeignRequestInterceptorBuilder requestInterceptorBuilder) {
|
||||||
|
requestInterceptorBuilder
|
||||||
|
.withAccessTokenProviderInterceptors(new BasicAuthenticationInterceptor("username", "password"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+96
-15
@@ -17,35 +17,56 @@
|
|||||||
package org.springframework.cloud.openfeign;
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import feign.Client;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
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.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doCallRealMethod;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Matt King
|
* @author Matt King
|
||||||
* @author Sam Kruglov
|
* @author Sam Kruglov
|
||||||
|
* @author Felix Dittrich
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
public class FeignBuilderCustomizerTests {
|
class FeignBuilderCustomizerTests {
|
||||||
|
|
||||||
|
private static final Targeter targeterSpy = spy(DefaultTargeter.class);
|
||||||
|
|
||||||
|
private static final Client defaultClient = mock(Client.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuilderCustomizer() {
|
void testBuilderCustomizer() {
|
||||||
|
ArgumentCaptor<Feign.Builder> feignBuilderCaptor = ArgumentCaptor.forClass(Feign.Builder.class);
|
||||||
|
doCallRealMethod().when(targeterSpy).target(any(), feignBuilderCaptor.capture(), any(), any());
|
||||||
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
FeignBuilderCustomizerTests.SampleConfiguration2.class);
|
FeignBuilderCustomizerTests.SampleConfiguration2.class);
|
||||||
|
|
||||||
FeignClientFactoryBean clientFactoryBean = context.getBean(FeignClientFactoryBean.class);
|
FeignClientFactoryBean clientFactoryBean = context.getBean(FeignClientFactoryBean.class);
|
||||||
FeignContext feignContext = context.getBean(FeignContext.class);
|
clientFactoryBean.getTarget();
|
||||||
|
|
||||||
Feign.Builder builder = clientFactoryBean.feign(feignContext);
|
Assertions.assertNotNull(feignBuilderCaptor.getValue());
|
||||||
|
Feign.Builder builder = feignBuilderCaptor.getValue();
|
||||||
assertFeignBuilderField(builder, "logLevel", Logger.Level.HEADERS);
|
assertFeignBuilderField(builder, "logLevel", Logger.Level.HEADERS);
|
||||||
assertFeignBuilderField(builder, "decode404", true);
|
assertFeignBuilderField(builder, "decode404", true);
|
||||||
|
|
||||||
@@ -61,14 +82,18 @@ public class FeignBuilderCustomizerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildCustomizerOrdered() {
|
void testBuildCustomizerOrdered() {
|
||||||
|
ArgumentCaptor<Feign.Builder> feignBuilderCaptor = ArgumentCaptor.forClass(Feign.Builder.class);
|
||||||
|
doCallRealMethod().when(targeterSpy).target(any(), feignBuilderCaptor.capture(), any(), any());
|
||||||
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
||||||
|
|
||||||
FeignClientFactoryBean clientFactoryBean = context.getBean(FeignClientFactoryBean.class);
|
FeignClientFactoryBean clientFactoryBean = context.getBean(FeignClientFactoryBean.class);
|
||||||
FeignContext feignContext = context.getBean(FeignContext.class);
|
clientFactoryBean.getTarget();
|
||||||
|
|
||||||
Feign.Builder builder = clientFactoryBean.feign(feignContext);
|
Assertions.assertNotNull(feignBuilderCaptor.getValue());
|
||||||
|
Feign.Builder builder = feignBuilderCaptor.getValue();
|
||||||
assertFeignBuilderField(builder, "logLevel", Logger.Level.FULL);
|
assertFeignBuilderField(builder, "logLevel", Logger.Level.FULL);
|
||||||
assertFeignBuilderField(builder, "decode404", true);
|
assertFeignBuilderField(builder, "decode404", true);
|
||||||
|
|
||||||
@@ -76,16 +101,20 @@ public class FeignBuilderCustomizerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildCustomizerOrderedWithAdditional() {
|
void testBuildCustomizerOrderedWithAdditional() {
|
||||||
|
ArgumentCaptor<Feign.Builder> feignBuilderCaptor = ArgumentCaptor.forClass(Feign.Builder.class);
|
||||||
|
doCallRealMethod().when(targeterSpy).target(any(), feignBuilderCaptor.capture(), any(), any());
|
||||||
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
||||||
|
|
||||||
FeignClientFactoryBean clientFactoryBean = context.getBean(FeignClientFactoryBean.class);
|
FeignClientFactoryBean clientFactoryBean = context.getBean(FeignClientFactoryBean.class);
|
||||||
clientFactoryBean.addCustomizer(builder -> builder.logLevel(Logger.Level.BASIC));
|
clientFactoryBean.addCustomizer(builder -> builder.logLevel(Logger.Level.BASIC));
|
||||||
clientFactoryBean.addCustomizer(Feign.Builder::doNotCloseAfterDecode);
|
clientFactoryBean.addCustomizer(Feign.Builder::doNotCloseAfterDecode);
|
||||||
FeignContext feignContext = context.getBean(FeignContext.class);
|
clientFactoryBean.getTarget();
|
||||||
|
|
||||||
Feign.Builder builder = clientFactoryBean.feign(feignContext);
|
Assertions.assertNotNull(feignBuilderCaptor.getValue());
|
||||||
|
Feign.Builder builder = feignBuilderCaptor.getValue();
|
||||||
assertFeignBuilderField(builder, "logLevel", Logger.Level.BASIC);
|
assertFeignBuilderField(builder, "logLevel", Logger.Level.BASIC);
|
||||||
assertFeignBuilderField(builder, "decode404", true);
|
assertFeignBuilderField(builder, "decode404", true);
|
||||||
assertFeignBuilderField(builder, "closeAfterDecode", false);
|
assertFeignBuilderField(builder, "closeAfterDecode", false);
|
||||||
@@ -93,16 +122,41 @@ public class FeignBuilderCustomizerTests {
|
|||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FeignClientFactoryBean defaultFeignClientFactoryBean() {
|
@ParameterizedTest(name = "should use custom HttpClient with config: {0}")
|
||||||
|
@MethodSource("testConfiguration")
|
||||||
|
void testBuildCustomizerWithCustomHttpClient(Class configClass) {
|
||||||
|
ArgumentCaptor<Feign.Builder> feignBuilderCaptor = ArgumentCaptor.forClass(Feign.Builder.class);
|
||||||
|
doCallRealMethod().when(targeterSpy).target(any(), feignBuilderCaptor.capture(), any(), any());
|
||||||
|
Client customClientMock = mock(Client.class);
|
||||||
|
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClass);
|
||||||
|
FeignClientFactoryBean clientFactoryBean = context.getBean(FeignClientFactoryBean.class);
|
||||||
|
clientFactoryBean.addCustomizer(builder -> builder.client(customClientMock));
|
||||||
|
clientFactoryBean.getTarget();
|
||||||
|
|
||||||
|
Assertions.assertNotNull(feignBuilderCaptor.getValue());
|
||||||
|
Feign.Builder builder = feignBuilderCaptor.getValue();
|
||||||
|
assertFeignBuilderField(builder, "client", customClientMock);
|
||||||
|
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FeignClientFactoryBean defaultFeignClientFactoryBean(String url) {
|
||||||
FeignClientFactoryBean feignClientFactoryBean = new FeignClientFactoryBean();
|
FeignClientFactoryBean feignClientFactoryBean = new FeignClientFactoryBean();
|
||||||
feignClientFactoryBean.setContextId("test");
|
feignClientFactoryBean.setContextId("test");
|
||||||
feignClientFactoryBean.setName("test");
|
feignClientFactoryBean.setName("test");
|
||||||
feignClientFactoryBean.setType(FeignClientFactoryTests.TestType.class);
|
feignClientFactoryBean.setType(FeignClientFactoryTests.TestType.class);
|
||||||
feignClientFactoryBean.setPath("");
|
feignClientFactoryBean.setPath("");
|
||||||
feignClientFactoryBean.setUrl("http://some.absolute.url");
|
if (url != null) {
|
||||||
|
feignClientFactoryBean.setUrl(url);
|
||||||
|
}
|
||||||
return feignClientFactoryBean;
|
return feignClientFactoryBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Stream<Class> testConfiguration() {
|
||||||
|
return Stream.of(SampleConfiguration3.class, LoadBalancedSampleConfiguration.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(FeignClientsConfiguration.class)
|
@Import(FeignClientsConfiguration.class)
|
||||||
protected static class SampleConfiguration2 {
|
protected static class SampleConfiguration2 {
|
||||||
@@ -129,7 +183,12 @@ public class FeignBuilderCustomizerTests {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
FeignClientFactoryBean feignClientFactoryBean() {
|
FeignClientFactoryBean feignClientFactoryBean() {
|
||||||
return defaultFeignClientFactoryBean();
|
return defaultFeignClientFactoryBean("http://some.absolute.url");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Targeter targeter() {
|
||||||
|
return targeterSpy;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -167,7 +226,29 @@ public class FeignBuilderCustomizerTests {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
FeignClientFactoryBean feignClientFactoryBean() {
|
FeignClientFactoryBean feignClientFactoryBean() {
|
||||||
return defaultFeignClientFactoryBean();
|
return defaultFeignClientFactoryBean("http://some.absolute.url");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Targeter targeter() {
|
||||||
|
return targeterSpy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Client client() {
|
||||||
|
return defaultClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@Import(SampleConfiguration3.class)
|
||||||
|
protected static class LoadBalancedSampleConfiguration {
|
||||||
|
|
||||||
|
@Primary
|
||||||
|
@Bean
|
||||||
|
FeignClientFactoryBean feignClientFactoryBean() {
|
||||||
|
return defaultFeignClientFactoryBean(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-25
@@ -25,11 +25,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import org.hamcrest.Matchers;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import org.springframework.cloud.openfeign.testclients.TestClient;
|
import org.springframework.cloud.openfeign.testclients.TestClient;
|
||||||
@@ -37,15 +34,14 @@ import org.springframework.context.ApplicationContext;
|
|||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sven Döring
|
* @author Sven Döring
|
||||||
* @author Sam Kruglov
|
* @author Sam Kruglov
|
||||||
|
* @author Szymon Linowski
|
||||||
*/
|
*/
|
||||||
public class FeignClientBuilderTests {
|
class FeignClientBuilderTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private FeignClientBuilder feignClientBuilder;
|
private FeignClientBuilder feignClientBuilder;
|
||||||
|
|
||||||
@@ -75,14 +71,14 @@ public class FeignClientBuilderTests {
|
|||||||
return (T) ReflectionUtils.getField(field, factoryBean);
|
return (T) ReflectionUtils.getField(field, factoryBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
this.applicationContext = Mockito.mock(ApplicationContext.class);
|
this.applicationContext = Mockito.mock(ApplicationContext.class);
|
||||||
this.feignClientBuilder = new FeignClientBuilder(this.applicationContext);
|
this.feignClientBuilder = new FeignClientBuilder(this.applicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void safetyCheckForNewFieldsOnTheFeignClientAnnotation() {
|
void safetyCheckForNewFieldsOnTheFeignClientAnnotation() {
|
||||||
final List<String> methodNames = new ArrayList();
|
final List<String> methodNames = new ArrayList();
|
||||||
for (final Method method : FeignClient.class.getMethods()) {
|
for (final Method method : FeignClient.class.getMethods()) {
|
||||||
methodNames.add(method.getName());
|
methodNames.add(method.getName());
|
||||||
@@ -101,7 +97,7 @@ public class FeignClientBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forType_preinitializedBuilder() {
|
void forType_preinitializedBuilder() {
|
||||||
// when:
|
// when:
|
||||||
final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestFeignClient.class, "TestClient");
|
final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestFeignClient.class, "TestClient");
|
||||||
|
|
||||||
@@ -120,7 +116,7 @@ public class FeignClientBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forType_allFieldsSetOnBuilder() {
|
void forType_allFieldsSetOnBuilder() {
|
||||||
// when:
|
// when:
|
||||||
final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestFeignClient.class, "TestClient")
|
final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestFeignClient.class, "TestClient")
|
||||||
.decode404(true).url("Url/").path("/Path").contextId("TestContext");
|
.decode404(true).url("Url/").path("/Path").contextId("TestContext");
|
||||||
@@ -139,7 +135,7 @@ public class FeignClientBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forType_clientFactoryBeanProvided() {
|
void forType_clientFactoryBeanProvided() {
|
||||||
// when:
|
// when:
|
||||||
final FeignClientBuilder.Builder builder = this.feignClientBuilder
|
final FeignClientBuilder.Builder builder = this.feignClientBuilder
|
||||||
.forType(TestFeignClient.class, new FeignClientFactoryBean(), "TestClient").decode404(true)
|
.forType(TestFeignClient.class, new FeignClientFactoryBean(), "TestClient").decode404(true)
|
||||||
@@ -160,21 +156,19 @@ public class FeignClientBuilderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void forType_build() {
|
void forType_build() {
|
||||||
// given:
|
// given:
|
||||||
Mockito.when(this.applicationContext.getBean(FeignContext.class)).thenThrow(new ClosedFileSystemException()); // throw
|
Mockito.when(this.applicationContext.getBean(FeignContext.class)).thenThrow(new ClosedFileSystemException()); // throw
|
||||||
// an
|
// an
|
||||||
// unusual
|
// unusual
|
||||||
// exception
|
// exception
|
||||||
// in
|
// in
|
||||||
// the
|
// the
|
||||||
// FeignClientFactoryBean
|
// FeignClientFactoryBean
|
||||||
final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestClient.class, "TestClient");
|
final FeignClientBuilder.Builder builder = this.feignClientBuilder.forType(TestClient.class, "TestClient");
|
||||||
|
|
||||||
// expect: 'the build will fail right after calling build() with the mocked
|
// expect: 'the build will fail right after calling build() with the mocked
|
||||||
// unusual exception'
|
// unusual exception'
|
||||||
this.thrown.expect(Matchers.isA(ClosedFileSystemException.class));
|
assertThatExceptionOfType(ClosedFileSystemException.class).isThrownBy(() -> builder.build());
|
||||||
builder.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface TestFeignClient {
|
private interface TestFeignClient {
|
||||||
|
|||||||
+123
@@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign;
|
||||||
|
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import feign.Contract;
|
||||||
|
import feign.RequestLine;
|
||||||
|
import feign.RetryableException;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.cache.CacheManager;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.cache.interceptor.SimpleKey;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sam Kruglov
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = FeignClientCacheTests.TestConfiguration.class)
|
||||||
|
@DirtiesContext
|
||||||
|
public class FeignClientCacheTests {
|
||||||
|
|
||||||
|
private static final String CACHE_NAME = "foo-cache";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FooClient foo;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cacheExists(@Autowired CacheManager cacheManager) {
|
||||||
|
assertThat(cacheManager.getCache(CACHE_NAME)).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void interceptedCallsReal() {
|
||||||
|
assertThatExceptionOfType(RetryableException.class).isThrownBy(foo::getWithCache)
|
||||||
|
.withRootCauseInstanceOf(UnknownHostException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void nonInterceptedCallsReal() {
|
||||||
|
assertThatExceptionOfType(RetryableException.class).isThrownBy(foo::getWithoutCache)
|
||||||
|
.withRootCauseInstanceOf(UnknownHostException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class givenCached {
|
||||||
|
|
||||||
|
String cachedValue = "cached";
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp(@Autowired CacheManager cacheManager) {
|
||||||
|
cacheManager.getCache(CACHE_NAME).put(SimpleKey.EMPTY, cachedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void interceptedReturnsCached() {
|
||||||
|
assertThat(foo.getWithCache()).isSameAs(cachedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void nonInterceptedCallsReal() {
|
||||||
|
assertThatExceptionOfType(RetryableException.class).isThrownBy(foo::getWithoutCache)
|
||||||
|
.withRootCauseInstanceOf(UnknownHostException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@EnableFeignClients(clients = FooClient.class)
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@EnableCaching
|
||||||
|
protected static class TestConfiguration {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@FeignClient(name = "foo", url = "http://foo", configuration = FooConfiguration.class)
|
||||||
|
interface FooClient {
|
||||||
|
|
||||||
|
@RequestLine("GET /with-cache")
|
||||||
|
@Cacheable(cacheNames = CACHE_NAME)
|
||||||
|
String getWithCache();
|
||||||
|
|
||||||
|
@RequestLine("GET /without-cache")
|
||||||
|
String getWithoutCache();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class FooConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
Contract feignContract() {
|
||||||
|
return new Contract.Default();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
@@ -24,6 +24,7 @@ import feign.Capability;
|
|||||||
import feign.Contract;
|
import feign.Contract;
|
||||||
import feign.ExceptionPropagationPolicy;
|
import feign.ExceptionPropagationPolicy;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
|
import feign.QueryMapEncoder;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.Retryer;
|
import feign.Retryer;
|
||||||
import feign.codec.Decoder;
|
import feign.codec.Decoder;
|
||||||
@@ -43,6 +44,7 @@ import static org.springframework.cloud.openfeign.test.EqualsAndHashCodeAssert.a
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jonatan Ivanov
|
* @author Jonatan Ivanov
|
||||||
|
* @author Hyeonmin Park
|
||||||
*/
|
*/
|
||||||
class FeignClientConfigurationTests {
|
class FeignClientConfigurationTests {
|
||||||
|
|
||||||
@@ -64,6 +66,7 @@ class FeignClientConfigurationTests {
|
|||||||
assertThat(config.getContract()).isNull();
|
assertThat(config.getContract()).isNull();
|
||||||
assertThat(config.getExceptionPropagationPolicy()).isNull();
|
assertThat(config.getExceptionPropagationPolicy()).isNull();
|
||||||
assertThat(config.getCapabilities()).isNull();
|
assertThat(config.getCapabilities()).isNull();
|
||||||
|
assertThat(config.getQueryMapEncoder()).isNull();
|
||||||
assertThat(config.getMetrics()).isNull();
|
assertThat(config.getMetrics()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +91,7 @@ class FeignClientConfigurationTests {
|
|||||||
config.setExceptionPropagationPolicy(ExceptionPropagationPolicy.UNWRAP);
|
config.setExceptionPropagationPolicy(ExceptionPropagationPolicy.UNWRAP);
|
||||||
List<Class<Capability>> capabilities = Lists.list(Capability.class);
|
List<Class<Capability>> capabilities = Lists.list(Capability.class);
|
||||||
config.setCapabilities(capabilities);
|
config.setCapabilities(capabilities);
|
||||||
|
config.setQueryMapEncoder(QueryMapEncoder.class);
|
||||||
FeignClientProperties.MetricsProperties metrics = new FeignClientProperties.MetricsProperties();
|
FeignClientProperties.MetricsProperties metrics = new FeignClientProperties.MetricsProperties();
|
||||||
config.setMetrics(metrics);
|
config.setMetrics(metrics);
|
||||||
|
|
||||||
@@ -105,6 +109,7 @@ class FeignClientConfigurationTests {
|
|||||||
assertThat(config.getContract()).isSameAs(Contract.class);
|
assertThat(config.getContract()).isSameAs(Contract.class);
|
||||||
assertThat(config.getExceptionPropagationPolicy()).isSameAs(ExceptionPropagationPolicy.UNWRAP);
|
assertThat(config.getExceptionPropagationPolicy()).isSameAs(ExceptionPropagationPolicy.UNWRAP);
|
||||||
assertThat(config.getCapabilities()).isSameAs(capabilities);
|
assertThat(config.getCapabilities()).isSameAs(capabilities);
|
||||||
|
assertThat(config.getQueryMapEncoder()).isSameAs(QueryMapEncoder.class);
|
||||||
assertThat(config.getMetrics()).isSameAs(metrics);
|
assertThat(config.getMetrics()).isSameAs(metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-20
@@ -79,7 +79,7 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
when(beanProvider.getIfAvailable()).thenReturn(null);
|
when(beanProvider.getIfAvailable()).thenReturn(null);
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment, never()).getProperty("feign.client.name");
|
verify(environment, never()).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -89,7 +89,7 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
when(feignClientProperties.getConfig()).thenReturn(null);
|
when(feignClientProperties.getConfig()).thenReturn(null);
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment, never()).getProperty("feign.client.name");
|
verify(environment, never()).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,11 +97,11 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("foo");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("foo");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(new HashMap<>());
|
when(feignClientProperties.getConfig()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -109,11 +109,11 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn(null);
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn(null);
|
||||||
when(feignClientProperties.getConfig()).thenReturn(new HashMap<>());
|
when(feignClientProperties.getConfig()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -121,12 +121,12 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(new HashMap<>());
|
when(feignClientProperties.getConfig()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
|
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -134,11 +134,11 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
FeignClientProperties feignClientProperties = mock(FeignClientProperties.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("foo");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("foo");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", null));
|
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", null));
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -148,12 +148,12 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties.FeignClientConfiguration.class);
|
FeignClientProperties.FeignClientConfiguration.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("foo");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("foo");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
||||||
when(feignClientConfig.getMetrics()).thenReturn(null);
|
when(feignClientConfig.getMetrics()).thenReturn(null);
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -163,12 +163,12 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties.FeignClientConfiguration.class);
|
FeignClientProperties.FeignClientConfiguration.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("foo");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("foo");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
||||||
when(feignClientConfig.getMetrics()).thenReturn(new FeignClientProperties.MetricsProperties());
|
when(feignClientConfig.getMetrics()).thenReturn(new FeignClientProperties.MetricsProperties());
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -178,14 +178,14 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties.FeignClientConfiguration.class);
|
FeignClientProperties.FeignClientConfiguration.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("foo");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("foo");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
||||||
FeignClientProperties.MetricsProperties metricsProperties = new FeignClientProperties.MetricsProperties();
|
FeignClientProperties.MetricsProperties metricsProperties = new FeignClientProperties.MetricsProperties();
|
||||||
metricsProperties.setEnabled(null);
|
metricsProperties.setEnabled(null);
|
||||||
when(feignClientConfig.getMetrics()).thenReturn(metricsProperties);
|
when(feignClientConfig.getMetrics()).thenReturn(metricsProperties);
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -195,14 +195,14 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties.FeignClientConfiguration.class);
|
FeignClientProperties.FeignClientConfiguration.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("foo");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("foo");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
||||||
FeignClientProperties.MetricsProperties metricsProperties = new FeignClientProperties.MetricsProperties();
|
FeignClientProperties.MetricsProperties metricsProperties = new FeignClientProperties.MetricsProperties();
|
||||||
metricsProperties.setEnabled(true);
|
metricsProperties.setEnabled(true);
|
||||||
when(feignClientConfig.getMetrics()).thenReturn(metricsProperties);
|
when(feignClientConfig.getMetrics()).thenReturn(metricsProperties);
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isTrue();
|
assertThat(condition.matches(context, metadata)).isTrue();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -212,14 +212,14 @@ class FeignClientMetricsEnabledConditionTests {
|
|||||||
FeignClientProperties.FeignClientConfiguration.class);
|
FeignClientProperties.FeignClientConfiguration.class);
|
||||||
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
when(beanProvider.getIfAvailable()).thenReturn(feignClientProperties);
|
||||||
when(context.getEnvironment()).thenReturn(environment);
|
when(context.getEnvironment()).thenReturn(environment);
|
||||||
when(environment.getProperty("feign.client.name")).thenReturn("foo");
|
when(environment.getProperty("spring.cloud.openfeign.client.name")).thenReturn("foo");
|
||||||
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
when(feignClientProperties.getConfig()).thenReturn(Maps.newHashMap("foo", feignClientConfig));
|
||||||
FeignClientProperties.MetricsProperties metricsProperties = new FeignClientProperties.MetricsProperties();
|
FeignClientProperties.MetricsProperties metricsProperties = new FeignClientProperties.MetricsProperties();
|
||||||
metricsProperties.setEnabled(false);
|
metricsProperties.setEnabled(false);
|
||||||
when(feignClientConfig.getMetrics()).thenReturn(metricsProperties);
|
when(feignClientConfig.getMetrics()).thenReturn(metricsProperties);
|
||||||
|
|
||||||
assertThat(condition.matches(context, metadata)).isFalse();
|
assertThat(condition.matches(context, metadata)).isFalse();
|
||||||
verify(environment).getProperty("feign.client.name");
|
verify(environment).getProperty("spring.cloud.openfeign.client.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-11
@@ -24,8 +24,7 @@ import feign.Feign;
|
|||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.micrometer.MicrometerCapability;
|
import feign.micrometer.MicrometerCapability;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
@@ -35,7 +34,6 @@ import org.springframework.cloud.openfeign.clientconfig.FeignClientConfigurer;
|
|||||||
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.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@@ -45,12 +43,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Jonatan Ivanov
|
* @author Jonatan Ivanov
|
||||||
*/
|
*/
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@SpringBootTest(classes = FeignClientUsingConfigurerTest.Application.class, value = {
|
@SpringBootTest(classes = FeignClientUsingConfigurerTest.Application.class, value = {
|
||||||
"feign.client.config.default.loggerLevel=full",
|
"spring.cloud.openfeign.client.config.default.loggerLevel=full",
|
||||||
"feign.client.config.default.requestInterceptors[0]=org.springframework.cloud.openfeign.FeignClientUsingPropertiesTests.FooRequestInterceptor",
|
"spring.cloud.openfeign.client.config.default.requestInterceptors[0]=org.springframework.cloud.openfeign.FeignClientUsingPropertiesTests.FooRequestInterceptor",
|
||||||
"feign.client.config.default.requestInterceptors[1]=org.springframework.cloud.openfeign.FeignClientUsingPropertiesTests.BarRequestInterceptor" })
|
"spring.cloud.openfeign.client.config.default.requestInterceptors[1]=org.springframework.cloud.openfeign.FeignClientUsingPropertiesTests.BarRequestInterceptor" })
|
||||||
public class FeignClientUsingConfigurerTest {
|
class FeignClientUsingConfigurerTest {
|
||||||
|
|
||||||
private static final String BEAN_NAME_PREFIX = "org.springframework.cloud.openfeign.FeignClientUsingConfigurerTest$";
|
private static final String BEAN_NAME_PREFIX = "org.springframework.cloud.openfeign.FeignClientUsingConfigurerTest$";
|
||||||
|
|
||||||
@@ -61,7 +58,7 @@ public class FeignClientUsingConfigurerTest {
|
|||||||
private FeignContext context;
|
private FeignContext context;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFeignClient() {
|
void testFeignClient() {
|
||||||
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
|
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
|
||||||
.getBeanDefinition(BEAN_NAME_PREFIX + "TestFeignClient")
|
.getBeanDefinition(BEAN_NAME_PREFIX + "TestFeignClient")
|
||||||
.getAttribute("feignClientsRegistrarFactoryBean");
|
.getAttribute("feignClientsRegistrarFactoryBean");
|
||||||
@@ -84,7 +81,7 @@ public class FeignClientUsingConfigurerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoInheritFeignClient() {
|
void testNoInheritFeignClient() {
|
||||||
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
|
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
|
||||||
.getBeanDefinition(BEAN_NAME_PREFIX + "NoInheritFeignClient")
|
.getBeanDefinition(BEAN_NAME_PREFIX + "NoInheritFeignClient")
|
||||||
.getAttribute("feignClientsRegistrarFactoryBean");
|
.getAttribute("feignClientsRegistrarFactoryBean");
|
||||||
@@ -100,7 +97,7 @@ public class FeignClientUsingConfigurerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoInheritFeignClient_ignoreProperties() {
|
void testNoInheritFeignClient_ignoreProperties() {
|
||||||
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
|
FeignClientFactoryBean factoryBean = (FeignClientFactoryBean) beanFactory
|
||||||
.getBeanDefinition(BEAN_NAME_PREFIX + "NoInheritFeignClient")
|
.getBeanDefinition(BEAN_NAME_PREFIX + "NoInheritFeignClient")
|
||||||
.getAttribute("feignClientsRegistrarFactoryBean");
|
.getAttribute("feignClientsRegistrarFactoryBean");
|
||||||
|
|||||||
+25
-2
@@ -32,11 +32,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import feign.Capability;
|
import feign.Capability;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import feign.InvocationHandlerFactory;
|
import feign.InvocationHandlerFactory;
|
||||||
|
import feign.QueryMapEncoder;
|
||||||
import feign.Request;
|
import feign.Request;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
@@ -46,6 +45,7 @@ import feign.codec.EncodeException;
|
|||||||
import feign.codec.Encoder;
|
import feign.codec.Encoder;
|
||||||
import feign.codec.ErrorDecoder;
|
import feign.codec.ErrorDecoder;
|
||||||
import feign.micrometer.MicrometerCapability;
|
import feign.micrometer.MicrometerCapability;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.condition.DisabledForJreRange;
|
import org.junit.jupiter.api.condition.DisabledForJreRange;
|
||||||
import org.junit.jupiter.api.condition.JRE;
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
@@ -78,6 +78,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
* @author Ilia Ilinykh
|
* @author Ilia Ilinykh
|
||||||
* @author Jonatan Ivanov
|
* @author Jonatan Ivanov
|
||||||
|
* @author Hyeonmin Park
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("FieldMayBeFinal")
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
@SpringBootTest(classes = FeignClientUsingPropertiesTests.Application.class, webEnvironment = RANDOM_PORT)
|
@SpringBootTest(classes = FeignClientUsingPropertiesTests.Application.class, webEnvironment = RANDOM_PORT)
|
||||||
@@ -246,6 +247,19 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
.hasAtLeastOneElementOfType(MicrometerCapability.class);
|
.hasAtLeastOneElementOfType(MicrometerCapability.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void clientShouldContainQueryMapEncoder() {
|
||||||
|
fooFactoryBean.setApplicationContext(applicationContext);
|
||||||
|
Feign.Builder feignBuilder = fooFactoryBean.feign(context);
|
||||||
|
FooClient fooClient = feignBuilder.target(FooClient.class, "http://localhost:" + port);
|
||||||
|
|
||||||
|
String response = fooClient.foo();
|
||||||
|
assertThat(response).isEqualTo("OK");
|
||||||
|
QueryMapEncoder queryMapEncoder = (QueryMapEncoder) ReflectionTestUtils.getField(feignBuilder,
|
||||||
|
"queryMapEncoder");
|
||||||
|
assertThat(queryMapEncoder).isInstanceOf(NoOpQueryMapEncoder.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisabledForJreRange(min = JRE.JAVA_16)
|
@DisabledForJreRange(min = JRE.JAVA_16)
|
||||||
public void shouldSetFollowRedirects() {
|
public void shouldSetFollowRedirects() {
|
||||||
@@ -418,4 +432,13 @@ public class FeignClientUsingPropertiesTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class NoOpQueryMapEncoder implements QueryMapEncoder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> encode(Object o) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-37
@@ -18,17 +18,22 @@ package org.springframework.cloud.openfeign;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.junit.Test;
|
import feign.Target;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.condition.DisabledForJreRange;
|
||||||
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,42 +43,42 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|||||||
* @author Szymon Linowski
|
* @author Szymon Linowski
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
public class FeignClientsRegistrarTests {
|
class FeignClientsRegistrarTests {
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test
|
||||||
public void badNameHttpPrefix() {
|
void badNameHttpPrefix() {
|
||||||
testGetName("https://bad_hostname");
|
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("http://bad_hostname"));
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
|
||||||
public void badNameHttpsPrefix() {
|
|
||||||
testGetName("https://bad_hostname");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
|
||||||
public void badName() {
|
|
||||||
testGetName("bad_hostname");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
|
||||||
public void badNameStartsWithHttp() {
|
|
||||||
testGetName("http_bad_hostname");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void goodName() {
|
void badNameHttpsPrefix() {
|
||||||
|
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("https://bad_hostname"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void badName() {
|
||||||
|
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("bad_hostname"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void badNameStartsWithHttp() {
|
||||||
|
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> testGetName("http_bad_hostname"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void goodName() {
|
||||||
String name = testGetName("good-name");
|
String name = testGetName("good-name");
|
||||||
assertThat(name).as("name was wrong").isEqualTo("good-name");
|
assertThat(name).as("name was wrong").isEqualTo("good-name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void goodNameHttpPrefix() {
|
void goodNameHttpPrefix() {
|
||||||
String name = testGetName("https://good-name");
|
String name = testGetName("https://good-name");
|
||||||
assertThat(name).as("name was wrong").isEqualTo("https://good-name");
|
assertThat(name).as("name was wrong").isEqualTo("https://good-name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void goodNameHttpsPrefix() {
|
void goodNameHttpsPrefix() {
|
||||||
String name = testGetName("https://goodname");
|
String name = testGetName("https://goodname");
|
||||||
assertThat(name).as("name was wrong").isEqualTo("https://goodname");
|
assertThat(name).as("name was wrong").isEqualTo("https://goodname");
|
||||||
}
|
}
|
||||||
@@ -84,28 +89,46 @@ public class FeignClientsRegistrarTests {
|
|||||||
return registrar.getName(Collections.singletonMap("name", name));
|
return registrar.getName(Collections.singletonMap("name", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testFallback() {
|
void testFallback() {
|
||||||
new AnnotationConfigApplicationContext(FallbackTestConfig.class);
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
}
|
.isThrownBy(() -> new AnnotationConfigApplicationContext(FallbackTestConfig.class));
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testFallbackFactory() {
|
|
||||||
new AnnotationConfigApplicationContext(FallbackFactoryTestConfig.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldPassSubLevelFeignClient() {
|
void testFallbackFactory() {
|
||||||
AnnotationConfigApplicationContext config = new AnnotationConfigApplicationContext();
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
((DefaultListableBeanFactory) config.getBeanFactory()).setAllowBeanDefinitionOverriding(false);
|
.isThrownBy(() -> new AnnotationConfigApplicationContext(FallbackFactoryTestConfig.class));
|
||||||
config.register(TopLevelSubLevelTestConfig.class);
|
}
|
||||||
assertThatCode(() -> config.refresh())
|
|
||||||
|
@Test
|
||||||
|
void shouldPassSubLevelFeignClient() {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
((DefaultListableBeanFactory) context.getBeanFactory()).setAllowBeanDefinitionOverriding(false);
|
||||||
|
context.register(TopLevelSubLevelTestConfig.class);
|
||||||
|
assertThatCode(context::refresh)
|
||||||
.as("Case https://github.com/spring-cloud/spring-cloud-openfeign/issues/331 should be solved")
|
.as("Case https://github.com/spring-cloud/spring-cloud-openfeign/issues/331 should be solved")
|
||||||
.doesNotThrowAnyException();
|
.doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldResolveAndValidateNullName() {
|
@DisabledForJreRange(min = JRE.JAVA_16)
|
||||||
|
void shouldResolveNullUrl() {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
context.register(NullUrlFeignClientTestConfig.class);
|
||||||
|
context.refresh();
|
||||||
|
|
||||||
|
Object feignClientBean = context.getBean(NullUrlFeignClient.class);
|
||||||
|
|
||||||
|
Object invocationHandlerLambda = ReflectionTestUtils.getField(feignClientBean, "h");
|
||||||
|
Target.HardCodedTarget<NullUrlFeignClient> target = (Target.HardCodedTarget<NullUrlFeignClient>) ReflectionTestUtils
|
||||||
|
.getField(invocationHandlerLambda, "arg$3");
|
||||||
|
assertThat(target.name()).isEqualTo("nullUrlFeignClient");
|
||||||
|
assertThat(target.url()).isEqualTo("http://nullUrlFeignClient");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldResolveAndValidateNullName() {
|
||||||
assertThatIllegalStateException().isThrownBy(() -> {
|
assertThatIllegalStateException().isThrownBy(() -> {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.register(NullExpressionNameFeignClientTestConfig.class);
|
context.register(NullExpressionNameFeignClientTestConfig.class);
|
||||||
|
|||||||
+6
-10
@@ -21,8 +21,7 @@ import java.util.Map;
|
|||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.httpclient.ApacheHttpClient;
|
import feign.httpclient.ApacheHttpClient;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
@@ -32,8 +31,6 @@ import org.springframework.cloud.openfeign.encoding.FeignAcceptGzipEncodingAutoC
|
|||||||
import org.springframework.cloud.openfeign.encoding.FeignAcceptGzipEncodingInterceptor;
|
import org.springframework.cloud.openfeign.encoding.FeignAcceptGzipEncodingInterceptor;
|
||||||
import org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingAutoConfiguration;
|
import org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingAutoConfiguration;
|
||||||
import org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingInterceptor;
|
import org.springframework.cloud.openfeign.encoding.FeignContentGzipEncodingInterceptor;
|
||||||
import org.springframework.cloud.test.ClassPathExclusions;
|
|
||||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -43,15 +40,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
* @author Biju Kunjummen
|
* @author Biju Kunjummen
|
||||||
*/
|
*/
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
class FeignCompressionTests {
|
||||||
@ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar" })
|
|
||||||
public class FeignCompressionTests {
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInterceptors() {
|
void testInterceptors() {
|
||||||
new ApplicationContextRunner()
|
new ApplicationContextRunner()
|
||||||
.withPropertyValues("feign.compression.response.enabled=true", "feign.compression.request.enabled=true",
|
.withPropertyValues("spring.cloud.openfeign.compression.response.enabled=true",
|
||||||
"feign.okhttp.enabled=false")
|
"spring.cloud.openfeign.compression.request.enabled=true",
|
||||||
|
"spring.cloud.openfeign.okhttp.enabled=false")
|
||||||
.withConfiguration(AutoConfigurations.of(FeignAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(FeignAutoConfiguration.class,
|
||||||
FeignContentGzipEncodingAutoConfiguration.class, FeignAcceptGzipEncodingAutoConfiguration.class,
|
FeignContentGzipEncodingAutoConfiguration.class, FeignAcceptGzipEncodingAutoConfiguration.class,
|
||||||
HttpClientConfiguration.class, PlainConfig.class))
|
HttpClientConfiguration.class, PlainConfig.class))
|
||||||
|
|||||||
+6
-6
@@ -21,7 +21,7 @@ import java.util.Collection;
|
|||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import org.assertj.core.util.Lists;
|
import org.assertj.core.util.Lists;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -30,10 +30,10 @@ import org.springframework.context.annotation.Import;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class FeignContextTest {
|
class FeignContextTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInstanceWithoutAncestors_verifyNullForMissing() {
|
void getInstanceWithoutAncestors_verifyNullForMissing() {
|
||||||
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
||||||
parent.refresh();
|
parent.refresh();
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ public class FeignContextTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInstancesWithoutAncestors_verifyEmptyForMissing() {
|
void getInstancesWithoutAncestors_verifyEmptyForMissing() {
|
||||||
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
||||||
parent.refresh();
|
parent.refresh();
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class FeignContextTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInstanceWithoutAncestors() {
|
void getInstanceWithoutAncestors() {
|
||||||
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
||||||
parent.refresh();
|
parent.refresh();
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class FeignContextTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getInstancesWithoutAncestors() {
|
void getInstancesWithoutAncestors() {
|
||||||
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
||||||
parent.refresh();
|
parent.refresh();
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -18,7 +18,7 @@ package org.springframework.cloud.openfeign;
|
|||||||
|
|
||||||
import feign.Response;
|
import feign.Response;
|
||||||
import feign.codec.ErrorDecoder;
|
import feign.codec.ErrorDecoder;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
/**
|
/**
|
||||||
* @author Michael Cramer
|
* @author Michael Cramer
|
||||||
*/
|
*/
|
||||||
public class FeignErrorDecoderFactoryTests {
|
class FeignErrorDecoderFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoDefaultFactory() {
|
void testNoDefaultFactory() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration1.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration1.class);
|
||||||
String[] beanNamesForType = context.getBeanNamesForType(FeignErrorDecoderFactory.class);
|
String[] beanNamesForType = context.getBeanNamesForType(FeignErrorDecoderFactory.class);
|
||||||
assertThat(beanNamesForType).isEmpty();
|
assertThat(beanNamesForType).isEmpty();
|
||||||
@@ -41,7 +41,7 @@ public class FeignErrorDecoderFactoryTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomErrorDecoderFactory() {
|
void testCustomErrorDecoderFactory() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration2.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration2.class);
|
||||||
FeignErrorDecoderFactory errorDecoderFactory = context.getBean(FeignErrorDecoderFactory.class);
|
FeignErrorDecoderFactory errorDecoderFactory = context.getBean(FeignErrorDecoderFactory.class);
|
||||||
assertThat(errorDecoderFactory).isNotNull();
|
assertThat(errorDecoderFactory).isNotNull();
|
||||||
@@ -52,7 +52,7 @@ public class FeignErrorDecoderFactoryTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomErrorDecoderFactoryNotOverwritingErrorDecoder() {
|
void testCustomErrorDecoderFactoryNotOverwritingErrorDecoder() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration3.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration3.class);
|
||||||
FeignErrorDecoderFactory errorDecoderFactory = context.getBean(FeignErrorDecoderFactory.class);
|
FeignErrorDecoderFactory errorDecoderFactory = context.getBean(FeignErrorDecoderFactory.class);
|
||||||
assertThat(errorDecoderFactory).isNotNull();
|
assertThat(errorDecoderFactory).isNotNull();
|
||||||
|
|||||||
+49
-55
@@ -22,14 +22,12 @@ import feign.httpclient.ApacheHttpClient;
|
|||||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
|
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
|
||||||
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
|
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.WebApplicationType;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
||||||
import org.springframework.cloud.test.ClassPathExclusions;
|
import org.springframework.cloud.test.ClassPathExclusions;
|
||||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@@ -37,7 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
/**
|
/**
|
||||||
* @author Nguyen Ky Thanh
|
* @author Nguyen Ky Thanh
|
||||||
*/
|
*/
|
||||||
public class FeignHttpClient5ConfigurationTests {
|
class FeignHttpClient5ConfigurationTests {
|
||||||
|
|
||||||
private static void verifyHc4BeansAvailable(ConfigurableApplicationContext context) {
|
private static void verifyHc4BeansAvailable(ConfigurableApplicationContext context) {
|
||||||
org.apache.http.impl.client.CloseableHttpClient httpClient4 = context
|
org.apache.http.impl.client.CloseableHttpClient httpClient4 = context
|
||||||
@@ -59,64 +57,60 @@ public class FeignHttpClient5ConfigurationTests {
|
|||||||
assertThat(client).isInstanceOf(ApacheHttp5Client.class);
|
assertThat(client).isInstanceOf(ApacheHttp5Client.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
@Test
|
||||||
@ClassPathExclusions("ribbon-loadbalancer-{version:\\d.*}.jar")
|
void verifyHttpClient5AutoConfig() {
|
||||||
public static class WithoutLoadBalancerInClasspath {
|
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||||
|
.properties("spring.cloud.openfeign.httpclient.hc5.enabled=true",
|
||||||
|
"spring.cloud.openfeign.httpclient.enabled=false")
|
||||||
|
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
||||||
|
.run();
|
||||||
|
|
||||||
@Test
|
verifyHc5BeansAvailable(context);
|
||||||
public void verifyHttpClient5AutoConfig() {
|
|
||||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
|
||||||
.properties("feign.httpclient.hc5.enabled=true", "feign.httpclient.enabled=false")
|
|
||||||
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
|
||||||
.run();
|
|
||||||
|
|
||||||
verifyHc5BeansAvailable(context);
|
if (context != null) {
|
||||||
|
context.close();
|
||||||
if (context != null) {
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hc5ShouldWinIfTheBothVersionsAvailable() {
|
|
||||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
|
||||||
.properties("feign.httpclient.hc5.enabled=true", "feign.httpclient.enabled=true")
|
|
||||||
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
|
||||||
.run();
|
|
||||||
|
|
||||||
Client client = context.getBean(Client.class);
|
|
||||||
assertThat(client).isInstanceOf(ApacheHttp5Client.class);
|
|
||||||
|
|
||||||
if (context != null) {
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void hc4ShouldBeTheDefaultIfHc5NotEnabled() {
|
|
||||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
|
||||||
.properties("feign.httpclient.hc5.enabled=false", "feign.httpclient.enabled=true")
|
|
||||||
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
|
||||||
.run();
|
|
||||||
|
|
||||||
verifyHc4BeansAvailable(context);
|
|
||||||
|
|
||||||
if (context != null) {
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
@Test
|
||||||
@ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar", "feign-hc5-{version:\\d.*}.jar",
|
void hc5ShouldWinIfTheBothVersionsAvailable() {
|
||||||
"httpclient5-{version:\\d.*}.jar", "httpcore5-{version:\\d.*}.jar", "httpcore5-h2-{version:\\d.*}.jar" })
|
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||||
public static class WithoutLoadBalancerAndHc5InClasspath {
|
.properties("spring.cloud.openfeign.httpclient.hc5.enabled=true",
|
||||||
|
"spring.cloud.openfeign.httpclient.enabled=true")
|
||||||
|
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
||||||
|
.run();
|
||||||
|
|
||||||
|
Client client = context.getBean(Client.class);
|
||||||
|
assertThat(client).isInstanceOf(ApacheHttp5Client.class);
|
||||||
|
|
||||||
|
if (context != null) {
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void hc4ShouldBeTheDefaultIfHc5NotEnabled() {
|
||||||
|
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||||
|
.properties("spring.cloud.openfeign.httpclient.hc5.enabled=false",
|
||||||
|
"spring.cloud.openfeign.httpclient.enabled=true")
|
||||||
|
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
||||||
|
.run();
|
||||||
|
|
||||||
|
verifyHc4BeansAvailable(context);
|
||||||
|
|
||||||
|
if (context != null) {
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ClassPathExclusions({ "feign-hc5-{version:\\d.*}.jar", "httpclient5-{version:\\d.*}.jar",
|
||||||
|
"httpcore5-{version:\\d.*}.jar", "httpcore5-h2-{version:\\d.*}.jar" })
|
||||||
|
static class WithoutLoadBalancerAndHc5InClasspath {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hc4ShouldWinEvenHc5ConfigEnabled() {
|
void hc4ShouldWinEvenHc5ConfigEnabled() {
|
||||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||||
.properties("feign.httpclient.hc5.enabled=true").web(WebApplicationType.NONE)
|
.properties("spring.cloud.openfeign.httpclient.hc5.enabled=true").web(WebApplicationType.NONE)
|
||||||
.sources(HttpClientConfiguration.class, FeignAutoConfiguration.class).run();
|
.sources(HttpClientConfiguration.class, FeignAutoConfiguration.class).run();
|
||||||
|
|
||||||
verifyHc4BeansAvailable(context);
|
verifyHc4BeansAvailable(context);
|
||||||
@@ -127,7 +121,7 @@ public class FeignHttpClient5ConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hc4ShouldBeTheDefault() {
|
void hc4ShouldBeTheDefault() {
|
||||||
ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
ConfigurableApplicationContext context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||||
.sources(HttpClientConfiguration.class, FeignAutoConfiguration.class).run();
|
.sources(HttpClientConfiguration.class, FeignAutoConfiguration.class).run();
|
||||||
|
|
||||||
|
|||||||
+12
-16
@@ -26,16 +26,13 @@ import org.apache.http.config.Lookup;
|
|||||||
import org.apache.http.conn.HttpClientConnectionManager;
|
import org.apache.http.conn.HttpClientConnectionManager;
|
||||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||||
import org.apache.http.impl.conn.DefaultHttpClientConnectionOperator;
|
import org.apache.http.impl.conn.DefaultHttpClientConnectionOperator;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.WebApplicationType;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
||||||
import org.springframework.cloud.test.ClassPathExclusions;
|
|
||||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
@@ -44,28 +41,27 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
/**
|
/**
|
||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
*/
|
*/
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
class FeignHttpClientConfigurationTests {
|
||||||
@ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar" })
|
|
||||||
public class FeignHttpClientConfigurationTests {
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
this.context = new SpringApplicationBuilder()
|
this.context = new SpringApplicationBuilder()
|
||||||
.properties("debug=true", "feign.httpclient.disableSslValidation=true").web(WebApplicationType.NONE)
|
.properties("debug=true", "spring.cloud.openfeign.httpclient.disableSslValidation=true")
|
||||||
.sources(HttpClientConfiguration.class, FeignAutoConfiguration.class).run();
|
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
void tearDown() {
|
||||||
if (this.context != null) {
|
if (this.context != null) {
|
||||||
this.context.close();
|
this.context.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void disableSslTest() throws Exception {
|
void disableSslTest() {
|
||||||
try {
|
try {
|
||||||
HttpClientConnectionManager connectionManager = this.context.getBean(HttpClientConnectionManager.class);
|
HttpClientConnectionManager connectionManager = this.context.getBean(HttpClientConnectionManager.class);
|
||||||
Lookup<ConnectionSocketFactory> socketFactoryRegistry = getConnectionSocketFactoryLookup(connectionManager);
|
Lookup<ConnectionSocketFactory> socketFactoryRegistry = getConnectionSocketFactoryLookup(connectionManager);
|
||||||
|
|||||||
+4
-4
@@ -31,12 +31,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
||||||
|
import org.springframework.cloud.test.TestSocketUtils;
|
||||||
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;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.util.SocketUtils;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -48,8 +48,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignHttpClientUrlTests.TestConfig.class, webEnvironment = DEFINED_PORT,
|
@SpringBootTest(classes = FeignHttpClientUrlTests.TestConfig.class, webEnvironment = DEFINED_PORT,
|
||||||
value = { "spring.application.name=feignclienturltest", "feign.circuitbreaker.enabled=false",
|
value = { "spring.application.name=feignclienturltest", "spring.cloud.openfeign.circuitbreaker.enabled=false",
|
||||||
"feign.okhttp.enabled=false", "spring.cloud.loadbalancer.retry.enabled=false" })
|
"spring.cloud.openfeign.okhttp.enabled=false", "spring.cloud.loadbalancer.retry.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
class FeignHttpClientUrlTests {
|
class FeignHttpClientUrlTests {
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ class FeignHttpClientUrlTests {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void beforeClass() {
|
static void beforeClass() {
|
||||||
port = SocketUtils.findAvailableTcpPort();
|
port = TestSocketUtils.findAvailableTcpPort();
|
||||||
System.setProperty("server.port", String.valueOf(port));
|
System.setProperty("server.port", String.valueOf(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -31,12 +31,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
||||||
|
import org.springframework.cloud.test.TestSocketUtils;
|
||||||
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;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
import org.springframework.util.SocketUtils;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignHttpClientUrlTestsWithRetryableLoadBalancer.TestConfig.class,
|
@SpringBootTest(classes = FeignHttpClientUrlTestsWithRetryableLoadBalancer.TestConfig.class,
|
||||||
webEnvironment = DEFINED_PORT,
|
webEnvironment = DEFINED_PORT,
|
||||||
value = { "spring.application.name=feignclienturlwithretryableloadbalancertest", "feign.hystrix.enabled=false",
|
value = { "spring.application.name=feignclienturlwithretryableloadbalancertest",
|
||||||
"feign.okhttp.enabled=false", "spring.cloud.loadbalancer.ribbon.enabled=false" })
|
"spring.cloud.openfeign.hystrix.enabled=false", "spring.cloud.openfeign.okhttp.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
class FeignHttpClientUrlTestsWithRetryableLoadBalancer {
|
class FeignHttpClientUrlTestsWithRetryableLoadBalancer {
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ class FeignHttpClientUrlTestsWithRetryableLoadBalancer {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void beforeClass() {
|
static void beforeClass() {
|
||||||
port = SocketUtils.findAvailableTcpPort();
|
port = TestSocketUtils.findAvailableTcpPort();
|
||||||
System.setProperty("server.port", String.valueOf(port));
|
System.setProperty("server.port", String.valueOf(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -18,7 +18,7 @@ package org.springframework.cloud.openfeign;
|
|||||||
|
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
import feign.slf4j.Slf4jLogger;
|
import feign.slf4j.Slf4jLogger;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
/**
|
/**
|
||||||
* @author Venil Noronha
|
* @author Venil Noronha
|
||||||
*/
|
*/
|
||||||
public class FeignLoggerFactoryTests {
|
class FeignLoggerFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultLogger() {
|
void testDefaultLogger() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration1.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration1.class);
|
||||||
FeignLoggerFactory loggerFactory = context.getBean(FeignLoggerFactory.class);
|
FeignLoggerFactory loggerFactory = context.getBean(FeignLoggerFactory.class);
|
||||||
assertThat(loggerFactory).isNotNull();
|
assertThat(loggerFactory).isNotNull();
|
||||||
@@ -44,7 +44,7 @@ public class FeignLoggerFactoryTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomLogger() {
|
void testCustomLogger() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration2.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration2.class);
|
||||||
FeignLoggerFactory loggerFactory = context.getBean(FeignLoggerFactory.class);
|
FeignLoggerFactory loggerFactory = context.getBean(FeignLoggerFactory.class);
|
||||||
assertThat(loggerFactory).isNotNull();
|
assertThat(loggerFactory).isNotNull();
|
||||||
@@ -55,7 +55,7 @@ public class FeignLoggerFactoryTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomLoggerFactory() {
|
void testCustomLoggerFactory() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration3.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SampleConfiguration3.class);
|
||||||
FeignLoggerFactory loggerFactory = context.getBean(FeignLoggerFactory.class);
|
FeignLoggerFactory loggerFactory = context.getBean(FeignLoggerFactory.class);
|
||||||
assertThat(loggerFactory).isNotNull();
|
assertThat(loggerFactory).isNotNull();
|
||||||
|
|||||||
+24
-21
@@ -21,17 +21,14 @@ import java.lang.reflect.Field;
|
|||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
|
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.WebApplicationType;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
||||||
import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
|
import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
|
||||||
import org.springframework.cloud.test.ClassPathExclusions;
|
|
||||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
@@ -40,36 +37,42 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
/**
|
/**
|
||||||
* @author Ryan Baxter
|
* @author Ryan Baxter
|
||||||
*/
|
*/
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
class FeignOkHttpConfigurationTests {
|
||||||
@ClassPathExclusions({ "ribbon-loadbalancer-{version:\\d.*}.jar" })
|
|
||||||
public class FeignOkHttpConfigurationTests {
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
this.context = new SpringApplicationBuilder()
|
this.context = new SpringApplicationBuilder()
|
||||||
.properties("debug=true", "feign.httpclient.disableSslValidation=true", "feign.okhttp.enabled=true",
|
.properties("debug=true", "spring.cloud.openfeign.httpclient.disableSslValidation=true",
|
||||||
"feign.httpclient.enabled=false")
|
"spring.cloud.openfeign.okhttp.enabled=true", "spring.cloud.openfeign.httpclient.enabled=false",
|
||||||
|
"spring.cloud.openfeign.httpclient.okhttp.read-timeout=9s")
|
||||||
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
.web(WebApplicationType.NONE).sources(HttpClientConfiguration.class, FeignAutoConfiguration.class)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() {
|
void tearDown() {
|
||||||
if (this.context != null) {
|
if (context != null) {
|
||||||
this.context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void disableSslTest() throws Exception {
|
void disableSslTest() {
|
||||||
OkHttpClient httpClient = this.context.getBean(OkHttpClient.class);
|
OkHttpClient httpClient = context.getBean(OkHttpClient.class);
|
||||||
HostnameVerifier hostnameVerifier = (HostnameVerifier) this.getField(httpClient, "hostnameVerifier");
|
HostnameVerifier hostnameVerifier = (HostnameVerifier) this.getField(httpClient, "hostnameVerifier");
|
||||||
assertThat(OkHttpClientFactory.TrustAllHostnames.class.isInstance(hostnameVerifier)).isTrue();
|
assertThat(hostnameVerifier instanceof OkHttpClientFactory.TrustAllHostnames).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> Object getField(Object target, String name) {
|
@Test
|
||||||
|
void shouldConfigureReadTimeout() {
|
||||||
|
OkHttpClient httpClient = context.getBean(OkHttpClient.class);
|
||||||
|
|
||||||
|
assertThat(httpClient.readTimeoutMillis()).isEqualTo(9000);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Object getField(Object target, String name) {
|
||||||
Field field = ReflectionUtils.findField(target.getClass(), name);
|
Field field = ReflectionUtils.findField(target.getClass(), name);
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
Object value = ReflectionUtils.getField(field, target);
|
Object value = ReflectionUtils.getField(field, target);
|
||||||
|
|||||||
+12
-12
@@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
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;
|
||||||
@@ -31,7 +30,6 @@ import org.springframework.context.annotation.Import;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -39,15 +37,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jaesik Kim
|
* @author Jaesik Kim
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@SpringBootTest(classes = GzipDecodingTests.Application.class,
|
||||||
@SpringBootTest(classes = DefaultGzipDecoderTests.Application.class,
|
|
||||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
value = { "spring.application.name=defaultGzipDecoderTests", "feign.compression.response.enabled=true",
|
value = { "spring.application.name=defaultGzipDecoderTests",
|
||||||
"feign.compression.response.useGzipDecoder=true", "feign.client.config.default.loggerLevel=full",
|
"spring.cloud.openfeign.compression.response.enabled=true",
|
||||||
|
"spring.cloud.openfeign.client.config.default.loggerLevel=none",
|
||||||
|
"spring.cloud.openfeign.metrics.enabled=false",
|
||||||
"logging.level.org.springframework.cloud.openfeign=DEBUG" })
|
"logging.level.org.springframework.cloud.openfeign=DEBUG" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
|
class GzipDecodingTests extends FeignClientFactoryBean {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
FeignContext context;
|
FeignContext context;
|
||||||
@@ -55,7 +55,7 @@ public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
|
|||||||
@Value("${local.server.port}")
|
@Value("${local.server.port}")
|
||||||
private int port = 0;
|
private int port = 0;
|
||||||
|
|
||||||
public DefaultGzipDecoderTests() {
|
GzipDecodingTests() {
|
||||||
setName("tests");
|
setName("tests");
|
||||||
setContextId("test");
|
setContextId("test");
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBodyDecompress() {
|
void testBodyDecompress() {
|
||||||
ResponseEntity<Hello> response = testClient().getGzipResponse();
|
ResponseEntity<Hello> response = testClient().getGzipResponse();
|
||||||
assertThat(response).as("response was null").isNotNull();
|
assertThat(response).as("response was null").isNotNull();
|
||||||
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
||||||
@@ -76,7 +76,7 @@ public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullBodyDecompress() {
|
void testNullBodyDecompress() {
|
||||||
ResponseEntity<Hello> response = testClient().getNullResponse();
|
ResponseEntity<Hello> response = testClient().getNullResponse();
|
||||||
assertThat(response).as("response was null").isNotNull();
|
assertThat(response).as("response was null").isNotNull();
|
||||||
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
||||||
@@ -86,7 +86,7 @@ public class DefaultGzipDecoderTests extends FeignClientFactoryBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCharsetDecompress() {
|
void testCharsetDecompress() {
|
||||||
ResponseEntity<Hello> response = testClient().getUtf8Response();
|
ResponseEntity<Hello> response = testClient().getUtf8Response();
|
||||||
assertThat(response).as("response was null").isNotNull();
|
assertThat(response).as("response was null").isNotNull();
|
||||||
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
||||||
+19
-20
@@ -21,14 +21,14 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
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.boot.web.server.LocalServerPort;
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
@@ -37,7 +37,6 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -46,12 +45,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author Szymon Linowski
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@SpringBootTest(classes = SpringDecoderTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
@SpringBootTest(classes = SpringDecoderTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||||
value = { "spring.application.name=springdecodertest", "spring.jmx.enabled=false" })
|
value = { "spring.application.name=springdecodertest", "spring.jmx.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class SpringDecoderTests extends FeignClientFactoryBean {
|
class SpringDecoderTests extends FeignClientFactoryBean {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
FeignContext context;
|
FeignContext context;
|
||||||
@@ -59,7 +58,7 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
@LocalServerPort
|
@LocalServerPort
|
||||||
private int port = 0;
|
private int port = 0;
|
||||||
|
|
||||||
public SpringDecoderTests() {
|
SpringDecoderTests() {
|
||||||
setName("test");
|
setName("test");
|
||||||
setContextId("test");
|
setContextId("test");
|
||||||
}
|
}
|
||||||
@@ -75,7 +74,7 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseEntity() {
|
void testResponseEntity() {
|
||||||
ResponseEntity<Hello> response = testClient().getHelloResponse();
|
ResponseEntity<Hello> response = testClient().getHelloResponse();
|
||||||
assertThat(response).as("response was null").isNotNull();
|
assertThat(response).as("response was null").isNotNull();
|
||||||
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
assertThat(response.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
||||||
@@ -85,14 +84,14 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleType() {
|
void testSimpleType() {
|
||||||
Hello hello = testClient().getHello();
|
Hello hello = testClient().getHello();
|
||||||
assertThat(hello).as("hello was null").isNotNull();
|
assertThat(hello).as("hello was null").isNotNull();
|
||||||
assertThat(hello).as("first hello didn't match").isEqualTo(new Hello("hello world 1"));
|
assertThat(hello).as("first hello didn't match").isEqualTo(new Hello("hello world 1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserParameterizedTypeDecode() {
|
void testUserParameterizedTypeDecode() {
|
||||||
List<Hello> hellos = testClient().getHellos();
|
List<Hello> hellos = testClient().getHellos();
|
||||||
assertThat(hellos).as("hellos was null").isNotNull();
|
assertThat(hellos).as("hellos was null").isNotNull();
|
||||||
assertThat(hellos.size()).as("hellos was not the right size").isEqualTo(2);
|
assertThat(hellos.size()).as("hellos was not the right size").isEqualTo(2);
|
||||||
@@ -100,7 +99,7 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleParameterizedTypeDecode() {
|
void testSimpleParameterizedTypeDecode() {
|
||||||
List<String> hellos = testClient().getHelloStrings();
|
List<String> hellos = testClient().getHelloStrings();
|
||||||
assertThat(hellos).as("hellos was null").isNotNull();
|
assertThat(hellos).as("hellos was null").isNotNull();
|
||||||
assertThat(hellos.size()).as("hellos was not the right size").isEqualTo(2);
|
assertThat(hellos.size()).as("hellos was not the right size").isEqualTo(2);
|
||||||
@@ -109,7 +108,7 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testWildcardTypeDecode() {
|
void testWildcardTypeDecode() {
|
||||||
ResponseEntity<?> wildcard = testClient().getWildcard();
|
ResponseEntity<?> wildcard = testClient().getWildcard();
|
||||||
assertThat(wildcard).as("wildcard was null").isNotNull();
|
assertThat(wildcard).as("wildcard was null").isNotNull();
|
||||||
assertThat(wildcard.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
assertThat(wildcard.getStatusCode()).as("wrong status code").isEqualTo(HttpStatus.OK);
|
||||||
@@ -121,7 +120,7 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseEntityVoid() {
|
void testResponseEntityVoid() {
|
||||||
ResponseEntity<Void> response = testClient().getHelloVoid();
|
ResponseEntity<Void> response = testClient().getHelloVoid();
|
||||||
assertThat(response).as("response was null").isNotNull();
|
assertThat(response).as("response was null").isNotNull();
|
||||||
List<String> headerVals = response.getHeaders().get("x-test-header");
|
List<String> headerVals = response.getHeaders().get("x-test-header");
|
||||||
@@ -131,13 +130,13 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
assertThat(header).as("header was wrong").isEqualTo("myval");
|
assertThat(header).as("header was wrong").isEqualTo("myval");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = RuntimeException.class)
|
@Test
|
||||||
public void test404() {
|
void test404() {
|
||||||
testClient().getNotFound();
|
Assertions.assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> testClient().getNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecodes404() {
|
void testDecodes404() {
|
||||||
final ResponseEntity<String> response = testClient(true).getNotFound();
|
final ResponseEntity<String> response = testClient(true).getNotFound();
|
||||||
assertThat(response).as("response was null").isNotNull();
|
assertThat(response).as("response was null").isNotNull();
|
||||||
assertThat(response.getBody()).as("response body was not null").isNull();
|
assertThat(response.getBody()).as("response body was not null").isNull();
|
||||||
@@ -145,7 +144,7 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
// Issue: https://github.com/spring-cloud/spring-cloud-openfeign/issues/456
|
// Issue: https://github.com/spring-cloud/spring-cloud-openfeign/issues/456
|
||||||
public void testResponseEntityHeaders() {
|
void testResponseEntityHeaders() {
|
||||||
ResponseEntity<String> response = testClient().getContentType();
|
ResponseEntity<String> response = testClient().getContentType();
|
||||||
assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
|
assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
|
||||||
}
|
}
|
||||||
@@ -182,10 +181,10 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
|
|||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public Hello() {
|
Hello() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hello(String message) {
|
Hello(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-12
@@ -21,8 +21,7 @@ import java.lang.reflect.Proxy;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
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.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
@@ -38,7 +37,6 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -52,11 +50,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Halvdan Hoem Grelland
|
* @author Halvdan Hoem Grelland
|
||||||
* @author Aaron Whiteside
|
* @author Aaron Whiteside
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@SpringBootTest(classes = BeansFeignClientTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
@SpringBootTest(classes = BeansFeignClientTests.Application.class, webEnvironment = WebEnvironment.RANDOM_PORT,
|
||||||
value = { "spring.application.name=feignclienttest",
|
value = { "spring.application.name=feignclienttest",
|
||||||
"logging.level.org.springframework.cloud.openfeign.valid=DEBUG", "feign.httpclient.enabled=false",
|
"logging.level.org.springframework.cloud.openfeign.valid=DEBUG",
|
||||||
"feign.okhttp.enabled=false" })
|
"spring.cloud.openfeign.httpclient.enabled=false", "spring.cloud.openfeign.okhttp.enabled=false" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class BeansFeignClientTests {
|
public class BeansFeignClientTests {
|
||||||
|
|
||||||
@@ -78,13 +75,13 @@ public class BeansFeignClientTests {
|
|||||||
private TestClient buildByBuilder;
|
private TestClient buildByBuilder;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAnnotations() {
|
void testAnnotations() {
|
||||||
Map<String, Object> beans = this.context.getBeansWithAnnotation(FeignClient.class);
|
Map<String, Object> beans = this.context.getBeansWithAnnotation(FeignClient.class);
|
||||||
assertThat(beans.containsKey(TestClient.class.getName())).as("Wrong clients: " + beans).isTrue();
|
assertThat(beans.containsKey(TestClient.class.getName())).as("Wrong clients: " + beans).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClient() {
|
void testClient() {
|
||||||
assertThat(this.testClient).as("testClient was null").isNotNull();
|
assertThat(this.testClient).as("testClient was null").isNotNull();
|
||||||
assertThat(this.extraClient).as("extraClient was null").isNotNull();
|
assertThat(this.extraClient).as("extraClient was null").isNotNull();
|
||||||
assertThat(Proxy.isProxyClass(this.testClient.getClass())).as("testClient is not a java Proxy").isTrue();
|
assertThat(Proxy.isProxyClass(this.testClient.getClass())).as("testClient is not a java Proxy").isTrue();
|
||||||
@@ -93,7 +90,7 @@ public class BeansFeignClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extraClient() {
|
void extraClient() {
|
||||||
assertThat(this.extraClient).as("extraClient was null").isNotNull();
|
assertThat(this.extraClient).as("extraClient was null").isNotNull();
|
||||||
assertThat(Proxy.isProxyClass(this.extraClient.getClass())).as("extraClient is not a java Proxy").isTrue();
|
assertThat(Proxy.isProxyClass(this.extraClient.getClass())).as("extraClient is not a java Proxy").isTrue();
|
||||||
InvocationHandler invocationHandler = Proxy.getInvocationHandler(this.extraClient);
|
InvocationHandler invocationHandler = Proxy.getInvocationHandler(this.extraClient);
|
||||||
@@ -101,7 +98,7 @@ public class BeansFeignClientTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildByBuilder() {
|
void buildByBuilder() {
|
||||||
assertThat(this.buildByBuilder).as("buildByBuilder was null").isNotNull();
|
assertThat(this.buildByBuilder).as("buildByBuilder was null").isNotNull();
|
||||||
assertThat(Proxy.isProxyClass(this.buildByBuilder.getClass())).as("buildByBuilder is not a java Proxy")
|
assertThat(Proxy.isProxyClass(this.buildByBuilder.getClass())).as("buildByBuilder is not a java Proxy")
|
||||||
.isTrue();
|
.isTrue();
|
||||||
@@ -132,10 +129,10 @@ public class BeansFeignClientTests {
|
|||||||
|
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public Hello() {
|
Hello() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hello(String message) {
|
Hello(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -21,9 +21,8 @@ import java.util.Objects;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
@@ -60,7 +59,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
* @author John Niang
|
* @author John Niang
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = AsyncCircuitBreakerTest.Application.class, webEnvironment = RANDOM_PORT,
|
@SpringBootTest(classes = AsyncCircuitBreakerTest.Application.class, webEnvironment = RANDOM_PORT,
|
||||||
properties = "feign.circuitbreaker.enabled=true")
|
properties = "spring.cloud.openfeign.circuitbreaker.enabled=true")
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
class AsyncCircuitBreakerTest {
|
class AsyncCircuitBreakerTest {
|
||||||
|
|
||||||
|
|||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2022 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.cloud.openfeign.circuitbreaker;
|
||||||
|
|
||||||
|
import feign.Target;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.cloud.openfeign.CircuitBreakerNameResolver;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Ryan Baxter
|
||||||
|
*/
|
||||||
|
public class CircuitBreakerAutoConfigurationTests {
|
||||||
|
|
||||||
|
@SpringBootTest(classes = CircuitBreakerTests.Application.class,
|
||||||
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
|
value = { "spring.application.name=springcircuittest", "spring.jmx.enabled=false",
|
||||||
|
"spring.cloud.openfeign.circuitbreaker.enabled=true",
|
||||||
|
"spring.cloud.openfeign.circuitbreaker.alphanumeric-ids.enabled=false" })
|
||||||
|
@Nested
|
||||||
|
class DefaultNamingStrategy {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CircuitBreakerNameResolver nameResolver;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertDefaultNamingStrategy() throws Exception {
|
||||||
|
Target target = mock(Target.class);
|
||||||
|
when(target.type()).thenReturn(CircuitBreakerTests.TestClientWithFactory.class);
|
||||||
|
assertThat(nameResolver.resolveCircuitBreakerName("foo", target,
|
||||||
|
CircuitBreakerTests.TestClientWithFactory.class.getMethod("getHello")))
|
||||||
|
.isEqualTo("TestClientWithFactory#getHello()");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SpringBootTest(classes = CircuitBreakerTests.Application.class,
|
||||||
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||||
|
value = { "spring.application.name=springcircuittest", "spring.jmx.enabled=false",
|
||||||
|
"spring.cloud.openfeign.circuitbreaker.enabled=true" })
|
||||||
|
@Nested
|
||||||
|
class AlphanumericNamingStrategy {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CircuitBreakerNameResolver nameResolver;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertAlphanumericNamingStrategy() throws Exception {
|
||||||
|
Target target = mock(Target.class);
|
||||||
|
when(target.type()).thenReturn(CircuitBreakerTests.TestClientWithFactory.class);
|
||||||
|
assertThat(nameResolver.resolveCircuitBreakerName("foo", target,
|
||||||
|
CircuitBreakerTests.TestClientWithFactory.class.getMethod("getHello")))
|
||||||
|
.isEqualTo("TestClientWithFactorygetHello");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+18
-20
@@ -21,11 +21,10 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
@@ -39,13 +38,12 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
||||||
|
import org.springframework.cloud.test.TestSocketUtils;
|
||||||
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;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
import org.springframework.util.SocketUtils;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -55,11 +53,11 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||||||
/**
|
/**
|
||||||
* @author Spencer Gibb
|
* @author Spencer Gibb
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@SpringBootTest(classes = CircuitBreakerTests.Application.class, webEnvironment = WebEnvironment.DEFINED_PORT,
|
||||||
@SpringBootTest(classes = CircuitBreakerTests.Application.class, webEnvironment = WebEnvironment.DEFINED_PORT, value = {
|
value = { "spring.application.name=springcircuittest", "spring.jmx.enabled=false",
|
||||||
"spring.application.name=springcircuittest", "spring.jmx.enabled=false", "feign.circuitbreaker.enabled=true" })
|
"spring.cloud.openfeign.circuitbreaker.enabled=true" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class CircuitBreakerTests {
|
class CircuitBreakerTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
MyCircuitBreaker myCircuitBreaker;
|
MyCircuitBreaker myCircuitBreaker;
|
||||||
@@ -74,22 +72,22 @@ public class CircuitBreakerTests {
|
|||||||
TestClientWithFactory testClientWithFactory;
|
TestClientWithFactory testClientWithFactory;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void beforeClass() {
|
static void beforeClass() {
|
||||||
System.setProperty("server.port", String.valueOf(SocketUtils.findAvailableTcpPort()));
|
System.setProperty("server.port", String.valueOf(TestSocketUtils.findAvailableTcpPort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void afterClass() {
|
static void afterClass() {
|
||||||
System.clearProperty("server.port");
|
System.clearProperty("server.port");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void setup() {
|
||||||
this.myCircuitBreaker.clear();
|
this.myCircuitBreaker.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleTypeWithFallback() {
|
void testSimpleTypeWithFallback() {
|
||||||
Hello hello = testClient.getHello();
|
Hello hello = testClient.getHello();
|
||||||
|
|
||||||
assertThat(hello).as("hello was null").isNotNull();
|
assertThat(hello).as("hello was null").isNotNull();
|
||||||
@@ -98,12 +96,12 @@ public class CircuitBreakerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test404WithFallback() {
|
void test404WithFallback() {
|
||||||
assertThat(testClient.getException()).isEqualTo("Fixed response");
|
assertThat(testClient.getException()).isEqualTo("Fixed response");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleTypeWithFallbackFactory() {
|
void testSimpleTypeWithFallbackFactory() {
|
||||||
Hello hello = testClientWithFactory.getHello();
|
Hello hello = testClientWithFactory.getHello();
|
||||||
|
|
||||||
assertThat(hello).as("hello was null").isNotNull();
|
assertThat(hello).as("hello was null").isNotNull();
|
||||||
@@ -112,18 +110,18 @@ public class CircuitBreakerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test404WithFallbackFactory() {
|
void test404WithFallbackFactory() {
|
||||||
assertThat(testClientWithFactory.getException()).isEqualTo("Fixed response");
|
assertThat(testClientWithFactory.getException()).isEqualTo("Fixed response");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRuntimeExceptionUnwrapped() {
|
void testRuntimeExceptionUnwrapped() {
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
.isThrownBy(() -> exceptionClient.getRuntimeException());
|
.isThrownBy(() -> exceptionClient.getRuntimeException());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckedExceptionWrapped() {
|
void testCheckedExceptionWrapped() {
|
||||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> exceptionClient.getCheckedException());
|
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> exceptionClient.getCheckedException());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -35,11 +35,11 @@ import org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableExcept
|
|||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
import org.springframework.cloud.openfeign.test.NoSecurityConfiguration;
|
||||||
|
import org.springframework.cloud.test.TestSocketUtils;
|
||||||
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;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.util.SocketUtils;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|||||||
@SpringBootTest(classes = CircuitBreakerWithNoFallbackTests.Application.class,
|
@SpringBootTest(classes = CircuitBreakerWithNoFallbackTests.Application.class,
|
||||||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
|
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
|
||||||
value = { "spring.application.name=springcircuittest", "spring.jmx.enabled=false",
|
value = { "spring.application.name=springcircuittest", "spring.jmx.enabled=false",
|
||||||
"feign.circuitbreaker.enabled=true" })
|
"spring.cloud.openfeign.circuitbreaker.enabled=true" })
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class CircuitBreakerWithNoFallbackTests {
|
public class CircuitBreakerWithNoFallbackTests {
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class CircuitBreakerWithNoFallbackTests {
|
|||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
System.setProperty("server.port", String.valueOf(SocketUtils.findAvailableTcpPort()));
|
System.setProperty("server.port", String.valueOf(TestSocketUtils.findAvailableTcpPort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
|
|||||||
+5
-8
@@ -18,13 +18,12 @@ package org.springframework.cloud.openfeign.encoding;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
||||||
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
||||||
@@ -39,7 +38,6 @@ import org.springframework.context.annotation.Import;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
@@ -50,16 +48,15 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignAcceptEncodingTests.Application.class, webEnvironment = RANDOM_PORT,
|
@SpringBootTest(classes = FeignAcceptEncodingTests.Application.class, webEnvironment = RANDOM_PORT,
|
||||||
value = { "feign.compression.response.enabled=true" })
|
value = { "spring.cloud.openfeign.compression.response.enabled=true" })
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignAcceptEncodingTests {
|
class FeignAcceptEncodingTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private InvoiceClient invoiceClient;
|
private InvoiceClient invoiceClient;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compressedResponse() {
|
void compressedResponse() {
|
||||||
|
|
||||||
// when
|
// when
|
||||||
final ResponseEntity<List<Invoice>> invoices = this.invoiceClient.getInvoices();
|
final ResponseEntity<List<Invoice>> invoices = this.invoiceClient.getInvoices();
|
||||||
|
|||||||
+5
-8
@@ -18,13 +18,12 @@ package org.springframework.cloud.openfeign.encoding;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
||||||
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
||||||
@@ -38,7 +37,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
@@ -49,15 +47,14 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignContentEncodingTests.Application.class, webEnvironment = RANDOM_PORT,
|
@SpringBootTest(classes = FeignContentEncodingTests.Application.class, webEnvironment = RANDOM_PORT,
|
||||||
value = { "feign.compression.request.enabled=true", "ribbon.OkToRetryOnAllOperations=false" })
|
value = { "spring.cloud.openfeign.compression.request.enabled=true" })
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
class FeignContentEncodingTests {
|
||||||
public class FeignContentEncodingTests {
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private InvoiceClient invoiceClient;
|
private InvoiceClient invoiceClient;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compressedResponse() {
|
void compressedResponse() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
final List<Invoice> invoices = Invoices.createInvoiceList(50);
|
final List<Invoice> invoices = Invoices.createInvoiceList(50);
|
||||||
|
|||||||
+13
-15
@@ -19,14 +19,13 @@ package org.springframework.cloud.openfeign.encoding;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
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.boot.web.server.LocalServerPort;
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
||||||
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
||||||
@@ -45,7 +44,6 @@ import org.springframework.data.domain.Sort;
|
|||||||
import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
@@ -57,15 +55,15 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Hyeonmin Park
|
* @author Hyeonmin Park
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignPageableEncodingTests.Application.class, webEnvironment = RANDOM_PORT,
|
@SpringBootTest(classes = FeignPageableEncodingTests.Application.class, webEnvironment = RANDOM_PORT,
|
||||||
value = { "feign.compression.request.enabled=true", "feign.autoconfiguration.jackson.enabled=true" })
|
value = { "spring.cloud.openfeign.compression.request.enabled=true",
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
"spring.cloud.openfeign.autoconfiguration.jackson.enabled=true" })
|
||||||
public class FeignPageableEncodingTests {
|
class FeignPageableEncodingTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private InvoiceClient invoiceClient;
|
private InvoiceClient invoiceClient;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPageable() {
|
void testPageable() {
|
||||||
// given
|
// given
|
||||||
Pageable pageable = PageRequest.of(0, 10, Sort.Direction.ASC, "sortProperty");
|
Pageable pageable = PageRequest.of(0, 10, Sort.Direction.ASC, "sortProperty");
|
||||||
|
|
||||||
@@ -87,7 +85,7 @@ public class FeignPageableEncodingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPageableWithDescDirection() {
|
void testPageableWithDescDirection() {
|
||||||
// given
|
// given
|
||||||
Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "sortProperty");
|
Pageable pageable = PageRequest.of(0, 10, Sort.Direction.DESC, "sortProperty");
|
||||||
|
|
||||||
@@ -113,7 +111,7 @@ public class FeignPageableEncodingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPageableWithMultipleSort() {
|
void testPageableWithMultipleSort() {
|
||||||
// given
|
// given
|
||||||
Pageable pageable = PageRequest.of(0, 10,
|
Pageable pageable = PageRequest.of(0, 10,
|
||||||
Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2")));
|
Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2")));
|
||||||
@@ -143,7 +141,7 @@ public class FeignPageableEncodingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPageableWithoutSort() {
|
void testPageableWithoutSort() {
|
||||||
// given
|
// given
|
||||||
Pageable pageable = PageRequest.of(0, 10);
|
Pageable pageable = PageRequest.of(0, 10);
|
||||||
|
|
||||||
@@ -162,7 +160,7 @@ public class FeignPageableEncodingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPageableWithoutSortWithBody() {
|
void testPageableWithoutSortWithBody() {
|
||||||
// given
|
// given
|
||||||
Pageable pageable = PageRequest.of(0, 10);
|
Pageable pageable = PageRequest.of(0, 10);
|
||||||
|
|
||||||
@@ -184,7 +182,7 @@ public class FeignPageableEncodingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPageableWithBody() {
|
void testPageableWithBody() {
|
||||||
// given
|
// given
|
||||||
Pageable pageable = PageRequest.of(0, 10,
|
Pageable pageable = PageRequest.of(0, 10,
|
||||||
Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2")));
|
Sort.by(Sort.Order.desc("sortProperty1"), Sort.Order.asc("sortProperty2")));
|
||||||
@@ -221,7 +219,7 @@ public class FeignPageableEncodingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnpagedWithBody() {
|
void testUnpagedWithBody() {
|
||||||
// given
|
// given
|
||||||
Pageable unpaged = Pageable.unpaged();
|
Pageable unpaged = Pageable.unpaged();
|
||||||
|
|
||||||
@@ -242,7 +240,7 @@ public class FeignPageableEncodingTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSortWithBody() {
|
void testSortWithBody() {
|
||||||
// given
|
// given
|
||||||
Sort sort = Sort.by(Sort.Order.desc("amount"));
|
Sort sort = Sort.by(Sort.Order.desc("amount"));
|
||||||
|
|
||||||
|
|||||||
+5
@@ -27,9 +27,14 @@ import org.springframework.cloud.openfeign.encoding.app.domain.Invoice;
|
|||||||
* Utility class used for testing.
|
* Utility class used for testing.
|
||||||
*
|
*
|
||||||
* @author Jakub Narloch
|
* @author Jakub Narloch
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
final class Invoices {
|
final class Invoices {
|
||||||
|
|
||||||
|
private Invoices() {
|
||||||
|
throw new IllegalStateException("Can't instantiate a utility class");
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Invoice> createInvoiceList(int count) {
|
public static List<Invoice> createInvoiceList(int count) {
|
||||||
final List<Invoice> invoices = new ArrayList<>();
|
final List<Invoice> invoices = new ArrayList<>();
|
||||||
for (int ind = 0; ind < count; ind++) {
|
for (int ind = 0; ind < count; ind++) {
|
||||||
|
|||||||
+3
-6
@@ -17,14 +17,12 @@
|
|||||||
package org.springframework.cloud.openfeign.encoding.proto;
|
package org.springframework.cloud.openfeign.encoding.proto;
|
||||||
|
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
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.support.SpringEncoder;
|
import org.springframework.cloud.openfeign.support.SpringEncoder;
|
||||||
import org.springframework.cloud.test.ClassPathExclusions;
|
import org.springframework.cloud.test.ClassPathExclusions;
|
||||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
|
|
||||||
import static feign.Request.HttpMethod.POST;
|
import static feign.Request.HttpMethod.POST;
|
||||||
@@ -34,12 +32,11 @@ import static feign.Request.HttpMethod.POST;
|
|||||||
*
|
*
|
||||||
* @author ScienJus
|
* @author ScienJus
|
||||||
*/
|
*/
|
||||||
@RunWith(ModifiedClassPathRunner.class)
|
|
||||||
@ClassPathExclusions("protobuf-*.jar")
|
@ClassPathExclusions("protobuf-*.jar")
|
||||||
public class ProtobufNotInClasspathTest {
|
class ProtobufNotInClasspathTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeWhenProtobufNotInClasspath() {
|
void testEncodeWhenProtobufNotInClasspath() {
|
||||||
ObjectFactory<HttpMessageConverters> converters = () -> new HttpMessageConverters(
|
ObjectFactory<HttpMessageConverters> converters = () -> new HttpMessageConverters(
|
||||||
new StringHttpMessageConverter());
|
new StringHttpMessageConverter());
|
||||||
RequestTemplate requestTemplate = new RequestTemplate();
|
RequestTemplate requestTemplate = new RequestTemplate();
|
||||||
|
|||||||
+7
-8
@@ -18,7 +18,6 @@ package org.springframework.cloud.openfeign.encoding.proto;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -35,12 +34,12 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
|||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
import org.apache.http.message.BasicHttpResponse;
|
import org.apache.http.message.BasicHttpResponse;
|
||||||
import org.apache.http.message.BasicStatusLine;
|
import org.apache.http.message.BasicStatusLine;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.ArgumentMatchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.BDDMockito;
|
import org.mockito.BDDMockito;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectFactory;
|
import org.springframework.beans.factory.ObjectFactory;
|
||||||
@@ -58,8 +57,8 @@ import static org.assertj.core.api.Assertions.fail;
|
|||||||
*
|
*
|
||||||
* @author ScienJus
|
* @author ScienJus
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ProtobufSpringEncoderTest {
|
class ProtobufSpringEncoderTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
@@ -70,7 +69,7 @@ public class ProtobufSpringEncoderTest {
|
|||||||
.setMsg("Erlang/OTP 最初是爱立信为开发电信设备系统设计的编程语言平台," + "电信设备(路由器、接入网关、…)典型设计是通过背板连接主控板卡与多块业务板卡的分布式系统。").build();
|
.setMsg("Erlang/OTP 最初是爱立信为开发电信设备系统设计的编程语言平台," + "电信设备(路由器、接入网关、…)典型设计是通过背板连接主控板卡与多块业务板卡的分布式系统。").build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProtobuf() throws IOException {
|
void testProtobuf() throws IOException {
|
||||||
// protobuf convert to request by feign and ProtobufHttpMessageConverter
|
// protobuf convert to request by feign and ProtobufHttpMessageConverter
|
||||||
RequestTemplate requestTemplate = newRequestTemplate();
|
RequestTemplate requestTemplate = newRequestTemplate();
|
||||||
newEncoder().encode(this.request, Request.class, requestTemplate);
|
newEncoder().encode(this.request, Request.class, requestTemplate);
|
||||||
@@ -84,7 +83,7 @@ public class ProtobufSpringEncoderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProtobufWithCharsetWillFail() throws IOException, URISyntaxException {
|
void testProtobufWithCharsetWillFail() throws IOException {
|
||||||
// protobuf convert to request by feign and ProtobufHttpMessageConverter
|
// protobuf convert to request by feign and ProtobufHttpMessageConverter
|
||||||
RequestTemplate requestTemplate = newRequestTemplate();
|
RequestTemplate requestTemplate = newRequestTemplate();
|
||||||
newEncoder().encode(this.request, Request.class, requestTemplate);
|
newEncoder().encode(this.request, Request.class, requestTemplate);
|
||||||
|
|||||||
+14
-14
@@ -74,21 +74,21 @@ public final class Request extends com.google.protobuf.GeneratedMessageV3 implem
|
|||||||
while (!done) {
|
while (!done) {
|
||||||
int tag = input.readTag();
|
int tag = input.readTag();
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case 0:
|
case 0:
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!parseUnknownFieldProto3(input, unknownFields, extensionRegistry, tag)) {
|
|
||||||
done = true;
|
done = true;
|
||||||
}
|
break;
|
||||||
break;
|
default:
|
||||||
case 8:
|
if (!parseUnknownFieldProto3(input, unknownFields, extensionRegistry, tag)) {
|
||||||
this.id_ = input.readInt32();
|
done = true;
|
||||||
break;
|
}
|
||||||
case 18:
|
break;
|
||||||
String s = input.readStringRequireUtf8();
|
case 8:
|
||||||
this.msg_ = s;
|
this.id_ = input.readInt32();
|
||||||
break;
|
break;
|
||||||
|
case 18:
|
||||||
|
String s = input.readStringRequireUtf8();
|
||||||
|
this.msg_ = s;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-16
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.hateoas;
|
package org.springframework.cloud.openfeign.hateoas;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
@@ -27,19 +27,20 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
|||||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||||
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
|
||||||
import org.springframework.hateoas.RepresentationModel;
|
import org.springframework.hateoas.config.WebConverters;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hector Espert
|
* @author Hector Espert
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
public class FeignHalAutoConfigurationContextTests {
|
class FeignHalAutoConfigurationContextTests {
|
||||||
|
|
||||||
private WebApplicationContextRunner contextRunner;
|
private WebApplicationContextRunner contextRunner;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
contextRunner = new WebApplicationContextRunner()
|
contextRunner = new WebApplicationContextRunner()
|
||||||
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class,
|
.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class,
|
||||||
HttpMessageConvertersAutoConfiguration.class, HypermediaAutoConfiguration.class,
|
HttpMessageConvertersAutoConfiguration.class, HypermediaAutoConfiguration.class,
|
||||||
@@ -48,23 +49,18 @@ public class FeignHalAutoConfigurationContextTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHalJacksonHttpMessageConverterIsNotLoaded() {
|
void shouldNotLoadWebConvertersCustomizerWhenNotWebConvertersNotInClasspath() {
|
||||||
FilteredClassLoader filteredClassLoader = new FilteredClassLoader(RepositoryRestMvcConfiguration.class,
|
FilteredClassLoader filteredClassLoader = new FilteredClassLoader(RepositoryRestMvcConfiguration.class,
|
||||||
RepresentationModel.class);
|
WebConverters.class);
|
||||||
contextRunner.withClassLoader(filteredClassLoader)
|
contextRunner.withClassLoader(filteredClassLoader)
|
||||||
.run(context -> assertThat(context).doesNotHaveBean("halJacksonHttpMessageConverter"));
|
.run(context -> assertThat(context).doesNotHaveBean("webConvertersCustomizer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHalJacksonHttpMessageConverterIsLoaded() {
|
void shouldLoadWebConvertersCustomizer() {
|
||||||
FilteredClassLoader filteredClassLoader = new FilteredClassLoader(RepositoryRestMvcConfiguration.class);
|
FilteredClassLoader filteredClassLoader = new FilteredClassLoader(RepositoryRestMvcConfiguration.class);
|
||||||
contextRunner.withClassLoader(filteredClassLoader)
|
contextRunner.withClassLoader(filteredClassLoader)
|
||||||
.run(context -> assertThat(context).hasBean("halJacksonHttpMessageConverter"));
|
.run(context -> assertThat(context).hasBean("webConvertersCustomizer"));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHalJacksonHttpMessageConverterIsNotLoadedUseRestDataMessageConverterInstead() {
|
|
||||||
contextRunner.run(context -> assertThat(context).hasBean("halJacksonHttpMessageConverter"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-90
@@ -1,90 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2016-2022 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.cloud.openfeign.hateoas;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
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.beans.factory.support.DefaultListableBeanFactory;
|
|
||||||
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.HalMediaTypeConfiguration;
|
|
||||||
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
|
|
||||||
* @author Olga Maciaszek-Sharma
|
|
||||||
*/
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
|
||||||
public class FeignHalAutoConfigurationTests {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ObjectProvider<HalConfiguration> halConfiguration;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ObjectProvider<ObjectMapper> objectMapper;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private LinkRelationProvider relProvider;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ObjectProvider<CurieProvider> curieProvider;
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private 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(curieProvider.getIfAvailable(any())).thenReturn(mock(CurieProvider.class));
|
|
||||||
|
|
||||||
HalMediaTypeConfiguration halMediaTypeConfiguration = new HalMediaTypeConfiguration(relProvider, curieProvider,
|
|
||||||
halConfiguration, messageResolver, new DefaultListableBeanFactory());
|
|
||||||
|
|
||||||
TypeConstrainedMappingJackson2HttpMessageConverter converter = feignHalAutoConfiguration
|
|
||||||
.halJacksonHttpMessageConverter(objectMapper, halMediaTypeConfiguration);
|
|
||||||
|
|
||||||
assertThat(converter).isNotNull();
|
|
||||||
assertThat(converter.getObjectMapper()).isNotNull();
|
|
||||||
assertThat(converter.getSupportedMediaTypes()).isEqualTo(Collections.singletonList(HAL_JSON));
|
|
||||||
|
|
||||||
assertThat(Jackson2HalModule.isAlreadyRegisteredIn(converter.getObjectMapper())).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+5
-8
@@ -18,8 +18,7 @@ package org.springframework.cloud.openfeign.hateoas;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@@ -31,7 +30,6 @@ import org.springframework.hateoas.EntityModel;
|
|||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.hateoas.PagedModel;
|
import org.springframework.hateoas.PagedModel;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||||
@@ -42,15 +40,14 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
|||||||
* @author Hector Espert
|
* @author Hector Espert
|
||||||
*/
|
*/
|
||||||
@SpringBootTest(classes = FeignHalApplication.class, webEnvironment = RANDOM_PORT, value = "debug=true")
|
@SpringBootTest(classes = FeignHalApplication.class, webEnvironment = RANDOM_PORT, value = "debug=true")
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public class FeignHalTests {
|
class FeignHalTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FeignHalClient feignHalClient;
|
private FeignHalClient feignHalClient;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityModel() {
|
void testEntityModel() {
|
||||||
EntityModel<MarsRover> entity = feignHalClient.entity();
|
EntityModel<MarsRover> entity = feignHalClient.entity();
|
||||||
assertThat(entity).isNotNull();
|
assertThat(entity).isNotNull();
|
||||||
|
|
||||||
@@ -65,7 +62,7 @@ public class FeignHalTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCollectionModel() {
|
void testCollectionModel() {
|
||||||
CollectionModel<MarsRover> collectionModel = feignHalClient.collection();
|
CollectionModel<MarsRover> collectionModel = feignHalClient.collection();
|
||||||
assertThat(collectionModel).isNotNull();
|
assertThat(collectionModel).isNotNull();
|
||||||
assertThat(collectionModel).isNotEmpty();
|
assertThat(collectionModel).isNotEmpty();
|
||||||
@@ -84,7 +81,7 @@ public class FeignHalTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPagedModel() {
|
void testPagedModel() {
|
||||||
PagedModel<MarsRover> paged = feignHalClient.paged();
|
PagedModel<MarsRover> paged = feignHalClient.paged();
|
||||||
assertThat(paged).isNotNull();
|
assertThat(paged).isNotNull();
|
||||||
assertThat(paged).isNotEmpty();
|
assertThat(paged).isNotEmpty();
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ package org.springframework.cloud.openfeign.hateoas.app;
|
|||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||||
import org.springframework.boot.web.server.LocalServerPort;
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||||
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
|
||||||
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
/**
|
/**
|
||||||
* @author Hector Espert
|
* @author Hector Espert
|
||||||
*/
|
*/
|
||||||
public class FeignHalRibbonConfiguration {
|
public class FeignHalConfiguration {
|
||||||
|
|
||||||
@Value("${local.server.port}")
|
@Value("${local.server.port}")
|
||||||
private int serverPort = 0;
|
private int serverPort = 0;
|
||||||
+6
-6
@@ -35,25 +35,25 @@ public class FeignHalController {
|
|||||||
public EntityModel<MarsRover> getEntity() {
|
public EntityModel<MarsRover> getEntity() {
|
||||||
MarsRover marsRover = new MarsRover();
|
MarsRover marsRover = new MarsRover();
|
||||||
marsRover.setName("Sojourner");
|
marsRover.setName("Sojourner");
|
||||||
Link link = new Link("/entity", "self");
|
Link link = Link.of("/entity", "self");
|
||||||
return new EntityModel<>(marsRover, link);
|
return EntityModel.of(marsRover, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/collection")
|
@GetMapping("/collection")
|
||||||
public CollectionModel<MarsRover> getCollection() {
|
public CollectionModel<MarsRover> getCollection() {
|
||||||
MarsRover marsRover = new MarsRover();
|
MarsRover marsRover = new MarsRover();
|
||||||
marsRover.setName("Opportunity");
|
marsRover.setName("Opportunity");
|
||||||
Link link = new Link("/collection", "self");
|
Link link = Link.of("/collection", "self");
|
||||||
return new CollectionModel<>(Collections.singleton(marsRover), link);
|
return CollectionModel.of(Collections.singleton(marsRover), link);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/paged")
|
@GetMapping("/paged")
|
||||||
public CollectionModel<MarsRover> getPaged() {
|
public CollectionModel<MarsRover> getPaged() {
|
||||||
MarsRover marsRover = new MarsRover();
|
MarsRover marsRover = new MarsRover();
|
||||||
marsRover.setName("Curiosity");
|
marsRover.setName("Curiosity");
|
||||||
Link link = new Link("/paged", "self");
|
Link link = Link.of("/paged", "self");
|
||||||
PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(1, 1, 1);
|
PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(1, 1, 1);
|
||||||
return new PagedModel<>(Collections.singleton(marsRover), metadata, link);
|
return PagedModel.of(Collections.singleton(marsRover), metadata, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-12
@@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.invalid;
|
package org.springframework.cloud.openfeign.invalid;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration;
|
import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration;
|
||||||
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
|
||||||
@@ -31,17 +29,16 @@ import org.springframework.context.annotation.Import;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Szymon Linowski
|
||||||
*/
|
*/
|
||||||
public class FeignClientValidationTests {
|
class FeignClientValidationTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException expected = ExpectedException.none();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServiceIdAndValue() {
|
void testServiceIdAndValue() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
LoadBalancerAutoConfiguration.class, NameAndServiceIdConfiguration.class);
|
LoadBalancerAutoConfiguration.class, NameAndServiceIdConfiguration.class);
|
||||||
assertThat(context.getBean(NameAndServiceIdConfiguration.Client.class)).isNotNull();
|
assertThat(context.getBean(NameAndServiceIdConfiguration.Client.class)).isNotNull();
|
||||||
@@ -49,7 +46,7 @@ public class FeignClientValidationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDuplicatedClientNames() {
|
void testDuplicatedClientNames() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
context.setAllowBeanDefinitionOverriding(false);
|
context.setAllowBeanDefinitionOverriding(false);
|
||||||
context.register(LoadBalancerAutoConfiguration.class, DuplicatedFeignClientNamesConfiguration.class);
|
context.register(LoadBalancerAutoConfiguration.class, DuplicatedFeignClientNamesConfiguration.class);
|
||||||
@@ -60,9 +57,10 @@ public class FeignClientValidationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotLegalHostname() {
|
void testNotLegalHostname() {
|
||||||
this.expected.expectMessage("not legal hostname (foo_bar)");
|
assertThatExceptionOfType(IllegalStateException.class)
|
||||||
new AnnotationConfigApplicationContext(BadHostnameConfiguration.class);
|
.isThrownBy(() -> new AnnotationConfigApplicationContext(BadHostnameConfiguration.class))
|
||||||
|
.withMessage("Service id not legal hostname (foo_bar)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
|||||||
+58
-8
@@ -16,12 +16,16 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.openfeign.loadbalancer;
|
package org.springframework.cloud.openfeign.loadbalancer;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -29,6 +33,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import feign.Client;
|
import feign.Client;
|
||||||
import feign.Request;
|
import feign.Request;
|
||||||
import feign.Response;
|
import feign.Response;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
@@ -62,23 +67,32 @@ import static org.mockito.Mockito.when;
|
|||||||
* Commons project, so here we are only testing the interactions between
|
* Commons project, so here we are only testing the interactions between
|
||||||
* {@link FeignBlockingLoadBalancerClient} and its delegates.
|
* {@link FeignBlockingLoadBalancerClient} and its delegates.
|
||||||
*
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
* "https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClientTests.java">BlockingLoadBalancerClientTests</a>
|
* "https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClientTests.java">BlockingLoadBalancerClientTests</a>
|
||||||
* @author Olga Maciaszek-Sharma
|
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class FeignBlockingLoadBalancerClientTests {
|
class FeignBlockingLoadBalancerClientTests {
|
||||||
|
|
||||||
private Client delegate = mock(Client.class);
|
private final Client delegate = mock(Client.class);
|
||||||
|
|
||||||
private BlockingLoadBalancerClient loadBalancerClient = mock(BlockingLoadBalancerClient.class);
|
private final BlockingLoadBalancerClient loadBalancerClient = mock(BlockingLoadBalancerClient.class);
|
||||||
|
|
||||||
private final LoadBalancerClientFactory loadBalancerClientFactory = mock(LoadBalancerClientFactory.class);
|
private final LoadBalancerClientFactory loadBalancerClientFactory = mock(LoadBalancerClientFactory.class);
|
||||||
|
|
||||||
private final LoadBalancerProperties loadBalancerProperties = new LoadBalancerProperties();
|
private final LoadBalancerProperties loadBalancerProperties = new LoadBalancerProperties();
|
||||||
|
|
||||||
private FeignBlockingLoadBalancerClient feignBlockingLoadBalancerClient = new FeignBlockingLoadBalancerClient(
|
private final List<LoadBalancerFeignRequestTransformer> transformers = Arrays.asList(new InstanceIdTransformer(),
|
||||||
delegate, loadBalancerClient, loadBalancerProperties, loadBalancerClientFactory);
|
new ServiceIdTransformer());
|
||||||
|
|
||||||
|
private final FeignBlockingLoadBalancerClient feignBlockingLoadBalancerClient = new FeignBlockingLoadBalancerClient(
|
||||||
|
delegate, loadBalancerClient, loadBalancerClientFactory, transformers);
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
when(loadBalancerClientFactory.getProperties(any(String.class))).thenReturn(loadBalancerProperties);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldExtractServiceIdFromRequestUrl() throws IOException {
|
void shouldExtractServiceIdFromRequestUrl() throws IOException {
|
||||||
@@ -105,8 +119,7 @@ class FeignBlockingLoadBalancerClientTests {
|
|||||||
Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options());
|
Response response = feignBlockingLoadBalancerClient.execute(request, new Request.Options());
|
||||||
|
|
||||||
assertThat(response.status()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
assertThat(response.status()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE.value());
|
||||||
assertThat(response.body().toString())
|
assertThat(read(response)).isEqualTo("Load balancer does not contain an instance for the service test");
|
||||||
.isEqualTo("Load balancer does not contain an instance for the service test");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -126,9 +139,11 @@ class FeignBlockingLoadBalancerClientTests {
|
|||||||
Request actualRequest = captor.getValue();
|
Request actualRequest = captor.getValue();
|
||||||
assertThat(actualRequest.httpMethod()).isEqualTo(Request.HttpMethod.GET);
|
assertThat(actualRequest.httpMethod()).isEqualTo(Request.HttpMethod.GET);
|
||||||
assertThat(actualRequest.url()).isEqualTo(url);
|
assertThat(actualRequest.url()).isEqualTo(url);
|
||||||
assertThat(actualRequest.headers()).hasSize(1);
|
assertThat(actualRequest.headers()).hasSize(3);
|
||||||
assertThat(actualRequest.headers()).containsEntry(HttpHeaders.CONTENT_TYPE,
|
assertThat(actualRequest.headers()).containsEntry(HttpHeaders.CONTENT_TYPE,
|
||||||
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
||||||
|
assertThat(actualRequest.headers()).containsEntry("X-ServiceId", Collections.singletonList("test"));
|
||||||
|
assertThat(actualRequest.headers()).containsEntry("X-InstanceId", Collections.singletonList("test-1"));
|
||||||
assertThat(new String(actualRequest.body())).isEqualTo("hello");
|
assertThat(new String(actualRequest.body())).isEqualTo("hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +182,17 @@ class FeignBlockingLoadBalancerClientTests {
|
|||||||
.contains(HttpStatus.OK);
|
.contains(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String read(Response response) throws IOException {
|
||||||
|
BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(response.body().asInputStream(), StandardCharsets.UTF_8));
|
||||||
|
String outputString = "";
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
outputString += line;
|
||||||
|
}
|
||||||
|
return outputString;
|
||||||
|
}
|
||||||
|
|
||||||
private Request testRequest() {
|
private Request testRequest() {
|
||||||
return testRequest("test");
|
return testRequest("test");
|
||||||
}
|
}
|
||||||
@@ -235,4 +261,28 @@ class FeignBlockingLoadBalancerClientTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class InstanceIdTransformer implements LoadBalancerFeignRequestTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Request transformRequest(Request request, ServiceInstance instance) {
|
||||||
|
Map<String, Collection<String>> headers = new HashMap<>(request.headers());
|
||||||
|
headers.put("X-InstanceId", Collections.singletonList(instance.getInstanceId()));
|
||||||
|
return Request.create(request.httpMethod(), request.url(), headers, request.body(), request.charset(),
|
||||||
|
request.requestTemplate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ServiceIdTransformer implements LoadBalancerFeignRequestTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Request transformRequest(Request request, ServiceInstance instance) {
|
||||||
|
Map<String, Collection<String>> headers = new HashMap<>(request.headers());
|
||||||
|
headers.put("X-ServiceId", Collections.singletonList(instance.getServiceId()));
|
||||||
|
return Request.create(request.httpMethod(), request.url(), headers, request.body(), request.charset(),
|
||||||
|
request.requestTemplate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-15
@@ -33,6 +33,7 @@ import org.springframework.cloud.loadbalancer.config.LoadBalancerAutoConfigurati
|
|||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.springframework.test.util.ReflectionTestUtils.getField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Olga Maciaszek-Sharma
|
* @author Olga Maciaszek-Sharma
|
||||||
@@ -42,7 +43,7 @@ class FeignLoadBalancerAutoConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateDefaultFeignBlockingLoadBalancerClientWhenHttpClientDisabled() {
|
void shouldInstantiateDefaultFeignBlockingLoadBalancerClientWhenHttpClientDisabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=false",
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=false",
|
||||||
"spring.cloud.loadbalancer.retry.enabled=false");
|
"spring.cloud.loadbalancer.retry.enabled=false");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalanced(context, Client.Default.class);
|
assertLoadBalanced(context, Client.Default.class);
|
||||||
@@ -57,16 +58,25 @@ class FeignLoadBalancerAutoConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateOkHttpFeignClientWhenEnabled() {
|
void shouldInstantiateOkHttpFeignClientWhenEnabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=false",
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=false",
|
||||||
"feign.okhttp.enabled=true", "spring.cloud.loadbalancer.retry.enabled=false");
|
"spring.cloud.openfeign.okhttp.enabled=true", "spring.cloud.loadbalancer.retry.enabled=false",
|
||||||
|
"spring.cloud.openfeign.httpclient.okhttp.read-timeout=9s");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalanced(context, OkHttpClient.class);
|
Map<String, FeignBlockingLoadBalancerClient> beans = context
|
||||||
|
.getBeansOfType(FeignBlockingLoadBalancerClient.class);
|
||||||
|
assertThat(beans).as("Missing bean of type %s", OkHttpClient.class).hasSize(1);
|
||||||
|
Client client = beans.get("feignClient").getDelegate();
|
||||||
|
assertThat(client).isInstanceOf(OkHttpClient.class);
|
||||||
|
OkHttpClient okHttpClient = (OkHttpClient) client;
|
||||||
|
okhttp3.OkHttpClient httpClient = (okhttp3.OkHttpClient) getField(okHttpClient, "delegate");
|
||||||
|
assertThat(httpClient.readTimeoutMillis()).isEqualTo(9000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateHttpFeignClient5WhenEnabled() {
|
void shouldInstantiateHttpFeignClient5WhenEnabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=false",
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=false",
|
||||||
"feign.okhttp.enabled=false", "feign.httpclient.hc5.enabled=true",
|
"spring.cloud.openfeign.okhttp.enabled=false", "spring.cloud.openfeign.httpclient.hc5.enabled=true",
|
||||||
"spring.cloud.loadbalancer.retry.enabled=false");
|
"spring.cloud.loadbalancer.retry.enabled=false");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalanced(context, ApacheHttp5Client.class);
|
assertLoadBalanced(context, ApacheHttp5Client.class);
|
||||||
@@ -74,8 +84,8 @@ class FeignLoadBalancerAutoConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateHttpFeignClient5WhenBothHttpClientAndHttpClient5Enabled() {
|
void shouldInstantiateHttpFeignClient5WhenBothHttpClientAndHttpClient5Enabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=true",
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=true",
|
||||||
"feign.okhttp.enabled=false", "feign.httpclient.hc5.enabled=true",
|
"spring.cloud.openfeign.okhttp.enabled=false", "spring.cloud.openfeign.httpclient.hc5.enabled=true",
|
||||||
"spring.cloud.loadbalancer.retry.enabled=false");
|
"spring.cloud.loadbalancer.retry.enabled=false");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalanced(context, ApacheHttp5Client.class);
|
assertLoadBalanced(context, ApacheHttp5Client.class);
|
||||||
@@ -83,7 +93,7 @@ class FeignLoadBalancerAutoConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateRetryableDefaultFeignBlockingLoadBalancerClientWhenHttpClientDisabled() {
|
void shouldInstantiateRetryableDefaultFeignBlockingLoadBalancerClientWhenHttpClientDisabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=false");
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=false");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalancedWithRetries(context, Client.Default.class);
|
assertLoadBalancedWithRetries(context, Client.Default.class);
|
||||||
}
|
}
|
||||||
@@ -97,24 +107,24 @@ class FeignLoadBalancerAutoConfigurationTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateRetryableOkHttpFeignClientWhenEnabled() {
|
void shouldInstantiateRetryableOkHttpFeignClientWhenEnabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=false",
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=false",
|
||||||
"feign.okhttp.enabled=true");
|
"spring.cloud.openfeign.okhttp.enabled=true");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalancedWithRetries(context, OkHttpClient.class);
|
assertLoadBalancedWithRetries(context, OkHttpClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateRetryableHttpFeignClient5WhenEnabled() {
|
void shouldInstantiateRetryableHttpFeignClient5WhenEnabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=false",
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=false",
|
||||||
"feign.okhttp.enabled=false", "feign.httpclient.hc5.enabled=true");
|
"spring.cloud.openfeign.okhttp.enabled=false", "spring.cloud.openfeign.httpclient.hc5.enabled=true");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalancedWithRetries(context, ApacheHttp5Client.class);
|
assertLoadBalancedWithRetries(context, ApacheHttp5Client.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldInstantiateRetryableHttpFeignClient5WhenBothHttpClientAndHttpClient5Enabled() {
|
void shouldInstantiateRetryableHttpFeignClient5WhenBothHttpClientAndHttpClient5Enabled() {
|
||||||
ConfigurableApplicationContext context = initContext("feign.httpclient.enabled=true",
|
ConfigurableApplicationContext context = initContext("spring.cloud.openfeign.httpclient.enabled=true",
|
||||||
"feign.okhttp.enabled=false", "feign.httpclient.hc5.enabled=true");
|
"spring.cloud.openfeign.okhttp.enabled=false", "spring.cloud.openfeign.httpclient.hc5.enabled=true");
|
||||||
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
assertThatOneBeanPresent(context, BlockingLoadBalancerClient.class);
|
||||||
assertLoadBalancedWithRetries(context, ApacheHttp5Client.class);
|
assertLoadBalancedWithRetries(context, ApacheHttp5Client.class);
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-9
@@ -22,9 +22,11 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -69,30 +71,35 @@ import static org.mockito.Mockito.when;
|
|||||||
* Commons project, so here we are only testing the interactions between
|
* Commons project, so here we are only testing the interactions between
|
||||||
* {@link RetryableFeignBlockingLoadBalancerClient} and its delegates.
|
* {@link RetryableFeignBlockingLoadBalancerClient} and its delegates.
|
||||||
*
|
*
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
|
* @author changjin wei(魏昌进)
|
||||||
* @see <a href=
|
* @see <a href=
|
||||||
* "https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClientTests.java">BlockingLoadBalancerClientTests</a>
|
* "https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/blocking/client/BlockingLoadBalancerClientTests.java">BlockingLoadBalancerClientTests</a>
|
||||||
* @author Olga Maciaszek-Sharma
|
|
||||||
*/
|
*/
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
class RetryableFeignBlockingLoadBalancerClientTests {
|
class RetryableFeignBlockingLoadBalancerClientTests {
|
||||||
|
|
||||||
private Client delegate = mock(Client.class);
|
private final Client delegate = mock(Client.class);
|
||||||
|
|
||||||
private LoadBalancedRetryFactory retryFactory = mock(LoadBalancedRetryFactory.class);
|
private final LoadBalancedRetryFactory retryFactory = mock(LoadBalancedRetryFactory.class);
|
||||||
|
|
||||||
private BlockingLoadBalancerClient loadBalancerClient = mock(BlockingLoadBalancerClient.class);
|
private final BlockingLoadBalancerClient loadBalancerClient = mock(BlockingLoadBalancerClient.class);
|
||||||
|
|
||||||
private final LoadBalancerClientFactory loadBalancerClientFactory = mock(LoadBalancerClientFactory.class);
|
private final LoadBalancerClientFactory loadBalancerClientFactory = mock(LoadBalancerClientFactory.class);
|
||||||
|
|
||||||
private LoadBalancerProperties properties = new LoadBalancerProperties();
|
private final LoadBalancerProperties properties = new LoadBalancerProperties();
|
||||||
|
|
||||||
private RetryableFeignBlockingLoadBalancerClient feignBlockingLoadBalancerClient = new RetryableFeignBlockingLoadBalancerClient(
|
private final List<LoadBalancerFeignRequestTransformer> transformers = Arrays.asList(new InstanceIdTransformer(),
|
||||||
delegate, loadBalancerClient, retryFactory, properties, loadBalancerClientFactory);
|
new ServiceIdTransformer());
|
||||||
|
|
||||||
private ServiceInstance serviceInstance = new DefaultServiceInstance("test-a", "test", "testhost", 80, false);
|
private final RetryableFeignBlockingLoadBalancerClient feignBlockingLoadBalancerClient = new RetryableFeignBlockingLoadBalancerClient(
|
||||||
|
delegate, loadBalancerClient, retryFactory, loadBalancerClientFactory, transformers);
|
||||||
|
|
||||||
|
private final ServiceInstance serviceInstance = new DefaultServiceInstance("test-a", "test", "testhost", 80, false);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
|
when(loadBalancerClientFactory.getProperties(any(String.class))).thenReturn(properties);
|
||||||
when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient)))
|
when(retryFactory.createRetryPolicy(any(), eq(loadBalancerClient)))
|
||||||
.thenReturn(new BlockingLoadBalancedRetryPolicy(properties));
|
.thenReturn(new BlockingLoadBalancedRetryPolicy(properties));
|
||||||
when(loadBalancerClient.choose(eq("test"), any())).thenReturn(serviceInstance);
|
when(loadBalancerClient.choose(eq("test"), any())).thenReturn(serviceInstance);
|
||||||
@@ -196,9 +203,11 @@ class RetryableFeignBlockingLoadBalancerClientTests {
|
|||||||
Request actualRequest = captor.getValue();
|
Request actualRequest = captor.getValue();
|
||||||
assertThat(actualRequest.httpMethod()).isEqualTo(Request.HttpMethod.GET);
|
assertThat(actualRequest.httpMethod()).isEqualTo(Request.HttpMethod.GET);
|
||||||
assertThat(actualRequest.url()).isEqualTo(url);
|
assertThat(actualRequest.url()).isEqualTo(url);
|
||||||
assertThat(actualRequest.headers()).hasSize(1);
|
assertThat(actualRequest.headers()).hasSize(3);
|
||||||
assertThat(actualRequest.headers()).containsEntry(HttpHeaders.CONTENT_TYPE,
|
assertThat(actualRequest.headers()).containsEntry(HttpHeaders.CONTENT_TYPE,
|
||||||
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
||||||
|
assertThat(actualRequest.headers()).containsEntry("X-ServiceId", Collections.singletonList("test"));
|
||||||
|
assertThat(actualRequest.headers()).containsEntry("X-InstanceId", Collections.singletonList("test-1"));
|
||||||
assertThat(new String(actualRequest.body())).isEqualTo("hello");
|
assertThat(new String(actualRequest.body())).isEqualTo("hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,4 +318,28 @@ class RetryableFeignBlockingLoadBalancerClientTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class InstanceIdTransformer implements LoadBalancerFeignRequestTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Request transformRequest(Request request, ServiceInstance instance) {
|
||||||
|
Map<String, Collection<String>> headers = new HashMap<>(request.headers());
|
||||||
|
headers.put("X-InstanceId", Collections.singletonList(instance.getInstanceId()));
|
||||||
|
return Request.create(request.httpMethod(), request.url(), headers, request.body(), request.charset(),
|
||||||
|
request.requestTemplate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ServiceIdTransformer implements LoadBalancerFeignRequestTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Request transformRequest(Request request, ServiceInstance instance) {
|
||||||
|
Map<String, Collection<String>> headers = new HashMap<>(request.headers());
|
||||||
|
headers.put("X-ServiceId", Collections.singletonList(instance.getServiceId()));
|
||||||
|
return Request.create(request.httpMethod(), request.url(), headers, request.body(), request.charset(),
|
||||||
|
request.requestTemplate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user