Example usage for javax.servlet.http Cookie getPath

List of usage examples for javax.servlet.http Cookie getPath

Introduction

In this page you can find the example usage for javax.servlet.http Cookie getPath.

Prototype

public String getPath() 

Source Link

Document

Returns the path on the server to which the browser returns this cookie.

Usage

From source file:org.springframework.test.web.servlet.htmlunit.MockWebResponseBuilder.java

static com.gargoylesoftware.htmlunit.util.Cookie createCookie(Cookie cookie) {
    Date expires = null;/* ww  w.  j  a  va  2s. c om*/
    if (cookie.getMaxAge() > -1) {
        expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000);
    }
    BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue());
    result.setDomain(cookie.getDomain());
    result.setComment(cookie.getComment());
    result.setExpiryDate(expires);
    result.setPath(cookie.getPath());
    result.setSecure(cookie.getSecure());
    if (cookie.isHttpOnly()) {
        result.setAttribute("httponly", "true");
    }
    return new com.gargoylesoftware.htmlunit.util.Cookie(result);
}

From source file:de.betterform.agent.web.WebUtil.java

private static Vector<BasicClientCookie> saveAsBasicClientCookie(Iterator iterator,
        Vector<BasicClientCookie> commonsCookies) {
    while (iterator.hasNext()) {
        javax.servlet.http.Cookie c = (Cookie) iterator.next();
        BasicClientCookie commonsCookie = new BasicClientCookie(c.getName(), c.getValue());
        commonsCookie.setDomain(c.getDomain());
        commonsCookie.setPath(c.getPath());
        commonsCookie.setAttribute(ClientCookie.MAX_AGE_ATTR, Integer.toString(c.getMaxAge()));
        commonsCookie.setSecure(c.getSecure());

        commonsCookies.add(commonsCookie);

        if (WebUtil.LOGGER.isDebugEnabled()) {
            WebUtil.LOGGER.debug("adding cookie >>>>>");
            WebUtil.LOGGER.debug("name: " + c.getName());
            WebUtil.LOGGER.debug("value: " + c.getValue());
            WebUtil.LOGGER.debug("path: " + c.getPath());
            WebUtil.LOGGER.debug("maxAge: " + c.getMaxAge());
            WebUtil.LOGGER.debug("secure: " + c.getSecure());
            WebUtil.LOGGER.debug("adding cookie done <<<<<");
        }/*from w  ww .  ja va2  s  .c om*/
    }

    return commonsCookies;
}

From source file:RequestUtil.java

/**
 * Encode a cookie as per RFC 2109. The resulting string can be used as the
 * value for a <code>Set-Cookie</code> header.
 * /*from w  ww  . j  a  v a 2 s.  c om*/
 * @param cookie
 *            The cookie to encode.
 * @return A string following RFC 2109.
 */
public static String encodeCookie(Cookie cookie) {

    StringBuffer buf = new StringBuffer(cookie.getName());
    buf.append("=");
    buf.append(cookie.getValue());

    if (cookie.getComment() != null) {
        buf.append("; Comment=\"");
        buf.append(cookie.getComment());
        buf.append("\"");
    }

    if (cookie.getDomain() != null) {
        buf.append("; Domain=\"");
        buf.append(cookie.getDomain());
        buf.append("\"");
    }

    if (cookie.getMaxAge() >= 0) {
        buf.append("; Max-Age=\"");
        buf.append(cookie.getMaxAge());
        buf.append("\"");
    }

    if (cookie.getPath() != null) {
        buf.append("; Path=\"");
        buf.append(cookie.getPath());
        buf.append("\"");
    }

    if (cookie.getSecure()) {
        buf.append("; Secure");
    }

    if (cookie.getVersion() > 0) {
        buf.append("; Version=\"");
        buf.append(cookie.getVersion());
        buf.append("\"");
    }

    return (buf.toString());
}

From source file:org.codemucker.testserver.capturing.CapturedCookie.java

public CapturedCookie(Cookie c) {
    domain = c.getDomain();//from w w w  .ja  va  2  s.c om
    path = c.getPath();
    name = c.getName();
    value = c.getValue();
    secure = c.getSecure();
    maxAge = c.getMaxAge();
    version = c.getVersion();
}

From source file:org.codemucker.testserver.capturing.CapturedCookie.java

public CapturedCookie(org.apache.http.cookie.Cookie c) {
    domain = c.getDomain();//from w  w w  .  ja va  2  s. c om
    path = c.getPath();
    name = c.getName();
    value = c.getValue();
    secure = c.isSecure();
    maxAge = c.getExpiryDate() == null ? -1 : 0;
    version = c.getVersion();
}

From source file:com.google.acre.script.AcreCookie.java

public AcreCookie(Cookie servlet_cookie) {
    name = servlet_cookie.getName();//from ww w  .j  av  a  2 s.  c o  m
    value = servlet_cookie.getValue();
    domain = servlet_cookie.getDomain();
    path = servlet_cookie.getPath();
    secure = servlet_cookie.getSecure();
    max_age = servlet_cookie.getMaxAge();
}

From source file:com.google.acre.script.AcreCookie.java

public AcreCookie(org.apache.http.cookie.Cookie c) {
    name = c.getName();//w ww .  j ava 2  s .c om
    value = c.getValue();
    secure = c.isSecure();
    domain = c.getDomain();
    path = c.getPath();
    max_age = -1;
    // XXX translate into max-age?
    // c.getExpiryDate();
}

From source file:com.acc.storefront.filters.RequestLoggerFilter.java

protected void logCookies(final HttpServletRequest httpRequest) {
    if (LOG.isDebugEnabled()) {
        final Cookie[] cookies = httpRequest.getCookies();
        if (cookies != null) {
            for (final Cookie cookie : cookies) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("COOKIE Name: [" + cookie.getName() + "] Path: [" + cookie.getPath()
                            + "] Value: [" + cookie.getValue() + "]");
                }/*from  w  ww. j  a va 2  s  . c om*/
            }
        }
    }
}

From source file:org.tonguetied.web.CookieUtilsTest.java

/**
 * Test method for {@link org.tonguetied.web.CookieUtils#createCookie(HttpServletRequest, String, String)}.
 *///from w  w  w  .  jav a 2s  .c o m
@Test
public final void testCreateCookie() {
    Cookie cookie = CookieUtils.createCookie(request, "name", "value");
    assertEquals("name", cookie.getName());
    assertEquals("value", cookie.getValue());
    assertEquals("/test", cookie.getPath());
    assertEquals(-1, cookie.getMaxAge());
}

From source file:com.xpn.xwiki.web.XWikiServletResponse.java

/**
 * Remove a cookie.//from  w  w w . ja va  2  s .  c o  m
 *
 * @param request The servlet request needed to find the cookie to remove
 * @param cookieName The name of the cookie that must be removed.
 */
@Override
public void removeCookie(String cookieName, XWikiRequest request) {
    Cookie cookie = request.getCookie(cookieName);
    if (cookie != null) {
        cookie.setMaxAge(0);
        cookie.setPath(cookie.getPath());
        addCookie(cookie);
    }
}