List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:com.google.gsa.valve.modules.utils.CookieManagement.java
/** * Transforms Servlet cookies into Apache Cookies * //from ww w .j a v a 2s . co m * @param servletCookie servlet cookie * * @return apache cookie */ public static org.apache.commons.httpclient.Cookie transformServletCookie( javax.servlet.http.Cookie servletCookie) { org.apache.commons.httpclient.Cookie newCookie = null; if (servletCookie != null) { newCookie = new org.apache.commons.httpclient.Cookie(servletCookie.getDomain(), servletCookie.getName(), servletCookie.getValue(), servletCookie.getPath() != null ? servletCookie.getPath() : "/", servletCookie.getMaxAge(), servletCookie.getSecure()); } return newCookie; }
From source file:com.anjz.util.CookieUtils.java
public static String getCookieValue(String key, HttpServletRequest request) { Cookie cookie = getCookie(key, request); if (cookie == null) { return null; }//from w ww .j ava 2s. c om return cookie.getValue(); }
From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java
/** * Convenience method to get a cookie by name * * @param request/*www.j av a2 s.c om*/ * 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 (int i = 0; i < cookies.length; i++) { final Cookie thisCookie = cookies[i]; 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.springframework.test.web.servlet.htmlunit.MockWebResponseBuilder.java
static com.gargoylesoftware.htmlunit.util.Cookie createCookie(Cookie cookie) { Date expires = null;//from w ww . ja va 2 s. co m if (cookie.getMaxAge() > -1) { expires = new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000); } BasicClientCookie result = new BasicClientCookie(cookie.getName(), cookie.getValue()); result.setDomain(cookie.getDomain()); result.setComment(cookie.getComment()); result.setExpiryDate(expires); result.setPath(cookie.getPath()); result.setSecure(cookie.getSecure()); if (cookie.isHttpOnly()) { result.setAttribute("httponly", "true"); } return new com.gargoylesoftware.htmlunit.util.Cookie(result); }
From source file:com.liusoft.dlog4j.util.RequestUtils.java
/** * ?FCKUpload??ID// w w w. ja v a2s.com * @return */ public static String getDlogSessionId(HttpServletRequest req) { //Cookie?ssn_id String ssn_id = null; Cookie cok = RequestUtils.getCookie(req, Globals.SESSION_ID_KEY_IN_COOKIE); if (cok != null) { ssn_id = cok.getValue(); } if (StringUtils.isEmpty(ssn_id)) { //Cookie???? HttpSession ssn = req.getSession(false); if (ssn != null) ssn_id = ssn.getId(); } return ssn_id; }
From source file:de.arago.portlet.util.UserContainer.java
private static User getUserFromCookies(HttpServletRequest request) throws Exception { // https://www.everit.biz/web/guest/everit-blog/-/blogs/getting-current-liferay-user-in-a-standalone-webapp final Cookie[] cookies = request.getCookies() == null ? new Cookie[0] : request.getCookies(); String userId = null;//from ww w. j ava 2 s.co m String password = null; String companyId = null; for (Cookie c : cookies) { if ("COMPANY_ID".equals(c.getName())) { companyId = c.getValue(); } else if ("ID".equals(c.getName())) { userId = hexStringToStringByAscii(c.getValue()); } else if ("PASSWORD".equals(c.getName())) { password = hexStringToStringByAscii(c.getValue()); } } if (userId != null && password != null && companyId != null) { final KeyValuePair kvp = UserLocalServiceUtil.decryptUserId(Long.parseLong(companyId), userId, password); return getUser(kvp.getKey()); } return null; }
From source file:com.aurel.track.master.ModuleBL.java
public static Cookie sendPOSTRequest(String urlString) { Cookie responseCookie = null;// w w w. j a v a 2s .c om try { HttpClient httpclient = new DefaultHttpClient();//HttpClients.createDefault(); HttpPost httppost = new HttpPost(urlString); // Request parameters and other properties. //Execute and get the response. HttpContext localContext = new BasicHttpContext(); CookieStore cookieStore = new BasicCookieStore(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpResponse response = httpclient.execute(httppost, localContext); if (cookieStore.getCookies().size() > 0) { List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies(); for (org.apache.http.cookie.Cookie cookie : cookies) { if (cookie.getName().equals("JSESSIONID")) { responseCookie = new Cookie(cookie.getName(), cookie.getValue()); responseCookie.setPath(cookie.getPath()); responseCookie.setDomain(cookie.getDomain()); } } } if (response.getEntity() != null) { response.getEntity().consumeContent(); } } catch (Exception ex) { LOGGER.debug(ExceptionUtils.getStackTrace(ex)); } return responseCookie; }
From source file:io.lavagna.web.helper.UserSession.java
public static void authenticateUserIfRemembered(HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { Cookie c; if (isUserAuthenticated(req) || (c = getCookie(req, "LAVAGNA_REMEMBER_ME")) == null) { return;//from w ww .j a va 2 s . co m } ImmutablePair<Integer, String> uIdToken = extractUserIdAndToken(c.getValue()); if (uIdToken != null && userRepository.rememberMeTokenExists(uIdToken.getLeft(), uIdToken.getRight())) { userRepository.deleteRememberMeToken(uIdToken.getLeft(), uIdToken.getRight()); User user = userRepository.findById(uIdToken.getLeft()); setUser(user.getId(), user.isAnonymous(), req, resp, userRepository, true); } else { // delete cookie because it's invalid c.setMaxAge(0); c.setValue(null); resp.addCookie(c); } }
From source file:com.mhe.imagebanksearch.controller.LoginController.java
/** * <p>/*from ww w . jav a2 s . c o m*/ * API to get cookie value. * </p> * @param cookies * @param cookieName * @param defaultValue * @return */ public static String getCookieValue(Cookie[] cookies, String cookieName, String defaultValue) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookieName.equals(cookie.getName())) { return (cookie.getValue()); } } return (defaultValue); }
From source file:com.rantop.web.util.web.ServletUtils.java
/** * Convenience method to get a cookie by name * * @param request the current request/* w w w . j a va 2 s . c o m*/ * @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 (int i = 0; i < cookies.length; i++) { Cookie thisCookie = cookies[i]; if (thisCookie.getName().equals(name)) { // cookies with no value do me no good! if (!thisCookie.getValue().equals("")) { returnCookie = thisCookie; break; } } } return returnCookie; }