List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:com.xidu.framework.common.util.CookieUtils.java
/** * set the name/value entry to the cookie * /*from w ww.java2 s . co m*/ * @Date : 2011-3-23 * @param req * - HttpServletRequest's instance * @param res * - HttpServletResponse's instance * @param domain * - the domain of sites * @param name * - cookie's entry name * @param value * - cookie's entry value * @param expiry * - cookie's expired time */ public static void setCookie(HttpServletRequest req, HttpServletResponse res, String domain, String name, String value, int expiry) { value = EnDecoderUtils.encode(value); if (StringUtils.isBlank(domain) || StringUtils.isBlank(name) || StringUtils.isBlank(value)) { return; } Cookie cookie = null; Cookie[] cookies = req.getCookies(); boolean isNew = true; if (null != cookies) { for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; if (name.equals(cookie.getName())) { isNew = false; setCookie(res, name, value, "/", domain, expiry); } } } if (isNew) { setCookie(res, name, value, "/", domain, expiry); } }
From source file:ai.susi.server.AbstractAPIHandler.java
/** * Returns a login cookie if present in the request * @param request// w w w . jav a 2 s.c o m * @return the login cookie if present, null otherwise */ private static Cookie getLoginCookie(HttpServletRequest request) { if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if ("login".equals(cookie.getName())) { return cookie; } } } return null; }
From source file:com.xidu.framework.common.util.CookieUtils.java
/** * get the value from cookie vai the name * /*from ww w.j a v a 2s . co m*/ * @param req * - HttpServletRequest's instance * @param res * - HttpServletResponse's instance * @param name * - Cookie's entry key * @return cookie's entry value */ public static String getCookie(HttpServletRequest req, HttpServletResponse res, String name) { if (StringUtils.isBlank(name)) { return null; } Cookie cookie = null; String value = null; Cookie[] cookies = req.getCookies(); if (null != cookies) { for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; logger.debug("Cookie name:" + cookie.getName() + " value:" + cookie.getValue()); if (name.equals(cookie.getName())) { value = cookie.getValue(); break; } } } logger.debug("Getting cookie value:" + value); return EnDecoderUtils.decode(value); }
From source file:org.dd4t.core.util.HttpUtils.java
public static String getSessionPreviewToken(HttpServletRequest request) { if (request == null) { return null; }/*w ww. j av a 2 s . c o m*/ Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (TridionUtils.PREVIEW_SESSION_TOKEN.equals(cookie.getName())) { return cookie.getValue(); } } } return null; }
From source file:com.liferay.portal.util.CookieKeys.java
public static void addCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie, boolean secure) { if (!PropsValues.SESSION_ENABLE_PERSISTENT_COOKIES || PropsValues.TCK_URL) { return;//from ww w.java2 s . c om } // LEP-5175 String name = cookie.getName(); String originalValue = cookie.getValue(); String encodedValue = originalValue; if (isEncodedCookie(name)) { encodedValue = new String(Hex.encodeHex(originalValue.getBytes())); if (_log.isDebugEnabled()) { _log.debug("Add encoded cookie " + name); _log.debug("Original value " + originalValue); _log.debug("Hex encoded value " + encodedValue); } } cookie.setSecure(secure); cookie.setValue(encodedValue); cookie.setVersion(VERSION); // Setting a cookie will cause the TCK to lose its ability to track // sessions response.addCookie(cookie); }
From source file:no.sesat.search.http.servlet.SearchServlet.java
static String getCookieValue(final HttpServletRequest request, final String cookieName) { String value = ""; // Look in attributes (it could have already been updated this request) if (null != request) { // Look through cookies if (null != request.getCookies()) { for (Cookie c : request.getCookies()) { if (c.getName().equals(cookieName)) { value = c.getValue(); break; }//from ww w .j a v a 2s. c om } } } return value; }
From source file:edu.stanford.epad.epadws.xnat.XNATSessionOperations.java
public static String getJSessionIDFromRequest(HttpServletRequest servletRequest) { String jSessionID = null;// w w w .j a va2 s . c o m Cookie[] cookies = servletRequest.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) { jSessionID = cookie.getValue(); break; } } } if (jSessionID == null) log.warning("No JSESESSIONID cookie present in request " + servletRequest.getRequestURL()); return jSessionID; }
From source file:com.persistent.cloudninja.controller.AuthFilterUtils.java
/** * // w w w.j a va 2s . co m * @param HttpServletRequest * object * @return cookie, if present, null otherwise. */ public static Cookie checkForPreExistentCookie(HttpServletRequest request, String cookieName) { // Check whether the browser already has a SSO cookie Cookie[] cookies = request.getCookies(); Cookie currentCookie = null; if (cookies != null && cookies.length > 0) { for (Cookie c : cookies) { if (cookieName.equals(c.getName())) { currentCookie = c; break; } } } return currentCookie; }
From source file:com.feilong.servlet.http.CookieUtil.java
/** * {@link Cookie} key value? map({@link TreeMap}). * * @param request// w ww .j a va 2 s . co m * the request * @return {@link HttpServletRequest#getCookies()}, {@link Collections#emptyMap()};<br> * ?, loop cookies,? {@link Cookie#getName()}? {@link Cookie#getValue()} ?map * @see HttpServletRequest#getCookies() * @see javax.servlet.http.Cookie#getName() * @see javax.servlet.http.Cookie#getValue() * @see javax.servlet.jsp.el.ImplicitObjectELResolver.ImplicitObjects#createCookieMap(javax.servlet.jsp.PageContext) */ public static Map<String, String> getCookieMap(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (isNullOrEmpty(cookies)) { return emptyMap(); } Map<String, String> map = new TreeMap<>(); for (Cookie cookie : cookies) { map.put(cookie.getName(), cookie.getValue()); } return map; }
From source file:com.vmware.identity.samlservice.Shared.java
/** * Return a cookie value or default/*from ww w . j a v a 2 s . c om*/ * @param cookies * @param cookieName * @param defaultValue * @return */ public static String getCookieValue(Cookie[] cookies, String cookieName, String defaultValue) { if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookieName.equals(cookie.getName())) { return (cookie.getValue()); } } } return (defaultValue); }