Skip to content
Advertisement

@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:

//works
MyItem myItem = webClient.get()
    .uri(url + "/items/" + tenant + "/" + itemId)
    .accept(MediaType.APPLICATION_JSON)
    .retrieve()
    .bodyToMono(MyItem.class)
    .block();
//returns without triggering the @DeleteMapping endpoint
Mono<Void> resp = webClient.delete()
    .uri(url + "/items/" + tenant + "/" + itemId)
    .retrieve()
    .bodyToMono(Void.class)
    .then();

The endpoints are:

@RestController
@RequestMapping("/items/{tenant}")
public class ItemController {
    @GetMapping("/{id}")
    public MyItem findById(@PathVariable String id, @PathVariable String tenant, Authentication auth) {
        ...
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable String id, @PathVariable String tenant, Authentication auth) {
        ...
        // breakpoint somewhere here
        ...
    }
}

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 the endpoint seems to not be triggered at all (I put a breakpoint inside the deleteById method, nothing happened).

Any clues why this is happening?

Advertisement

Answer

That stream:

Mono<Void> resp = webClient.delete()
    .uri(url + "/items/" + tenant + "/" + itemId)
    .retrieve()
    .bodyToMono(Void.class)
    .then();

is not subscribed, you have to use block() or subscribe() at the end of stream to perform delete request.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement