I am trying to define a generic method which takes responseHandler method as parameter and pass it to exchangeToMono method to avoid writing the lambda expression in the exchangeToMono which is discussed in almost all the internet and SO questions. How can I achieve this, I tried a various ways but it is not working.
public static Function<ClientResponse, Mono<Object>> clientResponseMonoFunction = response1 -> {
if (response1.statusCode().equals(HttpStatus.OK)) {
return response1.bodyToMono(Object.class);
} else {
// Turn to error
return null;
}
};
Mono<Object> retriveMono(Function responseHandler) {
return webClient.method(httpMethod).uri(uri).headers(headers).body(Mono.just(request), Object.class).exchangeToMono(MyTestClass::clientResponseMonoFunction); // This did not i.e. static method reference
Nothing is happenning unless I call subscribe method, but none of the examples in SO I read so far mentioned to use subscribe
Want to understand if I am missing anything or where I am doing wrong