Blame | Last modification | View Log | RSS feed
package com.saholic.profittill.Utils;import java.io.IOException;import java.net.CookieManager;import java.net.CookiePolicy;import java.net.CookieStore;import java.net.URI;import java.util.Arrays;import java.util.List;import java.util.Map;public class WebKitCookieManagerProxy extends CookieManager{private android.webkit.CookieManager webkitCookieManager;public WebKitCookieManagerProxy(){this(null, null);}public WebKitCookieManagerProxy(CookieStore store, CookiePolicy cookiePolicy){super(null, cookiePolicy);this.webkitCookieManager = android.webkit.CookieManager.getInstance();}@Overridepublic void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException{// make sure our args are validif ((uri == null) || (responseHeaders == null)) return;// save our url onceString url = uri.toString();// go over the headersfor (String headerKey : responseHeaders.keySet()){// ignore headers which aren't cookie relatedif ((headerKey == null) || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;// process each of the headersfor (String headerValue : responseHeaders.get(headerKey)){this.webkitCookieManager.setCookie(url, headerValue);}}}@Overridepublic Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException{// make sure our args are validif ((uri == null) || (requestHeaders == null)) throw new IllegalArgumentException("Argument is null");// save our url onceString url = uri.toString();// prepare our responseMap<String, List<String>> res = new java.util.HashMap<String, List<String>>();// get the cookieString cookie = this.webkitCookieManager.getCookie(url);// return itif (cookie != null) res.put("Cookie", Arrays.asList(cookie));return res;}@Overridepublic CookieStore getCookieStore(){// we don't want anyone to work with this cookie store directlythrow new UnsupportedOperationException();}}