Class HttpClientConfiguration

java.lang.Object
io.micronaut.http.client.HttpClientConfiguration
Direct Known Subclasses:
DefaultHttpClientConfiguration, ServiceHttpClientConfiguration

public abstract class HttpClientConfiguration extends Object
Configuration for the HttpClient.
Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • DEFAULT_READ_TIMEOUT_SECONDS

      public static final long DEFAULT_READ_TIMEOUT_SECONDS
      The default read timeout in seconds.
      See Also:
    • DEFAULT_READ_IDLE_TIMEOUT_MINUTES

      public static final long DEFAULT_READ_IDLE_TIMEOUT_MINUTES
      The default read idle timeout in minutes.
      See Also:
    • 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:
    • DEFAULT_SHUTDOWN_QUIET_PERIOD_MILLISECONDS

      public static final long DEFAULT_SHUTDOWN_QUIET_PERIOD_MILLISECONDS
      The default shutdown timeout in millis.
      See Also:
    • DEFAULT_SHUTDOWN_TIMEOUT_MILLISECONDS

      public static final long DEFAULT_SHUTDOWN_TIMEOUT_MILLISECONDS
      The default shutdown timeout in millis.
      See Also:
    • DEFAULT_MAX_CONTENT_LENGTH

      public static final int DEFAULT_MAX_CONTENT_LENGTH
      The default max content length in bytes.
      See Also:
    • DEFAULT_FOLLOW_REDIRECTS

      public static final boolean DEFAULT_FOLLOW_REDIRECTS
      The default follow redirects value.
      See Also:
    • DEFAULT_EXCEPTION_ON_ERROR_STATUS

      public static final boolean DEFAULT_EXCEPTION_ON_ERROR_STATUS
      The default value.
      See Also:
  • Constructor Details

    • HttpClientConfiguration

      public HttpClientConfiguration()
      Default constructor.
    • HttpClientConfiguration

      public HttpClientConfiguration(ApplicationConfiguration applicationConfiguration)
      Parameters:
      applicationConfiguration - The application configuration
    • HttpClientConfiguration

      public HttpClientConfiguration(HttpClientConfiguration copy)
      Copy constructor.
      Parameters:
      copy - The client configuration to copy settings from
  • Method Details

    • getHttpVersion

      @Deprecated public HttpVersion getHttpVersion()
      Deprecated.
      There are now separate settings for HTTP and HTTPS connections. To configure HTTP connections (e.g. for h2c), use plaintextMode. To configure ALPN, set alpnModes.
      The HTTP version to use. Defaults to HttpVersion.HTTP_1_1.
      Returns:
      The http version
    • setHttpVersion

      @Deprecated public void setHttpVersion(HttpVersion httpVersion)
      Deprecated.
      There are now separate settings for HTTP and HTTPS connections. To configure HTTP connections (e.g. for h2c), use plaintextMode. To configure ALPN, set alpnModes.
      Sets the HTTP version to use. Defaults to HttpVersion.HTTP_1_1.
      Parameters:
      httpVersion - The http version
    • getLogLevel

      public Optional<LogLevel> getLogLevel()
      Returns:
      The trace logging level
    • setLogLevel

      public void setLogLevel(@Nullable 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 String getEventLoopGroup()
      Returns:
      The event loop group to use.
    • setEventLoopGroup

      public void setEventLoopGroup(@NonNull 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 SslConfiguration getSslConfiguration()
      Returns:
      The SslConfiguration for the client
    • setSslConfiguration

      public void setSslConfiguration(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 Optional<String> getLoggerName()
      Returns:
      The client-specific logger name if configured
    • setLoggerName

      public void setLoggerName(@Nullable 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 Charset getDefaultCharset()
      Returns:
      The default charset to use
    • setDefaultCharset

      public void setDefaultCharset(Charset defaultCharset)
      Sets the default charset to use. Default value (UTF-8);
      Parameters:
      defaultCharset - The charset to use
    • getChannelOptions

      public Map<String,Object> getChannelOptions()
      Returns:
      The Client channel options.
    • setChannelOptions

      public void setChannelOptions(Map<String,Object> channelOptions)
      Parameters:
      channelOptions - The Client channel options
    • getReadTimeout

      public Optional<Duration> getReadTimeout()
      Returns:
      The default read timeout. Defaults to 10 seconds.
    • getReadIdleTimeout

      public Optional<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 Optional<Duration> getConnectionPoolIdleTimeout()
      Returns:
      The idle timeout for connection in the client connection pool. Defaults to 0.
    • getConnectTimeout

      public Optional<Duration> getConnectTimeout()
      Returns:
      The default connect timeout. Defaults to Netty default.
    • getConnectTtl

      public Optional<Duration> getConnectTtl()
      Returns:
      The connectTtl.
    • getShutdownQuietPeriod

      public Optional<Duration> getShutdownQuietPeriod()
      The amount of quiet period for shutdown.
      Returns:
      The shutdown timeout
    • getShutdownTimeout

      public Optional<Duration> getShutdownTimeout()
      The amount of time to wait for shutdown.
      Returns:
      The shutdown timeout
    • setShutdownQuietPeriod

      public void setShutdownQuietPeriod(@Nullable 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 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 Duration readTimeout)
      Sets the read timeout. Default value (10L seconds).
      Parameters:
      readTimeout - The read timeout
    • setReadIdleTimeout

      public void setReadIdleTimeout(@Nullable 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 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 Duration connectTimeout)
      Sets the connect timeout.
      Parameters:
      connectTimeout - The connect timeout
    • setConnectTtl

      public void setConnectTtl(@Nullable Duration connectTtl)
      Sets the connect timeout.
      Parameters:
      connectTtl - The connect timeout
    • getNumOfThreads

      public OptionalInt getNumOfThreads()
      Returns:
      The number of threads the client should use for requests
    • setNumOfThreads

      public void setNumOfThreads(@Nullable 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 Optional<Class<? extends ThreadFactory>> getThreadFactory()
      Returns:
      An Optional ThreadFactory
    • setThreadFactory

      public void setThreadFactory(Class<? extends 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 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(Proxy.Type proxyType)
      Parameters:
      proxyType - The proxy type
    • getProxyAddress

      public Optional<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(SocketAddress proxyAddress)
      Sets a proxy address.
      Parameters:
      proxyAddress - The proxy address
    • getProxyUsername

      public Optional<String> getProxyUsername()
      Returns:
      The proxy user name to use
    • setProxyUsername

      public void setProxyUsername(String proxyUsername)
      Sets the proxy user name to use.
      Parameters:
      proxyUsername - The proxy user name to use
    • getProxyPassword

      public Optional<String> getProxyPassword()
      Returns:
      The proxy password to use.
    • setProxyPassword

      public void setProxyPassword(String proxyPassword)
      Sets the proxy password.
      Parameters:
      proxyPassword - The proxy password
    • setProxySelector

      public void setProxySelector(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 Optional<ProxySelector> getProxySelector()
      Returns:
      The proxy selector provided
    • resolveProxy

      public Proxy resolveProxy(boolean isSsl, 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
    • getPlaintextMode

      @NonNull public HttpVersionSelection.PlaintextMode getPlaintextMode()
      The connection mode to use for plaintext (http as opposed to https) connections.
      Note: If httpVersion is set, this setting is ignored!
      Returns:
      The plaintext connection mode.
      Since:
      4.0.0
    • setPlaintextMode

      public void setPlaintextMode(@NonNull HttpVersionSelection.PlaintextMode plaintextMode)
      The connection mode to use for plaintext (http as opposed to https) connections.
      Note: If httpVersion is set, this setting is ignored!
      Parameters:
      plaintextMode - The plaintext connection mode.
      Since:
      4.0.0
    • getAlpnModes

      @NonNull public List<String> getAlpnModes()
      The protocols to support for TLS ALPN. If HTTP 2 is included, this will also restrict the TLS cipher suites to those supported by the HTTP 2 standard.
      Note: If httpVersion is set, this setting is ignored!
      Returns:
      The supported ALPN protocols.
      Since:
      4.0.0
    • setAlpnModes

      public void setAlpnModes(@NonNull List<String> alpnModes)
      The protocols to support for TLS ALPN. If HTTP 2 is included, this will also restrict the TLS cipher suites to those supported by the HTTP 2 standard.
      Note: If httpVersion is set, this setting is ignored!
      Parameters:
      alpnModes - The supported ALPN protocols.
      Since:
      4.0.0