示例#1
0
  /**
   * Returns an array of {@link Cookie cookies} in this HTTP state that match the given request
   * parameters.
   *
   * @param domain the request domain
   * @param port the request port
   * @param path the request path
   * @param secure <code>true</code> when using HTTPS
   * @return an array of {@link Cookie cookies}.
   * @see #getCookies()
   * @deprecated use CookieSpec#match(String, int, String, boolean, Cookie)
   */
  public synchronized Cookie[] getCookies(String domain, int port, String path, boolean secure) {
    LOG.trace("enter HttpState.getCookies(String, int, String, boolean)");

    CookieSpec matcher = CookiePolicy.getDefaultSpec();
    // BEGIN IA/HERITRIX CHANGES
    //      PRIOR IMPL & COMPARISON HARNESS LEFT COMMENTED OUT FOR TEMPORARY REFERENCE
    //        ArrayList list = new ArrayList(cookiesArrayList.size());
    //        for (int i = 0, m = cookiesArrayList.size(); i < m; i++) {
    //            Cookie cookie = (Cookie) (cookiesArrayList.get(i));
    //            if (matcher.match(domain, port, path, secure, cookie)) {
    //                list.add(cookie);
    //            }
    //        }
    //        Cookie[] arrayListAnswer = (Cookie[]) (list.toArray(new Cookie[list.size()]));
    Cookie[] mapAnswer = matcher.match(domain, port, path, secure, cookiesMap);

    //        if(! (new HashSet(list).equals(new HashSet(Arrays.asList(mapAnswer))))) {
    //            System.out.println("discrepancy");
    //        }
    return mapAnswer;
    // END IA/HERITRIX CHANGES
  }
  /**
   * Inject the login cookies into the http client.
   *
   * @param client the http client
   * @throws IOException on error
   */
  protected void injectLoginCookies(HttpClient client, Cookie[] cookies) throws IOException {
    client.getState().addCookies(cookies);

    CookiePolicy.registerCookieSpec("PermitAllCookiesSpec", PermitAllCookiesSpec.class);
    client.getParams().setCookiePolicy("PermitAllCookiesSpec");
  }