Example usage for java.net HttpCookie getName

List of usage examples for java.net HttpCookie getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the name of the cookie.

Usage

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

public static HarRequest createHarRequest(HttpMessage httpMessage) {
    HttpRequestHeader requestHeader = httpMessage.getRequestHeader();

    HarCookies harCookies = new HarCookies();
    try {/*from   w w w  .java2  s. c o m*/
        for (HttpCookie cookie : requestHeader.getHttpCookies()) {
            harCookies.addCookie(new HarCookie(cookie.getName(), cookie.getValue()));
        }
    } catch (IllegalArgumentException e) {
        LOGGER.warn("Ignoring cookies for HAR (\"request\") \"cookies\" list. Request contains invalid cookie: "
                + e.getMessage());
    }

    HarQueryString harQueryString = new HarQueryString();
    for (HtmlParameter param : httpMessage.getUrlParams()) {
        harQueryString.addQueryParam(new HarQueryParam(param.getName(), param.getValue()));
    }

    HarPostData harPostData = null;
    HttpRequestBody requestBody = httpMessage.getRequestBody();
    if (requestBody.length() >= 0) {
        HarPostDataParams params = new HarPostDataParams();
        String text = "";

        String contentType = requestHeader.getHeader(HttpHeader.CONTENT_TYPE);
        if (contentType == null) {
            contentType = "";
            text = requestBody.toString();
        } else {
            if (StringUtils.startsWithIgnoreCase(contentType.trim(), HttpHeader.FORM_URLENCODED_CONTENT_TYPE)) {
                for (HtmlParameter param : httpMessage.getFormParams()) {
                    params.addPostDataParam(new HarPostDataParam(param.getName(), param.getValue()));
                }
            } else {
                text = requestBody.toString();
            }
        }
        harPostData = new HarPostData(contentType, params, text, null);
    }

    return new HarRequest(requestHeader.getMethod(), requestHeader.getURI().toString(),
            requestHeader.getVersion(), harCookies, createHarHeaders(requestHeader), harQueryString,
            harPostData, requestHeader.toString().length(), httpMessage.getRequestBody().length(), null);
}

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

public static void setUpPersistentCookieStore() {
    if (context == null)
        return;/*from www . jav a  2s .c  o  m*/
    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:org.apache.hadoop.hive.druid.security.DruidKerberosUtil.java

static HttpCookie getAuthCookie(CookieStore cookieStore, URI uri) {
    if (cookieStore == null) {
        return null;
    }//  w ww .ja  va 2s . co m
    boolean isSSL = uri.getScheme().equals("https");
    List<HttpCookie> cookies = cookieStore.getCookies();

    for (HttpCookie c : cookies) {
        // If this is a secured cookie and the current connection is non-secured,
        // then, skip this cookie. We need to skip this cookie because, the cookie
        // replay will not be transmitted to the server.
        if (c.getSecure() && !isSSL) {
            continue;
        }
        if (c.getName().equals(AuthenticatedURL.AUTH_COOKIE)) {
            return c;
        }
    }
    return null;
}

From source file:io.druid.security.kerberos.DruidKerberosUtil.java

public static HttpCookie getAuthCookie(CookieStore cookieStore, URI uri) {
    if (cookieStore == null) {
        return null;
    }/*  w  w  w  .jav a  2  s  .  c  o  m*/
    boolean isSSL = uri.getScheme().equals("https");
    List<HttpCookie> cookies = cookieStore.getCookies();

    for (HttpCookie c : cookies) {
        // If this is a secured cookie and the current connection is non-secured,
        // then, skip this cookie. We need to skip this cookie because, the cookie
        // replay will not be transmitted to the server.
        if (c.getSecure() && !isSSL) {
            continue;
        }
        if (c.getName().equals(AuthenticatedURL.AUTH_COOKIE)) {
            return c;
        }
    }
    return null;
}

From source file:org.apache.druid.security.kerberos.DruidKerberosUtil.java

public static HttpCookie getAuthCookie(CookieStore cookieStore, URI uri) {
    if (cookieStore == null) {
        return null;
    }/*  ww w  .  j av  a2  s. co m*/
    boolean isSSL = "https".equals(uri.getScheme());
    List<HttpCookie> cookies = cookieStore.getCookies();

    for (HttpCookie c : cookies) {
        // If this is a secured cookie and the current connection is non-secured,
        // then, skip this cookie. We need to skip this cookie because, the cookie
        // replay will not be transmitted to the server.
        if (c.getSecure() && !isSSL) {
            continue;
        }
        if (c.getName().equals(AuthenticatedURL.AUTH_COOKIE)) {
            return c;
        }
    }
    return null;
}

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  ava2  s  .  c  o m*/
    //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;/* ww w.  j a v a  2s . 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();
    value = cookie.getValue();/*from   w ww. j  a v  a 2  s.c o m*/
    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:com.github.parisoft.resty.response.http.HttpResponseExtensionImpl.java

@Override
public HttpCookie getCookie(String name) throws IOException {
    for (HttpCookie cookie : getCookies()) {
        if (Objects.equals(cookie.getName(), name)) {
            return cookie;
        }//from w w  w  .j  a  va2 s  . c om
    }

    return null;
}

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);//from w ww.  j  av a2 s.  c o m
        }

        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;
}