Class HttpClient

  • Direct Known Subclasses:
    HttpURLConnectionClient

    public abstract class HttpClient
    extends java.lang.Object
    Base abstract class for HTTP clients used to send requests to Stripe's API.
    • Field Detail

      • maxNetworkRetriesDelay

        public static final java.time.Duration maxNetworkRetriesDelay
        Maximum sleep time between tries to send HTTP requests after network failure.
      • minNetworkRetriesDelay

        public static final java.time.Duration minNetworkRetriesDelay
        Minimum sleep time between tries to send HTTP requests after network failure.
    • Constructor Detail

      • HttpClient

        protected HttpClient()
        Initializes a new instance of the HttpClient class.
    • Method Detail

      • request

        public abstract StripeResponse request​(StripeRequest request)
                                        throws StripeException
        Sends the given request to Stripe's API, buffering the response body into memory.
        Parameters:
        request - the request
        Returns:
        the response
        Throws:
        StripeException - If the request fails for any reason
      • requestWithTelemetry

        public StripeResponse requestWithTelemetry​(StripeRequest request)
                                            throws StripeException
        Sends the given request to Stripe's API, handling telemetry if not disabled.
        Parameters:
        request - the request
        Returns:
        the response
        Throws:
        StripeException - If the request fails for any reason
      • requestStreamWithTelemetry

        public StripeResponseStream requestStreamWithTelemetry​(StripeRequest request)
                                                        throws StripeException
        Sends the given request to Stripe's API, streaming the response, and handling telemetry if not disabled.
        Parameters:
        request - the request
        Returns:
        the response
        Throws:
        StripeException - If the request fails for any reason
      • sendWithRetries

        public <T extends com.stripe.net.AbstractStripeResponse<?>> T sendWithRetries​(StripeRequest request,
                                                                                      com.stripe.net.HttpClient.RequestSendFunction<T> send)
                                                                               throws StripeException
        Throws:
        StripeException
      • requestWithRetries

        public StripeResponse requestWithRetries​(StripeRequest request)
                                          throws StripeException
        Sends the given request to Stripe's API, retrying the request in cases of intermittent problems.
        Parameters:
        request - the request
        Returns:
        the response
        Throws:
        StripeException - If the request fails for any reason
      • requestStreamWithRetries

        public StripeResponseStream requestStreamWithRetries​(StripeRequest request)
                                                      throws StripeException
        Sends the given request to Stripe's API, streaming the response, retrying the request in cases of intermittent problems.
        Parameters:
        request - the request
        Returns:
        the response
        Throws:
        StripeException - If the request fails for any reason
      • buildUserAgentString

        protected static java.lang.String buildUserAgentString()
        Builds the value of the User-Agent header.
        Returns:
        a string containing the value of the User-Agent header
      • buildXStripeClientUserAgentString

        protected static java.lang.String buildXStripeClientUserAgentString()
        Builds the value of the X-Stripe-Client-User-Agent header.
        Returns:
        a string containing the value of the X-Stripe-Client-User-Agent header