List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:ai.susi.server.AbstractAPIHandler.java
/** * Delete the login cookie if present//from ww w . ja v a 2 s. com * @param response */ protected static void deleteLoginCookie(HttpServletResponse response) { Cookie deleteCookie = new Cookie("login", null); deleteCookie.setPath("/"); deleteCookie.setMaxAge(0); response.addCookie(deleteCookie); }
From source file:org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet.java
private static Cookie makeCheckCookie(ApplicationId id, boolean isSet) { Cookie c = new Cookie(getCheckCookieName(id), String.valueOf(isSet)); c.setPath(ProxyUriUtils.getPath(id)); c.setMaxAge(60 * 60 * 2); //2 hours in seconds return c;/*from www . ja v a 2 s . co m*/ }
From source file:org.jahia.params.valves.CookieAuthValveImpl.java
public static void createAndSendCookie(AuthValveContext authContext, JCRUserNode theUser, CookieAuthConfig cookieAuthConfig) { // now let's look for a free random cookie value key. String cookieUserKey = CookieAuthValveImpl.getAvailableCookieKey(cookieAuthConfig); // let's save the identifier for the user in the database try {//from www. j a va2 s . c om theUser.setProperty(cookieAuthConfig.getUserPropertyName(), cookieUserKey); theUser.getSession().save(); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } // now let's save the same identifier in the cookie. String realm = theUser.getRealm(); Cookie authCookie = new Cookie(cookieAuthConfig.getCookieName(), cookieUserKey + (realm != null ? (":" + realm) : "")); authCookie.setPath(StringUtils.isNotEmpty(authContext.getRequest().getContextPath()) ? authContext.getRequest().getContextPath() : "/"); authCookie.setMaxAge(cookieAuthConfig.getMaxAgeInSeconds()); authCookie.setHttpOnly(cookieAuthConfig.isHttpOnly()); authCookie.setSecure(cookieAuthConfig.isSecure()); authContext.getResponse().addCookie(authCookie); }
From source file:com.ax.utils.CookieUtils.java
/** * Deletes the specified cookie.//from w w w .ja v a 2s. c om * * @param request * the servlet request. * @param response * the servlet response. * @param cookie * the cookie object to be deleted. * @param path * the path. */ public static void deleteCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie, String path) { if (cookie != null) { // Invalidate the cookie if (StringUtils.isEmpty(path)) { path = "/"; } cookie.setPath(path); cookie.setValue(""); cookie.setMaxAge(0); response.addCookie(cookie); } }
From source file:org.apache.archiva.redback.integration.util.AutoLoginCookies.java
private static Cookie createCookie(String cookieName, String value, String domain, String path, HttpServletRequest httpRequest) { Cookie cookie = new Cookie(cookieName, value); if (domain != null) { cookie.setDomain(domain);//from w w w . ja v a2 s . c o m } if (path != null) { cookie.setPath(path); } else { // default to the context path, otherwise you get /security and such in some places cookie.setPath(getWebappContext(httpRequest)); } return cookie; }
From source file:com.leixl.easyframework.web.CookieUtils.java
/** * ?cookie?//from w w w . j a v a 2s. c o m * * @param request * @param response * @param name * @param value * @param expiry * @param domain * @return */ public static Cookie addCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, Integer expiry, String domain) { Cookie cookie = new Cookie(name, value); if (expiry != null) { cookie.setMaxAge(expiry); } if (StringUtils.isNotBlank(domain)) { cookie.setDomain(domain); } String ctx = request.getContextPath(); cookie.setPath(StringUtils.isBlank(ctx) ? "/" : ctx); response.addCookie(cookie); return cookie; }
From source file:com.activecq.api.utils.CookieUtil.java
/** * Remove the Cookies whose names match the provided Regex from Response * * @param request Request to get the Cookies to drop * @param response Response to expire the Cookies on * @param regexes Regex to find Cookies to drop * @return Number of Cookies dropped/*ww w. j a v a 2 s . c o m*/ */ public static int dropCookiesByRegexArray(HttpServletRequest request, HttpServletResponse response, String[] regexes) { int count = 0; if (regexes == null) { return count; } List<Cookie> cookies = new ArrayList<Cookie>(); for (final String regex : regexes) { cookies.addAll(getCookies(request, regex)); //cookies = CollectionUtils.union(cookies, getCookies(request, regex)); } for (final Cookie cookie : cookies) { if (cookie == null) { continue; } cookie.setMaxAge(0); cookie.setPath(cookie.getPath()); addCookie(cookie, response); count++; } return count; }
From source file:org.beanfuse.utils.web.CookieUtils.java
/** * Convenience method to set a cookie <br> * value?<br>/* w w w . j av a 2 s.c o m*/ * * @param response * @param name * @param value * @param path */ public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String path, int age) { LOG.debug("add cookie[name:{},value={},path={}]", new String[] { name, value, path }); Cookie cookie = null; try { cookie = new Cookie(name, new URLCodec().encode(value, "utf-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } cookie.setSecure(false); cookie.setPath(path); cookie.setMaxAge(age); response.addCookie(cookie); }
From source file:com.activecq.api.utils.CookieUtil.java
/** * Remove the named Cookies from Response * * @param request Request to get the Cookies to drop * @param response Response to expire the Cookies on * @param cookieNames Names of cookies to drop * @return Number of Cookies dropped//ww w . ja va 2s. co m */ public static int dropCookies(HttpServletRequest request, HttpServletResponse response, String... cookieNames) { int count = 0; if (cookieNames == null) { return count; } for (final String cookieName : cookieNames) { Cookie cookie = getCookie(request, cookieName); if (cookie == null) { continue; } cookie.setMaxAge(0); cookie.setPath(cookie.getPath()); addCookie(cookie, response); count++; } return count; }
From source file:com.anjz.util.CookieUtils.java
private static void setCookie(String key, String value, int maxAge, String path, String domainName, final boolean httpOnly, final boolean secure, HttpServletResponse response) { if (response != null) { Cookie cookie = new Cookie(key, value); cookie.setMaxAge(maxAge);//from ww w . j a v a 2s. c o m if (StringUtils.isNotBlank(path)) { cookie.setPath(path); } else { cookie.setPath(PATH); } if (StringUtils.isNotBlank(domainName)) { cookie.setDomain(domainName); } cookie.setVersion(0); cookie.setSecure(secure); if (httpOnly) { final StringBuffer buf = new StringBuffer(); getCookieHeaderValue(cookie, buf, httpOnly); response.addHeader(getCookieHeaderName(cookie), buf.toString()); } else { response.addCookie(cookie); } } }