Package io.micronaut.http.client
Class HttpClientConfiguration
- java.lang.Object
-
- io.micronaut.http.client.HttpClientConfiguration
-
- Direct Known Subclasses:
DefaultHttpClientConfiguration,ServiceHttpClientConfiguration
public abstract class HttpClientConfiguration extends java.lang.ObjectConfiguration for theHttpClient.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpClientConfiguration.ConnectionPoolConfigurationConfiguration for the HTTP client connnection pool.
-
Field Summary
Fields Modifier and Type Field Description static longDEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDSThe default pool idle timeout in seconds.static booleanDEFAULT_EXCEPTION_ON_ERROR_STATUSThe default value.static booleanDEFAULT_FOLLOW_REDIRECTSThe default follow redirects value.static intDEFAULT_MAX_CONTENT_LENGTHThe default max content length in bytes.static longDEFAULT_READ_IDLE_TIMEOUT_MINUTESThe default read idle timeout in minutes.static longDEFAULT_READ_TIMEOUT_SECONDSThe default read timeout in seconds.static longDEFAULT_SHUTDOWN_QUIET_PERIOD_MILLISECONDSThe default shutdown timeout in millis.static longDEFAULT_SHUTDOWN_TIMEOUT_MILLISECONDSThe default shutdown timeout in millis.
-
Constructor Summary
Constructors Constructor Description HttpClientConfiguration()Default constructor.HttpClientConfiguration(HttpClientConfiguration copy)Copy constructor.HttpClientConfiguration(io.micronaut.runtime.ApplicationConfiguration applicationConfiguration)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>getChannelOptions()abstract HttpClientConfiguration.ConnectionPoolConfigurationgetConnectionPoolConfiguration()Obtains the connection pool configuration.java.util.Optional<java.time.Duration>getConnectionPoolIdleTimeout()java.util.Optional<java.time.Duration>getConnectTimeout()java.util.Optional<java.time.Duration>getConnectTtl()java.nio.charset.CharsetgetDefaultCharset()java.lang.StringgetEventLoopGroup()io.micronaut.http.HttpVersiongetHttpVersion()The HTTP version to use.java.util.Optional<java.lang.String>getLoggerName()java.util.Optional<io.micronaut.logging.LogLevel>getLogLevel()intgetMaxContentLength()java.util.OptionalIntgetNumOfThreads()java.util.Optional<java.net.SocketAddress>getProxyAddress()The proxy to use.java.util.Optional<java.lang.String>getProxyPassword()java.util.Optional<java.net.ProxySelector>getProxySelector()java.net.Proxy.TypegetProxyType()The proxy to use.java.util.Optional<java.lang.String>getProxyUsername()java.util.Optional<java.time.Duration>getReadIdleTimeout()For streaming requests and WebSockets, thegetReadTimeout()method does not apply instead a configurable idle timeout is applied.java.util.Optional<java.time.Duration>getReadTimeout()java.util.Optional<java.time.Duration>getShutdownQuietPeriod()The amount of quiet period for shutdown.java.util.Optional<java.time.Duration>getShutdownTimeout()The amount of time to wait for shutdown.io.micronaut.http.ssl.SslConfigurationgetSslConfiguration()java.util.Optional<java.lang.Class<? extends java.util.concurrent.ThreadFactory>>getThreadFactory()booleanisExceptionOnErrorStatus()booleanisFollowRedirects()java.net.ProxyresolveProxy(boolean isSsl, java.lang.String host, int port)Resolves a proxy to use for connection.voidsetChannelOptions(java.util.Map<java.lang.String,java.lang.Object> channelOptions)voidsetConnectionPoolIdleTimeout(java.time.Duration connectionPoolIdleTimeout)Sets the idle timeout for connection in the client connection pool.voidsetConnectTimeout(java.time.Duration connectTimeout)Sets the connect timeout.voidsetConnectTtl(java.time.Duration connectTtl)Sets the connect timeout.voidsetDefaultCharset(java.nio.charset.Charset defaultCharset)Sets the default charset to use.voidsetEventLoopGroup(java.lang.String eventLoopGroup)voidsetExceptionOnErrorStatus(boolean exceptionOnErrorStatus)Sets whether throwing an exception upon HTTP error status (>= 400) is preferred.voidsetFollowRedirects(boolean followRedirects)Sets whether redirects should be followed.voidsetHttpVersion(io.micronaut.http.HttpVersion httpVersion)Sets the HTTP version to use.voidsetLoggerName(java.lang.String loggerName)Sets the client-specific logger name.voidsetLogLevel(io.micronaut.logging.LogLevel logLevel)Sets the level to enable trace logging at.voidsetMaxContentLength(int maxContentLength)Sets the maximum content length the client can consume.voidsetNumOfThreads(java.lang.Integer numOfThreads)Sets the number of threads the client should use for requests.voidsetProxyAddress(java.net.SocketAddress proxyAddress)Sets a proxy address.voidsetProxyPassword(java.lang.String proxyPassword)Sets the proxy password.voidsetProxySelector(java.net.ProxySelector proxySelector)Sets the proxy selector.voidsetProxyType(java.net.Proxy.Type proxyType)voidsetProxyUsername(java.lang.String proxyUsername)Sets the proxy user name to use.voidsetReadIdleTimeout(java.time.Duration readIdleTimeout)Sets the max read idle time for streaming requests.voidsetReadTimeout(java.time.Duration readTimeout)Sets the read timeout.voidsetShutdownQuietPeriod(java.time.Duration shutdownQuietPeriod)Sets the amount of quiet period for shutdown of client thread pools.voidsetShutdownTimeout(java.time.Duration shutdownTimeout)Sets the amount of time to wait for shutdown of client thread pools.voidsetSslConfiguration(io.micronaut.http.ssl.SslConfiguration sslConfiguration)Sets the SSL configuration for the client.voidsetThreadFactory(java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactory)Sets a thread factory.
-
-
-
Field Detail
-
DEFAULT_READ_TIMEOUT_SECONDS
public static final long DEFAULT_READ_TIMEOUT_SECONDS
The default read timeout in seconds.- See Also:
- Constant Field Values
-
DEFAULT_READ_IDLE_TIMEOUT_MINUTES
public static final long DEFAULT_READ_IDLE_TIMEOUT_MINUTES
The default read idle timeout in minutes.- See Also:
- Constant Field Values
-
DEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDS
public static final long DEFAULT_CONNECTION_POOL_IDLE_TIMEOUT_SECONDS
The default pool idle timeout in seconds.- See Also:
- Constant Field Values
-
DEFAULT_SHUTDOWN_QUIET_PERIOD_MILLISECONDS
public static final long DEFAULT_SHUTDOWN_QUIET_PERIOD_MILLISECONDS
The default shutdown timeout in millis.- See Also:
- Constant Field Values
-
DEFAULT_SHUTDOWN_TIMEOUT_MILLISECONDS
public static final long DEFAULT_SHUTDOWN_TIMEOUT_MILLISECONDS
The default shutdown timeout in millis.- See Also:
- Constant Field Values
-
DEFAULT_MAX_CONTENT_LENGTH
public static final int DEFAULT_MAX_CONTENT_LENGTH
The default max content length in bytes.- See Also:
- Constant Field Values
-
DEFAULT_FOLLOW_REDIRECTS
public static final boolean DEFAULT_FOLLOW_REDIRECTS
The default follow redirects value.- See Also:
- Constant Field Values
-
DEFAULT_EXCEPTION_ON_ERROR_STATUS
public static final boolean DEFAULT_EXCEPTION_ON_ERROR_STATUS
The default value.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HttpClientConfiguration
public HttpClientConfiguration()
Default constructor.
-
HttpClientConfiguration
public HttpClientConfiguration(io.micronaut.runtime.ApplicationConfiguration applicationConfiguration)
- Parameters:
applicationConfiguration- The application configuration
-
HttpClientConfiguration
public HttpClientConfiguration(HttpClientConfiguration copy)
Copy constructor.- Parameters:
copy- The client configuration to copy settings from
-
-
Method Detail
-
getHttpVersion
public io.micronaut.http.HttpVersion getHttpVersion()
The HTTP version to use. Defaults toHttpVersion.HTTP_1_1.- Returns:
- The http version
-
setHttpVersion
public void setHttpVersion(io.micronaut.http.HttpVersion httpVersion)
Sets the HTTP version to use. Defaults toHttpVersion.HTTP_1_1.- Parameters:
httpVersion- The http version
-
getLogLevel
public java.util.Optional<io.micronaut.logging.LogLevel> getLogLevel()
- Returns:
- The trace logging level
-
setLogLevel
public void setLogLevel(@Nullable io.micronaut.logging.LogLevel logLevel)Sets the level to enable trace logging at. Depending on the implementation this may activate additional handlers. For example in Netty this will activateLoggingHandlerat the given level.- Parameters:
logLevel- The trace logging level
-
getEventLoopGroup
public java.lang.String getEventLoopGroup()
- Returns:
- The event loop group to use.
-
setEventLoopGroup
public void setEventLoopGroup(@NonNull java.lang.String eventLoopGroup)- Parameters:
eventLoopGroup- Sets the event loop group to use for the client.
-
getConnectionPoolConfiguration
public abstract HttpClientConfiguration.ConnectionPoolConfiguration getConnectionPoolConfiguration()
Obtains the connection pool configuration.- Returns:
- The connection pool configuration.
-
getSslConfiguration
public io.micronaut.http.ssl.SslConfiguration getSslConfiguration()
- Returns:
- The
SslConfigurationfor the client
-
setSslConfiguration
public void setSslConfiguration(io.micronaut.http.ssl.SslConfiguration sslConfiguration)
Sets the SSL configuration for the client.- Parameters:
sslConfiguration- The SSL configuration
-
isFollowRedirects
public boolean isFollowRedirects()
- Returns:
- Whether redirects should be followed
-
isExceptionOnErrorStatus
public boolean isExceptionOnErrorStatus()
- Returns:
- Whether throwing an exception upon HTTP error status (>= 400) is preferred.
-
setExceptionOnErrorStatus
public void setExceptionOnErrorStatus(boolean exceptionOnErrorStatus)
Sets whether throwing an exception upon HTTP error status (>= 400) is preferred. Default value (DEFAULT_EXCEPTION_ON_ERROR_STATUS)- Parameters:
exceptionOnErrorStatus- Whether
-
getLoggerName
public java.util.Optional<java.lang.String> getLoggerName()
- Returns:
- The client-specific logger name if configured
-
setLoggerName
public void setLoggerName(@Nullable java.lang.String loggerName)Sets the client-specific logger name.- Parameters:
loggerName- The name of the logger.
-
setFollowRedirects
public void setFollowRedirects(boolean followRedirects)
Sets whether redirects should be followed. Default value (DEFAULT_FOLLOW_REDIRECTS).- Parameters:
followRedirects- Whether redirects should be followed
-
getDefaultCharset
public java.nio.charset.Charset getDefaultCharset()
- Returns:
- The default charset to use
-
setDefaultCharset
public void setDefaultCharset(java.nio.charset.Charset defaultCharset)
Sets the default charset to use. Default value (UTF-8);- Parameters:
defaultCharset- The charset to use
-
getChannelOptions
public java.util.Map<java.lang.String,java.lang.Object> getChannelOptions()
- Returns:
- The Client channel options.
-
setChannelOptions
public void setChannelOptions(java.util.Map<java.lang.String,java.lang.Object> channelOptions)
- Parameters:
channelOptions- The Client channel options
-
getReadTimeout
public java.util.Optional<java.time.Duration> getReadTimeout()
- Returns:
- The default read timeout. Defaults to 10 seconds.
-
getReadIdleTimeout
public java.util.Optional<java.time.Duration> getReadIdleTimeout()
For streaming requests and WebSockets, thegetReadTimeout()method does not apply instead a configurable idle timeout is applied.- Returns:
- The default amount of time to allow read operation connections to remain idle
-
getConnectionPoolIdleTimeout
public java.util.Optional<java.time.Duration> getConnectionPoolIdleTimeout()
- Returns:
- The idle timeout for connection in the client connection pool. Defaults to 0.
-
getConnectTimeout
public java.util.Optional<java.time.Duration> getConnectTimeout()
- Returns:
- The default connect timeout. Defaults to Netty default.
-
getConnectTtl
public java.util.Optional<java.time.Duration> getConnectTtl()
- Returns:
- The connectTtl.
-
getShutdownQuietPeriod
public java.util.Optional<java.time.Duration> getShutdownQuietPeriod()
The amount of quiet period for shutdown.- Returns:
- The shutdown timeout
-
getShutdownTimeout
public java.util.Optional<java.time.Duration> getShutdownTimeout()
The amount of time to wait for shutdown.- Returns:
- The shutdown timeout
-
setShutdownQuietPeriod
public void setShutdownQuietPeriod(@Nullable java.time.Duration shutdownQuietPeriod)Sets the amount of quiet period for shutdown of client thread pools. Default value (1L milliseconds). If a task is submitted during the quiet period, it will be accepted and the quiet period will start over.- Parameters:
shutdownQuietPeriod- The shutdown quiet period
-
setShutdownTimeout
public void setShutdownTimeout(@Nullable java.time.Duration shutdownTimeout)Sets the amount of time to wait for shutdown of client thread pools. Default value (100L milliseconds).- Parameters:
shutdownTimeout- The shutdown time
-
setReadTimeout
public void setReadTimeout(@Nullable java.time.Duration readTimeout)Sets the read timeout. Default value (10L seconds).- Parameters:
readTimeout- The read timeout
-
setReadIdleTimeout
public void setReadIdleTimeout(@Nullable java.time.Duration readIdleTimeout)Sets the max read idle time for streaming requests. Default value (5L minutes).- Parameters:
readIdleTimeout- The read idle time
-
setConnectionPoolIdleTimeout
public void setConnectionPoolIdleTimeout(@Nullable java.time.Duration connectionPoolIdleTimeout)Sets the idle timeout for connection in the client connection pool. Defaults to 0.- Parameters:
connectionPoolIdleTimeout- The connection pool idle timeout
-
setConnectTimeout
public void setConnectTimeout(@Nullable java.time.Duration connectTimeout)Sets the connect timeout.- Parameters:
connectTimeout- The connect timeout
-
setConnectTtl
public void setConnectTtl(@Nullable java.time.Duration connectTtl)Sets the connect timeout.- Parameters:
connectTtl- The connect timeout
-
getNumOfThreads
public java.util.OptionalInt getNumOfThreads()
- Returns:
- The number of threads the client should use for requests
-
setNumOfThreads
public void setNumOfThreads(@Nullable java.lang.Integer numOfThreads)Sets the number of threads the client should use for requests.- Parameters:
numOfThreads- The number of threads the client should use for requests
-
getThreadFactory
public java.util.Optional<java.lang.Class<? extends java.util.concurrent.ThreadFactory>> getThreadFactory()
- Returns:
- An
OptionalThreadFactory
-
setThreadFactory
public void setThreadFactory(java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactory)
Sets a thread factory.- Parameters:
threadFactory- The thread factory
-
getMaxContentLength
public int getMaxContentLength()
- Returns:
- The maximum content length the client can consume
-
setMaxContentLength
public void setMaxContentLength(@ReadableBytes int maxContentLength)Sets the maximum content length the client can consume. Default value (10485760 => 10MB).- Parameters:
maxContentLength- The maximum content length the client can consume
-
getProxyType
public java.net.Proxy.Type getProxyType()
The proxy to use. For authentication specify http.proxyUser and http.proxyPassword system properties.
Alternatively configure a
java.net.ProxySelector- Returns:
- The proxy type
-
setProxyType
public void setProxyType(java.net.Proxy.Type proxyType)
- Parameters:
proxyType- The proxy type
-
getProxyAddress
public java.util.Optional<java.net.SocketAddress> getProxyAddress()
The proxy to use. For authentication specify http.proxyUser and http.proxyPassword system properties.Alternatively configure a
java.net.ProxySelector- Returns:
- The optional proxy address
-
setProxyAddress
public void setProxyAddress(java.net.SocketAddress proxyAddress)
Sets a proxy address.- Parameters:
proxyAddress- The proxy address
-
getProxyUsername
public java.util.Optional<java.lang.String> getProxyUsername()
- Returns:
- The proxy user name to use
-
setProxyUsername
public void setProxyUsername(java.lang.String proxyUsername)
Sets the proxy user name to use.- Parameters:
proxyUsername- The proxy user name to use
-
getProxyPassword
public java.util.Optional<java.lang.String> getProxyPassword()
- Returns:
- The proxy password to use.
-
setProxyPassword
public void setProxyPassword(java.lang.String proxyPassword)
Sets the proxy password.- Parameters:
proxyPassword- The proxy password
-
setProxySelector
public void setProxySelector(java.net.ProxySelector proxySelector)
Sets the proxy selector. ProxySelector decides what proxy to use and take precedence oversetProxyAddress(SocketAddress)andsetProxyType(Proxy.Type).- Parameters:
proxySelector- The proxy selector to use
-
getProxySelector
public java.util.Optional<java.net.ProxySelector> getProxySelector()
- Returns:
- The proxy selector provided
-
resolveProxy
public java.net.Proxy resolveProxy(boolean isSsl, java.lang.String host, int port)Resolves a proxy to use for connection.If ProxySelector is set by
setProxySelector(ProxySelector)then it constructs URI and pass it toProxySelector.select(URI). First proxy returned by proxy selector will be used. If no proxy is returned by select, thenProxy.NO_PROXYwill be used.If ProxySelector is not set then parameters are ignored and a proxy as defined by
setProxyAddress(SocketAddress)andsetProxyType(Proxy.Type)will be returned. If no proxy is defined then parameters are ignored andProxy.NO_PROXYis returned.- Parameters:
isSsl- is it http or https connectionhost- connection hostport- connection port- Returns:
- A non null proxy instance
-
-