Example usage for java.net HttpCookie getValue

List of usage examples for java.net HttpCookie getValue

Introduction

In this page you can find the example usage for java.net HttpCookie getValue.

Prototype

public String getValue() 

Source Link

Document

Returns the value of the cookie.

Usage

From source file:cn.ttyhuo.common.MyApplication.java

public static void setUpPersistentCookieStore() {
    if (context == null)
        return;//from   w w w .  j  ava  2  s  .c  om
    cookieStore = new PersistentCookieStore(context);

    CookieStore httpCookieStore = HttpRequestUtil.cookieManager.getCookieStore();
    for (HttpCookie h : httpCookieStore.getCookies()) {
        BasicClientCookie newCookie = new BasicClientCookie(h.getName(), h.getValue());
        newCookie.setVersion(h.getVersion());
        newCookie.setDomain(h.getDomain());
        newCookie.setPath(h.getPath());
        newCookie.setSecure(h.getSecure());
        newCookie.setComment(h.getComment());
        cookieStore.addCookie(newCookie);
    }
}

From source file:io.jari.geenstijl.API.API.java

public static boolean logIn(String email, String password, Context context)
        throws IOException, URISyntaxException {
    ensureCookies();/*from   w ww .  j  a va  2 s  . c om*/
    //add params
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("t", "666"));
    params.add(new BasicNameValuePair("_mode", "handle_sign_in"));
    params.add(new BasicNameValuePair("_return",
            "http%3A%2F%2Fapp.steylloos.nl%2Fmt-comments.fcgi%3F__mode%3Dhandle_sign_in%26entry_id%3D3761581%26static%3Dhttp%3A%2F%2Fwww.steylloos.nl%2Fcookiesync.php%3Fsite%3DGSNL%2526return%3DaHR0cDovL3d3dy5nZWVuc3RpamwubmwvcmVhZGVyLWxvZ2dlZGlu"));
    params.add(new BasicNameValuePair("email", email));
    params.add(new BasicNameValuePair("password", password));

    String res = postUrl("http://registratie.geenstijl.nl/registratie/gs_engine.php?action=login", params, null,
            false);
    if (res.contains("font color=\"red\""))
        return false;
    else {
        List<HttpCookie> cookies = cookieManager.getCookieStore().get(new URI("http://app.steylloos.nl"));
        String commenter_name = null;
        String tk_commenter = null;
        for (HttpCookie cookie : cookies) {
            if (cookie.getName().equals("tk_commenter"))
                tk_commenter = cookie.getValue();
            else if (cookie.getName().equals("commenter_name"))
                commenter_name = cookie.getValue();
        }
        //sanity check
        if (commenter_name == null || tk_commenter == null) {
            Log.wtf(TAG,
                    "Ermmm, wut? GeenStijl redirected us to the correct URL but hasn't passed us the correct cookies?");
            return false;
        }

        String cheader = String.format("commenter_name=%s; tk_commenter=%s;", commenter_name, tk_commenter);
        Log.d(TAG, "Login completed, debug data:\ncookieheader: " + cheader);
        context.getSharedPreferences("geenstijl", 0).edit().putString("username", commenter_name).commit();
        setSession(cheader, context);
        return true;
    }
}

From source file:org.zaproxy.zap.utils.HarUtils.java

public static HarResponse createHarResponse(HttpMessage httpMessage) {
    HttpResponseHeader responseHeader = httpMessage.getResponseHeader();
    HarCookies harCookies = new HarCookies();

    long whenCreated = System.currentTimeMillis();
    for (HttpCookie cookie : responseHeader.getHttpCookies()) {
        Date expires;/*from   w  w  w .j  av  a 2 s  .c  o  m*/
        if (cookie.getVersion() == 0) {
            expires = new Date(whenCreated + (cookie.getMaxAge() * 1000));
        } else {
            expires = new Date(httpMessage.getTimeSentMillis() + httpMessage.getTimeElapsedMillis()
                    + (cookie.getMaxAge() * 1000));
        }

        harCookies.addCookie(new HarCookie(cookie.getName(), cookie.getValue(), cookie.getPath(),
                cookie.getDomain(), expires, cookie.isHttpOnly(), cookie.getSecure(), null));
    }

    String text = null;
    String encoding = null;
    String contentType = responseHeader.getHeader(HttpHeader.CONTENT_TYPE);
    if (contentType == null) {
        contentType = "";
    } else if (!contentType.isEmpty()) {
        String lcContentType = contentType.toLowerCase(Locale.ROOT);
        final int pos = lcContentType.indexOf(';');
        if (pos != -1) {
            lcContentType = lcContentType.substring(0, pos).trim();
        }

        if (!lcContentType.startsWith("text")) {
            encoding = "base64";
            text = Base64.encodeBytes(httpMessage.getResponseBody().getBytes());
        } else {
            text = httpMessage.getResponseBody().toString();
        }
    }

    HarContent harContent = new HarContent(httpMessage.getResponseBody().length(), 0, contentType, text,
            encoding, null);

    String redirectUrl = responseHeader.getHeader(HttpHeader.LOCATION);

    return new HarResponse(responseHeader.getStatusCode(), responseHeader.getReasonPhrase(),
            responseHeader.getVersion(), harCookies, createHarHeaders(responseHeader), harContent,
            redirectUrl == null ? "" : redirectUrl, responseHeader.toString().length(),
            httpMessage.getResponseBody().length(), null);
}

From source file:at.becast.youploader.youtube.data.Cookie.java

public Cookie(final HttpCookie cookie) {
    name = cookie.getName();/*from ww  w  . j  av  a2s  . c  om*/
    value = cookie.getValue();
    comment = cookie.getComment();
    commentUrl = cookie.getCommentURL();
    domain = cookie.getDomain();
    discard = cookie.getDiscard();
    maxAge = cookie.getMaxAge();
    path = cookie.getPath();
    portList = cookie.getPortlist();
    secure = cookie.getSecure();
    version = cookie.getVersion();
}

From source file:org.piwik.ResponseData.java

public List<Cookie> getCookies() {
    List<Cookie> cookies = new ArrayList<Cookie>();

    for (String key : headerData.keySet()) {
        List<String> headerParts = headerData.get(key);

        StringBuilder cookieInfo = new StringBuilder();
        for (String part : headerParts) {
            cookieInfo.append(part);//w  w  w. j  a  va2  s  . com
        }

        if (key == null && cookieInfo.toString().equals("")) {
            LOGGER.debug("No more headers, not proceeding");
            return null;
        }

        if (key == null) {
            LOGGER.debug("The header value contains the server's HTTP version, not proceeding");
        } else if (key.equals("Set-Cookie")) {
            List<HttpCookie> httpCookies = HttpCookie.parse(cookieInfo.toString());
            for (HttpCookie h : httpCookies) {
                Cookie c = new Cookie(h.getName(), h.getValue());
                c.setComment(h.getComment());
                if (h.getDomain() != null) {
                    c.setDomain(h.getDomain());
                }
                c.setMaxAge(Long.valueOf(h.getMaxAge()).intValue());
                c.setPath(h.getPath());
                c.setSecure(h.getSecure());
                c.setVersion(h.getVersion());
                cookies.add(c);
            }
        } else {
            LOGGER.debug("The provided key (" + key + ") with value (" + cookieInfo
                    + ") were not processed because the key is unknown");
        }
    }
    return cookies;
}

From source file:com.jaspersoft.android.jaspermobile.network.cookie.CookieMapper.java

@Nullable
public org.apache.http.cookie.Cookie toApacheCookie(@Nullable HttpCookie cookie) {
    if (cookie == null) {
        return null;
    }/* w  w  w . jav  a  2  s  . c  o m*/

    BasicClientCookie clientCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
    clientCookie.setDomain(cookie.getDomain());
    clientCookie.setPath(cookie.getPath());
    clientCookie.setVersion(cookie.getVersion());

    Date expiryDate = new Date(new Date().getTime() + cookie.getMaxAge());
    clientCookie.setExpiryDate(expiryDate);

    return clientCookie;
}

From source file:com.subgraph.vega.ui.scanner.ScanExecutor.java

private List<Cookie> getCookieList(List<String> cookieStringList, URI uri) {
    if (cookieStringList.size() != 0) {
        ArrayList<Cookie> cookieList = new ArrayList<Cookie>(cookieStringList.size());
        for (String cookieString : cookieStringList) {
            List<HttpCookie> parseList = HttpCookie.parse(cookieString);
            for (HttpCookie cookie : parseList) {
                BasicClientCookie cp = new BasicClientCookie(cookie.getName(), cookie.getValue());
                cp.setComment(cookie.getComment());
                if (cookie.getDomain() != null) {
                    cp.setDomain(cookie.getDomain());
                } else {
                    // just set it to the target host for now - may need something slightly less specific
                    cp.setDomain(uri.getHost());
                }/* ww w  . ja  v a 2  s . c o  m*/
                long maxAge = cookie.getMaxAge();
                if (maxAge > 0) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.add(Calendar.SECOND, (int) maxAge);
                    cp.setExpiryDate(calendar.getTime());
                }
                cp.setPath(cookie.getPath());
                cp.setSecure(cookie.getSecure());
                cp.setVersion(cookie.getVersion());
                cookieList.add(cp);
            }
        }
        return cookieList;
    }
    return null;
}

From source file:com.nominanuda.web.http.ServletHelper.java

public Cookie servletCookie(HttpCookie c) {
    Cookie _c = new Cookie(c.getName(), c.getValue());
    if (c.getComment() != null) {
        _c.setComment(c.getComment());/* w  w w.j a v  a2 s .c o  m*/
    }
    if (c.getDomain() != null) {
        _c.setDomain(c.getDomain());
    }
    if (c.getPath() != null) {
        _c.setPath(c.getPath());
    }
    _c.setSecure(c.getSecure());
    _c.setVersion(c.getVersion());
    _c.setHttpOnly(c.getDiscard());
    _c.setMaxAge((int) c.getMaxAge());
    return _c;
}

From source file:org.nextlets.erc.defaults.http.ERCHttpInvokerImpl.java

private Cookie toCookie(URI uri, HttpCookie httpCookie) {
    SetCookie cookie = new BasicClientCookie(httpCookie.getName(), httpCookie.getValue());
    cookie.setComment(httpCookie.getComment());
    if (httpCookie.getDomain() != null) {
        cookie.setDomain(httpCookie.getDomain());
    } else {/*from   ww  w  .  j a va2 s  . c  om*/
        cookie.setDomain(uri.getHost());
    }
    if (httpCookie.getMaxAge() != -1) {
        cookie.setExpiryDate(new Date(httpCookie.getMaxAge() * 1000));
    }
    if (httpCookie.getPath() != null) {
        cookie.setPath(httpCookie.getPath());
    } else {
        cookie.setPath(uri.getPath());
    }
    cookie.setSecure(httpCookie.getSecure());
    cookie.setVersion(httpCookie.getVersion());
    return cookie;
}

From source file:org.opentestsystem.shared.test.interactioncontext.FastInteractionContext.java

@Override
public String getCookie(String key) {
    final List<HttpCookie> cookieList = _cookies.getCookieStore().get(_baseURI);
    for (HttpCookie cookie_i : cookieList) {
        if (cookie_i.getName().equalsIgnoreCase(key)) {
            return cookie_i.getValue();
        }//w  w  w  .  j ava 2s.c  o  m
    }
    return null;
}