List of usage examples for javax.servlet.http Cookie getMaxAge
public int getMaxAge()
From source file:org.springframework.test.web.servlet.htmlunit.MockWebResponseBuilder.java
static com.gargoylesoftware.htmlunit.util.Cookie createCookie(Cookie cookie) { Date expires = null;/*from w ww.j av a 2 s . 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:com.openthinks.webscheduler.model.security.RememberMeCookie.java
public static RememberMeCookie valueOf(final Cookie cookie) { RememberMeCookie rememberMeCookie = new RememberMeCookie(); rememberMeCookie.setToken(cookie.getValue()); Date expireDate = DateUtils.addSeconds(new Date(), cookie.getMaxAge()); rememberMeCookie.setExpireTime(StaticUtils.formatDate(expireDate)); return rememberMeCookie; }
From source file:com.hortonworks.example.util.Util.java
public static String getCookieInfo(HttpServletRequest request, String name) { String info = null;// w ww . j a v a 2s .co m Cookie cookie = getCookie(request, name); if (cookie != null) { info = String.format("[value=%s,domain=%s,path=%s,expiry=%d]", cookie.getValue(), cookie.getDomain(), cookie.getPath(), cookie.getMaxAge()); } return info; }
From source file:com.activecq.api.utils.CookieUtil.java
/** * <p>/*from ww w. j a va2 s . co m*/ * Extend the cookie life. * <p></p> * This can be used when a cookie should be valid for X minutes from the last point of activity. * <p></p> * This method will leave expired or deleted cookies alone. * </p> * @param request Request to get the Cookie from * @param response Response to write the extended Cookie to * @param cookieName Name of Cookie to extend the life of * @param expiry New Cookie expiry */ public static boolean extendCookieLife(HttpServletRequest request, HttpServletResponse response, String cookieName, int expiry) { Cookie cookie = getCookie(request, cookieName); if (cookie == null) { return false; } if (cookie.getMaxAge() <= 0) { return false; } cookie.setMaxAge(expiry); cookie.setPath(cookie.getPath()); addCookie(cookie, response); return true; }
From source file:com.adobe.acs.commons.util.CookieUtil.java
/** * <p>//from www. ja va 2 s . co m * Extend the cookie life. * <p></p> * This can be used when a cookie should be valid for X minutes from the last point of activity. * <p></p> * This method will leave expired or deleted cookies alone. * </p> * * @param request Request to get the Cookie from * @param response Response to write the extended Cookie to * @param cookieName Name of Cookie to extend the life of * @param expiry New Cookie expiry */ public static boolean extendCookieLife(final HttpServletRequest request, final HttpServletResponse response, final String cookieName, final String cookiePath, final int expiry) { final Cookie cookie = getCookie(request, cookieName); if (cookie == null) { return false; } if (cookie.getMaxAge() <= 0) { return false; } final Cookie responseCookie = (Cookie) cookie.clone(); responseCookie.setMaxAge(expiry); responseCookie.setPath(cookiePath); addCookie(responseCookie, response); return true; }
From source file:net.bluehornreader.web.WebUtils.java
public static String cookieAsString(Cookie cookie) { StringBuilder bld = new StringBuilder(); bld.append("Name=").append(cookie.getName()).append(" "); bld.append("Value=").append(cookie.getValue()).append(" "); bld.append("Domain=").append(cookie.getDomain()).append(" "); bld.append("MaxAge=").append(cookie.getMaxAge()).append(" "); bld.append("Path=").append(cookie.getPath()).append(" "); bld.append("Secure=").append(cookie.getSecure()).append(" "); bld.append("Comment=").append(cookie.getComment()).append(" "); bld.append("Version=").append(cookie.getVersion()).append(" "); return bld.toString().trim(); }
From source file:com.google.gsa.valve.modules.utils.CookieManagement.java
/** * Transforms Servlet cookies into Apache Cookies * /*from w w w . j av a2 s.c o m*/ * @param servletCookie servlet cookie * * @return apache cookie */ public static org.apache.commons.httpclient.Cookie transformServletCookie( javax.servlet.http.Cookie servletCookie) { org.apache.commons.httpclient.Cookie newCookie = null; if (servletCookie != null) { newCookie = new org.apache.commons.httpclient.Cookie(servletCookie.getDomain(), servletCookie.getName(), servletCookie.getValue(), servletCookie.getPath() != null ? servletCookie.getPath() : "/", servletCookie.getMaxAge(), servletCookie.getSecure()); } return newCookie; }
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 w w. j av a 2s .c o m } 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. * // w w w . j av a2 s. c o m * @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.jasig.cas.web.support.CookieRetrievingCookieGeneratorTests.java
public void testCookieAddWithoutRememberMe() { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); this.g.addCookie(request, response, "test"); final Cookie c = response.getCookie("test"); assertEquals(5, c.getMaxAge()); assertEquals("test", c.getValue()); }