本文整理匯總了Java中java.net.ResponseCache.setDefault方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseCache.setDefault方法的具體用法?Java ResponseCache.setDefault怎麽用?Java ResponseCache.setDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.ResponseCache
的用法示例。
在下文中一共展示了ResponseCache.setDefault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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));
}
示例2: 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));
}
示例3: 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));
}
示例4: 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));
}
示例5: 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));
}
示例6: 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));
}
示例7: 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));
}
示例8: 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));
}
示例9: delete
import java.net.ResponseCache; //導入方法依賴的package包/類
/**
* Uninstalls the cache and deletes all of its stored contents.
*/
public void delete() throws IOException {
if (ResponseCache.getDefault() == this) {
ResponseCache.setDefault(null);
}
shimResponseCache.delete();
}
示例10: reset
import java.net.ResponseCache; //導入方法依賴的package包/類
public void reset() {
// Reset system properties.
System.setProperties(null);
// From "L" release onwards, calling System.setProperties(null) clears the java.io.tmpdir,
// so we set it again. No-op on earlier releases.
System.setProperty("java.io.tmpdir", tmpDir);
if (JAVA_RUNTIME_VERSION != null) {
System.setProperty("java.runtime.version", JAVA_RUNTIME_VERSION);
}
if (JAVA_VM_INFO != null) {
System.setProperty("java.vm.info", JAVA_VM_INFO);
}
if (JAVA_VM_VERSION != null) {
System.setProperty("java.vm.version", JAVA_VM_VERSION);
}
if (JAVA_VM_VENDOR != null) {
System.setProperty("java.vm.vendor", JAVA_VM_VENDOR);
}
if (JAVA_VM_NAME != null) {
System.setProperty("java.vm.name", JAVA_VM_NAME);
}
// Require writable java.home and user.dir directories for preferences
if ("Dalvik".equals(System.getProperty("java.vm.name"))) {
String javaHome = tmpDir + "/java.home";
IoUtils.safeMkdirs(new File(javaHome));
System.setProperty("java.home", javaHome);
}
String userHome = System.getProperty("user.home");
if (userHome.length() == 0) {
userHome = tmpDir + "/user.home";
IoUtils.safeMkdirs(new File(userHome));
System.setProperty("user.home", userHome);
}
// Localization
Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
// Preferences
// Temporarily silence the java.util.prefs logger, which otherwise emits
// an unactionable warning. See RI bug 4751540.
Logger loggerToMute = Logger.getLogger("java.util.prefs");
boolean usedParentHandlers = loggerToMute.getUseParentHandlers();
loggerToMute.setUseParentHandlers(false);
try {
// resetPreferences(Preferences.systemRoot());
resetPreferences(Preferences.userRoot());
} finally {
loggerToMute.setUseParentHandlers(usedParentHandlers);
}
// HttpURLConnection
Authenticator.setDefault(null);
CookieHandler.setDefault(null);
ResponseCache.setDefault(null);
HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);
// Logging
LogManager.getLogManager().reset();
Logger.getLogger("").addHandler(new ConsoleHandler());
// Cleanup to force CloseGuard warnings etc
System.gc();
System.runFinalization();
}
示例11: close
import java.net.ResponseCache; //導入方法依賴的package包/類
/**
* Uninstalls the cache and releases any active resources. Stored contents will remain on the
* filesystem.
*/
@Override public void close() throws IOException {
if (ResponseCache.getDefault() == this) {
ResponseCache.setDefault(null);
}
shimResponseCache.close();
}
示例12: reset
import java.net.ResponseCache; //導入方法依賴的package包/類
public static void reset() {
// Set system wide cache handler
System.out.println("install deploy cache handler");
ResponseCache.setDefault(new TestCache());
}
示例13: tearDown
import java.net.ResponseCache; //導入方法依賴的package包/類
@After public void tearDown() throws Exception {
ResponseCache.setDefault(null);
}
示例14: tearDown
import java.net.ResponseCache; //導入方法依賴的package包/類
@After public void tearDown() throws Exception {
ResponseCache.setDefault(null);
cache.delete();
}
示例15: tearDown
import java.net.ResponseCache; //導入方法依賴的package包/類
@After public void tearDown() throws Exception {
ProxySelector.setDefault(DEFAULT_PROXY_SELECTOR);
CookieManager.setDefault(DEFAULT_COOKIE_HANDLER);
ResponseCache.setDefault(DEFAULT_RESPONSE_CACHE);
}