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 List<HttpFilterResolver.FilterEntry>
protected final String
protected final HttpClientConfiguration
protected final String
protected final ConversionService
protected final CookieDecoder
protected final CookieManager
protected final HttpClientFilterResolver<ClientFilterResolutionContext>
static final String
static final String
protected final HttpVersionSelection
protected final LoadBalancer
protected final org.slf4j.Logger
protected MediaTypeCodecRegistry
protected MessageBodyHandlerRegistry
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, @Nullable HttpClientFilterResolver<ClientFilterResolutionContext> filterResolver, @Nullable List<HttpFilterResolver.FilterEntry> clientFilterEntries, MediaTypeCodecRegistry mediaTypeCodecRegistry, MessageBodyHandlerRegistry messageBodyHandlerRegistry, RequestBinderRegistry requestBinderRegistry, String clientId, ConversionService conversionService, JdkClientSslBuilder sslBuilder, CookieDecoder cookieDecoder) DefaultJdkHttpClient
(URI uri, ConversionService conversionService) DefaultJdkHttpClient
(URI uri, HttpClientConfiguration configuration, MediaTypeCodecRegistry mediaTypeCodecRegistry, MessageBodyHandlerRegistry messageBodyHandlerRegistry, ConversionService conversionService) -
Method Summary
Modifier and TypeMethodDescriptionprotected <I,
R extends HttpResponse<?>>
Publisher<R>applyFilterToResponsePublisher
(HttpRequest<I> request, URI requestURI, Publisher<R> responsePublisher) <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.protected <I,
O> reactor.core.publisher.Flux<HttpResponse<O>> exchangeImpl
(HttpRequest<I> request, @Nullable Argument<O> bodyType) boolean
protected <I> reactor.core.publisher.Mono<HttpRequest>
mapToHttpRequest
(HttpRequest<I> request, @Nullable Argument<?> bodyType) Convert the Micronaut request to a JDK request.protected reactor.core.publisher.Mono<URI>
resolveRequestUri
(HttpRequest<?> request) protected <O> @NonNull HttpResponse<O>
response
(HttpResponse<byte[]> netResponse, @NonNull Argument<O> bodyType) Convert the JDK response to a Micronaut response.protected <O> Publisher<HttpResponse<O>>
responsePublisher
(HttpRequest<?> request, @Nullable Argument<O> bodyType) void
setMediaTypeCodecRegistry
(MediaTypeCodecRegistry mediaTypeCodecRegistry) void
setMessageBodyHandlerRegistry
(MessageBodyHandlerRegistry messageBodyHandlerRegistry) 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 -
filterResolver
-
clientFilterEntries
-
cookieDecoder
-
mediaTypeCodecRegistry
-
messageBodyHandlerRegistry
-
-
Constructor Details
-
DefaultJdkHttpClient
public DefaultJdkHttpClient(@Nullable @Nullable LoadBalancer loadBalancer, HttpVersionSelection httpVersion, @NonNull @NonNull HttpClientConfiguration configuration, @Nullable @Nullable String contextPath, @Nullable @Nullable HttpClientFilterResolver<ClientFilterResolutionContext> filterResolver, @Nullable @Nullable List<HttpFilterResolver.FilterEntry> clientFilterEntries, MediaTypeCodecRegistry mediaTypeCodecRegistry, MessageBodyHandlerRegistry messageBodyHandlerRegistry, RequestBinderRegistry requestBinderRegistry, String clientId, ConversionService conversionService, JdkClientSslBuilder sslBuilder, CookieDecoder cookieDecoder) -
DefaultJdkHttpClient
-
DefaultJdkHttpClient
public DefaultJdkHttpClient(URI uri, HttpClientConfiguration configuration, MediaTypeCodecRegistry mediaTypeCodecRegistry, MessageBodyHandlerRegistry messageBodyHandlerRegistry, 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
-
getMessageBodyHandlerRegistry
- Returns:
- The
MessageBodyHandlerRegistry
-
setMessageBodyHandlerRegistry
- Parameters:
messageBodyHandlerRegistry
- TheMessageBodyHandlerRegistry
-
mapToHttpRequest
protected <I> reactor.core.publisher.Mono<HttpRequest> mapToHttpRequest(@NonNull HttpRequest<I> request, @Nullable @Nullable 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
-
resolveRequestUri
-
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
-
exchangeImpl
protected <I,O> reactor.core.publisher.Flux<HttpResponse<O>> exchangeImpl(@NonNull HttpRequest<I> request, @Nullable @Nullable Argument<O> bodyType) -
applyFilterToResponsePublisher
protected <I,R extends HttpResponse<?>> Publisher<R> applyFilterToResponsePublisher(HttpRequest<I> request, URI requestURI, Publisher<R> responsePublisher) -
responsePublisher
protected <O> Publisher<HttpResponse<O>> responsePublisher(@NonNull HttpRequest<?> request, @Nullable @Nullable Argument<O> bodyType)
-