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.mmj.app.common.cookie.parser.CookieUtils.java

/**
 * Cookie?cookie nameKeyCookie ValueValueMap
 * //  ww  w . ja v a 2 s  . co m
 * @return cookiesnull,emptyMap
 */
public static Map<String, String> arrayToMap(Cookie[] cookies) {
    if (cookies == null || cookies.length == 0) {
        return Collections.<String, String>emptyMap();
    }
    Map<String, String> values = new HashMap<String, String>(cookies.length);
    for (Cookie cookie : cookies) {
        values.put(cookie.getName(), cookie.getValue());
    }
    return values;
}

From source file:com.jsmartframework.web.util.WebUtils.java

public static String getCookie(HttpServletRequest request, String name) {
    if (name == null) {
        return null;
    }/*ww  w. j  av a2  s.co  m*/
    Cookie[] cookies = request.getCookies();
    if (cookies == null || cookies.length == 0) {
        return null;
    }
    for (Cookie cookie : cookies) {
        if (name.equalsIgnoreCase(cookie.getName())) {
            return cookie.getValue();
        }
    }
    return null;
}

From source file:com.hp.octane.integrations.testhelpers.OctaneSecuritySimulationUtils.java

static boolean authenticate(Request request) {
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            if (SECURITY_COOKIE_NAME.equals(cookie.getName())) {
                String[] securityItems = cookie.getValue().split(SECURITY_TOKEN_SEPARATOR);
                long issuedAt = Long.parseLong(securityItems[2]);
                if (System.currentTimeMillis() - issuedAt > 2000) {
                    Cookie securityCookie = createSecurityCookie(securityItems[0], securityItems[1]);
                    request.getResponse().addCookie(securityCookie);
                }//  w  w  w.j  av a 2  s. c o  m
                return true;
            }
        }
    }
    request.getResponse().setStatus(HttpStatus.SC_UNAUTHORIZED);
    request.setHandled(true);
    return false;
}

From source file:com.netsteadfast.greenstep.base.sys.UserCurrentCookie.java

public static Map<String, String> getCurrentData(HttpServletRequest request) {
    Map<String, String> dataMap = new HashMap<String, String>();
    try {//from  w w w.  j ava 2s.  co m
        Cookie[] cookies = request.getCookies();
        for (int i = 0; cookies != null && dataMap.size() == 0 && i < cookies.length; i++) {
            Cookie cookie = cookies[i];
            if (cookie.getName().equals(Constants.APP_SITE_CURRENTID_COOKIE_NAME)) {
                if (StringUtils.isBlank(cookie.getValue())) {
                    return dataMap;
                }
                String decVal = SimpleUtils.deHex(cookie.getValue());
                decVal = EncryptorUtils.decrypt(Constants.getEncryptorKey1(), Constants.getEncryptorKey2(),
                        decVal);
                String tmp[] = decVal.split(Constants.ID_DELIMITER);
                if (tmp != null && tmp.length == 4) {
                    dataMap.put("currentId", tmp[0]);
                    dataMap.put("sessionId", tmp[1]);
                    dataMap.put("account", tmp[2]);
                    dataMap.put("lang", tmp[3]);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return dataMap;
}

From source file:fedroot.dacs.http.DacsCookie.java

public static boolean isDacsSelectCookie(javax.servlet.http.Cookie cookie) {
    return isDacsSelectCookieName(cookie.getName());
}

From source file:net.mindengine.oculus.frontend.web.Auth.java

public static User getUserFromRequest(HttpServletRequest request) {
    Cookie cookies[] = request.getCookies();

    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals("_u")) {
                User user = decodeUser(cookie.getValue());
                return user;
            }//from   w  w  w  .  ja  v a2  s .  co  m
        }
    }
    return null;
}

From source file:com.sniper.springmvc.utils.CookieUtils.java

/**
 * Cookie//w ww  . j a v  a 2 s .c om
 * 
 * @param request
 *            
 * @param response
 *            ?
 * @param name
 *            ??
 * @param isRemove
 *            ?
 * @return 
 */
public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name,
        boolean isRemove) {
    String value = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(name)) {
                try {
                    value = URLDecoder.decode(cookie.getValue(), "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                if (isRemove) {
                    cookie.setMaxAge(0);
                    response.addCookie(cookie);
                }
            }
        }
    }
    return value;
}

From source file:com.baifendian.swordfish.common.utils.http.HttpUtil.java

/**
 * ? cookie ?/* w  ww . j  a v a 2  s . com*/
 */
public static Cookie getCookieByName(HttpServletRequest request, String name) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (StringUtils.equalsIgnoreCase(name, cookie.getName())) {
                return cookie;
            }
        }
    }

    return null;
}

From source file:com.leixl.easyframework.web.CookieUtils.java

/**
 * cookie/*  ww  w. jav a  2  s.c om*/
 * 
 * @param request
 *            HttpServletRequest
 * @param name
 *            cookie name
 * @return if exist return cookie, else return null.
 */
public static Cookie getCookie(HttpServletRequest request, String name) {
    Assert.notNull(request);
    Cookie[] cookies = request.getCookies();
    if (cookies != null && cookies.length > 0) {
        for (Cookie c : cookies) {
            if (c.getName().equals(name)) {
                return c;
            }
        }
    }
    return null;
}

From source file:com.hortonworks.example.util.Util.java

public static Cookie getCookie(HttpServletRequest request, String name) {
    for (Cookie cookie : request.getCookies()) {
        if (cookie.getName().equalsIgnoreCase(name)) {
            return cookie;
        }//from  w  w w  .  jav  a  2s .c  o  m
    }
    return null;
}