Example usage for org.apache.commons.httpclient Cookie setExpiryDate

List of usage examples for org.apache.commons.httpclient Cookie setExpiryDate

Introduction

In this page you can find the example usage for org.apache.commons.httpclient Cookie setExpiryDate.

Prototype

public void setExpiryDate(Date paramDate) 

Source Link

Usage

From source file:arena.httpclient.commons.JakartaCommonsHttpClient.java

public void addCookie(String name, String value, int maxAge, String domain, String path) {
    org.apache.commons.httpclient.Cookie commonsCookie = new org.apache.commons.httpclient.Cookie();
    commonsCookie.setName(name);/*from ww  w  . jav a2 s .c o m*/
    commonsCookie.setValue(value);
    if (maxAge >= 0) {
        commonsCookie.setExpiryDate(new Date(System.currentTimeMillis() + maxAge));
    }
    if (path != null) {
        commonsCookie.setPath(path);
    }
    if (domain != null) {
        commonsCookie.setDomain(domain);
    }
    this.state.addCookie(commonsCookie);
}

From source file:dslab.crawler.pack.CrawlerPack.java

/**
 * Return a Cookie array//from  w w  w.  jav a 2 s.c om
 * and auto importing domain and path when domain was empty.
 *
 * @param uri required Apache Common VFS supported file systems and response JSON format content.
 * @return Cookie[]
 */
Cookie[] getCookies(String uri) {
    if (null == cookies || 0 == cookies.size())
        return null;

    for (Cookie cookie : cookies) {

        if ("".equals(cookie.getDomain())) {
            String domain = uri.replaceAll("^.*:\\/\\/([^\\/]+)[\\/]?.*$", "$1");
            //                System.out.println(domain);
            cookie.setDomain(domain);
            cookie.setPath("/");
            cookie.setExpiryDate(null);
            cookie.setSecure(false);
        }
    }

    return cookies.toArray(new Cookie[cookies.size()]);
}

From source file:com.github.abola.crawler.CrawlerPack.java

/**
 * Return a Cookie array/*from w  w w.  j  ava  2 s.c  o m*/
 * and auto importing domain and path when domain was empty.
 *
 * @param uri required Apache Common VFS supported file systems and response JSON format content.
 * @return Cookie[]
 */
Cookie[] getCookies(String uri) {
    if (null == cookies || 0 == cookies.size())
        return null;

    for (Cookie cookie : cookies) {

        if ("".equals(cookie.getDomain())) {
            String domain = uri.replaceAll("^.*:\\/\\/([^\\/]+)[\\/]?.*$", "$1");
            cookie.setDomain(domain);
            cookie.setPath("/");
            cookie.setExpiryDate(null);
            cookie.setSecure(false);
        }
    }

    return cookies.toArray(new Cookie[cookies.size()]);
}

From source file:org.apache.cactus.WebResponse.java

/**
 * @return the cookies returned by the server
 *//*w  ww  . j  a  va 2 s .c om*/
public Cookie[] getCookies() {
    Cookie[] returnCookies = null;

    // There can be several headers named "Set-Cookie", so loop through
    // all the headers, looking for cookies
    String headerName = this.connection.getHeaderFieldKey(0);
    String headerValue = this.connection.getHeaderField(0);

    Vector cookieVector = new Vector();
    CookieSpec cookieSpec = CookiePolicy.getDefaultSpec();

    for (int i = 1; (headerName != null) || (headerValue != null); i++) {
        LOGGER.debug("Header name  = [" + headerName + "]");
        LOGGER.debug("Header value = [" + headerValue + "]");

        if ((headerName != null) && (headerName.toLowerCase().equals("set-cookie")
                || headerName.toLowerCase().equals("set-cookie2"))) {
            // Parse the cookie definition
            org.apache.commons.httpclient.Cookie[] cookies;
            try {
                cookies = cookieSpec.parse(
                        CookieUtil.getCookieDomain(getWebRequest(), getConnection().getURL().getHost()),
                        CookieUtil.getCookiePort(getWebRequest(), getConnection().getURL().getPort()),
                        CookieUtil.getCookiePath(getWebRequest(), getConnection().getURL().getFile()), false,
                        new Header(headerName, headerValue));
            } catch (HttpException e) {
                throw new ChainedRuntimeException("Error parsing cookies", e);
            }

            // Transform the HttpClient cookies into Cactus cookies and
            // add them to the cookieVector vector
            for (int j = 0; j < cookies.length; j++) {
                Cookie cookie = new Cookie(cookies[j].getDomain(), cookies[j].getName(), cookies[j].getValue());

                cookie.setComment(cookies[j].getComment());
                cookie.setExpiryDate(cookies[j].getExpiryDate());
                cookie.setPath(cookies[j].getPath());
                cookie.setSecure(cookies[j].getSecure());

                cookieVector.addElement(cookie);
            }
        }

        headerName = this.connection.getHeaderFieldKey(i);
        headerValue = this.connection.getHeaderField(i);
    }

    returnCookies = new Cookie[cookieVector.size()];
    cookieVector.copyInto(returnCookies);

    return returnCookies;
}

From source file:org.mule.transport.http.CookieWrapper.java

public Cookie createCookie() throws ParseException {
    Cookie cookie = new Cookie();
    cookie.setName(getName());//from  w  w  w . j  a  v  a  2 s  .c o m
    cookie.setValue(getValue());
    cookie.setDomain(domain);
    cookie.setPath(path);

    if (expiryDate != null) {
        cookie.setExpiryDate(formatExpiryDate(expiryDate));
    }

    if (maxAge != null && expiryDate == null) {
        cookie.setExpiryDate(new Date(System.currentTimeMillis() + Integer.valueOf(maxAge) * 1000L));
    }

    if (secure != null) {
        cookie.setSecure(Boolean.valueOf(secure));
    }
    if (version != null) {
        cookie.setVersion(Integer.valueOf(version));
    }

    return cookie;
}