WebClient makes it possible to perform reactive non-blocking HTTP requests in Spring applications. Use this tag for any questions involving its usage.
Questions tagged [spring-webclient]
992 questions
3
votes
1 answer
How to mock error response using MockWebServer in WebClient unit tests
I am writing unit test for a method which uses WebClient to call a REST end point.
Using MockWebServer, I am able to cover the code for a success response, but
I am unable to find any way to simulate error response so that the related code…

Ajay Singh
- 441
- 6
- 18
3
votes
4 answers
Spring RestTemplate vs WebClient for sync requests
Sorry if this was asked before, but I didn't find a matching question.
I have an application that performs api calls to other services. I'm thinking of using WebClient over RestTemplate as it's advised by Spring. I'm performing exclusively…

tracer_13
- 33
- 1
- 4
3
votes
1 answer
Is Mono.doFinally sufficient to handle release/cleanup?
I am trying to synchronize a resource with spring webClient:
this.semaphore.acquire()
webClient
.post()
.uri("/a")
.bodyValue(payload)
.retrieve()
.bodyToMono(String.class)
// release
.doFinally(st ->…

Maros Ivanco
- 55
- 4
3
votes
0 answers
Spring WebClient taking extra time to read Response
We are using WebClient to communicate with another service. For the time being (in performance testing) its a mock which returns response after 150 ms.
But in the service, time taken by WebClient is far greater than this. We had set timeout at 250…

Akash
- 99
- 6
3
votes
1 answer
Deserialize error response without object mapper in WebClient onErrorResume
I wonder if there is a better way to get error response in WebClient in a way that does not involve using additional ObjectMapper when calling onErrorResume?
In my WebClient:
import…

pixel
- 24,905
- 36
- 149
- 251
3
votes
1 answer
How to build URI with UriBuilder without specifying scheme, host separately?
Ref: org.springframework.web.util.UriBuilder
I am using UriBuilder to build a URI for an endpoint
final String response = myWebClient.get()
.uri(uriBuilder -> uriBuilder.scheme("https").path("example.com/mypage").path("/{id}.xml").build(id))
…

Saif
- 2,530
- 3
- 27
- 45
3
votes
0 answers
How to set netty log level on selected spring boot Webclient instances
We have 2 different instances of spring boot Webclients. We want one of them to log all requests/responses and the other to log nothing. Settiing:
logging.level.reactor.netty.http.client=debug
in the application.properties file causes both…

Fredo
- 111
- 1
- 2
- 4
3
votes
1 answer
Spring WebClient how to log each retry at INFO level?
I have following WebClient - makes http call to localhost:8090 - bean defined:
@Configuration
class WebClientConfig {
@Bean
public WebClient webClientBean() {
return WebClient.create("http://localhost:8090");
}
}
And a call…

夢のの夢
- 5,054
- 7
- 33
- 63
3
votes
0 answers
Java Spring Security WebClient Threw SSLHandshakeException when used with ServerOAuth2AuthorizedClientExchangeFilterFunction
I am trying to call a customer's endpoint to retrieve their data using WebClient. We have to use certificate when calling the endpoint. I configured the WebClient with filter (to handle auto-refresh of the access token) and also with httpclient…

jlp
- 1,656
- 6
- 33
- 48
3
votes
0 answers
Spring security context propagation through webClient Future Chain
TLDR: Security context is not propagated to the chained future produced by Mono.toFuture() when making a WebClient request.
I have a web application that is using spring security OAuth2 to enforce authorization on controllers. The application uses…

Matthew.Lothian
- 2,072
- 17
- 23
3
votes
0 answers
Spring WebFlux - Distinguish exception types
I have to handle different exceptions in the Spring WebFlux chain. There is a WebClient and I need to have the logic, which would look like below code using the imperative style:
try {
} catch (WebClientResponseException e) {
// flow 1
} catch…

Rahul
- 1,727
- 3
- 18
- 33
3
votes
2 answers
In Spring WebClient used with block(), get body on error
I am using WebClient from Spring WebFlux to communicate with a REST API backend from a Spring client.
When this REST API backend throws an exception, it answers with a specific format (ErrorDTO) that I would like to collect from my client.
What I…

kevinls
- 31
- 1
- 5
3
votes
1 answer
Spring-Boot WebClient block() method returns error java.lang.IllegalStateException
I'm trying to fetch value(string) using Spring WebFlux WebClient, (Using SpringBoot version 2.4.5,)
@GetMapping("/test")
public Mono getData(){
WebClient webClient = WebClient.create("http://localhost:9999");
Mono stringMono…

Gautam Garg
- 56
- 1
- 1
- 7
3
votes
1 answer
How to correctly simulate latency with Spring WebClient
I want to add code that would simulate latency in my WebClient calls so I could ensure my timeouts/retries/etc are working correctly.
Since WebClient is reactive and uses a thread pool, it seems like Thread.sleep would block the thread in a way that…

checketts
- 14,167
- 10
- 53
- 82
3
votes
1 answer
java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
Spring boot version 2.4.4
Java version 15
@Bean
public WebClient webClient() {
return WebClient.builder().baseUrl(BASE_URL)
.defaultHeaders(header -> header.setBasicAuth("test",
"testpwd"))
…

user1578872
- 7,808
- 29
- 108
- 206