Java Code Examples for java.net.CookieHandler#getDefault()
The following examples show how to use
java.net.CookieHandler#getDefault() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OkHttpClient.java From crosswalk-cordova-android with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: OkHttpClient.java From reader with MIT License | 6 votes |
/** * 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; }
Example 3
Source File: OkHttpClient.java From CordovaYoutubeVideoPlayer with MIT License | 6 votes |
/** * 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; }
Example 4
Source File: OkHttpClient.java From reader with MIT License | 6 votes |
/** * 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; }
Example 5
Source File: AuthCookie.java From utexas-utilities with Apache License 2.0 | 6 votes |
/** * Executes a login request with the AuthCookie's OkHttpClient. This should only be called * when persistent login is activated. * @param request Request to execute * @return true if the cookie was set successfully, false if the cookie was not set * @throws IOException */ protected boolean performLogin(Request request) throws IOException { Response response = client.newCall(request).execute(); if (!response.isSuccessful()) { throw new IOException("Bad response code: " + response + " during login."); } response.body().close(); CookieManager cm = (CookieManager) CookieHandler.getDefault(); List<HttpCookie> cookies = cm.getCookieStore().getCookies(); for (HttpCookie cookie : cookies) { String cookieVal = cookie.getValue(); if (cookie.getName().equals(authCookieKey)) { setAuthCookieVal(cookieVal); return true; } } return false; }
Example 6
Source File: IosHttpURLConnection.java From j2objc with Apache License 2.0 | 5 votes |
/** * Add any cookies for this URI to the request headers. */ private void loadRequestCookies() throws IOException { CookieHandler cookieHandler = CookieHandler.getDefault(); if (cookieHandler != null) { try { URI uri = getURL().toURI(); Map<String, List<String>> cookieHeaders = cookieHandler.get(uri, getHeaderFieldsDoNotForceResponse()); for (Map.Entry<String, List<String>> entry : cookieHeaders.entrySet()) { String key = entry.getKey(); if (("Cookie".equalsIgnoreCase(key) || "Cookie2".equalsIgnoreCase(key)) && !entry.getValue().isEmpty()) { List<String> cookies = entry.getValue(); StringBuilder sb = new StringBuilder(); for (int i = 0, size = cookies.size(); i < size; i++) { if (i > 0) { sb.append("; "); } sb.append(cookies.get(i)); } setHeader(key, sb.toString()); } } } catch (URISyntaxException e) { throw new IOException(e); } } }
Example 7
Source File: AbstractCookiesTest.java From j2objc with Apache License 2.0 | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); server = new MockWebServer(); defaultHandler = CookieHandler.getDefault(); cookieManager = new CookieManager(createCookieStore(), null); cookieStore = cookieManager.getCookieStore(); }
Example 8
Source File: OldCookieHandlerTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_get_put() throws Exception { MockCookieHandler mch = new MockCookieHandler(); CookieHandler defaultHandler = CookieHandler.getDefault(); try { CookieHandler.setDefault(mch); server.play(); server.enqueue(new MockResponse().addHeader("Set-Cookie2: a=\"android\"; " + "Comment=\"this cookie is delicious\"; " + "CommentURL=\"http://google.com/\"; " + "Discard; " + "Domain=\"" + server.getCookieDomain() + "\"; " + "Max-Age=\"60\"; " + "Path=\"/path\"; " + "Port=\"80,443," + server.getPort() + "\"; " + "Secure; " + "Version=\"1\"")); URLConnection connection = server.getUrl("/path/foo").openConnection(); connection.getContent(); assertTrue(mch.wasGetCalled()); assertTrue(mch.wasPutCalled()); } finally { CookieHandler.setDefault(defaultHandler); } }
Example 9
Source File: LibrariesTest.java From appengine-plugins-core with Apache License 2.0 | 5 votes |
@Before public void parseJson() { oldCookieHandler = CookieHandler.getDefault(); // https://github.com/GoogleCloudPlatform/appengine-plugins-core/issues/822 CookieHandler.setDefault(new CookieManager()); JsonReaderFactory factory = Json.createReaderFactory(null); InputStream in = LibrariesTest.class.getResourceAsStream("libraries.json"); JsonReader reader = factory.createReader(in); apis = reader.readArray().toArray(new JsonObject[0]); }
Example 10
Source File: HttpOnly.java From hottub with GNU General Public License v2.0 | 5 votes |
void test(String[] args) throws Exception { HttpServer server = startHttpServer(); CookieHandler previousHandler = CookieHandler.getDefault(); try { InetSocketAddress address = server.getAddress(); URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH); populateCookieStore(uri); doClient(uri); } finally { CookieHandler.setDefault(previousHandler); server.stop(0); } }
Example 11
Source File: LiveVideoPlayerActivity.java From LiveVideoBroadcaster with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); userAgent = Util.getUserAgent(this, "ExoPlayerDemo"); shouldAutoPlay = true; clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); rtmpDataSourceFactory = new RtmpDataSource.RtmpDataSourceFactory(); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.activity_live_video_player); View rootView = findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) findViewById(R.id.controls_root); debugTextView = (TextView) findViewById(R.id.debug_text_view); retryButton = (Button) findViewById(R.id.retry_button); retryButton.setOnClickListener(this); videoNameEditText = (EditText) findViewById(R.id.video_name_edit_text); videoStartControlLayout = findViewById(R.id.video_start_control_layout); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); }
Example 12
Source File: HttpOnly.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
void test(String[] args) throws Exception { HttpServer server = startHttpServer(); CookieHandler previousHandler = CookieHandler.getDefault(); try { InetSocketAddress address = server.getAddress(); URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH); populateCookieStore(uri); doClient(uri); } finally { CookieHandler.setDefault(previousHandler); server.stop(0); } }
Example 13
Source File: HttpOnly.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void test(String[] args) throws Exception { HttpServer server = startHttpServer(); CookieHandler previousHandler = CookieHandler.getDefault(); try { InetSocketAddress address = server.getAddress(); URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH); populateCookieStore(uri); doClient(uri); } finally { CookieHandler.setDefault(previousHandler); server.stop(0); } }
Example 14
Source File: IosHttpURLConnection.java From j2objc with Apache License 2.0 | 5 votes |
private static void saveResponseCookies(URL url, Map<String, List<String>> headerFields) throws IOException { CookieHandler cookieHandler = CookieHandler.getDefault(); if (cookieHandler != null) { try { URI uri = url.toURI(); cookieHandler.put(uri, headerFields); } catch (URISyntaxException e) { throw new IOException(e); } } }
Example 15
Source File: HttpOnly.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void test(String[] args) throws Exception { HttpServer server = startHttpServer(); CookieHandler previousHandler = CookieHandler.getDefault(); try { InetSocketAddress address = server.getAddress(); URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH); populateCookieStore(uri); doClient(uri); } finally { CookieHandler.setDefault(previousHandler); server.stop(0); } }
Example 16
Source File: HttpOnly.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
void test(String[] args) throws Exception { HttpServer server = startHttpServer(); CookieHandler previousHandler = CookieHandler.getDefault(); try { InetSocketAddress address = server.getAddress(); URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH); populateCookieStore(uri); doClient(uri); } finally { CookieHandler.setDefault(previousHandler); server.stop(0); } }
Example 17
Source File: HttpOnly.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
void test(String[] args) throws Exception { HttpServer server = startHttpServer(); CookieHandler previousHandler = CookieHandler.getDefault(); try { InetSocketAddress address = server.getAddress(); URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH); populateCookieStore(uri); doClient(uri); } finally { CookieHandler.setDefault(previousHandler); server.stop(0); } }
Example 18
Source File: ReactExoplayerView.java From react-native-video with MIT License | 5 votes |
private void createViews() { clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } LayoutParams layoutParams = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); exoPlayerView = new ExoPlayerView(getContext()); exoPlayerView.setLayoutParams(layoutParams); addView(exoPlayerView, 0, layoutParams); }
Example 19
Source File: HttpClientUtil.java From DevToolBox with GNU Lesser General Public License v2.1 | 4 votes |
private static void initHeader(HttpRequestBase base, String header) throws Exception { if (header != null && !header.trim().isEmpty()) { String[] tmp = header.split("&"); for (String str : tmp) { if (str.startsWith(COOKIE)) { base.addHeader(COOKIE, str.replace(COOKIE + "=", "")); } else { int idx = str.indexOf("="); if (idx > 0) { base.addHeader(str.substring(0, idx), str.substring(idx + 1)); } } } } CookieManager cm = (CookieManager) CookieHandler.getDefault(); Field fd = cm.getClass().getDeclaredField("store"); fd.setAccessible(true); Object cs = fd.get(cm);//cookieStore fd = cs.getClass().getDeclaredField("buckets"); fd.setAccessible(true); cs = fd.get(cs);//Map<String,Map<Cookie,Cookie>> Method md = cs.getClass().getDeclaredMethod("get", Object.class); String domain = base.getURI().getHost(); Map map = new HashMap(); while (domain.length() > 0) { Object bucket = md.invoke(cs, domain); if (bucket != null) { map.putAll((Map) bucket); } int nextPoint = domain.indexOf('.'); if (nextPoint != -1) { domain = domain.substring(nextPoint + 1); } else { break; } } if (!map.isEmpty()) { Iterator it = map.keySet().iterator(); StringBuilder sb = new StringBuilder(); while (it.hasNext()) { Object next = it.next(); fd = next.getClass().getDeclaredField("name"); fd.setAccessible(true); sb.append(fd.get(next)); fd = next.getClass().getDeclaredField("value"); fd.setAccessible(true); sb.append("=").append(fd.get(next)).append(";"); } if (!sb.toString().isEmpty()) { Header h = base.getFirstHeader(COOKIE); String ck = ""; if (h != null) { ck = h.getValue(); } base.addHeader(COOKIE, sb.toString() + ck); } } }
Example 20
Source File: DemoUtil.java From Exoplayer_VLC with Apache License 2.0 | 4 votes |
public static void setDefaultCookieManager() { CookieHandler currentHandler = CookieHandler.getDefault(); if (currentHandler != defaultCookieManager) { CookieHandler.setDefault(defaultCookieManager); } }