Example usage for org.apache.http.cookie SetCookie setExpiryDate

List of usage examples for org.apache.http.cookie SetCookie setExpiryDate

Introduction

In this page you can find the example usage for org.apache.http.cookie SetCookie setExpiryDate.

Prototype

void setExpiryDate(Date expiryDate);

Source Link

Document

Sets expiration date.

Usage

From source file:org.nextlets.erc.defaults.http.ERCHttpInvokerImpl.java

private Cookie toCookie(URI uri, HttpCookie httpCookie) {
    SetCookie cookie = new BasicClientCookie(httpCookie.getName(), httpCookie.getValue());
    cookie.setComment(httpCookie.getComment());
    if (httpCookie.getDomain() != null) {
        cookie.setDomain(httpCookie.getDomain());
    } else {//from  w ww  .j  a  v a2  s. c  o  m
        cookie.setDomain(uri.getHost());
    }
    if (httpCookie.getMaxAge() != -1) {
        cookie.setExpiryDate(new Date(httpCookie.getMaxAge() * 1000));
    }
    if (httpCookie.getPath() != null) {
        cookie.setPath(httpCookie.getPath());
    } else {
        cookie.setPath(uri.getPath());
    }
    cookie.setSecure(httpCookie.getSecure());
    cookie.setVersion(httpCookie.getVersion());
    return cookie;
}

From source file:com.gargoylesoftware.htmlunit.httpclient.HtmlUnitExpiresHandler.java

@Override
public void parse(final SetCookie cookie, String value) throws MalformedCookieException {
    if (value.startsWith("\"") && value.endsWith("\"")) {
        value = value.substring(1, value.length() - 1);
    }/*w  w w.j a  va 2s. co m*/
    value = value.replaceAll("[ ,:-]+", " ");

    Date startDate = null;
    String[] datePatterns = DEFAULT_DATE_PATTERNS;

    if (null != browserVersion_) {
        if (browserVersion_.hasFeature(HTTP_COOKIE_START_DATE_1970)) {
            startDate = HtmlUnitBrowserCompatCookieSpec.DATE_1_1_1970;
        }

        if (browserVersion_.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS_1)) {
            datePatterns = EXTENDED_DATE_PATTERNS_1;
        }

        if (browserVersion_.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS_2)) {
            final Calendar calendar = Calendar.getInstance(Locale.ROOT);
            calendar.setTimeZone(DateUtils.GMT);
            calendar.set(1969, Calendar.JANUARY, 1, 0, 0, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            startDate = calendar.getTime();

            datePatterns = EXTENDED_DATE_PATTERNS_2;
        }
    }

    final Date expiry = DateUtils.parseDate(value, datePatterns, startDate);
    cookie.setExpiryDate(expiry);
}