Using WebClient I want to handle ClientResponse separately according to HTTP status codes. Below you see two new subscribe() method used in top doOnSuccess. How can I carry those nested Monos to WebClient's Mono chain? That is to say, how to eliminate inner monos.
webClient.post()
.uri( soapServiceUrl )
.contentType(MediaType.TEXT_XML)
//.body(Mono.just(req), String.class )
.body( Mono.just(getCountryRequest) , GetCountryRequest.class )
.exchange()
.filter( (ClientResponse response) -> { return true; } )
.doOnSuccess( (ClientResponse response) -> {
//nested mono 1
if( response.statusCode().is5xxServerError() ){
response.toEntity(String.class).doOnSuccess(
error -> {
System.out.println("error : "+ error);
}).subscribe();
}
//nested mono 2
if( response.statusCode().is2xxSuccessful() ){
response.toEntity(GetCountryResponse.class).doOnSuccess(
getCountryResponse -> {
System.out.println("success : "+ getCountryResponse.getBody().getCountry().getCapital());
}).subscribe();
}
})
.doOnError( (Throwable error) -> {
System.out.println( "getCountryResponse.error : "+ error );
})
.subscribe();