Class RetryInterceptor

  • All Implemented Interfaces:
    IRetryInterceptor, okhttp3.Interceptor

    public class RetryInterceptor
    extends java.lang.Object
    implements IRetryInterceptor
    This class is an okhttp Interceptor implementation that will try to automatically retry failed requests, based on the type of failure that occurred. This class is configured with the following:
    • the maximum number of retries to attempt for a failed request
    • the maximum retry interval (in seconds) to wait between retry attempts
    • the Authenticator instance to use to authenticate each retry attempt
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  RetryInterceptor.RetryContext  
      • Nested classes/interfaces inherited from interface okhttp3.Interceptor

        okhttp3.Interceptor.Chain, okhttp3.Interceptor.Companion
    • Field Summary

      • Fields inherited from interface okhttp3.Interceptor

        Companion
    • Constructor Summary

      Constructors 
      Constructor Description
      RetryInterceptor​(int maxRetries, int maxRetryInterval, Authenticator authenticator)
      This ctor configures the RetryInterceptor instance with the max retries, retry interval and an authenticator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      okhttp3.Response intercept​(okhttp3.Interceptor.Chain chain)
      The "intercept()" method is the primary method of the interceptor.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RetryInterceptor

        public RetryInterceptor​(int maxRetries,
                                int maxRetryInterval,
                                Authenticator authenticator)
        This ctor configures the RetryInterceptor instance with the max retries, retry interval and an authenticator.
        Parameters:
        maxRetries - the maximum number of retries to attempt for a failed request
        maxRetryInterval - the maximum retry interval (in seconds) to wait between retry attempts
        authenticator - the Authenticator instance to use to authenticate retried requests
    • Method Detail

      • intercept

        public okhttp3.Response intercept​(okhttp3.Interceptor.Chain chain)
                                   throws java.io.IOException
        The "intercept()" method is the primary method of the interceptor. The chain of interceptors registered for a particular okhttp Client instance is in the form of an ordered list. When a request is invoked, each interceptor's "intercept" method is invoked and is passed the interceptor chain. The interceptor can inspect the request to determine how to proceed, and will invoke the interceptor chain's "proceed()" method to call the next interceptor in the chain. When the last interceptor invokes the chain's "proceed()" method, the request is sent over the wire and the response is returned via the return value of the proceed() method. The interceptor can then inspect the response and determine how to proceed. Ultimately the response is returned from this intercept() method and is ultimately propagated back through the chain's "proceed()" methods.
        Specified by:
        intercept in interface okhttp3.Interceptor
        Throws:
        java.io.IOException