Questions tagged [spring-webclient]

WebClient makes it possible to perform reactive non-blocking HTTP requests in Spring applications. Use this tag for any questions involving its usage.

992 questions
5
votes
2 answers

Spring WebFlux WebClient - How to resolve 400 Bad Request

I am a newbie to reactive programming and I am using Spring WebFlux's WebClient to make a POST request to the below URL as part of my Spring Boot application to assign an existing quiz to a candidate. I am having trouble understanding what I've done…
5
votes
1 answer

Java Stream vs Flux fromIterable

I have a list of usernames and want to fetch user details from the remote service without blocking the main thread. I'm using Spring's reactive client WebClient. For the response, I get Mono then subscribe it and print the result. private…
Sarvar Nishonboyev
  • 12,262
  • 10
  • 69
  • 70
5
votes
1 answer

How to expose webClient metrics in prometheus?

I want to expose the metrics of a WebClient call to a downstream system from the service, metrics like count of request, min, max time for the response is needed. I want to know how I can write a gauge for a reactive webclient. Here is a sample…
5
votes
1 answer

Configuring Spring WebFlux WebClient to use a custom thread pool

Is it possible to configure WebClient to use a custom thread pool other than the reactor-http-nio thread pool (When using Netty)? If it is possible , can we somehow restrict that custom thread pool to run only on a particular processor core?
5
votes
1 answer

Spring Webclient connection not closed properly

I am trying to make HTTP calls using Springboot-Reactive webclient. I am getting connection closed by remote server error. Please find the following code which uses Webclient to make rest call. Mono post(String url, JSONObject body) { …
5
votes
2 answers

How to throw WebClientResponseException when using exchange() with Spring WebClient

When using the retrieve() method of Spring WebClient in conjunction with bodyToMono default error handling is applied (if the response has status code 4xx or 5xx, the Mono will contain a WebClientException). In error cases the resulting…
Fable
  • 371
  • 1
  • 4
  • 11
5
votes
1 answer

Spring webflux WebClient logs 'Connection reset by peer'

I have this following code which uses WebClient to make HTTP calls. webClient.post() .uri("/users/track") .body(BodyInserters.fromObject(getUserTrackPayload(selection, customAttribute, partyId).toString())) …
chom
  • 651
  • 3
  • 9
  • 23
4
votes
1 answer

Spring WebClient how to reduce DNS cache TTL?

I'm using WebClient (from Spring-Weblux) and currently it caches DNS for 30 mins. I don't see any information how to reduce this DNS cache. How can I reduce it to 30sec? HttpClient client =…
4
votes
1 answer

How to retrieve the configured base URL from the Spring WebClient?

The Spring reactive WebClient can be built with a base URL: import org.springframework.web.reactive.function.client.WebClient; ... @Bean public WebClient webClient(WebClient.Builder builder) { return builder …
Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
4
votes
0 answers

How to configure proxy with username and password in Spring-boot Webclient?

I want to use Spring-boot WebClient to make restful API calls with a proxy server. This is what I did: I first created a HttpClient with proxy specified. Then I created a ReactorClientHttpConnector. Finally I created the WebClient using the above…
4
votes
0 answers

Spring WebClient Preferred HttpClient Library?

Spring Webclient supports 3 HttpClient libraries - Reactor Netty, Jetty Rective Http Client, and Apache Http Components . Which is the most recommended one and in what circumstances?
Anuja Barve
  • 300
  • 1
  • 4
  • 23
4
votes
3 answers

Spring Boot WebClient Connection and Read Timeout

Currently my post and get requests are handled through WebClients which has a common connection and read timeout in Spring Boot. I have 5 different classes each requiring its own set of connection and read timeout. I don't want to create 5 different…
Aditya K
  • 135
  • 2
  • 4
  • 10
4
votes
0 answers

Spring reactive WebClient retry tests with StepVerifier

I have a simple implementation of WebClient request: public Mono getTodoWithSimpleRetry(String id) { RetryBackoffSpec retrySpec = Retry.fixedDelay(3, Duration.ofSeconds(2)) .doBeforeRetry(beforeRetry -> { …
ExcepOra
  • 117
  • 9
4
votes
1 answer

How to customize the Authorization header of the OAuth2 token request using spring-security-oauth2 with a WebClient?

I am trying to upgrade to spring security 5.5.1 on a WebClient call. I found out that the oauth2 clientId and secret are now URL encoded in AbstractWebClientReactiveOAuth2AccessTokenResponseClient, but my token provider does not support this (for…
4
votes
0 answers

Using a Spring Cloud Gateway filter to retry a REST call with modified headers?

I'm currently working on a REST 'proxy' for use in development. The idea is to launch a jar on the command-line, supplying it with a base url for the 'proxied' REST API and an existing secret key used for authentication. The proxy handles…