NG Interceptors
A RestCallInterceptor observes
or modifies a call at three points. All methods have no-op defaults, so implement only what you need.
public interface RestCallInterceptor {
default void onInit(RestRequest req) throws Exception {}
default void onConnect(RestRequest req, RestResponse res) throws Exception {}
default void onClose(RestRequest req, RestResponse res) throws Exception {}
}
| Hook | Runs | Typical use |
|---|---|---|
onInit | After the request is built, before it is sent. | Add headers (signing, correlation ids). |
onConnect | After the response status and headers arrive, before the body is read. | Metrics, auth refresh checks. |
onClose | In run()'s finally block, before the debug logger; res can be null if the call failed before a response. | Cleanup, timing. |
RestCallInterceptor stamp = new RestCallInterceptor() {
@Override public void onInit(RestRequest req) {
req.header("X-Start", String.valueOf(System.nanoTime()));
}
};
RestClient client = RestClient.builder().interceptors(stamp).build();
Registration and order
Interceptors can be registered on the client builder, on a @Remote interface, on a @RemoteOp method,
or on a single request with RestRequest.interceptors(...). They run in that order
(builder, interface, method/request). The built-in request-id interceptor always runs first; it adds a
UUIDv7 X-Request-Id header unless you disable it with sendRequestId(false) or set your own with
requestId(...).
See Declarative Remote-Proxy Features for the annotation forms, and Logging and Debugging for the debug pipeline.