List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:com.leixl.easyframework.web.CookieUtils.java
/** * cookie??//from w w w . j a v a 2s. com * * _cookie_page_sizecookie name * * @param request * HttpServletRequest * @return default:20 max:200 */ public static int getPageSize(HttpServletRequest request) { Assert.notNull(request); Cookie cookie = getCookie(request, COOKIE_PAGE_SIZE); int count = 0; if (cookie != null) { if (NumberUtils.isDigits(cookie.getValue())) { count = Integer.parseInt(cookie.getValue()); } } if (count <= 0) { count = DEFAULT_SIZE; } else if (count > MAX_SIZE) { count = MAX_SIZE; } return count; }
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:de.itsvs.cwtrpc.controller.token.DefaultXsrfTokenService.java
protected static byte[] getCookieBytes(HttpServletRequest request, String cookieName) { final Cookie cookie; cookie = Util.getCookie(request, cookieName, false); if ((cookie == null) || (cookie.getValue() == null)) { /* request contains invalid cookie */ return null; }//from ww w.j a v a2 s . co m return cookie.getValue().getBytes(); }
From source file:io.lavagna.web.helper.UserSession.java
public static void invalidate(HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { req.getSession().invalidate();/*from w w w. j av a2 s .com*/ Cookie c = getCookie(req, "LAVAGNA_REMEMBER_ME"); if (c != null) { deleteTokenIfExist(c.getValue(), userRepository); c.setMaxAge(0); c.setValue(null); resp.addCookie(c); } }
From source file:net.bluehornreader.web.UserHelpers.java
public static LoginInfo.SessionInfo getSessionInfo(Request request) { Cookie[] cookies = request.getCookies(); LoginInfo.SessionInfo res = new LoginInfo.SessionInfo(); String cookieRepr = ""; if (cookies != null) { for (Cookie cookie : cookies) { cookieRepr += WebUtils.cookieAsString(cookie); if (cookie.getName().equals(ReaderHandler.SESSION_ID)) { res.sessionId = cookie.getValue(); }//from ww w .j a v a 2s . c o m if (cookie.getName().equals(ReaderHandler.BROWSER_ID)) { res.browserId = cookie.getValue(); } cookieRepr += " "; } } LOG.info("cookies: " + cookieRepr); return res; }
From source file:com.gisgraphy.webapp.util.RequestUtil.java
/** * Convenience method to get a cookie by name * //w w w . j ava 2 s . co 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(HttpServletRequest request, String name) { Cookie[] cookies = request.getCookies(); Cookie returnCookie = null; if (cookies == null) { return returnCookie; } for (Cookie thisCookie : cookies) { if (thisCookie.getName().equals(name)) { // cookies with no value do me no good! if (!thisCookie.getValue().equals("")) { returnCookie = thisCookie; break; } } } return returnCookie; }
From source file:org.craftercms.core.util.HttpServletUtils.java
public static Map<String, String> createCookiesMap(HttpServletRequest request) { Map<String, String> cookiesMap = new HashMap<String, String>(); Cookie[] cookies = request.getCookies(); if (ArrayUtils.isNotEmpty(cookies)) { for (Cookie cookie : request.getCookies()) { cookiesMap.put(cookie.getName(), cookie.getValue()); }/*from ww w . ja v a2 s. c o m*/ } return cookiesMap; }
From source file:cn.vlabs.duckling.vwb.VWBFilter.java
private static String getLocaleString(HttpServletRequest request) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals("Portal.Locale")) { return cookie.getValue(); }/* www. ja v a 2s.c o m*/ } } return null; }
From source file:net.shopxx.util.CookieUtils.java
/** * ?cookie//from ww w.j a v a2s . c o m * * @param request * HttpServletRequest * @param name * cookie?? * @return ?null */ public static String getCookie(HttpServletRequest request, String name) { Assert.notNull(request); Assert.hasText(name); Cookie[] cookies = request.getCookies(); if (cookies != null) { try { for (Cookie cookie : cookies) { if (name.equals(cookie.getName())) { return URLDecoder.decode(cookie.getValue(), "UTF-8"); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; }
From source file:com.buession.cas.web.utils.CaptchaUtils.java
/** * ???//from w w w.j a va2 s .co m * * @param request * HttpServletRequest * @param captchaProducer * ????? * @param validateCode * ???? * @return ??? */ public static boolean validate(final HttpServletRequest request, final Config config, final String validateCode) { if (validateCode == null || validateCode.length() == 0) { return false; } Cookie cookies[] = request.getCookies(); if (cookies == null || cookies.length == 0) { return false; } String captchaCookieName = CaptchaUtils.getCaptchaCookieName(config); for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (captchaCookieName.equals(cookie.getName()) == true) { mcrypt.setSalt(request.getSession().getId()); return mcrypt.encode(validateCode).equalsIgnoreCase(cookie.getValue()); } } return false; }