Tabnine Logo
OkHttpClient.newBuilder
Code IndexAdd Tabnine to your IDE (free)

How to use
newBuilder
method
in
okhttp3.OkHttpClient

Best Java code snippets using okhttp3.OkHttpClient.newBuilder (Showing top 20 results out of 1,485)

origin: square/okhttp

@Override public void setReadTimeout(int timeoutMillis) {
 client = client.newBuilder()
   .readTimeout(timeoutMillis, TimeUnit.MILLISECONDS)
   .build();
}
origin: square/okhttp

@Override public void setConnectTimeout(int timeoutMillis) {
 client = client.newBuilder()
   .connectTimeout(timeoutMillis, TimeUnit.MILLISECONDS)
   .build();
}
origin: spring-projects/spring-framework

/**
 * Set the underlying write timeout in milliseconds.
 * A value of 0 specifies an infinite timeout.
 */
public void setWriteTimeout(int writeTimeout) {
  this.client = this.client.newBuilder()
      .writeTimeout(writeTimeout, TimeUnit.MILLISECONDS)
      .build();
}
origin: spring-projects/spring-framework

/**
 * Set the underlying read timeout in milliseconds.
 * A value of 0 specifies an infinite timeout.
 */
public void setReadTimeout(int readTimeout) {
  this.client = this.client.newBuilder()
      .readTimeout(readTimeout, TimeUnit.MILLISECONDS)
      .build();
}
origin: spring-projects/spring-framework

/**
 * Set the underlying connect timeout in milliseconds.
 * A value of 0 specifies an infinite timeout.
 */
public void setConnectTimeout(int connectTimeout) {
  this.client = this.client.newBuilder()
      .connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
      .build();
}
origin: square/okhttp

@Override public void setInstanceFollowRedirects(boolean followRedirects) {
 client = client.newBuilder()
   .followRedirects(followRedirects)
   .build();
}
origin: square/okhttp

@Override public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
 delegate.client = delegate.client.newBuilder()
   .hostnameVerifier(hostnameVerifier)
   .build();
}
origin: square/okhttp

@Override public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
 if (sslSocketFactory == null) {
  throw new IllegalArgumentException("sslSocketFactory == null");
 }
 // This fails in JDK 9 because OkHttp is unable to extract the trust manager.
 delegate.client = delegate.client.newBuilder()
   .sslSocketFactory(sslSocketFactory)
   .build();
}
origin: square/okhttp

@Override public HttpParams setParameter(String name, Object value) {
 if (name.equals(ConnRouteParams.DEFAULT_PROXY)) {
  HttpHost host = (HttpHost) value;
  Proxy proxy = null;
  if (host != null) {
   proxy = new Proxy(HTTP, new InetSocketAddress(host.getHostName(), host.getPort()));
  }
  client = client.newBuilder()
    .proxy(proxy)
    .build();
  return this;
 }
 throw new IllegalArgumentException(name);
}
origin: org.springframework/spring-web

/**
 * Set the underlying read timeout in milliseconds.
 * A value of 0 specifies an infinite timeout.
 */
public void setReadTimeout(int readTimeout) {
  this.client = this.client.newBuilder()
      .readTimeout(readTimeout, TimeUnit.MILLISECONDS)
      .build();
}
origin: org.springframework/spring-web

/**
 * Set the underlying write timeout in milliseconds.
 * A value of 0 specifies an infinite timeout.
 */
public void setWriteTimeout(int writeTimeout) {
  this.client = this.client.newBuilder()
      .writeTimeout(writeTimeout, TimeUnit.MILLISECONDS)
      .build();
}
origin: org.springframework/spring-web

/**
 * Set the underlying connect timeout in milliseconds.
 * A value of 0 specifies an infinite timeout.
 */
public void setConnectTimeout(int connectTimeout) {
  this.client = this.client.newBuilder()
      .connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
      .build();
}
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("http://httpbin.org/delay/1") // This URL is served with a 1 second delay.
   .build();
 // Copy to customize OkHttp for this request.
 OkHttpClient client1 = client.newBuilder()
   .readTimeout(500, TimeUnit.MILLISECONDS)
   .build();
 try (Response response = client1.newCall(request).execute()) {
  System.out.println("Response 1 succeeded: " + response);
 } catch (IOException e) {
  System.out.println("Response 1 failed: " + e);
 }
 // Copy to customize OkHttp for this request.
 OkHttpClient client2 = client.newBuilder()
   .readTimeout(3000, TimeUnit.MILLISECONDS)
   .build();
 try (Response response = client2.newCall(request).execute()) {
  System.out.println("Response 2 succeeded: " + response);
 } catch (IOException e) {
  System.out.println("Response 2 failed: " + e);
 }
}
origin: square/okhttp

