/** * Returns a copy of this stream handler factory that includes a shallow copy of the internal * {@linkplain OkHttpClient HTTP client}. */ @Override public OkUrlFactory clone() { return new OkUrlFactory(client); }
@Override protected URLConnection openConnection(URL url, Proxy proxy) { return open(url, proxy); }
/** 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()); } }
@Override public HttpURLConnection openConnection(URL url) throws IOException { if (factory == null) { factory = new OkUrlFactory(clientBuilder.build()); } return factory.open(url); }
@Override public void shutdown() { try { factory.client().dispatcher().executorService().shutdown(); factory.client().dispatcher().executorService().awaitTermination(5, TimeUnit.MINUTES); // Evict all the connections factory.client().connectionPool().evictAll(); } catch (InterruptedException e) { // Oh well; we were only trying to aggressively shutdown } } }
HttpURLConnection connection = new OkUrlFactory(TmmHttpClient.getHttpClient()).open(new URL(request)); connection.setDoOutput(true); connection.setDoInput(true);
@Override protected URLConnection openConnection(URL url) { return open(url); }
Call c = new Call(methodName, params); HttpURLConnection http = new OkUrlFactory(client).open(url); http.setRequestProperty(USER_AGENT, userAgent); http.setRequestMethod(HTTP_POST);
/** * Returns a copy of this stream handler factory that includes a shallow copy of the internal * {@linkplain OkHttpClient HTTP client}. */ @Override public OkUrlFactory clone() { return new OkUrlFactory(client); }
/** 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()); } }
public HttpURLConnection open(URL url) { return open(url, client.proxy()); }
/** * Returns a copy of this stream handler factory that includes a shallow copy of the internal * {@linkplain OkHttpClient HTTP client}. */ @Override public OkUrlFactory clone() { return new OkUrlFactory(client); }
public HttpURLConnection connect(URL url) throws IOException { return urlFactory.open(url); } }
/** * Returns a copy of this stream handler factory that includes a shallow copy of the internal * {@linkplain OkHttpClient HTTP client}. */ @Override public OkUrlFactory clone() { return new OkUrlFactory(client); }
public HttpURLConnection connect(URL url) throws IOException { return urlFactory.open(url); } }
public FCUrlClient(String userAgent, Map<String, String> customHeaders, OkHttpClient client, String apiKey) { okUrlFactory = new OkUrlFactory(client); if(customHeaders != null) { this.headers = customHeaders; } //disallow api key, token, or user agent headers to be supplied by the user boolean removedBlocked = headers.remove(FCConstants.HEADER_AUTH_API_KEY) != null; removedBlocked |= headers.remove(FCConstants.HEADER_AUTH_ACCESS_TOKEN) != null; if(removedBlocked) { Utils.info("Custom FullContact header for api key or access token was supplied. It has been ignored."); } this.userAgent = userAgent; this.apiKey = apiKey; }
@Override protected URLConnection openConnection(URL url) { return open(url); }
private void retrieveRepositoryNames() throws IOException { System.err.println("Retrieving GitHub repository names..."); Cache cache = new Cache(GITHUB_API_CACHE, 20L*1024*1024); // 20 MB cache github = new GitHubBuilder().withConnector(new OkHttp3Connector(new OkUrlFactory(new OkHttpClient.Builder().cache(cache).build()))).withPassword(GITHUB_API_USERNAME, GITHUB_API_PASSWORD).build(); List<String> ret = new ArrayList<>(); for (GHRepository repo : github.getOrganization("jenkinsci").listRepositories().withPageSize(100)) { ret.add(repo.getHtmlUrl().toString()); } Files.write(GITHUB_REPO_LIST.toPath(), ret); }
@Override protected URLConnection openConnection(URL url, Proxy proxy) { return open(url, proxy); }
@Override protected URLConnection openConnection(URL url, Proxy proxy) { return open(url, proxy); }