List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:net.shopxx.util.CookieUtils.java
/** * ?cookie//from w w w .ja v a 2 s .co 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:edu.utah.further.i2b2.hook.further.web.ServletUtil.java
/** * Convenience method to get a cookie by name * * @param request/*from ww w . ja va 2 s .com*/ * 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.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 w w w . j av a2 s . c o m } return cookiesMap; }
From source file:com.aurel.track.master.ModuleBL.java
public static Cookie sendPOSTRequest(String urlString) { Cookie responseCookie = null;/*from ww w . ja va 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:com.anjz.util.CookieUtils.java
public static Cookie getCookie(String key, HttpServletRequest request) { if (request == null) { return null; }/*from w ww . j ava2 s. c o m*/ Cookie[] cookies = request.getCookies(); if (cookies == null) { return null; } Cookie value = null; for (Cookie c : cookies) { if (key.equals(c.getName())) { value = c; break; } } return value; }
From source file:com.activecq.api.utils.CookieUtil.java
/** * Get the named cookie from the HTTP Request * * @param request Request to get the Cookie from * @param cookieName name of Cookie to get * @return the named Cookie, null if the named Cookie cannot be found *///from ww w . ja va2 s. c o m public static Cookie getCookie(HttpServletRequest request, String cookieName) { cookieName = StringUtils.trimToNull(cookieName); if (cookieName == null) { return null; } Cookie[] cookies = request.getCookies(); if (cookies == null) { return null; } if (cookies.length > 0) { for (Cookie cookie : cookies) { if (StringUtils.equals(cookieName, cookie.getName())) { return cookie; } } } return null; }
From source file:com.adobe.acs.commons.util.CookieUtil.java
/** * Gets Cookies from the Request whose names match the provides Regex * * @param request Request to get the Cookie from * @param regex Regex to match against Cookie names * @return Cookies which match the Regex *///from w w w . java2 s .co m public static List<Cookie> getCookies(final HttpServletRequest request, final String regex) { final ArrayList<Cookie> foundCookies = new ArrayList<Cookie>(); if (StringUtils.isBlank(regex)) { return foundCookies; } final Cookie[] cookies = request.getCookies(); if (cookies == null) { return Collections.emptyList(); } final Pattern p = Pattern.compile(regex); for (final Cookie cookie : cookies) { final Matcher m = p.matcher(cookie.getName()); if (m.matches()) { foundCookies.add(cookie); } } return foundCookies; }
From source file:com.google.gsa.valve.modules.utils.CookieManagement.java
/** * Transforms Servlet cookies into Apache Cookies * //from w ww . ja v a 2 s .c o 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.paladin.mvc.RequestContext.java
/** * ? /*from www. j av a2s .c o m*/ * * @param ctx * @param req * @param res */ public static RequestContext begin(ServletContext ctx, HttpServletRequest req, HttpServletResponse res) { RequestContext rc = new RequestContext(); rc.context = ctx; rc.request = req;// _AutoUploadRequest(_AutoEncodingRequest(req)); rc.response = res; rc.response.setCharacterEncoding(UTF_8); rc.session = req.getSession(false); rc.cookies = new HashMap<String, Cookie>(); Cookie[] cookies = req.getCookies(); if (cookies != null) for (Cookie ck : cookies) { rc.cookies.put(ck.getName(), ck); } contexts.set(rc); return rc; }
From source file:com.rantop.web.util.web.ServletUtils.java
/** * Convenience method to get a cookie by name * * @param request the current request/*from w ww . 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; }