java - Is there a way to intercept the Jersey Client API both before and after the request? -


i need time jersey client (v1.17). see can use filter request not end of call (response).

doable?

got , embarassed how easy is...

public class jerseyclientfilter extends clientfilter {      @override     public clientresponse handle(clientrequest request) {         long starttime = system.currenttimemillis();          // execute call...         clientresponse response = getnext().handle(request);          // build log...         stringbuilder sb = new stringbuilder();         sb.append("http:").append(response.getstatus());         sb.append(" - time:[").append(system.currenttimemillis() - starttime).append("ms]");         sb.append(" - user:").append(this.findlogon(request));         sb.append(" - path:").append(request.geturi());         sb.append(" - content-type:").append(request.getheaders().get(httpheaders.content_type));         sb.append(" - accept:").append(request.getheaders().get(httpheaders.accept));         sb.append(" - requestbody:").append(request.getentity() != null ? request.getentity().tostring() : "none");         sb.append(" - responsebody:").append(this.logresponse(response));          new tmaticwsinfoevent(tmaticwsconstants.log_outbound_rest, this, request.getmethod(), sb.tostring());         return response;     } 

so extend clientfilter , inject this: this.theclient.addfilter(new jerseyclientfilter); bam!

if want understand this, check out jersey "loggingfilter". lots of stuff there...


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -