Interface RestCallInterceptor
- All Known Implementing Classes:
McpAuthInterceptor
RestClient.
Registered on the client builder via RestClient.Builder.interceptors(RestCallInterceptor...).
All callbacks have default no-op implementations so implementations only need to override the hooks they care about.
Example:
RestClient
See Also:
- Since:
- 9.2.1
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidonClose(RestRequest req, RestResponse res) Called when the request is being closed (in thefinallyblock ofRestRequest.run()).default voidonConnect(RestRequest req, RestResponse res) Called after a response has been received from the transport.default voidonInit(RestRequest req) Called before the transport request is built and sent.
-
Method Details
-
onInit
Called before the transport request is built and sent.Use this hook to add headers, modify query parameters, or short-circuit the call.
- Parameters:
req- The request being built. Nevernull .- Throws:
Exception- If the call should be aborted.
-
onConnect
Called after a response has been received from the transport.Use this hook to inspect status codes, validate headers, or modify how the response is interpreted.
- Parameters:
req- The request that was sent. Nevernull .res- The response received. Nevernull .- Throws:
Exception- If a post-connect error should be raised.
-
onClose
Called when the request is being closed (in thefinallyblock ofRestRequest.run()).This is called regardless of whether the call succeeded or failed, and is always invoked before the logger receives its entry. Use it for cleanup, metrics recording, or span/trace finalization.
- Parameters:
req- The request. Nevernull .res- The response, ornull if the transport failed before a response was received.- Throws:
Exception- If an error occurs during close handling.
-