Class InterceptingClient

  • All Implemented Interfaces:
    RocketClient

    public class InterceptingClient
    extends Object
    implements RocketClient
    Decorator that adds interceptor chain support to any RocketClient.

    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 Detail

      • InterceptingClient

        public InterceptingClient​(RocketClient delegate,
                                  List<RequestInterceptor> interceptors)
        Creates an intercepting client with the given interceptors.
        Parameters:
        delegate - The underlying client to wrap
        interceptors - 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 wrap
        interceptors - 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: RocketClient
        Executes an HTTP request based on the provided request specification.
        Specified by:
        execute in interface RocketClient
        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: RocketClient
        Sets the SSL context to be used for HTTPS requests.
        Specified by:
        configureSsl in interface RocketClient
        Parameters:
        sslContext - The SSL context to use.
      • getInterceptors

        public List<RequestInterceptor> getInterceptors()
        Gets the list of interceptors in execution order.
        Returns:
        Unmodifiable list of interceptors