Update Deprecated Reactor Usage

This commit is contained in:
Josh Cummings 2025-04-22 13:31:58 -06:00
parent 834370d8eb
commit eecd7d9559
No known key found for this signature in database
GPG Key ID: 869B37A20E876129
3 changed files with 8 additions and 7 deletions

View File

@ -84,9 +84,7 @@ public abstract class AbstractWebClientReactiveOAuth2AccessTokenResponseClient<T
Assert.notNull(grantRequest, "grantRequest cannot be null");
// @formatter:off
return Mono.defer(() -> this.requestEntityConverter.convert(grantRequest)
.exchange()
.flatMap((response) -> response.body(this.bodyExtractor))
);
.exchangeToMono((response) -> response.body(this.bodyExtractor)));
// @formatter:on
}

View File

@ -105,7 +105,6 @@ public class SpringReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
// @formatter:off
return Mono.just(token)
.flatMap(this::makeRequest)
.flatMap(this::adaptToNimbusResponse)
.map(this::convertClaimsSet)
.flatMap(this.authenticationConverter::convert)
.cast(OAuth2AuthenticatedPrincipal.class)
@ -113,13 +112,13 @@ public class SpringReactiveOpaqueTokenIntrospector implements ReactiveOpaqueToke
// @formatter:on
}
private Mono<ClientResponse> makeRequest(String token) {
private Mono<Map<String, Object>> makeRequest(String token) {
// @formatter:off
return this.webClient.post()
.uri(this.introspectionUri)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.body(BodyInserters.fromFormData("token", token))
.exchange();
.exchangeToMono(this::adaptToNimbusResponse);
// @formatter:on
}

View File

@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.mockwebserver.Dispatcher;
@ -322,7 +323,10 @@ public class SpringReactiveOpaqueTokenIntrospectorTests {
ClientResponse.Headers headers = mock(ClientResponse.Headers.class);
given(headers.contentType()).willReturn(Optional.of(MediaType.APPLICATION_JSON));
given(clientResponse.headers()).willReturn(headers);
given(spec.exchange()).willReturn(Mono.just(clientResponse));
given(spec.exchangeToMono(any())).willAnswer((invocation) -> {
Function<ClientResponse, Mono<ClientResponse>> fun = invocation.getArgument(0);
return fun.apply(clientResponse);
});
return webClient;
}