Compare commits
87
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc3a73c055 | ||
|
|
ad9998e68c | ||
|
|
8b1c1dbf4c | ||
|
|
eb11b51ee7 | ||
|
|
5dff9cfc49 | ||
|
|
468d18b8f7 | ||
|
|
234361e0fc | ||
|
|
d706e071f3 | ||
|
|
3e5aa41490 | ||
|
|
653a35270d | ||
|
|
c195a9a1db | ||
|
|
3a1d19f74f | ||
|
|
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:
|
||||||
|
|||||||
@@ -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=8.0.292.hs-adpt
|
||||||
+51
@@ -303,6 +303,57 @@ Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on t
|
|||||||
|
|
||||||
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
|
IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources.
|
||||||
|
|
||||||
|
=== Duplicate Finder
|
||||||
|
|
||||||
|
Spring Cloud Build brings along the `basepom:duplicate-finder-maven-plugin`, that enables flagging duplicate and conflicting classes and resources on the java classpath.
|
||||||
|
|
||||||
|
==== Duplicate Finder configuration
|
||||||
|
|
||||||
|
Duplicate finder is *enabled by default* and will run in the `verify` phase of your Maven build, but it will only take effect in your project if you add the `duplicate-finder-maven-plugin` to the `build` section of the projecst's `pom.xml`.
|
||||||
|
|
||||||
|
.pom.xml
|
||||||
|
[source,xml]
|
||||||
|
----
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.basepom.maven</groupId>
|
||||||
|
<artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
----
|
||||||
|
|
||||||
|
For other properties, we have set defaults as listed in the https://github.com/basepom/duplicate-finder-maven-plugin/wiki[plugin documentation].
|
||||||
|
|
||||||
|
You can easily override them but setting the value of the selected property prefixed with `duplicate-finder-maven-plugin`. For example, set `duplicate-finder-maven-plugin.skip` to `true` in order to skip duplicates check in your build.
|
||||||
|
|
||||||
|
If you need to add `ignoredClassPatterns` or `ignoredResourcePatterns` to your setup, make sure to add them in the plugin configuration section of your project:
|
||||||
|
|
||||||
|
[source,xml]
|
||||||
|
----
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.basepom.maven</groupId>
|
||||||
|
<artifactId>duplicate-finder-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<ignoredClassPatterns>
|
||||||
|
<ignoredClassPattern>org.joda.time.base.BaseDateTime</ignoredClassPattern>
|
||||||
|
<ignoredClassPattern>.*module-info</ignoredClassPattern>
|
||||||
|
</ignoredClassPatterns>
|
||||||
|
<ignoredResourcePatterns>
|
||||||
|
<ignoredResourcePattern>changelog.txt</ignoredResourcePattern>
|
||||||
|
</ignoredResourcePatterns>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
|
||||||
== License
|
== License
|
||||||
|
|
||||||
The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-openfeign/main/LICENSE.txt[here].
|
The project license file is available https://raw.githubusercontent.com/spring-cloud/spring-cloud-openfeign/main/LICENSE.txt[here].
|
||||||
|
|||||||
+1
-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.7-SNAPSHOT</version>
|
<version>3.1.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>spring-cloud-openfeign-docs</artifactId>
|
<artifactId>spring-cloud-openfeign-docs</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
|feign.compression.request.mime-types | `[text/xml, application/xml, application/json]` | The list of supported mime types.
|
|feign.compression.request.mime-types | `[text/xml, application/xml, application/json]` | The list of supported mime types.
|
||||||
|feign.compression.request.min-request-size | `2048` | The minimum threshold content size.
|
|feign.compression.request.min-request-size | `2048` | The minimum threshold content size.
|
||||||
|feign.compression.response.enabled | `false` | Enables the response from Feign to be compressed.
|
|feign.compression.response.enabled | `false` | Enables the response from Feign to be compressed.
|
||||||
|feign.compression.response.useGzipDecoder | `false` | Enables the default gzip decoder to be used.
|
|
||||||
|feign.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.
|
||||||
|feign.httpclient.connection-timeout | `2000` |
|
|feign.httpclient.connection-timeout | `2000` |
|
||||||
|feign.httpclient.connection-timer-repeat | `3000` |
|
|feign.httpclient.connection-timer-repeat | `3000` |
|
||||||
@@ -27,9 +26,12 @@
|
|||||||
|feign.httpclient.hc5.socket-timeout-unit | | Default value for socket timeout unit.
|
|feign.httpclient.hc5.socket-timeout-unit | | Default value for socket timeout unit.
|
||||||
|feign.httpclient.max-connections | `200` |
|
|feign.httpclient.max-connections | `200` |
|
||||||
|feign.httpclient.max-connections-per-route | `50` |
|
|feign.httpclient.max-connections-per-route | `50` |
|
||||||
|
|feign.httpclient.ok-http-client-properties.read-timeout | `60s` | {@link OkHttpClient} read timeout; defaults to 60 seconds.
|
||||||
|feign.httpclient.time-to-live | `900` |
|
|feign.httpclient.time-to-live | `900` |
|
||||||
|feign.httpclient.time-to-live-unit | |
|
|feign.httpclient.time-to-live-unit | |
|
||||||
|feign.metrics.enabled | `true` | Enables metrics capability for Feign.
|
|feign.metrics.enabled | `true` | Enables metrics capability for Feign.
|
||||||
|
|feign.oauth2.enabled | `false` | Enables feign interceptor for managing oauth2 access token.
|
||||||
|
|feign.oauth2.load-balanced | `false` | Enables load balancing for oauth2 access token provider.
|
||||||
|feign.okhttp.enabled | `false` | Enables the use of the OK HTTP Client by Feign.
|
|feign.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 `feign.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.
|
||||||
@@ -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,
|
||||||
@@ -192,6 +196,7 @@ feign:
|
|||||||
capabilities:
|
capabilities:
|
||||||
- com.example.FooCapability
|
- com.example.FooCapability
|
||||||
- com.example.BarCapability
|
- com.example.BarCapability
|
||||||
|
queryMapEncoder: com.example.SimpleQueryMapEncoder
|
||||||
metrics.enabled: false
|
metrics.enabled: false
|
||||||
----
|
----
|
||||||
|
|
||||||
@@ -515,14 +520,6 @@ feign.compression.request.min-request-size=2048
|
|||||||
|
|
||||||
These properties allow you to be selective about the compressed media types and minimum request threshold length.
|
These properties allow you to be selective about the compressed media types and minimum request threshold length.
|
||||||
|
|
||||||
For http clients except OkHttpClient, default gzip decoder can be enabled to decode gzip response in UTF-8 encoding:
|
|
||||||
|
|
||||||
[source,java]
|
|
||||||
----
|
|
||||||
feign.compression.response.enabled=true
|
|
||||||
feign.compression.response.useGzipDecoder=true
|
|
||||||
----
|
|
||||||
|
|
||||||
=== Feign logging
|
=== Feign logging
|
||||||
|
|
||||||
A logger is created for each Feign client created. By default the name of the logger is the full class name of the interface used to create the Feign client. Feign logging only responds to the `DEBUG` level.
|
A logger is created for each Feign client created. By default the name of the logger is the full class name of the interface used to create the Feign client. Feign logging only responds to the `DEBUG` level.
|
||||||
@@ -607,6 +604,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 `feign.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 +707,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 +739,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
|
||||||
@@ -747,6 +761,16 @@ feign.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:
|
||||||
|
----
|
||||||
|
feign.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:
|
||||||
|
----
|
||||||
|
feign.oauth2.load-balanced=true
|
||||||
|
----
|
||||||
|
|
||||||
== 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.7-SNAPSHOT</version>
|
<version>3.1.1-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>3.1.1-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.6-SNAPSHOT</spring-cloud-commons.version>
|
<spring-cloud-commons.version>3.1.1-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>
|
||||||
@@ -79,6 +79,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>
|
||||||
|
|
||||||
|
|||||||
@@ -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.7-SNAPSHOT</version>
|
<version>3.1.1-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>
|
||||||
@@ -70,6 +70,12 @@
|
|||||||
<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>
|
||||||
@@ -133,6 +139,16 @@
|
|||||||
<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>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -149,11 +165,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,13 +194,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.protobuf</groupId>
|
<groupId>com.google.protobuf</groupId>
|
||||||
<artifactId>protobuf-java</artifactId>
|
<artifactId>protobuf-java</artifactId>
|
||||||
<version>3.14.0</version>
|
<version>3.19.3</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vavr</groupId>
|
<groupId>io.vavr</groupId>
|
||||||
<artifactId>vavr</artifactId>
|
<artifactId>vavr</artifactId>
|
||||||
<version>0.10.3</version>
|
<version>0.10.4</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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 {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2020 the original author or authors.
|
* Copyright 2016-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+45
-11
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -18,6 +18,7 @@ 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;
|
||||||
@@ -27,6 +28,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import javax.annotation.PreDestroy;
|
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;
|
||||||
@@ -50,15 +52,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 +77,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 +89,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,6 +115,13 @@ public class FeignAutoConfiguration {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(value = "feign.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 = "feign.autoconfiguration.jackson.enabled", havingValue = "true")
|
||||||
@@ -260,8 +275,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 +284,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.getOkHttpClientProperties().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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,12 +330,30 @@ public class FeignAutoConfiguration {
|
|||||||
@ConditionalOnProperty("feign.oauth2.enabled")
|
@ConditionalOnProperty("feign.oauth2.enabled")
|
||||||
protected static class Oauth2FeignConfiguration {
|
protected static class Oauth2FeignConfiguration {
|
||||||
|
|
||||||
|
@ConditionalOnBean({ RetryLoadBalancerInterceptor.class, OAuth2ClientContext.class,
|
||||||
|
OAuth2ProtectedResourceDetails.class })
|
||||||
|
@ConditionalOnProperty(value = "feign.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 = "feign.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+6
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -68,6 +68,7 @@ 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
|
||||||
*/
|
*/
|
||||||
public class FeignClientFactoryBean
|
public class FeignClientFactoryBean
|
||||||
implements FactoryBean<Object>, InitializingBean, ApplicationContextAware, BeanFactoryAware {
|
implements FactoryBean<Object>, InitializingBean, ApplicationContextAware, BeanFactoryAware {
|
||||||
@@ -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) {
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021-2021 the original author or authors.
|
* Copyright 2021-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+16
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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,6 +41,7 @@ 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("feign.client")
|
||||||
public class FeignClientProperties {
|
public class FeignClientProperties {
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-14
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2020-2020 the original author or authors.
|
* Copyright 2020-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2020 the original author or authors.
|
* Copyright 2016-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2019 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+8
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
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 javax.annotation.PreDestroy;
|
||||||
@@ -48,8 +49,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 +58,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.getOkHttpClientProperties().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
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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
|
||||||
*/
|
*/
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+9
-25
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2016-2021 the original author or authors.
|
* Copyright 2016-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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-2021 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+7
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -25,7 +25,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;
|
||||||
@@ -39,15 +39,15 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* @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,
|
return new FeignBlockingLoadBalancerClient(new Client.Default(null, null), loadBalancerClient,
|
||||||
loadBalancerClientFactory);
|
loadBalancerClientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,10 +58,9 @@ 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) {
|
|
||||||
return new RetryableFeignBlockingLoadBalancerClient(new Client.Default(null, null), loadBalancerClient,
|
return new RetryableFeignBlockingLoadBalancerClient(new Client.Default(null, null), loadBalancerClient,
|
||||||
loadBalancedRetryFactory, properties, loadBalancerClientFactory);
|
loadBalancedRetryFactory, loadBalancerClientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -60,15 +60,24 @@ 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link FeignBlockingLoadBalancerClient#FeignBlockingLoadBalancerClient(Client, LoadBalancerClient, LoadBalancerClientFactory)}
|
||||||
|
*/
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
|
LoadBalancerClientFactory loadBalancerClientFactory) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +125,7 @@ public class FeignBlockingLoadBalancerClient 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;
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+7
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,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.cloud.openfeign.clientconfig.HttpClient5FeignConfiguration;
|
import org.springframework.cloud.openfeign.clientconfig.HttpClient5FeignConfiguration;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -46,16 +46,16 @@ import org.springframework.context.annotation.Import;
|
|||||||
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
@ConditionalOnBean({ LoadBalancerClient.class, LoadBalancerClientFactory.class })
|
||||||
@ConditionalOnProperty(value = "feign.httpclient.hc5.enabled", havingValue = "true")
|
@ConditionalOnProperty(value = "feign.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) {
|
||||||
Client delegate = new ApacheHttp5Client(httpClient5);
|
Client delegate = new ApacheHttp5Client(httpClient5);
|
||||||
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, properties, loadBalancerClientFactory);
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -65,11 +65,10 @@ 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) {
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -27,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.cloud.openfeign.HttpClient5DisabledConditions;
|
import org.springframework.cloud.openfeign.HttpClient5DisabledConditions;
|
||||||
import org.springframework.cloud.openfeign.clientconfig.HttpClientFeignConfiguration;
|
import org.springframework.cloud.openfeign.clientconfig.HttpClientFeignConfiguration;
|
||||||
@@ -50,16 +50,16 @@ import org.springframework.context.annotation.Import;
|
|||||||
@ConditionalOnProperty(value = "feign.httpclient.enabled", matchIfMissing = true)
|
@ConditionalOnProperty(value = "feign.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) {
|
||||||
ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
|
ApacheHttpClient delegate = new ApacheHttpClient(httpClient);
|
||||||
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, properties, loadBalancerClientFactory);
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -69,11 +69,10 @@ 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) {
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+7
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,7 +26,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;
|
||||||
@@ -46,16 +46,16 @@ import org.springframework.context.annotation.Import;
|
|||||||
@ConditionalOnProperty("feign.okhttp.enabled")
|
@ConditionalOnProperty("feign.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) {
|
||||||
OkHttpClient delegate = new OkHttpClient(okHttpClient);
|
OkHttpClient delegate = new OkHttpClient(okHttpClient);
|
||||||
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, properties, loadBalancerClientFactory);
|
return new FeignBlockingLoadBalancerClient(delegate, loadBalancerClient, loadBalancerClientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -65,11 +65,10 @@ 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) {
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+15
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -78,17 +78,27 @@ 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated in favour of
|
||||||
|
* {@link RetryableFeignBlockingLoadBalancerClient#RetryableFeignBlockingLoadBalancerClient(Client, LoadBalancerClient, LoadBalancedRetryFactory, LoadBalancerClientFactory)}
|
||||||
|
*/
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RetryableFeignBlockingLoadBalancerClient(Client delegate, LoadBalancerClient loadBalancerClient,
|
||||||
|
LoadBalancedRetryFactory loadBalancedRetryFactory, LoadBalancerClientFactory loadBalancerClientFactory) {
|
||||||
|
this.delegate = delegate;
|
||||||
|
this.loadBalancerClient = loadBalancerClient;
|
||||||
|
this.loadBalancedRetryFactory = loadBalancedRetryFactory;
|
||||||
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
this.loadBalancerClientFactory = loadBalancerClientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +242,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;
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2019 the original author or authors.
|
* Copyright 2015-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015-2021 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);
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
-80
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013-2020 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-2020 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
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+47
-10
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,13 +16,17 @@
|
|||||||
|
|
||||||
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 = "feign.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 OkHttpClientProperties okHttpClientProperties = new OkHttpClientProperties();
|
||||||
|
|
||||||
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 OkHttpClientProperties getOkHttpClientProperties() {
|
||||||
|
return okHttpClientProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOkHttpClientProperties(OkHttpClientProperties okHttpClientProperties) {
|
||||||
|
this.okHttpClientProperties = okHttpClientProperties;
|
||||||
|
}
|
||||||
|
|
||||||
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 OkHttpClientProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016-2021 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<?>>> {
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+7
-5
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -22,6 +22,7 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.core.Version;
|
import com.fasterxml.jackson.core.Version;
|
||||||
import com.fasterxml.jackson.databind.Module;
|
import com.fasterxml.jackson.databind.Module;
|
||||||
@@ -59,6 +60,7 @@ public class PageJacksonModule extends Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JsonDeserialize(as = SimplePageImpl.class)
|
@JsonDeserialize(as = SimplePageImpl.class)
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
private interface PageMixIn {
|
private interface PageMixIn {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -86,7 +88,7 @@ public class PageJacksonModule extends Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty
|
||||||
@Override
|
@Override
|
||||||
public int getTotalPages() {
|
public int getTotalPages() {
|
||||||
return delegate.getTotalPages();
|
return delegate.getTotalPages();
|
||||||
@@ -110,7 +112,7 @@ public class PageJacksonModule extends Module {
|
|||||||
return delegate.getSize();
|
return delegate.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty
|
||||||
@Override
|
@Override
|
||||||
public int getNumberOfElements() {
|
public int getNumberOfElements() {
|
||||||
return delegate.getNumberOfElements();
|
return delegate.getNumberOfElements();
|
||||||
@@ -134,13 +136,13 @@ public class PageJacksonModule extends Module {
|
|||||||
return delegate.getSort();
|
return delegate.getSort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty
|
||||||
@Override
|
@Override
|
||||||
public boolean isFirst() {
|
public boolean isFirst() {
|
||||||
return delegate.isFirst();
|
return delegate.isFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonProperty
|
||||||
@Override
|
@Override
|
||||||
public boolean isLast() {
|
public boolean isLast() {
|
||||||
return delegate.isLast();
|
return delegate.isLast();
|
||||||
|
|||||||
+4
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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) {
|
||||||
|
|||||||
+32
-4
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
+28
-10
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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) {
|
||||||
|
|||||||
+8
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-6
@@ -44,12 +44,6 @@
|
|||||||
"description": "Enables the response from Feign to be compressed.",
|
"description": "Enables the response from Feign to be compressed.",
|
||||||
"defaultValue": "false"
|
"defaultValue": "false"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "feign.compression.response.useGzipDecoder",
|
|
||||||
"type": "java.lang.Boolean",
|
|
||||||
"description": "Enables the default gzip decoder to be used.",
|
|
||||||
"defaultValue": "false"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "feign.compression.request.enabled",
|
"name": "feign.compression.request.enabled",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
@@ -67,6 +61,18 @@
|
|||||||
"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": "feign.oauth2.enabled",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "Enables feign interceptor for managing oauth2 access token.",
|
||||||
|
"defaultValue": "false"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "feign.oauth2.load-balanced",
|
||||||
|
"type": "java.lang.Boolean",
|
||||||
|
"description": "Enables load balancing for oauth2 access token provider.",
|
||||||
|
"defaultValue": "false"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-8
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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", "feign.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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+81
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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.client.loadbalancer.LoadBalancerInterceptor;
|
||||||
import org.springframework.cloud.openfeign.FeignAutoConfiguration.CircuitBreakerPresentFeignTargeterConfiguration.DefaultCircuitBreakerNameResolver;
|
import org.springframework.cloud.openfeign.FeignAutoConfiguration.CircuitBreakerPresentFeignTargeterConfiguration.DefaultCircuitBreakerNameResolver;
|
||||||
|
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,6 +45,7 @@ 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 {
|
||||||
|
|
||||||
@@ -81,6 +91,66 @@ class FeignAutoConfigurationTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateFeignOAuth2FeignRequestInterceptorWithoutInterceptors() {
|
||||||
|
runner.withPropertyValues("feign.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("feign.oauth2.enabled=true", "feign.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("feign.oauth2.enabled=true", "feign.oauth2.load-balanced=true")
|
||||||
|
.withBean(MockOAuth2ClientContext.class, "token").withBean(BaseOAuth2ProtectedResourceDetails.class)
|
||||||
|
.run(ctx -> {
|
||||||
|
assertOauth2FeignRequestInterceptorExists(ctx);
|
||||||
|
assertAccessTokenProviderInterceptorNotExists(ctx, LoadBalancerInterceptor.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldInstantiateFeignOAuth2FeignRequestInterceptorWithCustomAccessTokenProviderInterceptor() {
|
||||||
|
runner.withPropertyValues("feign.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 +178,14 @@ class FeignAutoConfigurationTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class CustomOAuth2FeignRequestInterceptorConfigurer implements OAuth2FeignRequestInterceptorConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void customize(OAuth2FeignRequestInterceptorBuilder requestInterceptorBuilder) {
|
||||||
|
requestInterceptorBuilder
|
||||||
|
.withAccessTokenProviderInterceptors(new BasicAuthenticationInterceptor("username", "password"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2020 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,7 +20,7 @@ import java.lang.reflect.Field;
|
|||||||
|
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import feign.Logger;
|
import feign.Logger;
|
||||||
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;
|
||||||
@@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author Matt King
|
* @author Matt King
|
||||||
* @author Sam Kruglov
|
* @author Sam Kruglov
|
||||||
*/
|
*/
|
||||||
public class FeignBuilderCustomizerTests {
|
class FeignBuilderCustomizerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuilderCustomizer() {
|
void testBuilderCustomizer() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
FeignBuilderCustomizerTests.SampleConfiguration2.class);
|
FeignBuilderCustomizerTests.SampleConfiguration2.class);
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public class FeignBuilderCustomizerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildCustomizerOrdered() {
|
void testBuildCustomizerOrdered() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class FeignBuilderCustomizerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildCustomizerOrderedWithAdditional() {
|
void testBuildCustomizerOrderedWithAdditional() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
FeignBuilderCustomizerTests.SampleConfiguration3.class);
|
||||||
|
|
||||||
|
|||||||
+20
-26
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2021 the original author or authors.
|
* Copyright 2013-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user