-
- Enclosing interface:
- HttpClientContext
public static interface HttpClientContext.BuilderBuilds 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.Builderauthenticator(Authenticator authenticator)Set a HttpClient authenticator to the underlyingHttpClient.HttpClientContext.BuilderauthTokenProvider(AuthTokenProvider authTokenProvider)Add a Authorization token provider.HttpClientContext.BuilderbaseUrl(String baseUrl)Set the base URL to use for requests created from the context.HttpClientContext.BuilderbodyAdapter(BodyAdapter adapter)Set the body adapter to use to convert beans to body content and response content back to beans.HttpClientContextbuild()Build and return the context.HttpClientContext.Builderclient(HttpClient client)Set the underlying HttpClient to use.HttpClientContext.BuildercookieHandler(CookieHandler cookieHandler)Specify a cookie handler to use on the HttpClient.HttpClientContext.Builderexecutor(Executor executor)Specify the Executor to use for asynchronous tasks.HttpClientContext.Builderpriority(int priority)Set the priority for HTTP/2 requests to the underlyingHttpClient.HttpClientContext.Builderproxy(ProxySelector proxySelector)Set the proxy to the underlyingHttpClient.HttpClientContext.Builderredirect(HttpClient.Redirect redirect)Specify the redirect policy.HttpClientContext.BuilderrequestIntercept(RequestIntercept requestIntercept)Add a request interceptor.HttpClientContext.BuilderrequestListener(RequestListener requestListener)Add a request listener.HttpClientContext.BuilderrequestLogging(boolean requestLogging)Disable or enable built in request and response logging.HttpClientContext.BuilderrequestTimeout(Duration requestTimeout)Set the default request timeout.HttpClientContext.BuilderretryHandler(RetryHandler retryHandler)Set a RetryHandler to use to retry requests.HttpClientContext.BuildersslContext(SSLContext sslContext)Set the sslContext to the underlyingHttpClient.HttpClientContext.BuildersslParameters(SSLParameters sslParameters)Set the sslParameters to the underlyingHttpClient.HttpClientContext.Builderversion(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
RequestLoggerbeing registered to log request and response headers and bodies etc.With logging level set to
DEBUGforio.avaje.http.client.RequestLoggerthe request and response are logged as a summary with response status and time.Set the logging level to
TRACEto 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.
AuthTokenProviderrequests 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
RequestLoggeris 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);
-
-