use of org.springframework.boot.web.reactive.function.client.WebClientCustomizer in project apollo by ctripcorp.
the class ApolloClientLongPollingExtensionInitializer method initialize.
@Override
public void initialize(ApolloClientProperties apolloClientProperties, Binder binder, BindHandler bindHandler) {
WebClient.Builder webClientBuilder = WebClient.builder();
List<ApolloClientWebClientCustomizerFactory> factories = ServiceBootstrap.loadAllOrdered(ApolloClientWebClientCustomizerFactory.class);
if (!CollectionUtils.isEmpty(factories)) {
for (ApolloClientWebClientCustomizerFactory factory : factories) {
WebClientCustomizer webClientCustomizer = factory.createWebClientCustomizer(apolloClientProperties, binder, bindHandler, this.log, this.bootstrapContext);
if (webClientCustomizer != null) {
webClientCustomizer.customize(webClientBuilder);
}
}
}
HttpClient httpClient = new ApolloWebClientHttpClient(webClientBuilder.build());
ApolloConfigDataInjectorCustomizer.registerIfAbsent(HttpClient.class, () -> httpClient);
}
use of org.springframework.boot.web.reactive.function.client.WebClientCustomizer in project spring-boot by spring-projects.
the class ClientHttpConnectorAutoConfigurationTests method shouldCreateHttpClientBeans.
@Test
void shouldCreateHttpClientBeans() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(ReactorResourceFactory.class);
assertThat(context).hasSingleBean(ReactorClientHttpConnector.class);
WebClientCustomizer clientCustomizer = context.getBean(WebClientCustomizer.class);
WebClient.Builder builder = mock(WebClient.Builder.class);
clientCustomizer.customize(builder);
then(builder).should().clientConnector(any(ReactorClientHttpConnector.class));
});
}
use of org.springframework.boot.web.reactive.function.client.WebClientCustomizer in project spring-boot by spring-projects.
the class WebClientAutoConfigurationTests method webClientShouldApplyCustomizers.
@Test
void webClientShouldApplyCustomizers() {
this.contextRunner.withUserConfiguration(WebClientCustomizerConfig.class).run((context) -> {
WebClient.Builder builder = context.getBean(WebClient.Builder.class);
WebClientCustomizer customizer = context.getBean("webClientCustomizer", WebClientCustomizer.class);
builder.build();
then(customizer).should().customize(any(WebClient.Builder.class));
});
}
use of org.springframework.boot.web.reactive.function.client.WebClientCustomizer in project spring-boot by spring-projects.
the class ClientHttpConnectorAutoConfigurationTests method shouldNotOverrideCustomClientConnector.
@Test
void shouldNotOverrideCustomClientConnector() {
this.contextRunner.withUserConfiguration(CustomClientHttpConnectorConfig.class).run((context) -> {
assertThat(context).hasSingleBean(ClientHttpConnector.class).hasBean("customConnector").doesNotHaveBean(ReactorResourceFactory.class);
WebClientCustomizer clientCustomizer = context.getBean(WebClientCustomizer.class);
WebClient.Builder builder = mock(WebClient.Builder.class);
clientCustomizer.customize(builder);
then(builder).should().clientConnector(any(ClientHttpConnector.class));
});
}
use of org.springframework.boot.web.reactive.function.client.WebClientCustomizer in project spring-boot by spring-projects.
the class WebClientAutoConfigurationTests method shouldGetPrototypeScopedBean.
@Test
void shouldGetPrototypeScopedBean() {
this.contextRunner.withUserConfiguration(WebClientCustomizerConfig.class).run((context) -> {
ClientHttpResponse response = mock(ClientHttpResponse.class);
given(response.getBody()).willReturn(Flux.empty());
given(response.getHeaders()).willReturn(new HttpHeaders());
ClientHttpConnector firstConnector = mock(ClientHttpConnector.class);
given(firstConnector.connect(any(), any(), any())).willReturn(Mono.just(response));
WebClient.Builder firstBuilder = context.getBean(WebClient.Builder.class);
firstBuilder.clientConnector(firstConnector).baseUrl("https://first.example.org");
ClientHttpConnector secondConnector = mock(ClientHttpConnector.class);
given(secondConnector.connect(any(), any(), any())).willReturn(Mono.just(response));
WebClient.Builder secondBuilder = context.getBean(WebClient.Builder.class);
secondBuilder.clientConnector(secondConnector).baseUrl("https://second.example.org");
assertThat(firstBuilder).isNotEqualTo(secondBuilder);
firstBuilder.build().get().uri("/foo").retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
secondBuilder.build().get().uri("/foo").retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
then(firstConnector).should().connect(eq(HttpMethod.GET), eq(URI.create("https://first.example.org/foo")), any());
then(secondConnector).should().connect(eq(HttpMethod.GET), eq(URI.create("https://second.example.org/foo")), any());
WebClientCustomizer customizer = context.getBean("webClientCustomizer", WebClientCustomizer.class);
then(customizer).should(times(2)).customize(any(WebClient.Builder.class));
});
}
Aggregations