-
Notifications
You must be signed in to change notification settings - Fork 60
Interceptors
Matija Mazi edited this page May 27, 2015
·
4 revisions
Rescu Interceptors are a simple way to apply the same cross-cutting concern to all HTTP method calls issued by rescu. Examples might include:
- adding a fixed set of HTTP headers to each request,
- logging of each request,
- timing of each request,
- custom handling of response properties like HTTP response codes,
- etc.
An Interceptor is a class that implements si.mazi.rescu.Interceptor
. The implementation must call the invoke
method of the passed InvocationHandler
with the passed parameters. Here's an example that logs method call duration:
class LoggingInterceptor implements Interceptor {
@Override
public Object aroundInvoke(InvocationHandler h, Object proxy, Method m, Object[] args)
throws Throwable {
long start = System.currentTimeMillis();
Object result = h.invoke(proxy, m, args);
System.out.printf("%s took %s ms.%n", m.getName(), System.currentTimeMillis() - start);
return result;
}
}