Class OkHttpClientBuilder

java.lang.Object
org.sonarqube.ws.client.OkHttpClientBuilder

public class OkHttpClientBuilder extends Object
Helper to build an instance of OkHttpClient that correctly supports HTTPS and proxy authentication. It also handles sending of User-Agent header.
  • Constructor Details

    • OkHttpClientBuilder

      public OkHttpClientBuilder()
  • Method Details

    • setUserAgent

      public OkHttpClientBuilder setUserAgent(@Nullable String s)
      Optional User-Agent. If set, then all the requests sent by the OkHttpClient will include the header "User-Agent".
    • setSSLSocketFactory

      public OkHttpClientBuilder setSSLSocketFactory(@Nullable SSLSocketFactory sslSocketFactory)
      Optional SSL socket factory with which SSL sockets will be created to establish SSL connections. If not set, a default SSL socket factory will be used, base d on the JVM's default key store.
    • setTrustManager

      public OkHttpClientBuilder setTrustManager(@Nullable X509TrustManager sslTrustManager)
      Optional SSL trust manager used to validate certificates. If not set, a default system trust manager will be used, based on the JVM's default truststore.
    • setProxy

      public OkHttpClientBuilder setProxy(@Nullable Proxy proxy)
      Optional proxy. If set, then all the requests sent by the OkHttpClient will reach the proxy. If not set, then the system-wide proxy is used.
    • setProxyLogin

      public OkHttpClientBuilder setProxyLogin(@Nullable String s)
      Login required for proxy authentication.
    • setProxyPassword

      public OkHttpClientBuilder setProxyPassword(@Nullable String s)
      Password used for proxy authentication. It is ignored if proxy login is not defined (see setProxyLogin(String)). It can be null or empty when login is defined.
    • setConnectTimeoutMs

      public OkHttpClientBuilder setConnectTimeoutMs(long l)
      Sets the default connect timeout for new connections. A value of 0 means no timeout. Default is defined by OkHttp (10 seconds in OkHttp 3.3).
    • setCredentials

      public OkHttpClientBuilder setCredentials(String credentials)
      Set credentials that will be passed on every request
    • setReadTimeoutMs

      public OkHttpClientBuilder setReadTimeoutMs(long l)
      Sets the default read timeout for new connections. A value of 0 means no timeout. Default is defined by OkHttp (10 seconds in OkHttp 3.3).
    • setFollowRedirects

      public OkHttpClientBuilder setFollowRedirects(Boolean followRedirects)
      Set if redirects should be followed or not. Default is defined by OkHttp (true, follow redirects).
    • build

      public okhttp3.OkHttpClient build()