Class HttpClientBuilder


  • public final class HttpClientBuilder
    extends Object
    Creates a new HTTP client that connects to the specified URI using the builder pattern. Use the factory methods in HttpClient if you do not have many options to override. Please refer to ClientBuilder for how decorators and HTTP headers are configured
    • Method Detail

      • defaultWriteTimeout

        @Deprecated
        public B defaultWriteTimeout​(Duration writeTimeout)
        Deprecated.
        Sets the timeout of a socket write attempt.
        Parameters:
        writeTimeout - the timeout. 0 disables the timeout.
      • defaultWriteTimeoutMillis

        @Deprecated
        public B defaultWriteTimeoutMillis​(long writeTimeoutMillis)
        Deprecated.
        Sets the timeout of a socket write attempt in milliseconds.
        Parameters:
        writeTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.
      • writeTimeout

        public B writeTimeout​(Duration writeTimeout)
        Sets the timeout of a socket write attempt.
        Parameters:
        writeTimeout - the timeout. 0 disables the timeout.
      • writeTimeoutMillis

        public B writeTimeoutMillis​(long writeTimeoutMillis)
        Sets the timeout of a socket write attempt in milliseconds.
        Parameters:
        writeTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.
      • defaultResponseTimeout

        @Deprecated
        public B defaultResponseTimeout​(Duration responseTimeout)
        Deprecated.
        Sets the timeout of a response.
        Parameters:
        responseTimeout - the timeout. 0 disables the timeout.
      • defaultResponseTimeoutMillis

        @Deprecated
        public B defaultResponseTimeoutMillis​(long responseTimeoutMillis)
        Deprecated.
        Sets the timeout of a response in milliseconds.
        Parameters:
        responseTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.
      • responseTimeout

        public B responseTimeout​(Duration responseTimeout)
        Sets the timeout of a response.
        Parameters:
        responseTimeout - the timeout. 0 disables the timeout.
      • responseTimeoutMillis

        public B responseTimeoutMillis​(long responseTimeoutMillis)
        Sets the timeout of a response in milliseconds.
        Parameters:
        responseTimeoutMillis - the timeout in milliseconds. 0 disables the timeout.
      • defaultMaxResponseLength

        @Deprecated
        public B defaultMaxResponseLength​(long maxResponseLength)
        Deprecated.
        Sets the maximum allowed length of a server response in bytes.
        Parameters:
        maxResponseLength - the maximum length in bytes. 0 disables the limit.
      • maxResponseLength

        public B maxResponseLength​(long maxResponseLength)
        Sets the maximum allowed length of a server response in bytes.
        Parameters:
        maxResponseLength - the maximum length in bytes. 0 disables the limit.
      • contentPreview

        public B contentPreview​(int length,
                                Charset defaultCharset)
        Sets the ContentPreviewerFactory for creating a ContentPreviewer which produces the preview with the maximum length limit for a request and a response. The previewer is enabled only if the content type of a request/response meets any of the following conditions:
        • when it matches text/* or application/x-www-form-urlencoded
        • when its charset has been specified
        • when its subtype is "xml" or "json"
        • when its subtype ends with "+xml" or "+json"
        Parameters:
        length - the maximum length of the preview
        defaultCharset - the default charset used when a charset is not specified in the "content-type" header
      • contentPreview

        public B contentPreview​(int length)
        Sets the ContentPreviewerFactory for creating a ContentPreviewer which produces the preview with the maximum length limit for a request and a response. The previewer is enabled only if the content type of a request/response meets any of the following conditions:
        • when it matches text/* or application/x-www-form-urlencoded
        • when its charset has been specified
        • when its subtype is "xml" or "json"
        • when its subtype ends with "+xml" or "+json"
        Parameters:
        length - the maximum length of the preview.
      • decorator

        public <T extends Client<I,​O>,​R extends Client<I,​O>,​I extends HttpRequest,​O extends HttpResponse> B decorator​(Function<T,​R> decorator)
        Adds the specified HTTP-level decorator.
        Type Parameters:
        T - the type of the Client being decorated
        R - the type of the Client produced by the decorator
        I - the Request type of the Client being decorated
        O - the Response type of the Client being decorated
        Parameters:
        decorator - the Function that transforms a Client to another
      • rpcDecorator

        public <T extends Client<I,​O>,​R extends Client<I,​O>,​I extends RpcRequest,​O extends RpcResponse> B rpcDecorator​(Function<T,​R> decorator)
        Adds the specified RPC-level decorator.
        Type Parameters:
        T - the type of the Client being decorated
        R - the type of the Client produced by the decorator
        I - the Request type of the Client being decorated
        O - the Response type of the Client being decorated
        Parameters:
        decorator - the Function that transforms a Client to another
      • addHttpHeader

        public B addHttpHeader​(CharSequence name,
                               Object value)
        Adds the specified HTTP header.
      • addHttpHeaders

        public B addHttpHeaders​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> httpHeaders)
        Adds the specified HTTP headers.
      • setHttpHeader

        public B setHttpHeader​(CharSequence name,
                               Object value)
        Sets the specified HTTP header.
      • setHttpHeaders

        public B setHttpHeaders​(Iterable<? extends Map.Entry<? extends CharSequence,​?>> httpHeaders)
        Sets the specified HTTP headers.