[英]CXF call duration logging
I'm using custom cxf interceptors to log requests/responses for service calls and I would like to log the time it took the call along with the response. 我正在使用自定义cxf拦截器来记录服务调用的请求/响应,并且我想记录调用与响应一起花费的时间。
Is there any way to do this? 有什么办法吗?
You need to store the start time onto the Exchange
in your in-interceptor (if you are a server, out-interceptor if you're a client) 您需要将开始时间存储在拦截器中的
Exchange
上(如果您是服务器,则将拦截器存储在Exchange
中,如果您是客户端)
message.getExchange().put("com.myapp.startTime", System.currentTimeMillis());
and retrieve it in the out (respectively in) interceptor 并在外(分别在)拦截器中检索它
long timeTaken = System.currentTimeMillis() - (Long)message.getExchange().get("com.myapp.startTime");
Depending exactly where in the chain your existing interceptors sit you may want to do this in a dedicated pair of interceptors, with the in one as early as possible in the chain and the out one as late as possible (for a server, vice-versa if you're a client). 根据现有拦截器在链中的确切位置,您可能需要在专用的一对拦截器中执行此操作,在链中尽早插入一个,而在链中尽早退出(对于服务器,反之亦然)如果您是客户)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.