本文整理汇总了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;
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}