Example usage for javax.servlet.http HttpServletRequest getCookies

List of usage examples for javax.servlet.http HttpServletRequest getCookies

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getCookies.

Prototype

public Cookie[] getCookies();

Source Link

Document

Returns an array containing all of the Cookie objects the client sent with this request.

Usage

From source file:com.google.gerrit.httpd.ProjectOAuthFilter.java

private static Cookie findGitCookie(HttpServletRequest req) {
    Cookie[] cookies = req.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().startsWith(GIT_COOKIE_PREFIX)) {
                return cookie;
            }/*  ww  w  . ja  va 2  s. c o m*/
        }
    }
    return null;
}

From source file:ai.susi.server.AbstractAPIHandler.java

/**
 * Returns a login cookie if present in the request
 * @param request/*from w  w  w.j  av  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 w  w w .j  a v  a  2  s.c  o  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:com.adobe.acs.commons.util.CookieUtil.java

/**
 * Removes all cookies for the domain/*from   ww w.  ja  va  2  s.  c  om*/
 *
 * @param request  Request to get the Cookies to drop
 * @param response Response to expire the Cookies on
 */
public static int dropAllCookies(final HttpServletRequest request, final HttpServletResponse response,
        final String cookiePath) {
    final Cookie[] cookies = request.getCookies();

    if (cookies == null) {
        return 0;
    }

    return dropCookies(response, cookies, cookiePath);
}

From source file:ke.alphacba.cms.core.util.NoSessionIdUtils.java

public static BaseResp writeCookie(HttpSession session, HttpServletRequest request,
        HttpServletResponse response, String loginCookieName, String domain, int cookieTime) {
    BaseResp baseResp = new BaseResp();
    String jsessionId = (String) session.getAttribute("jsessionId");
    try {/*  www .  j  a v a2s  . c  o m*/
        Cookie[] cookies = request.getCookies();
        if (cookies == null) {
            baseResp.setErrorNo(ErrorNoConstants.ERR_COM_ERRORINFO, "??");
            return baseResp;
        }
        boolean flag = false;
        boolean httpOnly = true;
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals(loginCookieName)) {
                if (StringUtils.isEmpty(cookies[i].getValue())) {
                    writeCookie(response, loginCookieName, domain, cookieTime, jsessionId, httpOnly);
                }
                flag = true;
            }
        }
        if (!flag) {
            writeCookie(response, loginCookieName, domain, cookieTime, jsessionId, httpOnly);
        }
    } catch (Exception e) {
        log.error("write cookie store error !", e);
    }
    return baseResp;
}

From source file:com.anjz.util.CookieUtils.java

public static Cookie getCookie(String key, HttpServletRequest request) {
    if (request == null) {
        return null;
    }//from   w w  w.  java 2s.  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.threewks.thundr.request.servlet.ServletSupport.java

/**
 * Gets all cookies of the given name from the request
 * /*from w w w .j  a v a2  s  .  c om*/
 * @param name
 * @param req
 * @return
 */
public static final List<javax.servlet.http.Cookie> getCookies(String name, HttpServletRequest req) {
    List<javax.servlet.http.Cookie> results = new ArrayList<>();
    if (req.getCookies() != null) {
        for (javax.servlet.http.Cookie cookie : req.getCookies()) {
            if (cookie.getName().equals(name)) {
                results.add(cookie);
            }
        }
    }
    return results;
}

From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java

public static String getBuildInfoCookie(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null)
        return null;
    for (Cookie c : cookies) {
        if (c.getName().equals(BUILD_INFO_COOKIE))
            return c.getValue();
    }//  w ww  . j  a v a  2  s . c o  m
    return null;
}

From source file:com.adobe.acs.commons.util.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  w  ww  .ja v  a 2 s  .c om
public static Cookie getCookie(final HttpServletRequest request, final String cookieName) {
    if (StringUtils.isBlank(cookieName)) {
        return null;
    }

    final Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }

    if (cookies.length > 0) {
        for (final Cookie cookie : cookies) {
            if (StringUtils.equals(cookieName, cookie.getName())) {
                return cookie;
            }
        }
    }

    return null;
}

From source file:de.anycook.session.Session.java

static public Session init(HttpServletRequest request) {
    Session session = init(request.getSession(true));
    if (session.login == null) {
        try {/*w  w w . ja v a 2  s.  c o  m*/
            session.loginWithCookies(request.getCookies());
        } catch (IOException | SQLException e) {
            LogManager.getLogger(Session.class).error(e, e);
        }
    }

    return session;
}