List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:dk.dma.msinm.common.util.WebUtils.java
/** * Returns the value of the cookie with the given name or null if not found * @param request the request/*from w ww . j a va 2 s .com*/ * @param name the name * @return the value of the cookie with the given name or null if not found */ public static String getCookieValue(HttpServletRequest request, String name) { Cookie c = getCookie(request, name); return (c == null) ? null : c.getValue(); }
From source file:com.hp.octane.integrations.testhelpers.OctaneSecuritySimulationUtils.java
static boolean authenticate(Request request) { if (request.getCookies() != null) { for (Cookie cookie : request.getCookies()) { if (SECURITY_COOKIE_NAME.equals(cookie.getName())) { String[] securityItems = cookie.getValue().split(SECURITY_TOKEN_SEPARATOR); long issuedAt = Long.parseLong(securityItems[2]); if (System.currentTimeMillis() - issuedAt > 2000) { Cookie securityCookie = createSecurityCookie(securityItems[0], securityItems[1]); request.getResponse().addCookie(securityCookie); }/*from w w w . ja v a 2 s . c o m*/ return true; } } } request.getResponse().setStatus(HttpStatus.SC_UNAUTHORIZED); request.setHandled(true); return false; }
From source file:com.erudika.scoold.utils.HttpUtils.java
/** * Reads a cookie.// w w w . j ava 2 s. c o m * @param name the name * @param req HTTP request * @return the cookie value */ public static String getCookieValue(HttpServletRequest req, String name) { if (StringUtils.isBlank(name) || req == null) { return null; } Cookie[] cookies = req.getCookies(); if (cookies == null) { return null; } //Otherwise, we have to do a linear scan for the cookie. for (Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie.getValue(); } } return null; }
From source file:com.pureinfo.tgirls.utils.servlet.CookieUtils.java
public static String getCookieValue(Cookie[] _cookies, String _attrLoginUser) { logger.debug("to get cookie value of name [" + _attrLoginUser + "]"); if (_cookies == null) { return null; }//from www .j av a2 s.c om for (int i = 0; i < _cookies.length; i++) { Cookie c = _cookies[i]; if (c.getName().equals(_attrLoginUser)) { logger.debug("cookie[" + _attrLoginUser + "] value[" + c.getValue() + "]"); return c.getValue(); } } return null; }
From source file:alpha.portal.webapp.util.RequestUtil.java
/** * Convenience method to get a cookie by name. * /*from w ww . j a v a 2 s . c o m*/ * @param request * the current request * @param name * the name of the cookie to find * @return the cookie (if found), null if not found */ public static Cookie getCookie(final HttpServletRequest request, final String name) { final Cookie[] cookies = request.getCookies(); Cookie returnCookie = null; if (cookies == null) return returnCookie; for (final Cookie thisCookie : cookies) { if (thisCookie.getName().equals(name) && !"".equals(thisCookie.getValue())) { returnCookie = thisCookie; break; } } return returnCookie; }
From source file:net.mindengine.oculus.frontend.web.Auth.java
public static User getUserFromRequest(HttpServletRequest request) { Cookie cookies[] = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals("_u")) { User user = decodeUser(cookie.getValue()); return user; }// w w w.j ava 2s. co m } } return null; }
From source file:com.ax.utils.CookieUtils.java
/** * ?cookie<code>name</code>//from w w w . j av a 2s . c o m * * @param request * the servlet request. * @param name * the name of the cookie. * @return the value if it exists, otherwise <tt>null</tt>. */ public static String getCookieValue(HttpServletRequest request, String name) { Cookie cookie = getCookie(request, name); return (cookie != null) ? cookie.getValue() : null; }
From source file:com.hortonworks.example.util.Util.java
public static String getCookieInfo(HttpServletRequest request, String name) { String info = null;// www . ja v a2s . c om 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.netsteadfast.greenstep.base.sys.UserCurrentCookie.java
public static Map<String, String> getCurrentData(HttpServletRequest request) { Map<String, String> dataMap = new HashMap<String, String>(); try {//from ww w. j a v a2 s . c om Cookie[] cookies = request.getCookies(); for (int i = 0; cookies != null && dataMap.size() == 0 && i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(Constants.APP_SITE_CURRENTID_COOKIE_NAME)) { if (StringUtils.isBlank(cookie.getValue())) { return dataMap; } String decVal = SimpleUtils.deHex(cookie.getValue()); decVal = EncryptorUtils.decrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(), decVal); String tmp[] = decVal.split(Constants.ID_DELIMITER); if (tmp != null && tmp.length == 4) { dataMap.put("currentId", tmp[0]); dataMap.put("sessionId", tmp[1]); dataMap.put("account", tmp[2]); dataMap.put("lang", tmp[3]); } } } } catch (Exception e) { e.printStackTrace(); } return dataMap; }
From source file:com.sniper.springmvc.utils.CookieUtils.java
/** * Cookie/*from www . j a v a2 s. c o m*/ * * @param request * * @param response * ? * @param name * ?? * @param isRemove * ? * @return */ public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name, boolean isRemove) { String value = null; Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(name)) { try { value = URLDecoder.decode(cookie.getValue(), "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (isRemove) { cookie.setMaxAge(0); response.addCookie(cookie); } } } } return value; }