Jersey records all service response times
2 answers
I added a filter for all service requests and it works great:
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain p_filterChain) throws IOException, ServletException {
long startTime = System.currentTimeMillis();
String url = "unknown";
if (request instanceof HttpServletRequest) {
url = ((HttpServletRequest)request).getRequestURL().toString();
String queryString = ((HttpServletRequest)request).getQueryString();
if(queryString != null)
url += "?" + queryString;
}
p_filterChain.doFilter(request, response);
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
LogManager logm = new LogManager();
logm.newLog(url,elapsedTime);
System.out.println("Request: " + url + " " + elapsedTime + "ms");
}
+1
source to share
Jersey event listeners
should be what you need.
There are two options for this event listeners
, as stated in their monitoring and tracking docs :
ApplicationEventListener
to listen for application events, andRequestEventListener
to listen for request processing events.Only the first type, ApplicationEventListener, can be directly registered as an application provider. RequestEventListener is for each specific request and can only be returned from the ApplicationEventListener itself.
+4
source to share