Java Code Examples for org.springframework.web.reactive.function.client.WebClient#Builder

The following examples show how to use org.springframework.web.reactive.function.client.WebClient#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HealthCheckConfiguration.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@Autowired
public HealthCheckConfiguration(
    WebClient.Builder webClientBuilder,
    HealthAggregator healthAggregator
) {
    this.webClientBuilder = webClientBuilder;
    this.healthAggregator = healthAggregator;
}
 
Example 2
Source File: HealthCheckConfiguration.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@Autowired
public HealthCheckConfiguration(
    WebClient.Builder webClientBuilder,
    HealthAggregator healthAggregator
) {
    this.webClientBuilder = webClientBuilder;
    this.healthAggregator = healthAggregator;
}
 
Example 3
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
* Build the RestTemplate used to make HTTP requests.
* @return RestTemplate
*/
public static WebClient buildWebClient(ObjectMapper mapper) {
    ExchangeStrategies strategies = ExchangeStrategies
        .builder()
        .codecs(clientDefaultCodecsConfigurer -> {
            clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper, MediaType.APPLICATION_JSON));
            clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper, MediaType.APPLICATION_JSON));
        }).build();
    WebClient.Builder webClient = WebClient.builder().exchangeStrategies(strategies);
    return webClient.build();
}
 
Example 4
Source File: ProductCompositeIntegration.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@Autowired
public ProductCompositeIntegration(
    WebClient.Builder webClientBuilder,
    ObjectMapper mapper,
    MessageSources messageSources
) {
    this.webClientBuilder = webClientBuilder;
    this.mapper = mapper;
    this.messageSources = messageSources;
}
 
Example 5
Source File: TracingWebClientBeanPostProcessor.java    From java-spring-web with Apache License 2.0 5 votes vote down vote up
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
	if (bean instanceof WebClient) {
		final WebClient webClient = (WebClient) bean;
		return webClient.mutate()
				.filters(addTraceExchangeFilterFunctionIfNotPresent()).build();
	} else if (bean instanceof WebClient.Builder) {
		final WebClient.Builder webClientBuilder = (WebClient.Builder) bean;
		return webClientBuilder.filters(addTraceExchangeFilterFunctionIfNotPresent());
	}
	return bean;
}
 
Example 6
Source File: DefaultWebTestClientBuilder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private DefaultWebTestClientBuilder(@Nullable WebClient.Builder webClientBuilder,
		@Nullable WebHttpHandlerBuilder httpHandlerBuilder, @Nullable ClientHttpConnector connector,
		@Nullable Duration responseTimeout) {

	Assert.isTrue(httpHandlerBuilder != null || connector != null,
			"Either WebHttpHandlerBuilder or ClientHttpConnector must be provided");

	this.webClientBuilder = (webClientBuilder != null ? webClientBuilder : WebClient.builder());
	this.httpHandlerBuilder = (httpHandlerBuilder != null ? httpHandlerBuilder.clone() : null);
	this.connector = connector;
	this.responseTimeout = responseTimeout;
}
 
Example 7
Source File: HealthCheckConfiguration.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@Autowired
public HealthCheckConfiguration(
    WebClient.Builder webClientBuilder,
    HealthAggregator healthAggregator
) {
    this.webClientBuilder = webClientBuilder;
    this.healthAggregator = healthAggregator;
}
 
Example 8
Source File: ProductCompositeIntegration.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@Autowired
public ProductCompositeIntegration(
    WebClient.Builder webClientBuilder,
    ObjectMapper mapper,
    MessageSources messageSources,
    @Value("${app.product-service.timeoutSec}") int productServiceTimeoutSec

) {
    this.webClientBuilder = webClientBuilder;
    this.mapper = mapper;
    this.messageSources = messageSources;
    this.productServiceTimeoutSec = productServiceTimeoutSec;
}
 
Example 9
Source File: CommonConfiguration.java    From microservices-dashboard with Apache License 2.0 5 votes vote down vote up
@Bean("machine-to-machine-web-client")
public WebClient m2mWebClient(List<MachineToMachineWebClientConfigurer> configurers) {
	WebClient.Builder builder = WebClient.builder()
			.apply(this::applyWebClientResponseExceptionFilter);
	configurers.forEach(builder::apply);
	return builder.build();
}
 
Example 10
Source File: GatewayApplication.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 4 votes vote down vote up
@Bean
@LoadBalanced
public WebClient.Builder loadBalancedWebClientBuilder() {
	final WebClient.Builder builder = WebClient.builder();
	return builder;
}
 
Example 11
Source File: DataHandler.java    From vertx-spring-boot with Apache License 2.0 4 votes vote down vote up
public DataHandler(MailClient mailClient, WebClient.Builder clientBuilder) {
    this.mailClient = mailClient;
    this.client = clientBuilder
        .baseUrl("https://httpbin.org")
        .build();
}
 
Example 12
Source File: GatewayApplication.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 4 votes vote down vote up
@Bean
@LoadBalanced
public WebClient.Builder loadBalancedWebClientBuilder() {
	final WebClient.Builder builder = WebClient.builder();
	return builder;
}
 
Example 13
Source File: InstanceWebClient.java    From spring-boot-admin with Apache License 2.0 4 votes vote down vote up
public Builder(WebClient.Builder webClientBuilder) {
	this.webClientBuilder = webClientBuilder;
}
 
Example 14
Source File: ApiGatewayApplication.java    From java-microservices-examples with Apache License 2.0 4 votes vote down vote up
@Bean
@LoadBalanced
public WebClient.Builder loadBalancedWebClientBuilder() {
    return WebClient.builder();
}
 
Example 15
Source File: CLR.java    From spring-graalvm-native with Apache License 2.0 4 votes vote down vote up
public CLR(WebClient.Builder builder) {
	this.client = builder.baseUrl("https://example.com").build();
}
 
Example 16
Source File: HttpBinService.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 4 votes vote down vote up
public HttpBinService(WebClient.Builder builder) {
	this.rest = builder.baseUrl("https://httpbin.org").build();
}
 
Example 17
Source File: SpringWebFluxAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static void client(final Object thiz) {
  final WebClient.Builder builder = (Builder)thiz;
  builder.filter(new TracingExchangeFilterFunction(GlobalTracer.get(), Collections.singletonList(new WebClientSpanDecorator.StandardTags())));
}
 
Example 18
Source File: GatewayApplication.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 4 votes vote down vote up
@Bean
@LoadBalanced
public WebClient.Builder loadBalancedWebClientBuilder() {
	final WebClient.Builder builder = WebClient.builder();
	return builder;
}
 
Example 19
Source File: InstanceWebClient.java    From spring-boot-admin with Apache License 2.0 4 votes vote down vote up
public Builder webClient(WebClient.Builder builder) {
	this.webClientBuilder = builder;
	return this;
}
 
Example 20
Source File: WebClientCustomizer.java    From spring-cloud-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Callback to customize a
 * {@link org.springframework.web.reactive.function.client.WebClient.Builder
 * WebClient.Builder} instance.
 * @param webClientBuilder the client builder to customize
 */
void customize(WebClient.Builder webClientBuilder);