Package io.micronaut.http.client.jdk
Class DefaultJdkHttpClient
java.lang.Object
io.micronaut.http.client.jdk.DefaultJdkHttpClient
- All Implemented Interfaces:
LifeCycle<HttpClient>
,HttpClient
,JdkHttpClient
,Closeable
,AutoCloseable
HttpClient
implementation for java.net.http.* HTTP Client.- Since:
- 4.0.0
- Author:
- Sergio del Amo
-
Field Summary
Modifier and TypeFieldDescriptionprotected final HttpClient
protected final String
protected final HttpClientConfiguration
protected final String
protected final ConversionService
protected final CookieDecoder
protected final CookieManager
static final String
static final String
protected final HttpVersionSelection
protected final LoadBalancer
protected final org.slf4j.Logger
protected MediaTypeCodecRegistry
protected final RequestBinderRegistry
protected final JdkClientSslBuilder
static final String
Fields inherited from interface io.micronaut.http.client.HttpClient
DEFAULT_ERROR_TYPE
-
Constructor Summary
ConstructorDescriptionDefaultJdkHttpClient
(@Nullable LoadBalancer loadBalancer, HttpVersionSelection httpVersion, @NonNull HttpClientConfiguration configuration, @Nullable String contextPath, MediaTypeCodecRegistry mediaTypeCodecRegistry, RequestBinderRegistry requestBinderRegistry, String clientId, ConversionService conversionService, JdkClientSslBuilder sslBuilder, CookieDecoder cookieDecoder) DefaultJdkHttpClient
(URI uri, ConversionService conversionService) DefaultJdkHttpClient
(URI uri, HttpClientConfiguration configuration, MediaTypeCodecRegistry mediaTypeCodecRegistry, ConversionService conversionService) -
Method Summary
Modifier and TypeMethodDescription<I,
O, E> Publisher<HttpResponse<O>> exchange
(@NonNull HttpRequest<I> request, @NonNull Argument<O> bodyType, @NonNull Argument<E> errorType) Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisher
and converting the response body to the specified type.boolean
protected <I> reactor.core.publisher.Mono<HttpRequest>
mapToHttpRequest
(HttpRequest<I> request, Argument<?> bodyType) Convert the Micronaut request to a JDK request.protected <O> @NonNull HttpResponse<O>
response
(HttpResponse<byte[]> netResponse, @NonNull Argument<O> bodyType) Convert the JDK response to a Micronaut response.void
setMediaTypeCodecRegistry
(MediaTypeCodecRegistry mediaTypeCodecRegistry) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
H2C_ERROR_MESSAGE
- See Also:
-
H3_ERROR_MESSAGE
- See Also:
-
WEIRD_ALPN_ERROR_MESSAGE
- See Also:
-
loadBalancer
-
httpVersion
-
configuration
-
contextPath
-
client
-
cookieManager
-
requestBinderRegistry
-
clientId
-
conversionService
-
sslBuilder
-
log
protected final org.slf4j.Logger log -
cookieDecoder
-
mediaTypeCodecRegistry
-
-
Constructor Details
-
DefaultJdkHttpClient
public DefaultJdkHttpClient(@Nullable @Nullable LoadBalancer loadBalancer, HttpVersionSelection httpVersion, @NonNull @NonNull HttpClientConfiguration configuration, @Nullable @Nullable String contextPath, MediaTypeCodecRegistry mediaTypeCodecRegistry, RequestBinderRegistry requestBinderRegistry, String clientId, ConversionService conversionService, JdkClientSslBuilder sslBuilder, CookieDecoder cookieDecoder) -
DefaultJdkHttpClient
-
DefaultJdkHttpClient
public DefaultJdkHttpClient(URI uri, HttpClientConfiguration configuration, MediaTypeCodecRegistry mediaTypeCodecRegistry, ConversionService conversionService)
-
-
Method Details
-
toBlocking
- Specified by:
toBlocking
in interfaceHttpClient
- Returns:
- A blocking HTTP client suitable for testing and non-production scenarios.
-
exchange
public <I,O, Publisher<HttpResponse<O>> exchangeE> (@NonNull @NonNull HttpRequest<I> request, @NonNull @NonNull Argument<O> bodyType, @NonNull @NonNull Argument<E> errorType) Description copied from interface:HttpClient
Perform an HTTP request for the given request object emitting the full HTTP response from returned
Publisher
and converting the response body to the specified type.This method will send a
Content-Length
header and except a content length header the response and is designed for simple non-streaming exchanges of dataBy default the exchange
Content-Type
is application/json, unless otherwise specified in the passedHttpRequest
- Specified by:
exchange
in interfaceHttpClient
- Type Parameters:
I
- The request body typeO
- The response body typeE
- The error type- Parameters:
request
- TheHttpRequest
to executebodyType
- The body typeerrorType
- The error type- Returns:
- A
Publisher
that emits the fullHttpResponse
object
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceLifeCycle<HttpClient>
- Returns:
- Whether the component is running
-
getMediaTypeCodecRegistry
- Returns:
- The
MediaTypeCodecRegistry
-
setMediaTypeCodecRegistry
- Parameters:
mediaTypeCodecRegistry
- TheMediaTypeCodecRegistry
-
mapToHttpRequest
protected <I> reactor.core.publisher.Mono<HttpRequest> mapToHttpRequest(HttpRequest<I> request, Argument<?> bodyType) Convert the Micronaut request to a JDK request.- Type Parameters:
I
- The body type- Parameters:
request
- The Micronaut request objectbodyType
- The body type- Returns:
- A JDK request object
-
response
@NonNull protected <O> @NonNull HttpResponse<O> response(@NonNull HttpResponse<byte[]> netResponse, @NonNull @NonNull Argument<O> bodyType) Convert the JDK response to a Micronaut response.- Type Parameters:
O
- The body type- Parameters:
netResponse
- The JDK responsebodyType
- The body type- Returns:
- A Micronaut response
-