title: Adding a retry all requests of WebClient
body: <p>we have a server to retrieve a OAUTH token, and the oauth token is added to each request via WebClient.filter method
  e.g</p>
  
  <pre><code>webClient
                  .mutate()
                  .filter((request, next) -&gt; tokenProvider.getBearerToken()
                          .map(token -&gt; ClientRequest.from(request)
                                  .headers(httpHeaders -&gt; httpHeaders.set("Bearer", token))
                                  .build()).flatMap(next::exchange))
                  .build();
  TokenProvider.getBearerToken returns Mono&lt;String&gt; since it is a webclient request (this is cached)
  </code></pre>
  
  <p>I want to have a retry functionality that on 401 error, will invalidate the token and try the request again
  I have this working like so</p>
  
  <pre><code>webClient.post()
              .uri(properties.getServiceRequestUrl())
              .contentType(MediaType.APPLICATION_JSON)
              .body(fromObject(createRequest))
              .retrieve()
              .bodyToMono(MyResponseObject.class)
              .retryWhen(retryOnceOn401(provider))
  
  private Retry&lt;Object&gt; retryOnceOn401(TokenProvider tokenProvider) {
          return Retry.onlyIf(context -&gt; context.exception() instanceof WebClientResponseException &amp;&amp; ((WebClientResponseException) context.exception()).getStatusCode() == HttpStatus.UNAUTHORIZED)
                  .doOnRetry(objectRetryContext -&gt; tokenProvider.invalidate());
      }
  </code></pre>
  
  <p>is there a way to move this up to the webClient.mutate().....build() function?
  so that all requests will have this retry facility?</p>
  
  <p>I tried adding as a filter but it didn't seem to work e.g.</p>
  
  <pre><code>.filter(((request, next) -&gt; next.exchange(request).retryWhen(retryOnceOn401(tokenProvider))))
  </code></pre>
  
  <p>any suggestions of the best way to approach this?
  Regards</p>