當前位置: 首頁>>代碼示例>>Java>>正文


Java ResponseCache類代碼示例

本文整理匯總了Java中java.net.ResponseCache的典型用法代碼示例。如果您正苦於以下問題:Java ResponseCache類的具體用法?Java ResponseCache怎麽用?Java ResponseCache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ResponseCache類屬於java.net包,在下文中一共展示了ResponseCache類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copyWithDefaults

import java.net.ResponseCache; //導入依賴的package包/類
/**
 * Returns a shallow copy of this OkHttpClient that uses the system-wide default for
 * each field that hasn't been explicitly configured.
 */
private OkHttpClient copyWithDefaults() {
  OkHttpClient result = new OkHttpClient(this);
  result.proxy = proxy;
  result.proxySelector = proxySelector != null ? proxySelector : ProxySelector.getDefault();
  result.cookieHandler = cookieHandler != null ? cookieHandler : CookieHandler.getDefault();
  result.responseCache = responseCache != null ? responseCache : ResponseCache.getDefault();
  result.sslSocketFactory = sslSocketFactory != null
      ? sslSocketFactory
      : HttpsURLConnection.getDefaultSSLSocketFactory();
  result.hostnameVerifier = hostnameVerifier != null
      ? hostnameVerifier
      : OkHostnameVerifier.INSTANCE;
  result.authenticator = authenticator != null
      ? authenticator
      : HttpAuthenticator.SYSTEM_DEFAULT;
  result.connectionPool = connectionPool != null ? connectionPool : ConnectionPool.getDefault();
  result.followProtocolRedirects = followProtocolRedirects;
  result.transports = transports != null ? transports : DEFAULT_TRANSPORTS;
  result.connectTimeout = connectTimeout;
  result.readTimeout = readTimeout;
  return result;
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:27,代碼來源:OkHttpClient.java

示例2: get_httpGet

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void get_httpGet() throws Exception {
  final URL serverUrl = configureServer(new MockResponse());
  assertEquals("http", serverUrl.getProtocol());

  ResponseCache responseCache = new AbstractResponseCache() {
    @Override public CacheResponse get(
        URI uri, String method, Map<String, List<String>> headers) throws IOException {
      try {
        assertEquals(toUri(serverUrl), uri);
        assertEquals("GET", method);
        assertTrue("Arbitrary standard header not present", headers.containsKey("User-Agent"));
        assertEquals(Collections.singletonList("value1"), headers.get("key1"));
        return null;
      } catch (Throwable t) {
        throw new IOException("unexpected cache failure", t);
      }
    }
  };
  setInternalCache(new CacheAdapter(responseCache));

  connection = new OkUrlFactory(client).open(serverUrl);
  connection.setRequestProperty("key1", "value1");

  executeGet(connection);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:CacheAdapterTest.java

示例3: otherStacks_cacheHitWithoutVary

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheHitWithoutVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("FAIL"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ResponseCacheTest.java

示例4: otherStacks_cacheMissWithVaryAcceptEncoding

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAcceptEncoding() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Encoding")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:ResponseCacheTest.java

示例5: otherStacks_cacheMissWithVary

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheMissWithVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Language")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  connection.setRequestProperty("Accept-Language", "en-US");
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:ResponseCacheTest.java

示例6: otherStacks_cacheMissWithVaryAsterisk

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAsterisk() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: *")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:ResponseCacheTest.java

示例7: get_httpGet

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void get_httpGet() throws Exception {
  final URL serverUrl = configureServer(new MockResponse());
  assertEquals("http", serverUrl.getProtocol());

  ResponseCache responseCache = new AbstractResponseCache() {
    @Override public CacheResponse get(
        URI uri, String method, Map<String, List<String>> headers) throws IOException {
      assertEquals(toUri(serverUrl), uri);
      assertEquals("GET", method);
      assertTrue("Arbitrary standard header not present", headers.containsKey("User-Agent"));
      assertEquals(Collections.singletonList("value1"), headers.get("key1"));
      return null;
    }
  };
  setInternalCache(new CacheAdapter(responseCache));

  connection = new OkUrlFactory(client).open(serverUrl);
  connection.setRequestProperty("key1", "value1");

  executeGet(connection);
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:22,代碼來源:CacheAdapterTest.java

示例8: get_httpsGet

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void get_httpsGet() throws Exception {
  final URL serverUrl = configureHttpsServer(new MockResponse());
  assertEquals("https", serverUrl.getProtocol());

  ResponseCache responseCache = new AbstractResponseCache() {
    @Override public CacheResponse get(URI uri, String method, Map<String, List<String>> headers)
        throws IOException {
      assertEquals("https", uri.getScheme());
      assertEquals(toUri(serverUrl), uri);
      assertEquals("GET", method);
      assertTrue("Arbitrary standard header not present", headers.containsKey("User-Agent"));
      assertEquals(Collections.singletonList("value1"), headers.get("key1"));
      return null;
    }
  };
  setInternalCache(new CacheAdapter(responseCache));
  client = client.newBuilder()
      .sslSocketFactory(sslContext.getSocketFactory())
      .hostnameVerifier(hostnameVerifier)
      .build();

  connection = new OkUrlFactory(client).open(serverUrl);
  connection.setRequestProperty("key1", "value1");

  executeGet(connection);
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:27,代碼來源:CacheAdapterTest.java

示例9: otherStacks_cacheHitWithoutVary

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheHitWithoutVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("FAIL"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:20,代碼來源:ResponseCacheTest.java

示例10: otherStacks_cacheMissWithVaryAcceptEncoding

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAcceptEncoding() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Encoding")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:21,代碼來源:ResponseCacheTest.java

示例11: otherStacks_cacheMissWithVary

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheMissWithVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Language")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  connection.setRequestProperty("Accept-Language", "en-US");
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:22,代碼來源:ResponseCacheTest.java

示例12: otherStacks_cacheMissWithVaryAsterisk

import java.net.ResponseCache; //導入依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAsterisk() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: *")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:21,代碼來源:ResponseCacheTest.java


注:本文中的java.net.ResponseCache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。