I have recently started reactive programming and trying to call a method which should return an Object, but i am getting the error of block()/blockFirst()...while calling that method. Below is the method which i am trying to call
private MyOrderResponse callmyOrderSvc(String path,Log log){
return WebClient.create().get()
.uri(myOrderSvcUrl +OrderConstant.SEP+path)
.header(OrderConstant.SECRETKEY,apiKey)
.retrieve()
.onStatus(HttpStatusCode :: isError,
response -> response.bodyToMono(MyOrderResponse.class)
.flatMap(error ->{
LogUtil.logError(logger,"Error occurred",error.getMessage());
return Mono.error(new CustomException(error.getMessage(),log.getId(),HttpStatus)));
}))
.bodyToMono(MyOrderResponse.class).block();
}
And this method is being called by another method which is also returning some object, like this below
public MyOrderDetailsResponse getMyOrderId(String Id,String type,Log log){
MyOrderResponse myOrderResponse;
myOrderResponse = callmyOrderSvc(path,log); //this method is calling the callmyOrderSvc which is returning and Object of MyOrderResponse
The criteria is i can not return Mono from here , i have to return MyOrderResponse Object. Any help is appreciated.