示例#1
0
  private static void saveCookies() {
    if (cookie_jar != null
        && (!cookie_jar.exists() || cookie_jar.isFile() && cookie_jar.canWrite())) {
      Hashtable cookie_list = new Hashtable();
      Enumeration en =
          Util.getList(cookie_cntxt_list, HTTPConnection.getDefaultContext()).elements();

      // discard cookies which are not to be kept across sessions

      while (en.hasMoreElements()) {
        Cookie cookie = (Cookie) en.nextElement();
        if (!cookie.discard()) cookie_list.put(cookie, cookie);
      }

      // save any remaining cookies in jar
      if (cookie_list.size() > 0) {
        try {
          ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(cookie_jar));
          oos.writeObject(cookie_list);
          oos.close();
        } catch (IOException t) {
          if (LOG.isTraceEnabled()) {
            LOG.trace("An exception occurred: " + t.getMessage());
          }
        }
      }
    }
  }
 private static void loadCookies() {
   // The isFile() etc need to be protected by the catch as signed
   // applets may be allowed to read properties but not do IO
   try {
     cookie_jar = new File(getCookieJarName());
     if (cookie_jar.isFile() && cookie_jar.canRead()) {
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream(cookie_jar));
       cookie_cntxt_list.put(HTTPConnection.getDefaultContext(), (Hashtable) ois.readObject());
       ois.close();
     }
   } catch (Throwable t) {
     cookie_jar = null;
   }
 }
示例#3
0
 /**
  * Remove the specified cookie from the list of cookies in the default context. If the cookie is
  * not found in the list then this method does nothing.
  *
  * @param cookie the Cookie to remove
  * @since V0.3-1
  */
 public static void removeCookie(Cookie cookie) {
   Hashtable cookie_list = Util.getList(cookie_cntxt_list, HTTPConnection.getDefaultContext());
   cookie_list.remove(cookie);
 }