/** * Adds a cookie containing the serialised contents of the form to a cookie named after the GET lookup key * @param response * @param form * @throws JSONException */ protected void addFlashCookie(SlingHttpServletResponse response, Form form) { final String name = this.getGetLookupKey(form.getName()); final String value = getQueryParameterValue(form); final Cookie cookie = new Cookie(name, value); cookie.setMaxAge(COOKIE_MAX_AGE); CookieUtil.addCookie(cookie, response); }
/** * Adds a cookie containing the serialised contents of the form to a cookie named after the GET lookup key * @param response * @param form * @throws JSONException */ protected void addFlashCookie(SlingHttpServletResponse response, Form form) throws JSONException { final String name = this.getGetLookupKey(form.getName()); final String value = getQueryParameterValue(form); final Cookie cookie = new Cookie(name, value); cookie.setMaxAge(COOKIE_MAX_AGE); CookieUtil.addCookie(cookie, response); }
/** * Internal method used for dropping cookies * * @param response * @param cookies * @param cookiePath * @return */ private static int dropCookies(final HttpServletResponse response, final Cookie[] cookies, final String cookiePath) { int count = 0; for (final Cookie cookie : cookies) { if (cookie == null) { continue; } final Cookie responseCookie = (Cookie) cookie.clone(); responseCookie.setMaxAge(0); responseCookie.setPath(cookiePath); responseCookie.setValue(""); addCookie(responseCookie, response); count++; } return count; }
/** * Internal method used for dropping cookies * * @param response * @param cookies * @param cookiePath * @return */ private static int dropCookies(final HttpServletResponse response, final Cookie[] cookies, final String cookiePath) { int count = 0; for (final Cookie cookie : cookies) { if (cookie == null) { continue; } final Cookie responseCookie = (Cookie) cookie.clone(); responseCookie.setMaxAge(0); responseCookie.setPath(cookiePath); responseCookie.setValue(""); addCookie(responseCookie, response); count++; } return count; } }
/** * <p> * 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; }
/** * <p> * 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; }