added an ExchangeFilterFunction to WebClient which logs request and response but while logging, was unable to log request and response body as a string or JSON. It prints as an object
Tried different castings and retrieving the body as a string using bodyToMono, toEntity but they return an object and not string exactly.
logRequest(clientRequest.url(), clientRequest.method(), clientRequest.headers(), clientRequest.body());
Mono<ClientResponse> response = exchangeFunction.exchange(clientRequest);
ClientResponse clientResponse = response.block();
logResponse(clientResponse.statusCode(), clientResponse.headers(), clientResponse.toString(), clientResponse);
return response;
}```
```private void logRequest(URI uri, HttpMethod method, HttpHeaders httpHeaders, BodyInserter<?, ? super ClientHttpRequest> body) {
log.info("Request: {}",
LogVar.with("Body", body)
);
}
private void logResponse(HttpStatus statusCode, Headers headers, String body, ClientResponse extractor) {
log.info("Response: {}",
, LogVar.with("Body", extractor.bodyToMono(String.class))
);
}```
Expecting Json OR XML whatever the request/response is, to be logged as a string.