I have created a reusable method that returns the headers, status, and body of an HTTP call using the Spring webclient’s exchange method. I want to capture the 4xx and 5xx errors in the method itself and log the response body. However, i am not able to return/throw custom exception when 4xx or 5xx error…
Tag: webclient
@DeleteMapping endpoint not triggered at all
My webClient calls work fine with @GetMapping, but @DeleteMapping isn’t even triggered. Here are the two methods I’m using: The endpoints are: When I try to delete an item I get no errors, no 405, no 400, no 403, nothing. The webClient call returns normally (with a MonoIgnorePublisher object), but…
How to refactor the deprecated method .exchange()?
I have next method that uses in AbstractWebClient. How can I refactor it to get rid of deprecated .exchange() and save availability to work in abstract way? Answer You can use retrieve() method as suggested in exchange() documentation something like below:
Java Specific webclient connect timeout per request
I have to call different urls with different connection timeout with webclient. But i found that we can set connect timeout globally only and not per resquest .. what to do please to set this timeout on a request without creating a new weblient each time. Answer You need to instantiate one webclient per url. …
Unable to receive data out of api call with webclient
So I’m trying to get my head around the webclient, but I keep getting a nullpointerexception, though my test work fine and say that object is not null. I also see my console making connection to the api. But when I ask the value, I get null. Here are the two objects I use for it: and then here I
How to handle UnsupportedMediaTypeException in Spring Boot?
Hello I’m trying to call API by using Webclient in spring boot. But I’m having some issue. Although the response I requested is a json response, the server gives me an xml response when server error occur. So I am getting UnsupportedMediaTypeException error when server error occur. Therefore I wou…
How i return Empty mono if the request doesn’t return error using webClient
i want to know how return a empty Mono when i use webClient, i have this code and it works when the request return a user. Answer First of all, don’t use block() if you really want to take full advantage of using reactive stack. With it you are blocking the thread to wait for a response, don’t do …
In the Response, i am getting scanAvailable=true when returning flux as ResponseEntity
I am slightly confused to get the proper response when the user tries to use two rest endpoints with WebClient. I want to use it as asynchronous and non-blocking in the code. I am returning the Flux from the controller. The code details are as below: The Controller Class method looks like this: It is calling …
Repeatedly filter a response using Spring WebClient
I’m new to Spring and even newer to WebClient. I want to filter the body of a Get response repeatedly with one second intervals for 2 minute duration using Springs’ WebClient. I’m performing a get request which returns an empty JSON list of strings. At some moment of time the body is going t…
WebClient – adding defaultHeaders
I’m trying to put multiple headers into defaultHeaders(), But I don’t have idea how to create Consumer object from return of createHeaders() method I can build my header in that way: but how to wrap it into Consumer? Answer Clearly the method doc says that it needs a Consumer of some Type. So you …