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?
JavaScript
x
private ClientResponse executeRequest(WebClient.RequestHeadersSpec<?> spec,
RequestContext requestContext,
String requestBody) {
logRequest(requestContext, requestBody);
return spec
.exchange()
.blockOptional()
.orElseThrow(() -> new InternalException(String.format("%s: can't extract response from method "%s"", externalServiceName, requestContext.getApiMethodName())));
}
Advertisement
Answer
You can use retrieve()
method as suggested in exchange()
documentation something like below:
JavaScript
return
spec.retrieve().bodyToMono(ClientResponse.class).blockOptional()
.orElseThrow(() -> new InternalException(String.format("%s: can't extract response from method "%s"",
externalServiceName, requestContext.getApiMethodName())));