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>
,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>, 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_PROTOCOL_NEGOTIATOR, HANDLER_HTTP2_SETTINGS, HANDLER_HTTP2_UPGRADE_REQUEST, HANDLER_IDLE_STATE, HANDLER_INITIAL_ERROR, HANDLER_MICRONAUT_FULL_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_UPGRADE
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Fields inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
DEFAULT_POSITION
-
Constructor Summary
ConstructorDescriptionDefaultNettyHttpClientRegistry
(HttpClientConfiguration defaultHttpClientConfiguration, HttpClientFilterResolver httpClientFilterResolver, LoadBalancerResolver loadBalancerResolver, ClientSslBuilder nettyClientSslBuilder, ThreadFactory threadFactory, MediaTypeCodecRegistry codecRegistry, MessageBodyHandlerRegistry handlerRegistry, EventLoopGroupRegistry eventLoopGroupRegistry, EventLoopGroupFactory eventLoopGroupFactory, BeanContext beanContext, JsonMapper jsonMapper) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
disposeClient
(AnnotationMetadata annotationMetadata) Dispose of the client defined by the given metadata.void
doOnConnect
(@NonNull ChannelPipelineListener listener) A hook to customize the pipeline upon establishing a connection.getClient
(@NonNull AnnotationMetadata metadata) Return the client for the given annotation metadata.getClient
(@NonNull HttpVersionSelection httpVersion, @NonNull 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
(@NonNull AnnotationMetadata metadata) Return the client for the given annotation metadata.getSseClient
(@NonNull AnnotationMetadata metadata) Return the client for the given annotation metadata.getStreamingHttpClient
(@NonNull AnnotationMetadata metadata) Return the client for the given annotation metadata.getWebSocketClient
(@NonNull AnnotationMetadata metadata) Return the client for the given annotation metadata.protected DefaultHttpClient
httpClient
(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Creates a newHttpClient
for the given injection point.boolean
void
onApplicationEvent
(RefreshEvent event) Handle an application event.void
register
(@NonNull NettyClientCustomizer customizer) Register a new customizer with this registry.resolveClient
(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, @NonNull BeanContext beanContext) Resolves aHttpClient
for the given injection point.resolveProxyHttpClient
(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, @NonNull BeanContext beanContext) Resolves aProxyHttpClient
for the given injection point.resolveSseClient
(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, @NonNull BeanContext beanContext) Resolves aSseClient
for the given injection point.resolveStreamingHttpClient
(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, @NonNull BeanContext beanContext) Resolves aStreamingHttpClient
for the given injection point.resolveWebSocketClient
(@Nullable InjectionPoint<?> injectionPoint, @Nullable LoadBalancer loadBalancer, @Nullable HttpClientConfiguration configuration, @NonNull BeanContext beanContext) Resolves aWebSocketClient
for the given injection point.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.http.netty.channel.ChannelPipelineCustomizer
isServerChannel
Methods inherited from interface io.micronaut.http.client.HttpClientRegistry
getClient, getDefaultClient
Methods inherited from interface io.micronaut.http.client.ProxyHttpClientRegistry
getDefaultProxyHttpClient
Methods inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
getOrder, supports
Methods inherited from interface io.micronaut.http.client.sse.SseClientRegistry
getDefaultSseClient
Methods inherited from interface io.micronaut.http.client.StreamingHttpClientRegistry
getDefaultStreamingHttpClient
Methods inherited from interface io.micronaut.websocket.WebSocketClientRegistry
getDefaultWebSocketClient
-
Constructor Details
-
DefaultNettyHttpClientRegistry
public DefaultNettyHttpClientRegistry(HttpClientConfiguration defaultHttpClientConfiguration, HttpClientFilterResolver httpClientFilterResolver, LoadBalancerResolver loadBalancerResolver, ClientSslBuilder nettyClientSslBuilder, ThreadFactory threadFactory, MediaTypeCodecRegistry codecRegistry, MessageBodyHandlerRegistry handlerRegistry, EventLoopGroupRegistry eventLoopGroupRegistry, EventLoopGroupFactory eventLoopGroupFactory, BeanContext beanContext, JsonMapper jsonMapper) Default constructor.- Parameters:
defaultHttpClientConfiguration
- The default HTTP client configurationhttpClientFilterResolver
- The HTTP client filter resolverloadBalancerResolver
- The load balancer resolvernettyClientSslBuilder
- The client SSL builderthreadFactory
- The thread factorycodecRegistry
- The codec registryhandlerRegistry
- The handler registryeventLoopGroupRegistry
- The event loop group registryeventLoopGroupFactory
- The event loop group factorybeanContext
- The bean contextjsonMapper
- JSON Mapper
-
-
Method Details
-
getClient
@NonNull public @NonNull HttpClient getClient(@NonNull @NonNull HttpVersionSelection httpVersion, @NonNull @NonNull String clientId, @Nullable @Nullable String path) Description copied from interface:HttpClientRegistry
Return the client for the client ID and path.- Specified by:
getClient
in interfaceHttpClientRegistry<HttpClient>
- Parameters:
httpVersion
- The HTTP versionclientId
- The client IDpath
- The path (Optional)- Returns:
- The client
-
getClient
Description copied from interface:HttpClientRegistry
Return the client for the given annotation metadata.- Specified by:
getClient
in interfaceHttpClientRegistry<HttpClient>
- Parameters:
metadata
- The annotation metadata.- Returns:
- The client
-
getSseClient
@NonNull public @NonNull DefaultHttpClient getSseClient(@NonNull @NonNull AnnotationMetadata metadata) Description copied from interface:SseClientRegistry
Return the client for the given annotation metadata.- Specified by:
getSseClient
in interfaceSseClientRegistry<SseClient>
- Parameters:
metadata
- The annotation metadata.- Returns:
- The client
-
getStreamingHttpClient
@NonNull public @NonNull DefaultHttpClient getStreamingHttpClient(@NonNull @NonNull AnnotationMetadata metadata) Description copied from interface:StreamingHttpClientRegistry
Return the client for the given annotation metadata.- Specified by:
getStreamingHttpClient
in interfaceStreamingHttpClientRegistry<StreamingHttpClient>
- Parameters:
metadata
- The annotation metadata.- Returns:
- The client
-
getProxyHttpClient
@NonNull public @NonNull DefaultHttpClient getProxyHttpClient(@NonNull @NonNull AnnotationMetadata metadata) Description copied from interface:ProxyHttpClientRegistry
Return the client for the given annotation metadata.- Specified by:
getProxyHttpClient
in interfaceProxyHttpClientRegistry<ProxyHttpClient>
- Parameters:
metadata
- The annotation metadata.- Returns:
- The client
-
getWebSocketClient
@NonNull public @NonNull DefaultHttpClient getWebSocketClient(@NonNull @NonNull AnnotationMetadata metadata) Description copied from interface:WebSocketClientRegistry
Return the client for the given annotation metadata.- Specified by:
getWebSocketClient
in interfaceWebSocketClientRegistry<WebSocketClient>
- Parameters:
metadata
- The annotation metadata.- Returns:
- The client
-
close
- Specified by:
close
in interfaceAutoCloseable
-
disposeClient
Description copied from interface:HttpClientRegistry
Dispose of the client defined by the given metadata.- Specified by:
disposeClient
in interfaceHttpClientRegistry<HttpClient>
- Specified by:
disposeClient
in interfaceProxyHttpClientRegistry<ProxyHttpClient>
- Specified by:
disposeClient
in interfaceSseClientRegistry<SseClient>
- Specified by:
disposeClient
in interfaceStreamingHttpClientRegistry<StreamingHttpClient>
- Specified by:
disposeClient
in interfaceWebSocketClientRegistry<WebSocketClient>
- Parameters:
annotationMetadata
- The annotation metadata
-
httpClient
@Bean @Primary protected DefaultHttpClient httpClient(@Nullable @Nullable InjectionPoint<?> injectionPoint, @Parameter @Nullable @Nullable LoadBalancer loadBalancer, @Parameter @Nullable @Nullable HttpClientConfiguration configuration, BeanContext beanContext) Creates a newHttpClient
for 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
@NonNull public @NonNull HttpClient resolveClient(@Nullable @Nullable InjectionPoint<?> injectionPoint, @Nullable @Nullable LoadBalancer loadBalancer, @Nullable @Nullable HttpClientConfiguration configuration, @NonNull @NonNull BeanContext beanContext) Description copied from interface:HttpClientRegistry
Resolves aHttpClient
for the given injection point.- Specified by:
resolveClient
in 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
@NonNull public @NonNull ProxyHttpClient resolveProxyHttpClient(@Nullable @Nullable InjectionPoint<?> injectionPoint, @Nullable @Nullable LoadBalancer loadBalancer, @Nullable @Nullable HttpClientConfiguration configuration, @NonNull @NonNull BeanContext beanContext) Description copied from interface:ProxyHttpClientRegistry
Resolves aProxyHttpClient
for the given injection point.- Specified by:
resolveProxyHttpClient
in 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
@NonNull public @NonNull SseClient resolveSseClient(@Nullable @Nullable InjectionPoint<?> injectionPoint, @Nullable @Nullable LoadBalancer loadBalancer, @Nullable @Nullable HttpClientConfiguration configuration, @NonNull @NonNull BeanContext beanContext) Description copied from interface:SseClientRegistry
Resolves aSseClient
for the given injection point.- Specified by:
resolveSseClient
in 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
@NonNull public @NonNull StreamingHttpClient resolveStreamingHttpClient(@Nullable @Nullable InjectionPoint<?> injectionPoint, @Nullable @Nullable LoadBalancer loadBalancer, @Nullable @Nullable HttpClientConfiguration configuration, @NonNull @NonNull BeanContext beanContext) Description copied from interface:StreamingHttpClientRegistry
Resolves aStreamingHttpClient
for the given injection point.- Specified by:
resolveStreamingHttpClient
in 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
@NonNull public @NonNull WebSocketClient resolveWebSocketClient(@Nullable @Nullable InjectionPoint<?> injectionPoint, @Nullable @Nullable LoadBalancer loadBalancer, @Nullable @Nullable HttpClientConfiguration configuration, @NonNull @NonNull BeanContext beanContext) Description copied from interface:WebSocketClientRegistry
Resolves aWebSocketClient
for the given injection point.- Specified by:
resolveWebSocketClient
in 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:
isClientChannel
in interfaceChannelPipelineCustomizer
- Returns:
- Is this customizer the client.
-
doOnConnect
Description copied from interface:ChannelPipelineCustomizer
A hook to customize the pipeline upon establishing a connection.- Specified by:
doOnConnect
in interfaceChannelPipelineCustomizer
- Parameters:
listener
- The listener The listener.
-
register
Description copied from interface:NettyClientCustomizer.Registry
Register a new customizer with this registry.- Specified by:
register
in interfaceNettyClientCustomizer.Registry
- Parameters:
customizer
- The customizer to register.
-
getObservedConfigurationPrefixes
Description copied from interface:RefreshEventListener
Returns the set of observed configuration prefixes that the event listener should listen for.- Specified by:
getObservedConfigurationPrefixes
in interfaceRefreshEventListener
- Returns:
- A set of prefixes
-
onApplicationEvent
Description copied from interface:ApplicationEventListener
Handle an application event.- Specified by:
onApplicationEvent
in interfaceApplicationEventListener<RefreshEvent>
- Parameters:
event
- the event to respond to
-