Module bus.http

Class Httpd.Builder

java.lang.Object
org.miaixz.bus.http.Httpd.Builder
Enclosing class:
Httpd

public static class Httpd.Builder extends Object
A builder for configuring and creating Httpd instances.
  • Constructor Details

    • Builder

      public Builder()
      Default constructor which initializes with default settings.
  • Method Details

    • callTimeout

      public Httpd.Builder callTimeout(long timeout, TimeUnit unit)
      Sets the default timeout for complete calls. A value of 0 means no timeout.
      Parameters:
      timeout - the timeout value.
      unit - the time unit.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
    • callTimeout

      public Httpd.Builder callTimeout(Duration duration)
      Sets the default timeout for complete calls. A value of 0 means no timeout.
      Parameters:
      duration - the timeout duration.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
    • connectTimeout

      public Httpd.Builder connectTimeout(long timeout, TimeUnit unit)
      Sets the default connect timeout for new connections. A value of 0 means no timeout.
      Parameters:
      timeout - the timeout value.
      unit - the time unit.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
    • connectTimeout

      public Httpd.Builder connectTimeout(Duration duration)
      Sets the default connect timeout for new connections. A value of 0 means no timeout.
      Parameters:
      duration - the timeout duration.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
    • readTimeout

      public Httpd.Builder readTimeout(long timeout, TimeUnit unit)
      Sets the default read timeout for new connections. A value of 0 means no timeout.
      Parameters:
      timeout - the timeout value.
      unit - the time unit.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
      See Also:
    • readTimeout

      public Httpd.Builder readTimeout(Duration duration)
      Sets the default read timeout for new connections. A value of 0 means no timeout.
      Parameters:
      duration - the timeout duration.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
      See Also:
    • writeTimeout

      public Httpd.Builder writeTimeout(long timeout, TimeUnit unit)
      Sets the default write timeout for new connections. A value of 0 means no timeout.
      Parameters:
      timeout - the timeout value.
      unit - the time unit.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
      See Also:
      • Sink.timeout()
    • writeTimeout

      public Httpd.Builder writeTimeout(Duration duration)
      Sets the default write timeout for new connections. A value of 0 means no timeout.
      Parameters:
      duration - the timeout duration.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the timeout value is invalid.
      See Also:
      • Sink.timeout()
    • pingInterval

      public Httpd.Builder pingInterval(long interval, TimeUnit unit)
      Sets the WebSocket ping interval. A value of 0 disables pings.
      Parameters:
      interval - the interval value.
      unit - the time unit.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the interval value is invalid.
    • pingInterval

      public Httpd.Builder pingInterval(Duration duration)
      Sets the WebSocket ping interval. A value of 0 disables pings.
      Parameters:
      duration - the interval duration.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the interval value is invalid.
    • proxy

      public Httpd.Builder proxy(Proxy proxy)
      Sets the HTTP proxy that will be used by connections created by this client.
      Parameters:
      proxy - the HTTP proxy.
      Returns:
      this builder instance.
    • proxySelector

      public Httpd.Builder proxySelector(ProxySelector proxySelector)
      Sets the proxy selector that will be used to select the HTTP proxy for each request.
      Parameters:
      proxySelector - the proxy selector.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if proxySelector is null.
    • cookieJar

      public Httpd.Builder cookieJar(CookieJar cookieJar)
      Sets the cookie jar that will be used to manage cookies for all HTTP requests.
      Parameters:
      cookieJar - the cookie jar.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if cookieJar is null.
    • cache

      public Httpd.Builder cache(Cache cache)
      Sets the cache to be used to read and write cached responses.
      Parameters:
      cache - the cache instance.
      Returns:
      this builder instance.
    • dns

      public Httpd.Builder dns(DnsX dns)
      Sets the DNS service used to lookup IP addresses for hostnames.
      Parameters:
      dns - the DNS service.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if dns is null.
    • socketFactory

      public Httpd.Builder socketFactory(SocketFactory socketFactory)
      Sets the socket factory used to create connections.
      Parameters:
      socketFactory - the socket factory.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if socketFactory is null.
      IllegalArgumentException - if socketFactory is an instance of SSLSocketFactory.
    • sslSocketFactory

      public Httpd.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory)
      Sets the SSL socket factory used to create HTTPS connections.
      Parameters:
      sslSocketFactory - the SSL socket factory.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if sslSocketFactory is null.
    • sslSocketFactory

      public Httpd.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager)
      Sets the SSL socket factory and trust manager used for HTTPS connections.

      Most applications should not call this method, and instead use the system defaults.

      Parameters:
      sslSocketFactory - the SSL socket factory.
      trustManager - the X.509 trust manager.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if sslSocketFactory or trustManager is null.
    • hostnameVerifier

      public Httpd.Builder hostnameVerifier(HostnameVerifier hostnameVerifier)
      Sets the verifier used to confirm that response certificates apply to the requested hostnames for HTTPS connections.
      Parameters:
      hostnameVerifier - the hostname verifier.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if hostnameVerifier is null.
    • certificatePinner

      public Httpd.Builder certificatePinner(CertificatePinner certificatePinner)
      Sets the certificate pinner that constrains which certificates are trusted.
      Parameters:
      certificatePinner - the certificate pinner.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if certificatePinner is null.
    • authenticator

      public Httpd.Builder authenticator(Authenticator authenticator)
      Sets the authenticator used to respond to challenges from origin servers.
      Parameters:
      authenticator - the authenticator.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if authenticator is null.
    • proxyAuthenticator

      public Httpd.Builder proxyAuthenticator(Authenticator proxyAuthenticator)
      Sets the authenticator used to respond to challenges from proxy servers.
      Parameters:
      proxyAuthenticator - the proxy authenticator.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if proxyAuthenticator is null.
    • connectionPool

      public Httpd.Builder connectionPool(ConnectionPool connectionPool)
      Sets the connection pool used to recycle HTTP and HTTPS connections.
      Parameters:
      connectionPool - the connection pool.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if connectionPool is null.
    • followSslRedirects

      public Httpd.Builder followSslRedirects(boolean followProtocolRedirects)
      Configures this client to follow redirects from HTTPS to HTTP and from HTTP to HTTPS.
      Parameters:
      followProtocolRedirects - whether to follow SSL redirects.
      Returns:
      this builder instance.
    • followRedirects

      public Httpd.Builder followRedirects(boolean followRedirects)
      Configures this client to follow redirects.
      Parameters:
      followRedirects - whether to follow HTTP redirects.
      Returns:
      this builder instance.
    • retryOnConnectionFailure

      public Httpd.Builder retryOnConnectionFailure(boolean retryOnConnectionFailure)
      Configures this client to retry or not to retry when a connectivity problem is encountered.
      Parameters:
      retryOnConnectionFailure - whether to retry on connection failure.
      Returns:
      this builder instance.
    • dispatcher

      public Httpd.Builder dispatcher(Dispatcher dispatcher)
      Sets the dispatcher used to execute asynchronous requests.
      Parameters:
      dispatcher - the dispatcher.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if dispatcher is null.
    • protocols

      public Httpd.Builder protocols(List<org.miaixz.bus.core.net.Protocol> protocols)
      Sets the protocols used for requests.
      Parameters:
      protocols - the list of protocols.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if the protocols list is invalid.
    • connectionSpecs

      public Httpd.Builder connectionSpecs(List<ConnectionSuite> connectionSuites)
      Sets the connection specs for this client.
      Parameters:
      connectionSuites - the list of connection specs.
      Returns:
      this builder instance.
    • interceptors

      public List<Interceptor> interceptors()
      Returns a mutable list of the application interceptors that observe the full span of each call.
      Returns:
      the list of application interceptors.
    • addInterceptor

      public Httpd.Builder addInterceptor(Interceptor interceptor)
      Adds an application interceptor.
      Parameters:
      interceptor - the application interceptor.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if interceptor is null.
    • networkInterceptors

      public List<Interceptor> networkInterceptors()
      Returns a mutable list of the network interceptors that observe a single network request and response.
      Returns:
      the list of network interceptors.
    • addNetworkInterceptor

      public Httpd.Builder addNetworkInterceptor(Interceptor interceptor)
      Adds a network interceptor.
      Parameters:
      interceptor - the network interceptor.
      Returns:
      this builder instance.
      Throws:
      IllegalArgumentException - if interceptor is null.
    • eventListener

      public Httpd.Builder eventListener(EventListener eventListener)
      Sets the event listener for monitoring request lifecycle events.
      Parameters:
      eventListener - the event listener.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if eventListener is null.
    • eventListenerFactory

      public Httpd.Builder eventListenerFactory(EventListener.Factory eventListenerFactory)
      Sets the factory for creating event listeners.
      Parameters:
      eventListenerFactory - the event listener factory.
      Returns:
      this builder instance.
      Throws:
      NullPointerException - if eventListenerFactory is null.
    • build

      public Httpd build()
      Builds a new Httpd instance with the configured settings.
      Returns:
      a new Httpd instance.