Example usage for javax.servlet.http Cookie getValue

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

Introduction

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

Prototype

public String getValue() 

Source Link

Document

Gets the current value of this Cookie.

Usage

From source file:Cookies.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    req.getSession();//w  w w  .j  a va 2  s.  com
    PrintWriter out = resp.getWriter();
    Cookie cookies[] = req.getCookies();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet Cookie Information</title>");
    out.println("</head>");
    out.println("<body>");

    if ((cookies == null) || (cookies.length == 0)) {
        out.println("<center><h1>No Cookies found</h1>");
    } else {

        out.println("<center><h1>Cookies found</h1>");
        out.println("<table border>");
        out.println("<tr><th>Name</th><th>Value</th>" + "<th>Comment</th><th>Max Age</th></tr>");

        for (int i = 0; i < cookies.length; i++) {
            Cookie c = cookies[i];
            out.println("<tr><td>" + c.getName() + "</td><td>" + c.getValue() + "</td><td>" + c.getComment()
                    + "</td><td>" + c.getMaxAge() + "</td></tr>");
        }

        out.println("</table></center>");
    }
    out.println("</body>");
    out.println("</html>");
    out.flush();
}

From source file:de.berlios.jhelpdesk.web.tools.ThemeCustomResolever.java

public String resolveThemeName(HttpServletRequest req) {
    User currentUser = (User) req.getSession().getAttribute("user");
    if (currentUser != null) {
        return currentUser.getPreferredTheme();
    }//  w ww.  j a v  a  2s.com

    Cookie themeCookie = WebUtils.getCookie(req, "jhd_theme");
    if (themeCookie != null) {
        return themeCookie.getValue();
    }
    return defaultThemeName;
}

From source file:csns.util.DefaultUrls.java

public String anonymousHomeUrl(HttpServletRequest request) {
    Cookie cookie = WebUtils.getCookie(request, "default-dept");
    return cookie != null ? "/department/" + cookie.getValue() + "/" : "/";
}

From source file:au.gov.dto.springframework.security.web.csrf.CookieCsrfTokenRepositoryTest.java

@Test
public void testSaveAndLoadToken() throws Exception {
    CookieCsrfTokenRepository csrfTokenRepository = new CookieCsrfTokenRepository();
    String csrfCookieName = "csrfCookie";
    csrfTokenRepository.setCsrfCookieName(csrfCookieName);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    CsrfToken token = csrfTokenRepository.generateToken(request);
    csrfTokenRepository.saveToken(token, request, response);

    Cookie cookie = response.getCookie(csrfCookieName);
    assertNotNull(cookie);/*from www.  jav a 2s .c om*/
    assertEquals(token.getToken(), cookie.getValue());
    assertEquals(true, cookie.isHttpOnly());

    request.setCookies(cookie);

    CsrfToken saved = csrfTokenRepository.loadToken(request);
    assertEquals(token.getToken(), saved.getToken());
    assertEquals(token.getHeaderName(), saved.getHeaderName());
    assertEquals(token.getParameterName(), saved.getParameterName());
}

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

@Test
public void testSaveAndLoadToken() throws Exception {
    CookieBasedCsrfTokenRepository repo = new CookieBasedCsrfTokenRepository();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    CsrfToken token = repo.generateToken(request);
    repo.saveToken(token, request, response);

    Cookie cookie = response.getCookie(token.getParameterName());
    assertNotNull(cookie);//  w  ww  . jav a  2s  .  c  o  m
    assertEquals(token.getToken(), cookie.getValue());
    assertEquals(true, cookie.isHttpOnly());

    request.setCookies(cookie);

    CsrfToken saved = repo.loadToken(request);
    assertEquals(token.getToken(), saved.getToken());
    assertEquals(token.getHeaderName(), saved.getHeaderName());
    assertEquals(token.getParameterName(), saved.getParameterName());
}

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;/*from   w ww.j  a  v  a 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;
    }//from  w ww  .  ja  va  2 s. c  o  m
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(cookieGenerator.getCookieName())) {
            return cookie.getValue();
        }
    }
    return null;
}

From source file:csns.util.DefaultUrls.java

public String userHomeUrl(HttpServletRequest request) {
    User user = SecurityUtils.getUser();
    if (user.isSysadmin())
        return "/admin/department/list";
    if (user.isTemporary())
        return "/register";

    Cookie cookie = WebUtils.getCookie(request, "default-home");
    if (cookie != null)
        return cookie.getValue();

    String homeUrl;/*  w  w  w .jav a2s  . c om*/
    if (user.isAdmin())
        homeUrl = "/user/search";
    else if (user.isFaculty() || user.isInstructor())
        homeUrl = "/section/taught";
    else if (user.isEvaluator())
        homeUrl = "/section/evaluated";
    else
        homeUrl = "/section/taken";

    return homeUrl;
}

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();
            }//from  www .j  a  va  2  s  .c o m
        }
    }
    return super.determineTargetUrl(request, response);
}

From source file:org.jasig.cas.web.support.CookieRetrievingCookieGenerator.java

public String retrieveCookieValue(final HttpServletRequest request) {
    final Cookie cookie = org.springframework.web.util.WebUtils.getCookie(request, getCookieName());

    return cookie == null ? null : cookie.getValue();
}