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
Post a Comment