当前位置: 首页>>代码示例>>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;未经允许,请勿转载。