HttpURLConnection open(URL url, @Nullable Proxy proxy) {
 String protocol = url.getProtocol();
 OkHttpClient copy = client.newBuilder()
   .proxy(proxy)
   .build();
 if (protocol.equals("http")) return new OkHttpURLConnection(url, copy, urlFilter);
 if (protocol.equals("https")) return new OkHttpsURLConnection(url, copy, urlFilter);
 throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
origin: prestodb/presto

private StatementClient startInternalQuery(ClientSession session, String query)
{
  OkHttpClient.Builder builder = httpClient.newBuilder();
  sslSetup.accept(builder);
  OkHttpClient client = builder.build();
  return newStatementClient(client, session, query);
}
origin: square/okhttp

DnsOverHttps(Builder builder) {
 if (builder.client == null) {
  throw new NullPointerException("client not set");
 }
 if (builder.url == null) {
  throw new NullPointerException("url not set");
 }
 this.url = builder.url;
 this.includeIPv6 = builder.includeIPv6;
 this.post = builder.post;
 this.resolvePrivateAddresses = builder.resolvePrivateAddresses;
 this.resolvePublicAddresses = builder.resolvePublicAddresses;
 this.client = builder.client.newBuilder().dns(buildBootstrapClient(builder)).build();
}
origin: square/okhttp

public void connect(OkHttpClient client) {
 client = client.newBuilder()
   .eventListener(EventListener.NONE)
   .build();
 call = client.newCall(request);
 call.timeout().clearTimeout();
 call.enqueue(this);
}
origin: square/okhttp

public void run() throws Exception {
 for (int i = 0; i < 5; i++) {
  System.out.println("    Request: " + i);
  Request request = new Request.Builder()
    .url("https://api.github.com/search/repositories?q=http")
    .build();
  OkHttpClient clientForCall;
  if (i == 2) {
   // Force this request's response to be written to the cache. This way, subsequent responses
   // can be read from the cache.
   System.out.println("Force cache: true");
   clientForCall = client.newBuilder()
     .addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
     .build();
  } else {
   System.out.println("Force cache: false");
   clientForCall = client;
  }
  try (Response response = clientForCall.newCall(request).execute()) {
   if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
   System.out.println("    Network: " + (response.networkResponse() != null));
   System.out.println();
  }
 }
}
origin: Graylog2/graylog2-server

@Inject
public HTTPFileRetriever(OkHttpClient httpClient) {
  this.client = httpClient.newBuilder()
      .followRedirects(true)
      .followSslRedirects(true)
      .build();
}
origin: square/okhttp

 /** Sets the response cache to be used to read and write cached responses. */
 public static void setResponseCache(OkUrlFactory okUrlFactory, ResponseCache responseCache) {
  OkHttpClient.Builder builder = okUrlFactory.client().newBuilder();
  if (responseCache instanceof OkCacheContainer) {
   // Avoid adding layers of wrappers. Rather than wrap the ResponseCache in yet another layer to
   // make the ResponseCache look like an InternalCache, we can unwrap the Cache instead.
   // This means that Cache stats will be correctly updated.
   OkCacheContainer okCacheContainer = (OkCacheContainer) responseCache;
   builder.cache(okCacheContainer.getCache());
  } else {
   builder.setInternalCache(responseCache != null ? new CacheAdapter(responseCache) : null);
  }
  okUrlFactory.setClient(builder.build());
 }
}
okhttp3OkHttpClientnewBuilder

Popular methods of OkHttpClient

  • newCall
    Prepares the request to be executed at some point in the future.
  • <init>
  • dispatcher
  • connectionPool
  • newWebSocket
    Uses request to connect a new web socket.
  • cache
  • connectTimeoutMillis
    Default connect timeout (in milliseconds).
  • interceptors
    Returns an immutable list of interceptors that observe the full span of each call: from before the c
  • readTimeoutMillis
    Default read timeout (in milliseconds).
  • proxy
  • networkInterceptors
    Returns an immutable list of interceptors that observe a single network request and response. These
  • cookieJar
  • networkInterceptors,
  • cookieJar,
  • sslSocketFactory,
  • writeTimeoutMillis,
  • followRedirects,
  • hostnameVerifier,
  • retryOnConnectionFailure,
  • authenticator,
  • connectionSpecs

Popular in Java

  • Updating database using SQL prepared statement
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • getSystemService (Context)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now