-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not set ClientHttpRequestFactory when Spring Boot >= 3.4.0 (#71)
* Do not set ClientHttpRequestFactory when Spring Boot >= 3.4.0 * not verify Spring Cloud version * use ? * reflection registers RestClientBuilderConfigurer and RestTemplateBuilderConfigurer * deprecate RequestConfigurator, Requester and requestMappingSupportEnabled * native compile is alive
- Loading branch information
1 parent
33720da
commit dfad8a5
Showing
16 changed files
with
404 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- 3.3.x | ||
- 3.2.x | ||
- 3.1.x | ||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ot-autoconfigure/src/main/java/io/github/danielliu1123/httpexchange/ConfigurerCopier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.github.danielliu1123.httpexchange; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import org.springframework.boot.autoconfigure.web.client.RestClientBuilderConfigurer; | ||
import org.springframework.boot.autoconfigure.web.client.RestTemplateBuilderConfigurer; | ||
import org.springframework.util.ReflectionUtils; | ||
|
||
/** | ||
* @author Freeman | ||
*/ | ||
final class ConfigurerCopier { | ||
|
||
private static final Map<String, Field> restClientBuilderConfigurerProperties; | ||
private static final Map<String, Field> restTemplateBuilderConfigurerProperties; | ||
|
||
static { | ||
restClientBuilderConfigurerProperties = Arrays.stream(RestClientBuilderConfigurer.class.getDeclaredFields()) | ||
.peek(ReflectionUtils::makeAccessible) | ||
.collect(Collectors.toMap(Field::getName, Function.identity())); | ||
restTemplateBuilderConfigurerProperties = Arrays.stream(RestTemplateBuilderConfigurer.class.getDeclaredFields()) | ||
.peek(ReflectionUtils::makeAccessible) | ||
.collect(Collectors.toMap(Field::getName, Function.identity())); | ||
} | ||
|
||
public static RestClientBuilderConfigurer copyRestClientBuilderConfigurer(RestClientBuilderConfigurer source) { | ||
|
||
var target = new RestClientBuilderConfigurer(); | ||
|
||
for (var entry : restClientBuilderConfigurerProperties.entrySet()) { | ||
var field = entry.getValue(); | ||
var value = ReflectionUtils.getField(field, source); | ||
if (value != null) { | ||
ReflectionUtils.setField(field, target, value); | ||
} | ||
} | ||
|
||
return target; | ||
} | ||
|
||
public static void setRestClientBuilderConfigurerProperty( | ||
RestClientBuilderConfigurer target, String name, Object value) { | ||
var field = restClientBuilderConfigurerProperties.get(name); | ||
if (field != null) { | ||
ReflectionUtils.setField(field, target, value); | ||
} | ||
} | ||
|
||
public static RestTemplateBuilderConfigurer copyRestTemplateBuilderConfigurer( | ||
RestTemplateBuilderConfigurer source) { | ||
|
||
var target = new RestTemplateBuilderConfigurer(); | ||
|
||
for (var entry : restTemplateBuilderConfigurerProperties.entrySet()) { | ||
var field = entry.getValue(); | ||
var value = ReflectionUtils.getField(field, source); | ||
if (value != null) { | ||
ReflectionUtils.setField(field, target, value); | ||
} | ||
} | ||
|
||
return target; | ||
} | ||
|
||
public static void setRestTemplateBuilderConfigurerProperty( | ||
RestTemplateBuilderConfigurer target, String name, Object value) { | ||
var field = restTemplateBuilderConfigurerProperties.get(name); | ||
if (field != null) { | ||
ReflectionUtils.setField(field, target, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.