Class HttpClientConfiguration

    • 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 to HttpVersion.HTTP_1_1.
        Returns:
        The http version
      • setHttpVersion

        public void setHttpVersion​(io.micronaut.http.HttpVersion httpVersion)
        Sets the HTTP version to use. Defaults to HttpVersion.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 activate LoggingHandler at 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.
      • getSslConfiguration

        public io.micronaut.http.ssl.SslConfiguration getSslConfiguration()
        Returns:
        The SslConfiguration for 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, the getReadTimeout() 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 Optional ThreadFactory
      • 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 over setProxyAddress(SocketAddress) and setProxyType(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 to ProxySelector.select(URI). First proxy returned by proxy selector will be used. If no proxy is returned by select, then Proxy.NO_PROXY will be used.

        If ProxySelector is not set then parameters are ignored and a proxy as defined by setProxyAddress(SocketAddress) and setProxyType(Proxy.Type) will be returned. If no proxy is defined then parameters are ignored and Proxy.NO_PROXY is returned.

        Parameters:
        isSsl - is it http or https connection
        host - connection host
        port - connection port
        Returns:
        A non null proxy instance