Package io.micronaut.http.client.netty
Class DefaultNettyHttpClientRegistry
java.lang.Object
io.micronaut.http.client.netty.DefaultNettyHttpClientRegistry
- All Implemented Interfaces:
ApplicationEventListener<RefreshEvent>,Ordered,HttpClientRegistry<HttpClient>,NettyClientCustomizer.Registry,ProxyHttpClientRegistry<ProxyHttpClient>,RawHttpClientRegistry,SseClientRegistry<SseClient>,StreamingHttpClientRegistry<StreamingHttpClient>,ChannelPipelineCustomizer,RefreshEventListener,WebSocketClientRegistry<WebSocketClient>,AutoCloseable,EventListener
@Factory
@Internal
public class DefaultNettyHttpClientRegistry
extends Object
implements AutoCloseable, HttpClientRegistry<HttpClient>, SseClientRegistry<SseClient>, StreamingHttpClientRegistry<StreamingHttpClient>, WebSocketClientRegistry<WebSocketClient>, ProxyHttpClientRegistry<ProxyHttpClient>, RawHttpClientRegistry, ChannelPipelineCustomizer, NettyClientCustomizer.Registry, RefreshEventListener
Factory for the default implementation of the
HttpClient interface based on Netty.- Since:
- 2.0
- Author:
- Graeme Rocher
-
Field Summary
Fields inherited from interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer
HANDLER_ACCESS_LOGGER, HANDLER_ACTIVITY_LISTENER, HANDLER_CONNECT_TTL, HANDLER_FLOW_CONTROL, HANDLER_HTTP_AGGREGATOR, HANDLER_HTTP_CHUNK, HANDLER_HTTP_CLIENT_CODEC, HANDLER_HTTP_CLIENT_INIT, HANDLER_HTTP_COMPRESSOR, HANDLER_HTTP_DECODER, HANDLER_HTTP_DECOMPRESSOR, HANDLER_HTTP_KEEP_ALIVE, HANDLER_HTTP_PROXY, HANDLER_HTTP_SERVER_CODEC, HANDLER_HTTP_STREAM, HANDLER_HTTP_TO_HTTPS_REDIRECT, HANDLER_HTTP2_CONNECTION, HANDLER_HTTP2_PING_SENDER, HANDLER_HTTP2_PROTOCOL_NEGOTIATOR, HANDLER_HTTP2_SETTINGS, HANDLER_HTTP2_UPGRADE_REQUEST, HANDLER_IDLE_STATE, HANDLER_INITIAL_ERROR, HANDLER_MICRONAUT_FULL_HTTP_RESPONSE, HANDLER_MICRONAUT_HTTP_RESPONSE, HANDLER_MICRONAUT_HTTP_RESPONSE_FULL, HANDLER_MICRONAUT_HTTP_RESPONSE_STREAM, HANDLER_MICRONAUT_INBOUND, HANDLER_MICRONAUT_SSE_CONTENT, HANDLER_MICRONAUT_SSE_EVENT_STREAM, HANDLER_MICRONAUT_WEBSOCKET_CLIENT, HANDLER_READ_TIMEOUT, HANDLER_SOCKS_5_PROXY, HANDLER_SSL, HANDLER_WEBSOCKET_UPGRADEFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
DEFAULT_POSITION -
Constructor Summary
ConstructorsConstructorDescriptionDefaultNettyHttpClientRegistry(HttpClientConfiguration defaultHttpClientConfiguration, HttpClientFilterResolver<ClientFilterResolutionContext> httpClientFilterResolver, LoadBalancerResolver loadBalancerResolver, ClientSslBuilder nettyClientSslBuilder, NettyClientSslFactory sslFactory, BeanProvider<CertificateProvider> certificateProviders, ThreadFactory threadFactory, MediaTypeCodecRegistry codecRegistry, MessageBodyHandlerRegistry handlerRegistry, EventLoopGroupRegistry eventLoopGroupRegistry, EventLoopGroupFactory eventLoopGroupFactory, BeanContext beanContext, JsonMapper jsonMapper, @Nullable ExecutorService blockingExecutor) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddisposeClient(AnnotationMetadata annotationMetadata) Dispose of the client defined by the given metadata.voiddoOnConnect(ChannelPipelineListener listener) A hook to customize the pipeline upon establishing a connection.getClient(AnnotationMetadata metadata) Return the client for the given annotation metadata.getClient(HttpVersionSelection httpVersion, String clientId, @Nullable String path) Return the client for the client ID and path.Returns the set of observed configuration prefixes that the event listener should listen for.getProxyHttpClient(AnnotationMetadata metadata) Return the client for the given annotation metadata.getRawClient(HttpVersionSelection httpVersion, String clientId, @Nullable String path) Return the client for the client ID and path.getSseClient(AnnotationMetadata metadata) Return the client for the given annotation metadata.getStreamingHttpClient(AnnotationMetadata metadata) Return the client for the given annotation metadata.getWebSocketClient(AnnotationMetadata metadata) Return the client for the given annotation metadata.protected DefaultHttpClienthttpClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Creates a newHttpClientfor the given injection point.booleanvoidonApplicationEvent(RefreshEvent event) Handle an application event.voidregister(NettyClientCustomizer customizer) Register a new customizer with this registry.resolveClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Resolves aHttpClientfor the given injection point.resolveProxyHttpClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Resolves aProxyHttpClientfor the given injection point.resolveSseClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Resolves aSseClientfor the given injection point.resolveStreamingHttpClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Resolves aStreamingHttpClientfor the given injection point.resolveWebSocketClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Resolves aWebSocketClientfor the given injection point.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer
isServerChannelMethods inherited from interface io.micronaut.http.client.HttpClientRegistry
getClient, getDefaultClientMethods inherited from interface io.micronaut.http.client.ProxyHttpClientRegistry
getDefaultProxyHttpClientMethods inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
getOrder, supportsMethods inherited from interface io.micronaut.http.client.sse.SseClientRegistry
getDefaultSseClientMethods inherited from interface io.micronaut.http.client.StreamingHttpClientRegistry
getDefaultStreamingHttpClientMethods inherited from interface io.micronaut.websocket.WebSocketClientRegistry
getDefaultWebSocketClient
-
Constructor Details
-
DefaultNettyHttpClientRegistry
public DefaultNettyHttpClientRegistry(HttpClientConfiguration defaultHttpClientConfiguration, HttpClientFilterResolver<ClientFilterResolutionContext> httpClientFilterResolver, LoadBalancerResolver loadBalancerResolver, ClientSslBuilder nettyClientSslBuilder, NettyClientSslFactory sslFactory, BeanProvider<CertificateProvider> certificateProviders, ThreadFactory threadFactory, MediaTypeCodecRegistry codecRegistry, MessageBodyHandlerRegistry handlerRegistry, EventLoopGroupRegistry eventLoopGroupRegistry, EventLoopGroupFactory eventLoopGroupFactory, BeanContext beanContext, JsonMapper jsonMapper, @Named("blocking") @Nullable ExecutorService blockingExecutor) Default constructor.- Parameters:
defaultHttpClientConfiguration- The default HTTP client configurationhttpClientFilterResolver- The HTTP client filter resolverloadBalancerResolver- The load balancer resolvernettyClientSslBuilder- The client SSL buildersslFactory- The client SSL builder factorycertificateProviders- Certificate provider bean for named lookupthreadFactory- The thread factorycodecRegistry- The codec registryhandlerRegistry- The handler registryeventLoopGroupRegistry- The event loop group registryeventLoopGroupFactory- The event loop group factorybeanContext- The bean contextjsonMapper- JSON MapperblockingExecutor- Optional executor for blocking operations
-
-
Method Details
-
getClient
public DefaultHttpClient getClient(HttpVersionSelection httpVersion, String clientId, @Nullable String path) Description copied from interface:HttpClientRegistryReturn the client for the client ID and path.- Specified by:
getClientin interfaceHttpClientRegistry<HttpClient>- Parameters:
httpVersion- The HTTP versionclientId- The client IDpath- The path (Optional)- Returns:
- The client
-
getRawClient
public RawHttpClient getRawClient(HttpVersionSelection httpVersion, String clientId, @Nullable String path) Description copied from interface:RawHttpClientRegistryReturn the client for the client ID and path.- Specified by:
getRawClientin interfaceRawHttpClientRegistry- Parameters:
httpVersion- The HTTP versionclientId- The client IDpath- The path (Optional)- Returns:
- The client
-
getClient
Description copied from interface:HttpClientRegistryReturn the client for the given annotation metadata.- Specified by:
getClientin interfaceHttpClientRegistry<HttpClient>- Parameters:
metadata- The annotation metadata.- Returns:
- The client
-
getSseClient
Description copied from interface:SseClientRegistryReturn the client for the given annotation metadata.- Specified by:
getSseClientin interfaceSseClientRegistry<SseClient>- Parameters:
metadata- The annotation metadata.- Returns:
- The client
-
getStreamingHttpClient
Description copied from interface:StreamingHttpClientRegistryReturn the client for the given annotation metadata.- Specified by:
getStreamingHttpClientin interfaceStreamingHttpClientRegistry<StreamingHttpClient>- Parameters:
metadata- The annotation metadata.- Returns:
- The client
-
getProxyHttpClient
Description copied from interface:ProxyHttpClientRegistryReturn the client for the given annotation metadata.- Specified by:
getProxyHttpClientin interfaceProxyHttpClientRegistry<ProxyHttpClient>- Parameters:
metadata- The annotation metadata.- Returns:
- The client
-
getWebSocketClient
Description copied from interface:WebSocketClientRegistryReturn the client for the given annotation metadata.- Specified by:
getWebSocketClientin interfaceWebSocketClientRegistry<WebSocketClient>- Parameters:
metadata- The annotation metadata.- Returns:
- The client
-
close
- Specified by:
closein interfaceAutoCloseable
-
disposeClient
Description copied from interface:HttpClientRegistryDispose of the client defined by the given metadata.- Specified by:
disposeClientin interfaceHttpClientRegistry<HttpClient>- Specified by:
disposeClientin interfaceProxyHttpClientRegistry<ProxyHttpClient>- Specified by:
disposeClientin interfaceSseClientRegistry<SseClient>- Specified by:
disposeClientin interfaceStreamingHttpClientRegistry<StreamingHttpClient>- Specified by:
disposeClientin interfaceWebSocketClientRegistry<WebSocketClient>- Parameters:
annotationMetadata- The annotation metadata
-
httpClient
@Bean @Primary protected DefaultHttpClient httpClient(@Nullable InjectionPoint<?> injectionPoint, @Parameter @Nullable LoadBalancer loadBalancer, @Parameter @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Creates a newHttpClientfor the given injection point.- Parameters:
injectionPoint- The injection pointloadBalancer- The load balancer to use (Optional)configuration- The configuration (Optional)beanContext- The bean context to use- Returns:
- The client
-
resolveClient
public HttpClient resolveClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Description copied from interface:HttpClientRegistryResolves aHttpClientfor the given injection point.- Specified by:
resolveClientin interfaceHttpClientRegistry<HttpClient>- Parameters:
injectionPoint- The injection pointloadBalancer- The load balancer to use (Optional)configuration- The configuration (Optional)beanContext- The bean context to use- Returns:
- The HTTP Client
-
resolveProxyHttpClient
public ProxyHttpClient resolveProxyHttpClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Description copied from interface:ProxyHttpClientRegistryResolves aProxyHttpClientfor the given injection point.- Specified by:
resolveProxyHttpClientin interfaceProxyHttpClientRegistry<ProxyHttpClient>- Parameters:
injectionPoint- The injection pointloadBalancer- The load balancer to use (Optional)configuration- The configuration (Optional)beanContext- The bean context to use- Returns:
- The Proxy HTTP Client
-
resolveSseClient
public SseClient resolveSseClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Description copied from interface:SseClientRegistryResolves aSseClientfor the given injection point.- Specified by:
resolveSseClientin interfaceSseClientRegistry<SseClient>- Parameters:
injectionPoint- The injection pointloadBalancer- The load balancer to use (Optional)configuration- The configuration (Optional)beanContext- The bean context to use- Returns:
- The SSE HTTP Client
-
resolveStreamingHttpClient
public StreamingHttpClient resolveStreamingHttpClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Description copied from interface:StreamingHttpClientRegistryResolves aStreamingHttpClientfor the given injection point.- Specified by:
resolveStreamingHttpClientin interfaceStreamingHttpClientRegistry<StreamingHttpClient>- Parameters:
injectionPoint- The injection pointloadBalancer- The load balancer to use (Optional)configuration- The configuration (Optional)beanContext- The bean context to use- Returns:
- The Streaming HTTP Client
-
resolveWebSocketClient
public WebSocketClient resolveWebSocketClient(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Description copied from interface:WebSocketClientRegistryResolves aWebSocketClientfor the given injection point.- Specified by:
resolveWebSocketClientin interfaceWebSocketClientRegistry<WebSocketClient>- Parameters:
injectionPoint- The injection pointloadBalancer- The load balancer to use (Optional)configuration- The configuration (Optional)beanContext- The bean context to use- Returns:
- The Streaming HTTP Client
-
isClientChannel
public boolean isClientChannel()- Specified by:
isClientChannelin interfaceChannelPipelineCustomizer- Returns:
- Is this customizer the client.
-
doOnConnect
Description copied from interface:ChannelPipelineCustomizerA hook to customize the pipeline upon establishing a connection.- Specified by:
doOnConnectin interfaceChannelPipelineCustomizer- Parameters:
listener- The listener The listener.
-
register
Description copied from interface:NettyClientCustomizer.RegistryRegister a new customizer with this registry.- Specified by:
registerin interfaceNettyClientCustomizer.Registry- Parameters:
customizer- The customizer to register.
-
getObservedConfigurationPrefixes
Description copied from interface:RefreshEventListenerReturns the set of observed configuration prefixes that the event listener should listen for.- Specified by:
getObservedConfigurationPrefixesin interfaceRefreshEventListener- Returns:
- A set of prefixes
-
onApplicationEvent
Description copied from interface:ApplicationEventListenerHandle an application event.- Specified by:
onApplicationEventin interfaceApplicationEventListener<RefreshEvent>- Parameters:
event- the event to respond to
-