问题描述
我正在使用ExchangeFilterFunction记录请求和响应,但是我不知道如何以字符串或JSON格式获取请求/响应主体并将其记录。
代码如下:
//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)
}
}
logClientResponse()中的bodyToFlux仅记录:
ExchangeFilterFunction Client CRM Response checkpoint("Body from PUT https:myurl [DefaultClientResponse]")
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)