public HttpCookie toHttpCookie() {
   HttpCookie cookie = new HttpCookie(name, value);
   cookie.setComment(comment);
   cookie.setCommentURL(commentURL);
   cookie.setDiscard(discard);
   cookie.setDomain(domain);
   cookie.setMaxAge((expiry - System.currentTimeMillis()) / 1000L);
   cookie.setPath(path);
   cookie.setPortlist(portList);
   cookie.setSecure(secure);
   cookie.setVersion(version);
   return cookie;
 }
Beispiel #2
0
  public static HttpCookie fromNewCookie(NewCookie c) {

    HttpCookie cookie = new HttpCookie(c.getName(), c.getValue());

    cookie.setComment(c.getComment());
    cookie.setCommentURL("not available");
    cookie.setDiscard(false);
    cookie.setDomain(c.getDomain());
    cookie.setMaxAge(c.getMaxAge());
    cookie.setPath(c.getPath());
    cookie.setPortlist("not available");
    cookie.setSecure(c.isSecure());
    cookie.setVersion(c.getVersion());
    cookie.setHttpOnly(c.isHttpOnly());

    return cookie;
  }
  public HttpCookie toHttpCookie() {
    HttpCookie cookie = null;

    long expiration = 0;
    try {
      expiration = getExpiration();
    } catch (Exception e) {
    }

    String domain = getDomain();
    String path = getPath();

    int secureFlag = 0;
    try {
      secureFlag = getSecure();
    } catch (Exception e) {
    }

    // Currently no use or need to use the HTTP-only flag in cookies for now
    cookie = new HttpCookie(getName(), getValue());
    cookie.setVersion(0);

    long currentTimeInSeconds = Calendar.getInstance().getTimeInMillis() / 1000;
    if (currentTimeInSeconds < expiration) {
      long maxAge = expiration - currentTimeInSeconds;
      cookie.setMaxAge(maxAge);
    }

    if (secureFlag != 0) {
      cookie.setSecure(true);
    }

    if (domain != null && domain.length() > 0) {
      cookie.setDomain(domain);
      if (path != null && path.length() > 0) {
        cookie.setPath(path);
      } else {
        cookie.setPath("/");
      }
      return cookie;
    }
    return null;
  }