Package io.micronaut.http.client.jdk
Class JdkBlockingHttpClient
java.lang.Object
io.micronaut.http.client.jdk.JdkBlockingHttpClient
- All Implemented Interfaces:
LifeCycle<BlockingHttpClient>,BlockingHttpClient,Closeable,AutoCloseable
HttpClient implementation for java.net.http.* HTTP Client.- Since:
- 4.0.0
- Author:
- Sergio del Amo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HttpClientprotected final List<HttpFilterResolver.FilterEntry>protected final Stringprotected final HttpClientConfigurationprotected final Stringprotected final ConversionServiceprotected final CookieDecoderprotected final CookieManagerprotected final HttpClientFilterResolver<ClientFilterResolutionContext>static final Stringstatic final Stringprotected final HttpVersionSelectionprotected final LoadBalancerprotected final org.slf4j.Loggerprotected MediaTypeCodecRegistryprotected MessageBodyHandlerRegistryprotected final RequestBinderRegistryprotected final JdkClientSslBuilderstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionJdkBlockingHttpClient(LoadBalancer loadBalancer, HttpVersionSelection httpVersion, HttpClientConfiguration configuration, 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) -
Method Summary
Modifier and TypeMethodDescriptionprotected <I,R extends HttpResponse<?>>
Publisher<R>applyFilterToResponsePublisher(HttpRequest<I> request, URI requestURI, Publisher<R> responsePublisher) voidclose()Delegates toLifeCycle.stop().<I,O, E> HttpResponse<O> Perform an HTTP request for the given request object emitting the full HTTP response from returnedPublisherand 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) booleanprotected <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) voidsetMediaTypeCodecRegistry(MediaTypeCodecRegistry mediaTypeCodecRegistry) voidsetMessageBodyHandlerRegistry(MessageBodyHandlerRegistry messageBodyHandlerRegistry) start()Starts the lifecyle component.stop()Stops the life cycle component.
-
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
-
JdkBlockingHttpClient
public JdkBlockingHttpClient(LoadBalancer loadBalancer, HttpVersionSelection httpVersion, HttpClientConfiguration configuration, 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)
-
-
Method Details
-
exchange
public <I,O, HttpResponse<O> exchangeE> (@NonNull HttpRequest<I> request, @Nullable @Nullable Argument<O> bodyType, @Nullable @Nullable Argument<E> errorType) Description copied from interface:BlockingHttpClientPerform an HTTP request for the given request object emitting the full HTTP response from returned
Publisherand converting the response body to the specified type.This method will send a
Content-Lengthheader and except a content length header the response and is designed for simple non-streaming exchanges of dataBy default the exchange
Content-Typeis application/json, unless otherwise specified in the passedHttpRequest- Specified by:
exchangein interfaceBlockingHttpClient- Type Parameters:
I- The request body typeO- The response body typeE- The error type- Parameters:
request- TheHttpRequestto executebodyType- The body typeerrorType- The error type- Returns:
- The full
HttpResponseobject
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceLifeCycle<BlockingHttpClient>- Returns:
- Whether the component is running
-
start
Description copied from interface:LifeCycleStarts the lifecyle component.- Specified by:
startin interfaceLifeCycle<BlockingHttpClient>- Returns:
- This lifecycle component
-
stop
Description copied from interface:LifeCycleStops the life cycle component.- Specified by:
stopin interfaceLifeCycle<BlockingHttpClient>- Returns:
- This lifecycle component
-
close
public void close()Description copied from interface:LifeCycleDelegates toLifeCycle.stop().- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceLifeCycle<BlockingHttpClient>
-
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)
-