Package com.chargebee.v4.client.request
Interface RequestInterceptor
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Functional interface for intercepting and customizing API requests.
Interceptors can modify requests (e.g., add headers, logging, metrics) or completely override request execution. They are invoked before sending requests to the Chargebee API.
RequestInterceptor loggingInterceptor = requestWrap -> {
System.out.println("Request: " + requestWrap.getRequest().getUrl());
return requestWrap.proceed(); // Continue with normal execution
};
ChargebeeClient client = ChargebeeClient.builder()
.apiKey("cb_test_...")
.siteName("acme")
.requestInterceptor(loggingInterceptor)
.build();
Thread Safety: Implementations should be thread-safe if shared across multiple clients or requests, as the same interceptor instance may be called concurrently.
Performance: Avoid blocking operations in interceptors to maintain request performance. Consider async logging or metrics collection for minimal overhead.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionhandleRequest(RequestWrap requestWrap) Handle the intercepted request.default CompletableFuture<Response>handleRequestAsync(RequestWrap requestWrap) Handle the intercepted request asynchronously.
-
Method Details
-
handleRequest
Handle the intercepted request.The interceptor can:
- Examine the request (URL, headers, method, body)
- Modify request properties before proceeding
- Log or collect metrics
- Call
requestWrap.proceed()to continue normal execution - Return a custom
Responseto bypass normal execution
- Parameters:
requestWrap- wrapper containing the transport request and execution context- Returns:
- the transport response, either from proceeding or custom implementation
- Throws:
ChargebeeException- if request processing fails
-
handleRequestAsync
Handle the intercepted request asynchronously.The default implementation calls the synchronous
handleRequestmethod and wraps the result in a CompletableFuture. Interceptors that need true async behavior should override this method.The interceptor can:
- Examine the request (URL, headers, method, body)
- Modify request properties before proceeding
- Log or collect metrics asynchronously
- Call
requestWrap.proceedAsync()to continue normal execution - Return a custom
Responseto bypass normal execution
- Parameters:
requestWrap- wrapper containing the transport request and execution context- Returns:
- a CompletableFuture that will complete with the transport response
-