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.xpn.xwiki.util.Util.java

public static Cookie getCookie(String cookieName, HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookieName.equals(cookie.getName())) {
                return (cookie);
            }/* w w  w  . j a v  a2  s.com*/
        }
    }

    return null;
}

From source file:dk.netarkivet.common.webinterface.HTMLUtils.java

/**
 * Get a locale from cookie, if present. The default request locale otherwise.
 *
 * @param request The request to get the locale for.
 * @return The cookie locale, if present. The default request locale otherwise.
 *//*  ww w  .j  av a 2  s .co m*/
public static String getLocale(HttpServletRequest request) {
    ArgumentNotValid.checkNotNull(request, "request");
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie c : cookies) {
            if (c.getName().equals("locale")) {
                return c.getValue();
            }
        }
    }
    return request.getLocale().toString();
}

From source file:com.ibm.jaggr.service.impl.transport.AbstractHttpTransport.java

/**
 * This method checks the request for the has conditions which may either be contained in URL 
 * query arguments or in a cookie sent from the client.
 * /*from www  .  java  2s  . c  o m*/
 * @return The has conditions from the request.
 * @throws UnsupportedEncodingException 
 */
protected static String getHasConditionsFromRequest(HttpServletRequest request) throws IOException {
    String ret = null;
    if (request.getParameter(FEATUREMAPHASH_REQPARAM) != null) {
        // The cookie called 'has' contains the has conditions
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (int i = 0; ret == null && i < cookies.length; i++) {
                Cookie cookie = cookies[i];
                if (cookie.getName().equals(FEATUREMAP_REQPARAM) && cookie.getValue() != null) {
                    ret = URLDecoder.decode(cookie.getValue(), "US-ASCII"); //$NON-NLS-1$
                    break;
                }
            }
        }
        if (ret == null) {
            if (log.isLoggable(Level.WARNING)) {
                StringBuffer url = request.getRequestURL();
                if (url != null) { // might be null if using mock request for unit testing
                    url.append("?").append(request.getQueryString()).toString(); //$NON-NLS-1$
                    log.warning(MessageFormat.format(Messages.AbstractHttpTransport_0,
                            new Object[] { url, request.getHeader("User-Agent") })); //$NON-NLS-1$
                }
            }
        }
    } else
        ret = request.getParameter(FEATUREMAP_REQPARAM);

    return ret;
}

From source file:com.erudika.para.utils.Utils.java

/**
 * Reads a cookie.//w w w  .j  a  v a 2 s.  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 || name == null || name.length() == 0) {
        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:org.itracker.web.util.LoginUtilities.java

public static User setupSession(String login, HttpServletRequest request, HttpServletResponse response) {
    if (null == login) {
        logger.warn("setupSession: null login", (logger.isDebugEnabled() ? new RuntimeException() : null));
        throw new IllegalArgumentException("null login");
    }/*w w w  .j a  va2s . co m*/
    UserService userService = ServletContextUtils.getItrackerServices().getUserService();
    User user = userService.getUserByLogin(login);
    if (user != null) {
        String encPassword = null;
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (Constants.COOKIE_NAME.equals(cookie.getName())) {
                    int seperator = cookie.getValue().indexOf('~');
                    if (seperator > 0) {
                        encPassword = cookie.getValue().substring(seperator + 1);
                    }
                }
            }
        }

        return setupSession(user, encPassword, request, response);
    }
    return null;
}

From source file:au.gov.dto.dibp.appointments.security.csrf.CookieBasedCsrfTokenRepository.java

@Override
public CsrfToken loadToken(HttpServletRequest request) {
    if (request.getCookies() != null) {
        for (Cookie cookie : request.getCookies()) {
            if (cookie != null && CSRF_COOKIE_AND_PARAMETER_NAME.equals(cookie.getName())) {
                return new DefaultCsrfToken(CSRF_HEADER_NAME, CSRF_COOKIE_AND_PARAMETER_NAME,
                        cookie.getValue());
            }//  www. ja  v  a2  s . com
        }
    }
    return null;
}

From source file:com.kdubb.social.user.UserCookieGenerator.java

public String readCookieValue(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();

    if (cookies == null)
        return null;

    for (Cookie cookie : cookies)
        if (cookie.getName().equals(userCookieGenerator.getCookieName()))
            return cookie.getValue();

    return null;// w ww .java 2 s .  c o m
}

From source file:com.captaindebug.social.facebookposts.implementation.UserCookieGenerator.java

public String readCookieValue(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }/* w w  w  .j a v  a  2 s. c o m*/
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(cookieGenerator.getCookieName())) {
            return cookie.getValue();
        }
    }
    return null;
}

From source file:com.awt.facebook.account.UserCookieGenerator.java

public String readCookieValue(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }/*from   w w  w. j a v a 2s . co m*/
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(userCookieGenerator.getCookieName())) {
            return cookie.getValue();
        }
    }
    return null;
}

From source file:com.liferay.portal.action.LoginAction.java

public static String getLogin(HttpServletRequest req, String paramName, Company company)
        throws PortalException, SystemException {

    String login = req.getParameter(paramName);

    if ((login == null) || (login.equals(StringPool.NULL))) {
        login = GetterUtil.getString(CookieUtil.get(req.getCookies(), CookieKeys.LOGIN));

        if (Validator.isNull(login) && company.getAuthType().equals(CompanyImpl.AUTH_TYPE_EA)) {

            login = "@" + company.getMx();
        }/*from w  w  w.j av  a 2  s .c  o  m*/
    }

    login = XSSUtil.strip(login);

    return login;
}