Class JdkHttpRestClient
- All Implemented Interfaces:
Closable, Closable.CloseBuilder<LinkComponent.LinkComponentBuilder<HttpRestClient>>, ConnectionStatusAccessor, LinkComponent, LinkComponent.LinkComponentBuilder<HttpRestClient>, Openable, Openable.OpenBuilder<LinkComponent.LinkComponentBuilder<HttpRestClient>>, OpenedAccessor, DeleteRestClient, GetRestClient, HttpRestClient, PostRestClient, PutRestClient, RestClient, RestRequestClient, RestRequestHandler, TrustStoreDescriptorAccessor, BaseUrlAccessor, BasicAuthCredentialsAccessor, BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestClient>, BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator, BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty, HttpClientInterceptable, MediaTypeFactoryLookup, MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup, OauthTokenAccessor, OauthTokenAccessor.OauthTokenBuilder<RestClient>, OauthTokenAccessor.OauthTokenMutator, OauthTokenAccessor.OauthTokenProperty, PostHttpClientInterceptable, PostHttpInterceptable<PostHttpClientInterceptor>, PreHttpClientInterceptable, PreHttpInterceptable<PreHttpClientInterceptor>, UserAgentAccessor, UserAgentAccessor.UserAgentBuilder<RestClient>, UserAgentAccessor.UserAgentMutator, UserAgentAccessor.UserAgentProperty
JDK based implementation of the HttpRestClient interface using the
HttpURLConnection infrastructure provided by the Java runtime.
The JdkHttpRestClient provides a lightweight embeddable REST client
implementation supporting HTTP as well as HTTPS communication alongside
request marshaling, response unmarshaling, media type negotiation,
authentication handling, redirect processing and interceptor chains.
The client integrates with the REFCODES web and REST infrastructure and is
preconfigured with several common MediaTypeFactory instances,
including:
JsonMediaTypeFactoryXmlMediaTypeFactoryTextMediaTypeFactoryFormMediaTypeFactoryHtmlMediaTypeFactory
The client supports:
- HTTP and HTTPS communication
- streaming request and response bodies
- automatic and controlled redirect handling
- HTTP Basic-Authentication
- OAuth token authentication
- custom request and response interceptors
- custom executor service integration
- typed request and response abstractions
HTTPS trust configuration may be provided through a
TrustStoreDescriptor. The trust store configuration is propagated to
the underlying JDK SSL infrastructure through the corresponding system
properties.
Requests are represented by HttpClientRequest instances while
responses are exposed as HttpClientResponse and RestResponse
abstractions supporting typed body processing and media type aware
unmarshaling.
Configuration is provided through HttpClientOptions, enabling a typed
ontology driven configuration model aligned with the REFCODES runtime and
diagnostics architecture.
This implementation is intended for lightweight embeddable REST clients, infrastructure tooling, standalone applications, integration tests and environments preferring minimal external dependencies.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructingJdkHttpRestClientinstances using a fluent and strongly typed configuration API.Nested classes/interfaces inherited from interface BaseUrlAccessor
BaseUrlAccessor.BaseUrlBuilder<B>, BaseUrlAccessor.BaseUrlMutator, BaseUrlAccessor.BaseUrlPropertyNested classes/interfaces inherited from interface BasicAuthCredentialsAccessor
BasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<B>, BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator, BasicAuthCredentialsAccessor.BasicAuthCredentialsPropertyNested classes/interfaces inherited from interface Closable
Closable.CloseAutomaton, Closable.CloseBuilder<B>Nested classes/interfaces inherited from interface ConnectionStatusAccessor
ConnectionStatusAccessor.ConnectionStatusMutator, ConnectionStatusAccessor.ConnectionStatusPropertyNested classes/interfaces inherited from interface LinkComponent
LinkComponent.LinkAutomaton, LinkComponent.LinkComponentBuilder<B>Nested classes/interfaces inherited from interface MediaTypeFactoryLookup
MediaTypeFactoryLookup.MutableMediaTypeFactoryLookupNested classes/interfaces inherited from interface OauthTokenAccessor
OauthTokenAccessor.OauthTokenBuilder<B>, OauthTokenAccessor.OauthTokenMutator, OauthTokenAccessor.OauthTokenPropertyNested classes/interfaces inherited from interface Openable
Openable.OpenAutomaton, Openable.OpenBuilder<B>Nested classes/interfaces inherited from interface OpenedAccessor
OpenedAccessor.OpenedMutator, OpenedAccessor.OpenedPropertyNested classes/interfaces inherited from interface TrustStoreDescriptorAccessor
TrustStoreDescriptorAccessor.TrustStoreDescriptorBuilder<B>, TrustStoreDescriptorAccessor.TrustStoreDescriptorMutator, TrustStoreDescriptorAccessor.TrustStoreDescriptorPropertyNested classes/interfaces inherited from interface UserAgentAccessor
UserAgentAccessor.UserAgentBuilder<B>, UserAgentAccessor.UserAgentMutator, UserAgentAccessor.UserAgentProperty -
Field Summary
Fields inherited from interface HttpRestClient
DEFAULT_KEYSTORE_TYPE, DEFAULT_SSL_PROTOCOL -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new HTTP rest client.JdkHttpRestClient(HttpClientOptions aHttpClientOptions) Instantiates a new HTTP rest client. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddPostHttpInterceptor(PostHttpClientInterceptor aPostInterceptor) booleanaddPreHttpInterceptor(PreHttpClientInterceptor aPreInterceptor) static JdkHttpRestClient.Builderbuilder()Creates a newJdkHttpRestClient.Builderfor constructingHttpRestClientinstances.voidclose()booleanhasPostHttpInterceptor(PostHttpClientInterceptor aPostInterceptor) booleanhasPreHttpInterceptor(PreHttpClientInterceptor aPreInterceptor) voidopen()protected static voidpipe(InputStream aInputStream, OutputStream aOutoutStream) Pipes theInputStreamto theOutputStream.protected voidpostIntercept(HttpClientRequest aRequest, HttpClientResponse aResponse) Invoked to post-process aHttpClientRequestalongside aHttpClientResponse.protected voidpreIntercept(HttpClientRequest aRequest, HttpClientResponse aResponse) Invoked to pre-process aHttpClientRequestalongside aHttpClientResponse.booleanremovePostHttpInterceptor(PostHttpClientInterceptor aPostInterceptor) booleanremovePreHttpInterceptor(PreHttpClientInterceptor aPreInterceptor) withBasicAuthCredentials(String aUserName, String aSecret) withBasicAuthCredentials(BasicAuthCredentials aBasicAuthCredentials) withCloseIn(int aCloseMillis) withOAuthToken(OauthToken aOauthToken) withOpen()Open the component's connection(s).withUserAgent(String aUserAgent) Methods inherited from class AbstractRestClient
addMediaTypeFactory, buildRequest, doRequest, getBasicAuthCredentials, getFactoryMediaTypes, getOauthToken, getUserAgent, initMedaTypeFactories, onResponse, onResponse, onRestRequest, preProcessHeaderFields, setBasicAuthCredentials, setOauthToken, setUserAgent, toMediaTypeFactoryMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BasicAuthCredentialsAccessor
getBasicAuthCredentialsMethods inherited from interface BasicAuthCredentialsAccessor.BasicAuthCredentialsMutator
setBasicAuthCredentials, setBasicAuthCredentialsMethods inherited from interface BasicAuthCredentialsAccessor.BasicAuthCredentialsProperty
letBasicAuthCredentials, letBasicAuthCredentialsMethods inherited from interface Closable
closeIn, closeQuietly, closeUncheckedMethods inherited from interface ConnectionStatusAccessor
isOpenedMethods inherited from interface DeleteRestClient
buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, buildDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, doDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDelete, onDeleteMethods inherited from interface GetRestClient
buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, buildGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, doGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGet, onGetMethods inherited from interface HttpClientInterceptable
addHttpInterceptor, hasHttpInterceptor, removeHttpInterceptorMethods inherited from interface MediaTypeFactoryLookup
getFactoryMediaTypes, hasMediaTypeFactory, toMediaTypeFactoryMethods inherited from interface MediaTypeFactoryLookup.MutableMediaTypeFactoryLookup
addMediaTypeFactoryMethods inherited from interface OauthTokenAccessor
getOauthTokenMethods inherited from interface OauthTokenAccessor.OauthTokenMutator
setOauthTokenMethods inherited from interface OauthTokenAccessor.OauthTokenProperty
letOauthTokenMethods inherited from interface PostRestClient
buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, buildPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, doPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPost, onPostMethods inherited from interface PutRestClient
buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, buildPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, doPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPut, onPutMethods inherited from interface RestRequestClient
buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, buildRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, doRequest, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponse, onResponseMethods inherited from interface UserAgentAccessor
getUserAgentMethods inherited from interface UserAgentAccessor.UserAgentMutator
setUserAgentMethods inherited from interface UserAgentAccessor.UserAgentProperty
letUserAgent
-
Constructor Details
-
JdkHttpRestClient
public JdkHttpRestClient()Instantiates a new HTTP rest client. -
JdkHttpRestClient
Instantiates a new HTTP rest client.- Parameters:
aHttpClientOptions- The options to use for configuring the HTTP rest client.
-
-
Method Details
-
close
- Specified by:
closein interfaceClosable- Throws:
IOException
-
getBaseUrl
- Specified by:
getBaseUrlin interfaceBaseUrlAccessor
-
getConnectionStatus
- Specified by:
getConnectionStatusin interfaceConnectionStatusAccessor
-
getTrustStoreDescriptor
- Specified by:
getTrustStoreDescriptorin interfaceTrustStoreDescriptorAccessor
-
open
- Specified by:
openin interfaceOpenable- Throws:
IOException
-
hasPreHttpInterceptor
- Specified by:
hasPreHttpInterceptorin interfacePreHttpInterceptable<PreHttpClientInterceptor>
-
addPreHttpInterceptor
- Specified by:
addPreHttpInterceptorin interfacePreHttpInterceptable<PreHttpClientInterceptor>
-
removePreHttpInterceptor
- Specified by:
removePreHttpInterceptorin interfacePreHttpInterceptable<PreHttpClientInterceptor>
-
hasPostHttpInterceptor
- Specified by:
hasPostHttpInterceptorin interfacePostHttpInterceptable<PostHttpClientInterceptor>
-
addPostHttpInterceptor
- Specified by:
addPostHttpInterceptorin interfacePostHttpInterceptable<PostHttpClientInterceptor>
-
removePostHttpInterceptor
- Specified by:
removePostHttpInterceptorin interfacePostHttpInterceptable<PostHttpClientInterceptor>
-
withOpen
Open the component's connection(s).- Specified by:
withOpenin interfaceHttpRestClient- Specified by:
withOpenin interfaceOpenable.OpenBuilder<LinkComponent.LinkComponentBuilder<HttpRestClient>>- Returns:
- This instance as of the builder pattern.
- Throws:
IOException- Thrown in case opening or accessing an open line (connection, junction, link) caused problems.
-
withClose
- Specified by:
withClosein interfaceClosable.CloseBuilder<LinkComponent.LinkComponentBuilder<HttpRestClient>>- Throws:
IOException
-
withCloseQuietly
- Specified by:
withCloseQuietlyin interfaceClosable.CloseBuilder<LinkComponent.LinkComponentBuilder<HttpRestClient>>
-
withCloseUnchecked
- Specified by:
withCloseUncheckedin interfaceClosable.CloseBuilder<LinkComponent.LinkComponentBuilder<HttpRestClient>>
-
withCloseIn
- Specified by:
withCloseInin interfaceClosable.CloseBuilder<LinkComponent.LinkComponentBuilder<HttpRestClient>>
-
withBasicAuthCredentials
- Specified by:
withBasicAuthCredentialsin interfaceBasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestClient>- Specified by:
withBasicAuthCredentialsin interfaceHttpRestClient
-
withBasicAuthCredentials
- Specified by:
withBasicAuthCredentialsin interfaceBasicAuthCredentialsAccessor.BasicAuthCredentialsBuilder<RestClient>- Specified by:
withBasicAuthCredentialsin interfaceHttpRestClient
-
withOAuthToken
- Specified by:
withOAuthTokenin interfaceHttpRestClient- Specified by:
withOAuthTokenin interfaceOauthTokenAccessor.OauthTokenBuilder<RestClient>
-
withUserAgent
- Specified by:
withUserAgentin interfaceHttpRestClient- Specified by:
withUserAgentin interfaceUserAgentAccessor.UserAgentBuilder<RestClient>
-
builder
Creates a newJdkHttpRestClient.Builderfor constructingHttpRestClientinstances.- Returns:
- A new builder instance.
-
pipe
Pipes theInputStreamto theOutputStream.- Parameters:
aInputStream- TheInputStreamfrom which to pipe.aOutoutStream- TheOutputStreamto pipe to.- Throws:
IOException- Signals that an I/O exception has occurred.
-
preIntercept
Invoked to pre-process aHttpClientRequestalongside aHttpClientResponse.- Overrides:
preInterceptin classAbstractRestClient- Parameters:
aRequest- TheHttpClientRequestto pre-process.aResponse- TheHttpClientResponseto post-process.
-
postIntercept
Invoked to post-process aHttpClientRequestalongside aHttpClientResponse.- Overrides:
postInterceptin classAbstractRestClient- Parameters:
aRequest- TheHttpClientRequestto post-process.aResponse- TheHttpClientResponseto post-process.
-