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:GetCookiesServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Cookie[] cookies = request.getCookies();

    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.println("<B>");
    for (int i = 0; i < cookies.length; i++) {
        String name = cookies[i].getName();
        String value = cookies[i].getValue();
        pw.println("name = " + name + "; value = " + value);
    }//from w w w  .j  a  va 2 s  . c o m
    pw.close();
}

From source file:net.sourceforge.vulcan.web.PreferencesFilter.java

private String getCookieData(HttpServletRequest request, String cookieName) {
    final Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie c : cookies) {
            if (c.getName().equals(cookieName)) {
                return c.getValue();
            }//from w  w w.  j av  a2  s  .c o m
        }
    }

    return null;
}

From source file:webim.service.WebimVisitorManager.java

private Cookie findCookie(HttpServletRequest request, String cookieId) {
    Cookie[] cookies = request.getCookies();
    for (Cookie c : cookies) {
        if (c.getName().equals(cookieId)) {
            return c;
        }//from  ww  w .java  2s .  c  om
    }
    return null;
}

From source file:com.persistent.cloudninja.web.security.CloudNinjaRemembermeService.java

private Cookie getCoockieFromRequest(HttpServletRequest request, String cookieName) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies)
            if (cookie.getName().equals(cookieName)) {
                return cookie;
            }/*from www.  ja v a2s.co m*/
    }
    return null;
}

From source file:com.zextras.zimbradrive.BackendUtils.java

private String assertZmAuthTokenFromCookies(HttpServletRequest httpServletRequest) {
    Cookie[] cookies = httpServletRequest.getCookies();
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(AUTH_TOKEN)) {
            return cookie.getValue();
        }//from ww  w  .j  a  v a2  s  . c o  m
    }
    throw new NoZmAuthTokenCookieFoundException();
}

From source file:com.wooki.services.security.spring.WookiTargetUrlResolver.java

@Override
protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response) {
    // Check first wooki last view
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (WookiModule.VIEW_REFERER.equals(cookie.getName())) {
                return cookie.getValue();
            }/*  w w  w .j a  v a2s .co  m*/
        }
    }
    return super.determineTargetUrl(request, response);
}

From source file:ru.org.linux.auth.SecurityFilter.java

private void CSRFManipulation(HttpServletRequest request, HttpServletResponse response) {
    Properties cookies = LorHttpUtils.getCookies(request.getCookies());
    if (cookies.get(CSRFProtectionService.CSRF_COOKIE) == null) {
        CSRFProtectionService.generateCSRFCookie(request, response);
    } else {/*from  w  w w . j  av a 2s  .  co m*/
        request.setAttribute(CSRFProtectionService.CSRF_ATTRIBUTE,
                cookies.getProperty(CSRFProtectionService.CSRF_COOKIE).trim());
    }
    response.addHeader("Cache-Control", "private");
}

From source file:edu.indiana.d2i.sloan.ui.SessionTimeoutInterceptor.java

@Override
public String intercept(final ActionInvocation invocation) throws Exception {
    Object action = invocation.getAction();
    if (!(action instanceof SessionTimeoutRequired)) {
        return invocation.invoke();
    }/*from  w  w  w . j  av a  2  s  .  c o  m*/

    Map<String, Object> session = invocation.getInvocationContext().getSession();
    if (session == null || session.isEmpty()) {
        HttpServletRequest httpRequest = ServletActionContext.getRequest();
        Cookie[] cookies = httpRequest.getCookies();
        for (int i = 0; i < cookies.length; i++) {
            if (cookies[i].getName().equals(Constants.SESSION_EXIST_BEFORE)
                    && (cookies[i].getValue().equals("true"))) {
                logger.info("Session expired.");
                session.put(Constants.SESSION_EXIST_BEFORE, new Boolean(true));
                return "sessionexpiredRedirect";
            }
        }

    }
    return invocation.invoke();
}

From source file:cn.vlabs.duckling.vwb.FetchToSession.java

private String getCookieParameter(HttpServletRequest request, String name) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null || cookies.length <= 0 || StringUtils.isBlank(name)) {
        return "";
    }//from   ww  w . j a  v  a 2  s. com

    for (Cookie cookie : cookies) {
        if (StringUtils.equals(name, cookie.getName())) {
            return cookie.getValue();
        }
    }

    return "";
}

From source file:com.redhat.rhn.frontend.servlets.PxtCookieManager.java

/**
 * Retrieves the pxt cookie from the request if one is included in the request.
 *
 * @param request The current request./*from  w w  w  .  j  a  v  a  2  s .c  o  m*/
 *
 * @return The pxt cookie included in the request, or <code>null</code> if no cookie is
 * found.
 */
public Cookie getPxtCookie(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();

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

    String pxtCookieName = getCookieName(request);

    for (int i = 0; i < cookies.length; ++i) {
        if (pxtCookieName.equals(cookies[i].getName())) {
            return cookies[i];
        }
    }

    return null;
}