Merge branch '1.3.x'
This commit is contained in:
@@ -70,6 +70,12 @@ public class TraceWebClientAutoConfiguration {
|
||||
@Autowired
|
||||
private TracingClientHttpRequestInterceptor clientInterceptor;
|
||||
|
||||
@Bean
|
||||
@Order
|
||||
RestTemplateCustomizer traceRestTemplateCustomizer() {
|
||||
return new TraceRestTemplateCustomizer(this.clientInterceptor);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
Map<String, RestTemplate> restTemplates = BeanFactoryUtils
|
||||
@@ -80,17 +86,6 @@ public class TraceWebClientAutoConfiguration {
|
||||
this.clientInterceptor).inject(restTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Order
|
||||
RestTemplateCustomizer traceRestTemplateCustomizer() {
|
||||
return new RestTemplateCustomizer() {
|
||||
@Override public void customize(RestTemplate restTemplate) {
|
||||
new RestTemplateInterceptorInjector(TraceInterceptorConfiguration.this.clientInterceptor)
|
||||
.inject(restTemplate);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,4 +125,18 @@ class RestTemplateInterceptorInjector {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class TraceRestTemplateCustomizer implements RestTemplateCustomizer {
|
||||
|
||||
private final TracingClientHttpRequestInterceptor interceptor;
|
||||
|
||||
TraceRestTemplateCustomizer(TracingClientHttpRequestInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
}
|
||||
|
||||
@Override public void customize(RestTemplate restTemplate) {
|
||||
new RestTemplateInterceptorInjector(this.interceptor)
|
||||
.inject(restTemplate);
|
||||
}
|
||||
}
|
||||
@@ -49,11 +49,13 @@ public class TraceWebClientAutoConfigurationTests {
|
||||
|
||||
@Autowired @Qualifier("firstRestTemplate") RestTemplate restTemplate;
|
||||
@Autowired @Qualifier("secondRestTemplate") RestTemplate secondRestTemplate;
|
||||
@Autowired RestTemplateBuilder builder;
|
||||
|
||||
@Test
|
||||
public void should_add_rest_template_interceptors() {
|
||||
assertInterceptorsOrder(assertInterceptorsNotEmpty(this.restTemplate));
|
||||
assertInterceptorsOrder(assertInterceptorsNotEmpty(this.restTemplate));
|
||||
assertInterceptorsOrder(assertInterceptorsNotEmpty(this.secondRestTemplate));
|
||||
assertInterceptorsOrder(assertInterceptorsNotEmpty(this.builder.build()));
|
||||
}
|
||||
|
||||
private List<ClientHttpRequestInterceptor> assertInterceptorsNotEmpty(RestTemplate restTemplate) {
|
||||
@@ -88,14 +90,23 @@ public class TraceWebClientAutoConfigurationTests {
|
||||
@EnableAutoConfiguration
|
||||
static class Config {
|
||||
|
||||
// custom builder
|
||||
@Bean
|
||||
RestTemplateBuilder myRestTemplateBuilder(List<RestTemplateCustomizer> customizers) {
|
||||
return new RestTemplateBuilder()
|
||||
.additionalCustomizers(customizers)
|
||||
.additionalInterceptors(new MyClientHttpRequestInterceptor());
|
||||
}
|
||||
|
||||
// rest template from builder
|
||||
@Bean
|
||||
@Qualifier("firstRestTemplate")
|
||||
RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
|
||||
return restTemplateBuilder
|
||||
.additionalInterceptors(new MyClientHttpRequestInterceptor())
|
||||
.build();
|
||||
}
|
||||
|
||||
// manual rest template
|
||||
@Bean
|
||||
@Qualifier("secondRestTemplate")
|
||||
RestTemplate secondRestTemplate() {
|
||||
@@ -106,6 +117,7 @@ public class TraceWebClientAutoConfigurationTests {
|
||||
return restTemplate;
|
||||
}
|
||||
|
||||
// custom customizer
|
||||
@Bean
|
||||
RestTemplateCustomizer myRestTemplateCustomizer() {
|
||||
return restTemplate -> {
|
||||
|
||||
Reference in New Issue
Block a user