简体   繁体   中英

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.

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)

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM