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:com.haulmont.cuba.web.sys.AppCookies.java

public String getCookieValue(String name) {
    Cookie cookie = getCookieIfEnabled(name);
    return cookie == null ? null : cookie.getValue();
}

From source file:com.reever.humilheme.web.CookieController.java

public String getCookie(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie iterator : cookies) {
            if (iterator.getName().equals(nomeCookie)) {
                String value = iterator.getValue();
                try {
                    return URLDecoder.decode(value, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    _logger.error("Erro no encode do cookie", e);
                }//from  w w w  .j a  v a2s  . c o m
                break;
            }
        }
    }
    return null;
}

From source file:it.f2informatica.webapp.utils.HttpRequest.java

/**
 * Returns the current locale associated to this request
 * if any has been selected, otherwise it will return the
 * default browser locale./*from ww  w .j a v  a  2 s . c o  m*/
 *
 * @return the current locale
 */
public Locale getLocale() {
    String languageParam = getHttpServletRequest().getParameter(WebApplicationConfig.LANGUAGE);
    if (StringUtils.hasText(languageParam)) {
        return LocaleUtils.toLocale(languageParam);
    }
    Cookie cookie = getCookie(WebApplicationConfig.CURRENT_LOCALE_COOKIE);
    return (cookie != null) ? LocaleUtils.toLocale(cookie.getValue()) : getHttpServletRequest().getLocale();
}

From source file:com.vmware.identity.openidconnect.common.HttpRequest.java

public String getCookieValue(String cookieName) {
    Validate.notEmpty(cookieName, "cookieName");

    String value = null;/*from ww w .  java  2  s  .com*/
    Cookie[] cookies = this.httpServletRequest.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(cookieName)) {
                value = cookie.getValue();
                break;
            }
        }
    }
    return value;
}

From source file:br.com.edo.atmlist.config.CsrfHeaderFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);//from w ww . ja  v  a2 s.com
        }
    }
    filterChain.doFilter(request, response);
}

From source file:org.codemucker.testserver.capturing.CapturedCookie.java

public CapturedCookie(org.apache.http.cookie.Cookie c) {
    domain = c.getDomain();//from www .j ava2s . c o m
    path = c.getPath();
    name = c.getName();
    value = c.getValue();
    secure = c.isSecure();
    maxAge = c.getExpiryDate() == null ? -1 : 0;
    version = c.getVersion();
}

From source file:com.haulmont.cuba.web.sys.CubaUIProvider.java

protected String getCookieValue(Cookie[] cookies, String key) {
    if (cookies == null || key == null) {
        return null;
    }// w w w .  j a v a 2s . co  m
    for (final Cookie cookie : cookies) {
        if (Objects.equals(cookie.getName(), key)) {
            return cookie.getValue();
        }
    }
    return null;
}

From source file:com.pokerweb.Game.GameChangesAsync.java

@Override
public void run() {
    try {/*  w  w w  .  ja v  a2  s . c o m*/
        System.out.println("RUNGET" + System.currentTimeMillis());
        StringBuilder jb = new StringBuilder();
        String line = null;
        BufferedReader reader = asyncContext.getRequest().getReader();
        while ((line = reader.readLine()) != null)
            jb.append(line);
        Cookie[] c = ((HttpServletRequest) asyncContext.getRequest()).getCookies();
        String Token = null;
        String Data = null;
        if (c != null) {
            for (Cookie object : c)
                if (object.getName().equals("JSESSIONID"))
                    Token = object.getValue();
            System.out.println(jb.toString());
            if (jb.length() > 0) {
                JSONObject jsonObject = new JSONObject(jb.toString());
                System.out.println("Token-" + Token);
                Data = TableStatus.GetInstance().GetNewData(jsonObject.getInt("start"), Token, Name);
                System.out.println("Data-" + Data);
            }
        }
        asyncContext.getResponse().setContentType("application/json; charset=utf-8");
        ((HttpServletResponse) asyncContext.getResponse()).setHeader("Cache-Control", "no-cache");
        asyncContext.getResponse().getWriter().write(Data);

        System.out.println("END-RUNGET" + System.currentTimeMillis());
        asyncContext.complete();
    } catch (IOException ex) {
        Logger.getLogger(GameChangesAsync.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JSONException ex) {
        Logger.getLogger(GameChangesAsync.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.aplikasi.penjualan.config.CsrfAttributeToCookieFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
    if (csrf != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrf.getToken();
        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);//w w w.  ja v a  2  s . c o m
        }
    }
    filterChain.doFilter(request, response);
}

From source file:net.nikey.interceptor.LoginRequiredInterceptor.java

@Override
public Object before(Invocation inv) throws Exception {
    // all non-root requests get analyzed
    Cookie[] cookies = inv.getRequest().getCookies();
    if (!ObjectUtils.isEmpty(cookies)) {
        for (Cookie cookie : cookies) {
            if (RETWIS_COOKIE.equals(cookie.getName())) {
                String auth = cookie.getValue();
                String name = user.findNameForAuth(auth);
                if (StringUtils.hasText(name)) {
                    String uid = user.findUid(name);
                    if (StringUtils.hasText(uid)) {
                        inv.addModel("isSignedIn", true);
                        inv.addModel("uid", uid);
                        NikeySecurity.setUser(name, uid);
                        return super.before(inv);
                    }//from w ww . j a  v a  2  s  . c o  m
                }
            }
        }
    }
    inv.addModel("isSignedIn", false);
    return super.before(inv);
}