-
- Enclosing interface:
- HttpClientContext
public static interface HttpClientContext.Builder
Builds the HttpClientContext.HttpClientContext ctx = HttpClientContext.newBuilder() .baseUrl("http://localhost:8080") .bodyAdapter(new JacksonBodyAdapter()) .build(); HelloDto dto = ctx.request() .path("hello") .queryParam("name", "Rob") .queryParam("say", "Whats up") .GET() .bean(HelloDto.class);
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description HttpClientContext.Builder
authenticator(Authenticator authenticator)
Set a HttpClient authenticator to the underlyingHttpClient
.HttpClientContext.Builder
authTokenProvider(AuthTokenProvider authTokenProvider)
Add a Authorization token provider.HttpClientContext.Builder
baseUrl(String baseUrl)
Set the base URL to use for requests created from the context.HttpClientContext.Builder
bodyAdapter(BodyAdapter adapter)
Set the body adapter to use to convert beans to body content and response content back to beans.HttpClientContext
build()
Build and return the context.HttpClientContext.Builder
client(HttpClient client)
Set the underlying HttpClient to use.HttpClientContext.Builder
cookieHandler(CookieHandler cookieHandler)
Specify a cookie handler to use on the HttpClient.HttpClientContext.Builder
executor(Executor executor)
Specify the Executor to use for asynchronous tasks.HttpClientContext.Builder
priority(int priority)
Set the priority for HTTP/2 requests to the underlyingHttpClient
.HttpClientContext.Builder
proxy(ProxySelector proxySelector)
Set the proxy to the underlyingHttpClient
.HttpClientContext.Builder
redirect(HttpClient.Redirect redirect)
Specify the redirect policy.HttpClientContext.Builder
requestIntercept(RequestIntercept requestIntercept)
Add a request interceptor.HttpClientContext.Builder
requestListener(RequestListener requestListener)
Add a request listener.HttpClientContext.Builder
requestLogging(boolean requestLogging)
Disable or enable built in request and response logging.HttpClientContext.Builder
requestTimeout(Duration requestTimeout)
Set the default request timeout.HttpClientContext.Builder
retryHandler(RetryHandler retryHandler)
Set a RetryHandler to use to retry requests.HttpClientContext.Builder
sslContext(SSLContext sslContext)
Set the sslContext to the underlyingHttpClient
.HttpClientContext.Builder
sslParameters(SSLParameters sslParameters)
Set the sslParameters to the underlyingHttpClient
.HttpClientContext.Builder
version(HttpClient.Version version)
Specify the HTTP version.
-
-
-
Method Detail
-
client
HttpClientContext.Builder client(HttpClient client)
Set the underlying HttpClient to use.Used when we wish to control all options of the HttpClient.
-
baseUrl
HttpClientContext.Builder baseUrl(String baseUrl)
Set the base URL to use for requests created from the context.Note that the base url can be replaced via
HttpClientRequest.url(String)
.
-
requestTimeout
HttpClientContext.Builder requestTimeout(Duration requestTimeout)
Set the default request timeout.- See Also:
HttpRequest.Builder.timeout(Duration)
-
bodyAdapter
HttpClientContext.Builder bodyAdapter(BodyAdapter adapter)
Set the body adapter to use to convert beans to body content and response content back to beans.
-
retryHandler
HttpClientContext.Builder retryHandler(RetryHandler retryHandler)
Set a RetryHandler to use to retry requests.
-
requestLogging
HttpClientContext.Builder requestLogging(boolean requestLogging)
Disable or enable built in request and response logging.By default request logging is enabled. Set this to false to stop the default
RequestLogger
being registered to log request and response headers and bodies etc.With logging level set to
DEBUG
forio.avaje.http.client.RequestLogger
the request and response are logged as a summary with response status and time.Set the logging level to
TRACE
to include the request and response headers and body payloads with truncation for large bodies.Suppression
We can also use
HttpClientRequest.suppressLogging()
to suppress logging on specific requests.Logging of Authorization headers is suppressed.
AuthTokenProvider
requests are suppressed.- Parameters:
requestLogging
- Disable/enable the registration of the default logger- See Also:
RequestLogger
-
requestListener
HttpClientContext.Builder requestListener(RequestListener requestListener)
Add a request listener. Multiple listeners may be added, when do so they will process events in the order they were added.Note that
RequestLogger
is an implementation for debug logging request/response headers and content which is registered by default depending onrequestLogging(boolean)
.- See Also:
RequestLogger
-
requestIntercept
HttpClientContext.Builder requestIntercept(RequestIntercept requestIntercept)
Add a request interceptor. Multiple interceptors may be added.
-
authTokenProvider
HttpClientContext.Builder authTokenProvider(AuthTokenProvider authTokenProvider)
Add a Authorization token provider.When set all requests are expected to use a Authorization Bearer token unless they are marked via
HttpClientRequest.skipAuthToken()
.The AuthTokenProvider obtains a new token typically with an expiry. This is automatically called as needed and the Authorization Bearer header set on all requests (not marked with skipAuthToken()).
-
cookieHandler
HttpClientContext.Builder cookieHandler(CookieHandler cookieHandler)
Specify a cookie handler to use on the HttpClient. This would override the default cookie handler.
-
redirect
HttpClientContext.Builder redirect(HttpClient.Redirect redirect)
Specify the redirect policy. Defaults to HttpClient.Redirect.NORMAL.
-
version
HttpClientContext.Builder version(HttpClient.Version version)
Specify the HTTP version. Defaults to not set.
-
executor
HttpClientContext.Builder executor(Executor executor)
Specify the Executor to use for asynchronous tasks. If not specified a default executor will be used.- See Also:
HttpClient.Builder.executor(Executor)
-
proxy
HttpClientContext.Builder proxy(ProxySelector proxySelector)
Set the proxy to the underlyingHttpClient
.- See Also:
HttpClient.Builder.proxy(ProxySelector)
-
sslContext
HttpClientContext.Builder sslContext(SSLContext sslContext)
Set the sslContext to the underlyingHttpClient
.
-
sslParameters
HttpClientContext.Builder sslParameters(SSLParameters sslParameters)
Set the sslParameters to the underlyingHttpClient
.
-
authenticator
HttpClientContext.Builder authenticator(Authenticator authenticator)
Set a HttpClient authenticator to the underlyingHttpClient
.
-
priority
HttpClientContext.Builder priority(int priority)
Set the priority for HTTP/2 requests to the underlyingHttpClient
.- See Also:
HttpClient.Builder.priority(int)
-
build
HttpClientContext build()
Build and return the context.HttpClientContext ctx = HttpClientContext.newBuilder() .baseUrl("http://localhost:8080") .bodyAdapter(new JacksonBodyAdapter()) .build(); HelloDto dto = ctx.request() .path("hello") .queryParam("say", "Whats up") .GET() .bean(HelloDto.class);
-
-