Example usage for javax.servlet.http Cookie getName

List of usage examples for javax.servlet.http Cookie getName

Introduction

In this page you can find the example usage for javax.servlet.http Cookie getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the cookie.

Usage

From source file:com.usefullc.platform.common.utils.CookieUtils.java

/**
 * cookie /*from ww w  .j  av a  2  s  . c  o  m*/
 * 
 * @param request
 * @param name
 * @param domain
 * @return
 */
public static Cookie getCookie(HttpServletRequest request, String name, String domain) {
    Cookie cookies[] = request.getCookies();
    if (cookies == null) {
        return null;
    }
    for (Cookie cookie : cookies) {
        String cookieName = cookie.getName();
        String cookieDomain = cookie.getDomain();
        if (!cookieName.equals(name)) {
            continue;
        }
        if (StringUtils.isNotEmpty(domain) && !cookieDomain.equals(domain)) {
            continue;
        }
        return cookie;
    }
    return null;
}

From source file:com.erudika.scoold.utils.HttpUtils.java

/**
 * Reads a cookie./*from www .j a v  a2s .  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.kamike.misc.CookieUtils.java

/**
 *
 * ?COOKIE/* w ww . j  a  v  a2s  .com*/
 *
 *
 *
 * @param name
 *
 */
public static Cookie getCookie(HttpServletRequest request, String name) {

    Cookie[] cookies = request.getCookies();

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

    for (Cookie ck : cookies) {

        if (StringUtils.equalsIgnoreCase(name, ck.getName())) {
            return ck;
        }
    }

    return null;

}

From source file:com.kamike.misc.CookieUtils.java

/**
 *
 * ?COOKIE//from   w  w w.j  a  va 2 s .  com
 *
 *
 *
 * @param name
 *
 */
public static String getCookieValue(HttpServletRequest request, String name) {

    Cookie[] cookies = request.getCookies();

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

    for (Cookie ck : cookies) {

        if (StringUtils.equalsIgnoreCase(name, ck.getName())) {

        }
    }

    return null;

}

From source file:com.buession.cas.web.utils.CaptchaUtils.java

/**
 * ???//from   www  .j a  v  a2 s .  com
 * 
 * @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;
}

From source file:alpha.portal.webapp.util.RequestUtil.java

/**
 * Convenience method to get a cookie by name.
 * //w w w.  j a v a2s .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:com.gisgraphy.webapp.util.RequestUtil.java

/**
 * Convenience method to get a cookie by name
 * //from www. j a v  a2 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(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:dk.dma.msinm.common.util.WebUtils.java

/**
 * Returns the cookie with the given name or null if not found
 * @param request the request//from   w w  w.  j  a  va 2 s.  c o m
 * @param name the name
 * @return the cookie with the given name or null if not found
 */
public static Cookie getCookie(HttpServletRequest request, String name) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie c : request.getCookies()) {
            if (c.getName().equals(name)) {
                return c;
            }
        }
    }
    return null;
}

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  w  w w .jav a  2  s.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.threewks.thundr.http.Cookies.java

/**
 * Gets the first cookie of the given name from the request
 * /*from w ww  .j a  va2 s .  c  o m*/
 * @param name
 * @param req
 * @return
 */
public static final Cookie getCookie(String name, HttpServletRequest req) {
    if (req.getCookies() != null) {
        for (Cookie cookie : req.getCookies()) {
            if (cookie.getName().equals(name)) {
                return cookie;
            }
        }
    }
    return null;
}