Class Builder<T,​U extends Builder<T,​U>>

  • Direct Known Subclasses:
    RxJavaHttpClient.Builder

    public abstract class Builder<T,​U extends Builder<T,​U>>
    extends java.lang.Object
    A Builder for RxHttpClient builders.
    • Field Detail

      • requestSigners

        protected java.util.List<RequestSigner> requestSigners
    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • build

        public T build()
      • createClient

        public abstract T createClient​(org.asynchttpclient.AsyncHttpClient innerClient,
                                       RestClientConfig rcConfig,
                                       ClientRequestLogFormatter logFmt,
                                       RequestSigner... signers)
        This is for internal use only. Clients are advised NOT to use this methode.
        Parameters:
        innerClient -
        rcConfig -
        logFmt -
        signers -
        Returns:
      • addRequestSigner

        public U addRequestSigner​(RequestSigner requestSigner)
      • setAccept

        public U setAccept​(java.lang.String acceptHeaderValue)
        Sets the default Accept request-header for requests built using this instance.
        Parameters:
        acceptHeaderValue - the Media-range and accept-params to use as value for the Accept request-header field
        Returns:
        (U)this Builder
        See Also:
        W3C HTTP 1.1 specs.
      • setBaseUrl

        public U setBaseUrl​(java.lang.String url)
        Sets the base URL for this client.

        The base url will be prepended to any relative URL path specified in the RequestBuilder

        Parameters:
        url - the base URL for this instance
        Returns:
        (U)this.Builder
      • setMaxConnections

        public U setMaxConnections​(int maxConnections)
        Set the maximum number of connections an AsyncHttpClient can handle.
        Parameters:
        maxConnections - the maximum number of connections an AsyncHttpClient can handle.
        Returns:
        a Builder
      • setAllowPoolingConnections

        @Deprecated
        public U setAllowPoolingConnections​(boolean allowPoolingConnections)
        Deprecated.
        Use setKeepAlive(boolean) instead
        Set true if connection can be pooled by a ChannelPool. Default is true.
        Parameters:
        allowPoolingConnections - true if connection can be pooled by a ChannelPool
        Returns:
        a Builder
      • setKeepAlive

        public U setKeepAlive​(boolean keepAlive)
        Set true if connection can be pooled by a ChannelPool. Default is true.
        Parameters:
        keepAlive - true if connection can be pooled by a ChannelPool
        Returns:
        a Builder
      • setThrottling

        public U setThrottling​(int maxWait)
        Throttles requests by blocking until connections in the pool become available, waiting for the response to arrives before executing the next request.
        Parameters:
        maxWait - timeout in millisceconds
        Returns:
        (U)this Builder
      • setConnectTimeout

        public U setConnectTimeout​(int connectTimeOut)
        Set the maximum time in millisecond an AsyncHttpClient can wait when connecting to a remote host
        Parameters:
        connectTimeOut - the maximum time in millisecond an AsyncHttpClient can wait when connecting to a remote host
        Returns:
        a Builder
      • setThreadFactory

        public U setThreadFactory​(java.util.concurrent.ThreadFactory threadFactory)
        Set the ExecutorService an AsyncHttpClient uses for handling asynchronous response.

        Parameters:
        threadFactory - the threadFactory an AsyncHttpClient use for handling asynchronous response.
        Returns:
        a Builder
      • setMaxRequestRetry

        public U setMaxRequestRetry​(int maxRequestRetry)
        Set the number of time a request will be retried when an IOException occurs because of a Network exception.
        Parameters:
        maxRequestRetry - the number of time a request will be retried
        Returns:
        (U)this
      • setEnabledProtocols

        public U setEnabledProtocols​(java.lang.String[] enabledProtocols)
      • setEnabledCipherSuites

        public U setEnabledCipherSuites​(java.lang.String[] enabledCipherSuites)
      • setUseProxyProperties

        public U setUseProxyProperties​(boolean useProxyProperties)
        Sets whether AHC should use the default http.proxy* system properties to obtain proxy information. This differs from setUseProxySelector(boolean) in that AsyncHttpClient will use its own logic to handle the system properties, potentially supporting other protocols that the the JDK ProxySelector doesn't.

        If useProxyProperties is set to true but setUseProxySelector(boolean) was also set to true, the latter is preferred.

        See http://download.oracle.com/javase/1.4.2/docs/guide/net/properties.html

        Parameters:
        useProxyProperties - whether AHC should use the default http.proxy* system properties
      • setUseProxySelector

        public U setUseProxySelector​(boolean useProxySelector)
        Sets whether AHC should use the default JDK ProxySelector to select a proxy server.

        See http://docs.oracle.com/javase/7/docs/api/java/net/ProxySelector.html

        Parameters:
        useProxySelector - whether AHC should use the default JDK ProxySelector to select a proxy server.
      • setMaxRedirects

        public U setMaxRedirects​(int maxRedirects)
        Set the maximum number of HTTP redirect
        Parameters:
        maxRedirects - the maximum number of HTTP redirect
        Returns:
        a Builder
      • setAcceptAnyCertificate

        public U setAcceptAnyCertificate​(boolean acceptAnyCertificate)
      • setUseInsecureTrustManager

        public U setUseInsecureTrustManager​(boolean useInsecureTrustManager)
      • setStrict302Handling

        public U setStrict302Handling​(boolean strict302Handling)
        Configures this AHC instance to be strict in it's handling of 302 redirects in a POST/Redirect/GET situation.
        Parameters:
        strict302Handling - strict handling
        Returns:
        (U)this
        Since:
        1.7.2
      • setConnectionTTL

        public U setConnectionTTL​(int connectionTTL)
        Set the maximum time in millisecond connection can be added to the pool for further reuse

        Default is -1 (no TTL set)

        Parameters:
        connectionTTL - the maximum time in millisecond connection can be added to the pool for further reuse
        Returns:
        a Builder
      • setUserAgent

        public U setUserAgent​(java.lang.String userAgent)
        Set the USER_AGENT header value
        Parameters:
        userAgent - the USER_AGENT header value
        Returns:
        a Builder
      • setFollowRedirect

        public U setFollowRedirect​(boolean followRedirect)
        Set to true to enable HTTP redirect
        Parameters:
        followRedirect -
        Returns:
        a Builder
      • setDisableUrlEncodingForBoundedRequests

        @Deprecated
        public U setDisableUrlEncodingForBoundedRequests​(boolean disableUrlEncodingForBoundedRequests)
        Deprecated.
        Use setDisableUrlEncodingForBoundRequests
        Disable automatic url escaping
        Parameters:
        disableUrlEncodingForBoundedRequests - disables the url encoding if set to true
        Returns:
        (U)this Builder
      • setDisableUrlEncodingForBoundRequests

        public U setDisableUrlEncodingForBoundRequests​(boolean disableUrlEncodingForBoundedRequests)
        Disable automatic url escaping
        Parameters:
        disableUrlEncodingForBoundedRequests - disables the url encoding if set to true
        Returns:
        (U)this Builder
      • setRequestTimeout

        public U setRequestTimeout​(int requestTimeout)
        Set the maximum time in millisecond an AsyncHttpClient waits until the response is completed.
        Parameters:
        requestTimeout - the maximum time in millisecond an AsyncHttpClient waits until the response is completed.
        Returns:
        a Builder
      • setSslContext

        public U setSslContext​(io.netty.handler.ssl.SslContext sslContext)
        Set the SslContext for secure connection.
        Parameters:
        sslContext - the SSLContext for secure connection
        Returns:
        a Builder
      • setCompressionEnforced

        public U setCompressionEnforced​(boolean compressionEnforced)
        Enforce HTTP compression.
        Parameters:
        compressionEnforced - true if compression is enforced
        Returns:
        a Builder
      • setPooledConnectionIdleTimeout

        public U setPooledConnectionIdleTimeout​(int pooledConnectionIdleTimeout)
        Set the maximum time in millisecond an AsyncHttpClient will keep connection idle in pool.

        Default is 60000 millis (1 min.)

        Parameters:
        pooledConnectionIdleTimeout -
        Returns:
        a Builder
      • setReadTimeout

        public U setReadTimeout​(int readTimeout)
        Set the maximum time in millisecond an AsyncHttpClient can stay idle.
        Parameters:
        readTimeout - the maximum time in millisecond an RestClient can stay idle.
        Returns:
        a Builder
      • setAwsEndPoint

        public U setAwsEndPoint​(AwsService service,
                                AwsRegion region,
                                java.lang.String domain)
      • logHeaders

        public U logHeaders​(java.util.List<java.lang.String> headerNames)
      • logFormParams

        public U logFormParams​(java.util.List<java.lang.String> formParameterNames)