List of usage examples for java.net CookieHandler setDefault
public static synchronized void setDefault(CookieHandler cHandler)
From source file:fi.elfcloud.sci.Connection.java
public Connection(Client client) { Connection.client = client;/*from ww w . j a v a 2 s. c o m*/ Connection.manager = new CookieManager(); Connection.manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(Connection.manager); Connection.cookieJar = manager.getCookieStore(); Connection.cookies = cookieJar.getCookies(); }
From source file:CookieAccessor.java
/** * Get cookies for a url from cookie store */// w ww. j a v a 2 s. c o m public void getCookieUsingCookieHandler() { try { // instantiate CookieManager; make sure to set CookiePolicy CookieManager manager = new CookieManager(); manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); // get content from URLConnection; cookies are set by web site URL url = new URL("http://host.example.com"); URLConnection connection = url.openConnection(); connection.getContent(); // get cookies from underlying CookieStore CookieStore cookieJar = manager.getCookieStore(); List<HttpCookie> cookies = cookieJar.getCookies(); for (HttpCookie cookie : cookies) { System.out.println("CookieHandler retrieved cookie: " + cookie); } } catch (Exception e) { System.out.println("Unable to get cookie using CookieHandler"); e.printStackTrace(); } }
From source file:com.wikaba.ogapp.AgentService.java
@Override public void onCreate() { super.onCreate(); if (ogameSessions == null) { ogameSessions = new LongSparseArray<OgameAgent>(); }/* w w w . j a va 2 s . co m*/ if (dbman == null) { dbman = new DatabaseManager(this); } CustomCookieManager cookieman = new CustomCookieManager(); CookieStore cookiestore = cookieman.getCookieStore(); //Retrieve all cookies from database. //Warning: This is currently done on the main thread. ArrayList<HttpCookie> cookieList = dbman.getCookies(); for (Iterator<HttpCookie> cookieIter = cookieList.iterator(); cookieIter.hasNext();) { HttpCookie cookie = cookieIter.next(); cookiestore.add(null, cookie); } CookieHandler.setDefault(cookieman); }
From source file:nl.phanos.liteliveresultsclient.LoginHandler.java
public LoginHandler() throws Exception { String url = "https://www.atletiek.nu/login/"; // make sure cookies is turn on CookieHandler.setDefault(new CookieManager()); String page = this.GetPageContent(url); String user = Main.getWindow().UserName; String pass = Main.getWindow().Pass; List<NameValuePair> postParams = this.getFormParams(page, user, pass); this.sendPost(url, postParams); }
From source file:org.exoplatform.utils.image.CookieAwarePicassoDownloader.java
/** * Creates a new CookieManager if none already exists and sets it as the * default CookieHandler/*from w w w . j a v a2 s .c om*/ * * @return the CookieManager newly created, or the existing one if it's * already the default CookieHandler */ private CookieManager initCookieManager() { CookieHandler handler = CookieHandler.getDefault(); CookieManager manager; if (handler == null || !(handler instanceof CookieManager)) { manager = new CookieManager(); CookieHandler.setDefault(manager); // Sync cookies from ExoConnectionUtils only // when the Cookies Manager is created syncCookies(manager); } else { manager = (CookieManager) handler; } return manager; }
From source file:org.droidparts.http.worker.HttpURLConnectionWorker.java
@Override public void setCookieJar(CookieJar cookieJar) { CookieHandler.setDefault(cookieJar); }
From source file:at.florian_lentsch.expirysync.net.JsonCaller.java
public JsonCaller(String hostStr) throws URISyntaxException { setHost(hostStr);/* ww w . j a v a 2 s . co m*/ this.cookieManager = (CookieManager) CookieHandler.getDefault(); if (this.cookieManager == null) { this.cookieManager = new CookieManager(); CookieHandler.setDefault(this.cookieManager); } }
From source file:org.jboss.aerogear.android.cookbook.agreddit.authentication.RedditAuthenticationModule.java
public void login(final String username, final String password, final Callback<HeaderAndBody> callback) { COOKIE_MANAGER = new CookieManager(null, CookiePolicy.ACCEPT_NONE); CookieHandler.setDefault(COOKIE_MANAGER); AsyncTask<Void, Void, HeaderAndBody> task = new AsyncTask<Void, Void, HeaderAndBody>() { private Exception exception; @Override//from w ww .ja v a2 s.c om protected HeaderAndBody doInBackground(Void... params) { HeaderAndBody result; try { HttpProvider provider = new HttpRestProvider(getLoginURL(username)); provider.setDefaultHeader("User-Agent", "AeroGear StoryList Demo /u/secondsun"); provider.setDefaultHeader("Content-Type", "application/x-www-form-urlencoded"); String loginData = buildLoginData(username, password); result = provider.post(loginData); Log.d("Auth", new String(result.getBody())); String json = new String(result.getBody()); JsonObject obj = new JsonParser().parse(json).getAsJsonObject().get("json").getAsJsonObject(); modHash = obj.get("data").getAsJsonObject().get("modhash").getAsString(); authToken = obj.get("data").getAsJsonObject().get("cookie").getAsString(); isLoggedIn = true; } catch (Exception e) { Log.e(RedditAuthenticationModule.class.getSimpleName(), "Error with Login", e); exception = e; return null; } return result; } @Override protected void onPostExecute(HeaderAndBody headerAndBody) { if (exception == null) { callback.onSuccess(headerAndBody); } else { callback.onFailure(exception); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:at.gv.egiz.bku.binding.AbstractBindingProcessor.java
@Override public void init(String id, STAL stal, SLCommandInvoker commandInvoker) { if (id == null) { throw new NullPointerException("Id must not be null."); }/*from w w w. j a v a 2s . com*/ if (stal == null) { throw new NullPointerException("STAL must not null."); } if (commandInvoker == null) { throw new NullPointerException("CommandInvoker must null."); } this.id = IdFactory.getInstance().createId(id); this.stal = stal; this.commandInvoker = commandInvoker; // disable cookies CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_NONE)); }
From source file:CookieAccessor.java
/** * Set cookie in cookie store/*w ww . j a v a 2 s. c om*/ */ public void setCookieUsingCookieHandler() { try { // instantiate CookieManager CookieManager manager = new CookieManager(); CookieHandler.setDefault(manager); CookieStore cookieJar = manager.getCookieStore(); // create cookie HttpCookie cookie = new HttpCookie("UserName", "John Doe"); // add cookie to CookieStore for a particular URL URL url = new URL("http://host.example.com"); cookieJar.add(url.toURI(), cookie); System.out.println("Added cookie using cookie handler"); } catch (Exception e) { System.out.println("Unable to set cookie using CookieHandler"); e.printStackTrace(); } }