I am using ExchangeFilterFunction to log requests and responses but I don't know how I can get the request/response body as a string or JSON format and log it.
The code looks as follows:
//logging method, url and headers, but the body of the request is needed
fun logClientRequest(): ExchangeFilterFunction {
return ExchangeFilterFunction.ofRequestProcessor() {
logger.info("Client CRM Request: {} {}", it.method(), it.url());
//TODO: LOG HERE BODY REQUEST
it.headers().forEach { name, values ->
run {
logger.info("Headers:")
values.forEach { value -> logger.info("{}={}", name, value) }
}
}
Mono.just(it)
}
}
fun logClientResponse(): ExchangeFilterFunction {
return ExchangeFilterFunction.ofResponseProcessor() {
logger.info("Client CRM Response {}", it.bodyToFlux(Any::class.java))
Mono.just(it)
}
}
The bodyToFlux in logClientResponse() logs only:
ExchangeFilterFunction Client CRM Response checkpoint("Body from PUT https:myurl [DefaultClientResponse]")