mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Fix bug where ZipkinRestTemplateBuilderCustomizer had no effect
Closes gh-33399
This commit is contained in:
parent
d88f968d22
commit
2ceee789ce
@ -80,10 +80,21 @@ class ZipkinConfigurations {
|
||||
ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers) {
|
||||
RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder()
|
||||
.setConnectTimeout(properties.getConnectTimeout()).setReadTimeout(properties.getReadTimeout());
|
||||
customizers.orderedStream().forEach((customizer) -> customizer.customize(restTemplateBuilder));
|
||||
restTemplateBuilder = applyCustomizers(restTemplateBuilder, customizers);
|
||||
return new ZipkinRestTemplateSender(properties.getEndpoint(), restTemplateBuilder.build());
|
||||
}
|
||||
|
||||
private RestTemplateBuilder applyCustomizers(RestTemplateBuilder restTemplateBuilder,
|
||||
ObjectProvider<ZipkinRestTemplateBuilderCustomizer> customizers) {
|
||||
Iterable<ZipkinRestTemplateBuilderCustomizer> orderedCustomizers = () -> customizers.orderedStream()
|
||||
.iterator();
|
||||
RestTemplateBuilder currentBuilder = restTemplateBuilder;
|
||||
for (ZipkinRestTemplateBuilderCustomizer customizer : orderedCustomizers) {
|
||||
currentBuilder = customizer.customize(currentBuilder);
|
||||
}
|
||||
return currentBuilder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
@ -31,7 +31,8 @@ public interface ZipkinRestTemplateBuilderCustomizer {
|
||||
/**
|
||||
* Customize the rest template builder.
|
||||
* @param restTemplateBuilder the {@code RestTemplateBuilder} to customize
|
||||
* @return the customized {@code RestTemplateBuilder}
|
||||
*/
|
||||
void customize(RestTemplateBuilder restTemplateBuilder);
|
||||
RestTemplateBuilder customize(RestTemplateBuilder restTemplateBuilder);
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
||||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
@ -143,8 +144,8 @@ class ZipkinConfigurationsSenderConfigurationTests {
|
||||
private static class RestTemplateConfiguration {
|
||||
|
||||
@Bean
|
||||
ZipkinRestTemplateBuilderCustomizer restTemplateBuilder() {
|
||||
return mock(ZipkinRestTemplateBuilderCustomizer.class);
|
||||
ZipkinRestTemplateBuilderCustomizer zipkinRestTemplateBuilderCustomizer() {
|
||||
return new DummyZipkinRestTemplateBuilderCustomizer();
|
||||
}
|
||||
|
||||
}
|
||||
@ -169,4 +170,13 @@ class ZipkinConfigurationsSenderConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
private static class DummyZipkinRestTemplateBuilderCustomizer implements ZipkinRestTemplateBuilderCustomizer {
|
||||
|
||||
@Override
|
||||
public RestTemplateBuilder customize(RestTemplateBuilder restTemplateBuilder) {
|
||||
return restTemplateBuilder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user