- Enclosing interface:
- HttpClientContext
public static interface HttpClientContext.Builder
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
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 Details
-
client
Set the underlying HttpClient to use.Used when we wish to control all options of the HttpClient.
-
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
Set the default request timeout.- See Also:
HttpRequest.Builder.timeout(Duration)
-
bodyAdapter
Set the body adapter to use to convert beans to body content and response content back to beans. -
retryHandler
Set a RetryHandler to use to retry requests. -
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
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
Add a request interceptor. Multiple interceptors may be added. -
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
Specify a cookie handler to use on the HttpClient. This would override the default cookie handler. -
redirect
Specify the redirect policy. Defaults to HttpClient.Redirect.NORMAL. -
version
Specify the HTTP version. Defaults to not set. -
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
Set the proxy to the underlyingHttpClient
.- See Also:
HttpClient.Builder.proxy(ProxySelector)
-
sslContext
Set the sslContext to the underlyingHttpClient
. -
sslParameters
Set the sslParameters to the underlyingHttpClient
. -
authenticator
Set a HttpClient authenticator to the underlyingHttpClient
. -
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);
-