Package com.guinetik.rr.interceptor
Class InterceptingClient
- java.lang.Object
-
- com.guinetik.rr.interceptor.InterceptingClient
-
- All Implemented Interfaces:
RocketClient
public class InterceptingClient extends Object implements RocketClient
Decorator that adds interceptor chain support to anyRocketClient.This client wraps another RocketClient and applies a chain of interceptors to every request. Interceptors can modify requests, transform responses, and handle errors including retry logic.
Interceptor Execution Order
Request Flow: beforeRequest(Interceptor 1) → beforeRequest(Interceptor 2) → ... → delegate.execute() Response Flow: delegate.execute() → ... → afterResponse(Interceptor 2) → afterResponse(Interceptor 1) Error Flow: exception → onError(Interceptor 1) → onError(Interceptor 2) → ...
Usage
RocketClient baseClient = new DefaultHttpClient("https://api.example.com"); List<RequestInterceptor> interceptors = new ArrayList<>(); interceptors.add(new LoggingInterceptor()); interceptors.add(new RetryInterceptor(3, 1000)); RocketClient client = new InterceptingClient(baseClient, interceptors);- Since:
- 1.1.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
RequestInterceptor,RocketClient
-
-
Constructor Summary
Constructors Constructor Description InterceptingClient(RocketClient delegate, List<RequestInterceptor> interceptors)Creates an intercepting client with the given interceptors.InterceptingClient(RocketClient delegate, List<RequestInterceptor> interceptors, int maxRetries)Creates an intercepting client with the given interceptors and retry limit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureSsl(SSLContext sslContext)Sets the SSL context to be used for HTTPS requests.<Req,Res>
Resexecute(RequestSpec<Req,Res> requestSpec)Executes an HTTP request based on the provided request specification.List<RequestInterceptor>getInterceptors()Gets the list of interceptors in execution order.voidsetBaseUrl(String baseUrl)
-
-
-
Constructor Detail
-
InterceptingClient
public InterceptingClient(RocketClient delegate, List<RequestInterceptor> interceptors)
Creates an intercepting client with the given interceptors.- Parameters:
delegate- The underlying client to wrapinterceptors- The interceptors to apply (will be sorted by order)
-
InterceptingClient
public InterceptingClient(RocketClient delegate, List<RequestInterceptor> interceptors, int maxRetries)
Creates an intercepting client with the given interceptors and retry limit.- Parameters:
delegate- The underlying client to wrapinterceptors- The interceptors to apply (will be sorted by order)maxRetries- The maximum number of retries allowed
-
-
Method Detail
-
execute
public <Req,Res> Res execute(RequestSpec<Req,Res> requestSpec) throws RocketRestException
Description copied from interface:RocketClientExecutes an HTTP request based on the provided request specification.- Specified by:
executein interfaceRocketClient- Type Parameters:
Req- The type of the request body.Res- The type of the response.- Parameters:
requestSpec- The specification of the request to be executed.- Returns:
- The response object.
- Throws:
RocketRestException- If an error occurs during the request execution.
-
configureSsl
public void configureSsl(SSLContext sslContext)
Description copied from interface:RocketClientSets the SSL context to be used for HTTPS requests.- Specified by:
configureSslin interfaceRocketClient- Parameters:
sslContext- The SSL context to use.
-
setBaseUrl
public void setBaseUrl(String baseUrl)
- Specified by:
setBaseUrlin interfaceRocketClient
-
getInterceptors
public List<RequestInterceptor> getInterceptors()
Gets the list of interceptors in execution order.- Returns:
- Unmodifiable list of interceptors
-
-