Package com.linecorp.armeria.client
Class HttpClientBuilder
- java.lang.Object
-
- com.linecorp.armeria.client.HttpClientBuilder
-
public final class HttpClientBuilder extends Object
Creates a new HTTP client that connects to the specifiedURI
using the builder pattern. Use the factory methods inHttpClient
if you do not have many options to override. Please refer toClientBuilder
for how decorators and HTTP headers are configured
-
-
Constructor Summary
Constructors Constructor Description HttpClientBuilder(SessionProtocol sessionProtocol, Endpoint endpoint)
Creates a new instance.HttpClientBuilder(String uri)
Creates a new instance.HttpClientBuilder(URI uri)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description B
addHttpHeader(CharSequence name, Object value)
Adds the specified HTTP header.B
addHttpHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> httpHeaders)
Adds the specified HTTP headers.HttpClient
build()
Returns a newly-created HTTP client based on the properties of this builder.B
contentPreview(int length)
Sets theContentPreviewerFactory
for creating aContentPreviewer
which produces the preview with the maximumlength
limit for a request and a response.B
contentPreview(int length, Charset defaultCharset)
Sets theContentPreviewerFactory
for creating aContentPreviewer
which produces the preview with the maximumlength
limit for a request and a response.B
contentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request and a response.<I extends HttpRequest,O extends HttpResponse>
Bdecorator(DecoratingClientFunction<I,O> decorator)
Adds the specified HTTP-leveldecorator
.<I extends Request,O extends Response>
Bdecorator(Class<I> requestType, Class<O> responseType, DecoratingClientFunction<I,O> decorator)
Deprecated.<T extends Client<I,O>,R extends Client<I,O>,I extends Request,O extends Response>
Bdecorator(Class<I> requestType, Class<O> responseType, Function<T,R> decorator)
Deprecated.<T extends Client<I,O>,R extends Client<I,O>,I extends HttpRequest,O extends HttpResponse>
Bdecorator(Function<T,R> decorator)
Adds the specified HTTP-leveldecorator
.B
defaultMaxResponseLength(long maxResponseLength)
Deprecated.B
defaultResponseTimeout(Duration responseTimeout)
Deprecated.B
defaultResponseTimeoutMillis(long responseTimeoutMillis)
Deprecated.B
defaultWriteTimeout(Duration writeTimeout)
Deprecated.B
defaultWriteTimeoutMillis(long writeTimeoutMillis)
Deprecated.HttpClientBuilder
factory(ClientFactory factory)
Sets theClientFactory
of the client.B
maxResponseLength(long maxResponseLength)
Sets the maximum allowed length of a server response in bytes.<T> B
option(ClientOption<T> option, T value)
Adds the specifiedClientOption
and itsvalue
.<T> B
option(ClientOptionValue<T> optionValue)
Adds the specifiedClientOptionValue
.B
options(ClientOptions options)
Adds the specifiedClientOptions
.B
options(ClientOptionValue<?>... options)
Adds the specifiedClientOptionValue
s.B
options(Iterable<ClientOptionValue<?>> options)
Adds the specifiedClientOptionValue
s.HttpClientBuilder
path(String path)
Sets thepath
of the client.B
requestContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request.B
responseContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a response.B
responseTimeout(Duration responseTimeout)
Sets the timeout of a response.B
responseTimeoutMillis(long responseTimeoutMillis)
Sets the timeout of a response in milliseconds.<I extends RpcRequest,O extends RpcResponse>
BrpcDecorator(DecoratingClientFunction<I,O> decorator)
Adds the specified RPC-leveldecorator
.<T extends Client<I,O>,R extends Client<I,O>,I extends RpcRequest,O extends RpcResponse>
BrpcDecorator(Function<T,R> decorator)
Adds the specified RPC-leveldecorator
.B
setHttpHeader(CharSequence name, Object value)
Sets the specified HTTP header.B
setHttpHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> httpHeaders)
Sets the specified HTTP headers.B
writeTimeout(Duration writeTimeout)
Sets the timeout of a socket write attempt.B
writeTimeoutMillis(long writeTimeoutMillis)
Sets the timeout of a socket write attempt in milliseconds.
-
-
-
Constructor Detail
-
HttpClientBuilder
public HttpClientBuilder(String uri)
Creates a new instance.- Throws:
IllegalArgumentException
- if the scheme of the uri is not one of the fields inSessionProtocol
or the uri violates RFC 2396
-
HttpClientBuilder
public HttpClientBuilder(URI uri)
Creates a new instance.- Throws:
IllegalArgumentException
- if the scheme of the uri is not one of the fields inSessionProtocol
-
HttpClientBuilder
public HttpClientBuilder(SessionProtocol sessionProtocol, Endpoint endpoint)
Creates a new instance.- Throws:
IllegalArgumentException
- if thesessionProtocol
is not one of the fields inSessionProtocol
-
-
Method Detail
-
factory
public HttpClientBuilder factory(ClientFactory factory)
Sets theClientFactory
of the client. The default isClientFactory.DEFAULT
.
-
path
public HttpClientBuilder path(String path)
Sets thepath
of the client.
-
build
public HttpClient build()
Returns a newly-created HTTP client based on the properties of this builder.- Throws:
IllegalArgumentException
- if the scheme of theuri
specified inHttpClientBuilder(String)
orHttpClientBuilder(URI)
is not an HTTP scheme
-
options
public B options(ClientOptions options)
Adds the specifiedClientOptions
.
-
options
public B options(ClientOptionValue<?>... options)
Adds the specifiedClientOptionValue
s.
-
options
public B options(Iterable<ClientOptionValue<?>> options)
Adds the specifiedClientOptionValue
s.
-
option
public <T> B option(ClientOption<T> option, T value)
Adds the specifiedClientOption
and itsvalue
.
-
option
public <T> B option(ClientOptionValue<T> optionValue)
Adds the specifiedClientOptionValue
.
-
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.
-
requestContentPreviewerFactory
public B requestContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request.
-
responseContentPreviewerFactory
public B responseContentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a response.
-
contentPreviewerFactory
public B contentPreviewerFactory(ContentPreviewerFactory factory)
Sets theContentPreviewerFactory
for a request and a response.
-
contentPreview
public B contentPreview(int length, Charset defaultCharset)
Sets theContentPreviewerFactory
for creating aContentPreviewer
which produces the preview with the maximumlength
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/*
orapplication/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 previewdefaultCharset
- the default charset used when a charset is not specified in the"content-type"
header
- when it matches
-
contentPreview
public B contentPreview(int length)
Sets theContentPreviewerFactory
for creating aContentPreviewer
which produces the preview with the maximumlength
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/*
orapplication/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.
- when it matches
-
decorator
@Deprecated public <T extends Client<I,O>,R extends Client<I,O>,I extends Request,O extends Response> B decorator(Class<I> requestType, Class<O> responseType, Function<T,R> decorator)
Deprecated.Adds the specifieddecorator
.- Type Parameters:
T
- the type of theClient
being decoratedR
- the type of theClient
produced by thedecorator
I
- theRequest
type of theClient
being decoratedO
- theResponse
type of theClient
being decorated- Parameters:
requestType
- the type of theRequest
that thedecorator
is interested inresponseType
- the type of theResponse
that thedecorator
is interested indecorator
- theFunction
that transforms aClient
to another
-
decorator
@Deprecated public <I extends Request,O extends Response> B decorator(Class<I> requestType, Class<O> responseType, DecoratingClientFunction<I,O> decorator)
Deprecated.Adds the specifieddecorator
.- Type Parameters:
I
- theRequest
type of theClient
being decoratedO
- theResponse
type of theClient
being decorated- Parameters:
requestType
- the type of theRequest
that thedecorator
is interested inresponseType
- the type of theResponse
that thedecorator
is interested indecorator
- theDecoratingClientFunction
that intercepts an invocation
-
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-leveldecorator
.
-
decorator
public <I extends HttpRequest,O extends HttpResponse> B decorator(DecoratingClientFunction<I,O> decorator)
Adds the specified HTTP-leveldecorator
.- Type Parameters:
I
- theRequest
type of theClient
being decoratedO
- theResponse
type of theClient
being decorated- Parameters:
decorator
- theDecoratingClientFunction
that intercepts an invocation
-
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-leveldecorator
.
-
rpcDecorator
public <I extends RpcRequest,O extends RpcResponse> B rpcDecorator(DecoratingClientFunction<I,O> decorator)
Adds the specified RPC-leveldecorator
.- Type Parameters:
I
- theRequest
type of theClient
being decoratedO
- theResponse
type of theClient
being decorated- Parameters:
decorator
- theDecoratingClientFunction
that intercepts an invocation
-
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.
-
-