Esempio n. 1
0
 public void setCookie(final String url, final String key, final String value) {
   final String host = Browser.getHost(url);
   Cookies cookies;
   if (!this.getCookies().containsKey(host) || (cookies = this.getCookies().get(host)) == null) {
     cookies = new Cookies();
     this.getCookies().put(host, cookies);
   }
   cookies.add(new Cookie(host, key, value));
 }
Esempio n. 2
0
 public void updateCookies(final Request request) {
   if (request == null) {
     return;
   }
   final String host = Browser.getHost(request.getUrl());
   Cookies cookies = this.getCookies().get(host);
   if (cookies == null) {
     cookies = new Cookies();
     this.getCookies().put(host, cookies);
   }
   cookies.add(request.getCookies());
 }
Esempio n. 3
0
  void doit() {
    String username = args.Username;
    String password = args.Password;
    if (username != null || password != null)
      Authenticator.setDefault(new MyAuthenticator(username, password));

    System.setProperty("java.protocol.handler.pkgs", "edu.mscd.cs");

    String[] add = args.additional;

    if (add == null) {
      logger.warning("No URLs specified, exiting");
      System.exit(1);
    }

    /*
     ** add the specified URLs to the list to be fetched.
     */
    String[] t = new String[add.length];
    for (int i = 0; i < add.length; i++) {
      t[i] = "<a href=\"" + add[i] + "\">";
    }

    /*
     ** add to the URLs, with no base
     */
    addToURLs(null, t);
    fetchAll();

    /*
     ** shall we save the cookies to a file?
     */
    String savecookies = args.SaveCookies;
    if (savecookies != null) cookies.saveCookies(savecookies);
  }
Esempio n. 4
0
  public void forwardCookies(final Request request) {
    if (request == null) {
      return;
    }
    final String host = Browser.getHost(request.getUrl());
    final Cookies cookies = this.getCookies().get(host);
    if (cookies == null) {
      return;
    }

    for (final Cookie cookie : cookies.getCookies()) {
      // Pfade sollten verarbeitet werden...TODO
      if (cookie.isExpired()) {
        continue;
      }
      request.getCookies().add(cookie);
    }
  }
Esempio n. 5
0
 @Get("/injection/:param1/:param2")
 public String route(
     String param1,
     String param2,
     Context context,
     Request request,
     Response response,
     Cookies cookies) {
   return String.join(
       "/",
       param1,
       param2,
       context.getClass().getSimpleName(),
       request.getClass().getSimpleName(),
       response.getClass().getSimpleName(),
       cookies.getClass().getSimpleName());
 }
Esempio n. 6
0
  REplican(String arguments[]) {
    JCLO jclo = new JCLO(args);

    if (arguments.length == 0) {
      System.out.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(1);
    }

    try {
      jclo.parse(arguments);
    } catch (IllegalArgumentException IAE) {
      System.err.println(IAE);
      System.err.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(0);
    }

    String logLevel = args.LogLevel;
    ConsoleHandler ch = new ConsoleHandler();

    if (logLevel != null) {
      Level level = JavaLN.getLevel(logLevel);
      ch.setLevel(level);
      ch.setFormatter(new LineNumberFormatter());
      logger.setLevel(level);
    } else {
      ch.setFormatter(new NullFormatter());
    }

    logger.addHandler(ch);
    logger.setUseParentHandlers(false);

    if (args.Version) {
      System.out.println(Version.getVersion());
      System.exit(0);
    }

    if (args.Help) {
      System.out.println("Arguments:\n" + jclo.usage() + "URLs...");
      System.exit(0);
    }

    cookies = new Cookies();

    setDefaults();

    if (args.LoadCookies != null) {
      for (int i = 0; i < args.LoadCookies.length; i++) {
        logger.config("Loading cookies from " + args.LoadCookies[i]);
        cookies.loadCookies(args.LoadCookies[i]);
      }
    }

    if (args.PlistCookies != null) {
      for (int i = 0; i < args.PlistCookies.length; i++) {
        logger.config("Loading cookies from " + args.PlistCookies[i]);
        new Plist("file:" + args.PlistCookies[i], cookies);
      }
    }

    if (args.CheckpointEvery != 0) {
      logger.config("Loading urls from " + args.CheckpointFile);

      try {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(args.CheckpointFile));
        urls = (Hashtable) ois.readObject();
        ois.close();
      } catch (IOException ioe) {
        logger.throwing(ioe);
      } catch (ClassNotFoundException cnfe) {
        logger.throwing(cnfe);
      }
    }

    if (args.FollowRedirects) HttpURLConnection.setFollowRedirects(false);
  }