Example usage for java.net HttpCookie getPath

List of usage examples for java.net HttpCookie getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Returns the path on the server to which the browser returns this cookie.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
        System.out.println("Name = " + cookie.getName());
        System.out.println("Value = " + cookie.getValue());
        System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
        System.out.println("Path = " + cookie.getPath());
        System.out.println();/*from   w w w .  j av a2 s.c om*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
        System.out.println("Name = " + cookie.getName());
        System.out.println("Value = " + cookie.getValue());
        System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
        System.out.println("Path = " + cookie.getPath());
        System.out.println();/*from   www  .  j  a v a  2 s. co  m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
        System.out.println("Name = " + cookie.getName());
        System.out.println("Value = " + cookie.getValue());
        System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
        System.out.println("Path = " + cookie.getPath());
        System.out.println();// w ww .  j a  v a 2 s  .  c o m
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();
    CookieStore cookieStore = cm.getCookieStore();

    List<HttpCookie> cookies = cookieStore.getCookies();
    for (HttpCookie cookie : cookies) {
        System.out.println("Name = " + cookie.getName());
        System.out.println("Value = " + cookie.getValue());
        System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
        System.out.println("Path = " + cookie.getPath());
        System.out.println();/*from w w w.ja  v  a  2 s  .  c  o  m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();
    CookieStore cookieStore = cm.getCookieStore();

    List<HttpCookie> cookies = cookieStore.get(new URI("http://google.com"));
    for (HttpCookie cookie : cookies) {
        System.out.println("Name = " + cookie.getName());
        System.out.println("Value = " + cookie.getValue());
        System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
        System.out.println("Path = " + cookie.getPath());
        System.out.println();// ww  w. jav  a  2 s.  c  o  m
    }
}

From source file:ListAllCookies.java

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("usage: java ListAllCookies url");
        return;/*from   w ww .j  a  v  a 2s.co  m*/
    }

    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL(args[0]).openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
        System.out.println("Name = " + cookie.getName());
        System.out.println("Value = " + cookie.getValue());
        System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
        System.out.println("Path = " + cookie.getPath());
        System.out.println();
    }
}

From source file:keywhiz.cli.JsonCookie.java

public static JsonCookie fromHttpCookie(HttpCookie cookie) {
    return JsonCookie.create(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(),
            cookie.getSecure(), cookie.isHttpOnly());
}

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

public static void setUpPersistentCookieStore() {
    if (context == null)
        return;//from   w  w  w.  j  a va  2  s .  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:com.github.parisoft.resty.utils.CookieUtils.java

public static String toString(HttpCookie... cookies) {
    if (isEmpty(cookies)) {
        return null;
    }//from   w  w  w  .  ja v a 2 s. co m

    final StringBuilder cookieBuilder = new StringBuilder();

    for (HttpCookie cookie : cookies) {
        cookieBuilder.append(cookie.getName()).append("=").append(cookie.getValue());

        if (cookie.getComment() != null) {
            cookieBuilder.append(";").append("Comment=").append(cookie.getComment());
        }

        if (cookie.getDomain() != null) {
            cookieBuilder.append(";").append("Domain=").append(cookie.getDomain());
        }

        if (cookie.getPath() != null) {
            cookieBuilder.append(";").append("Path=").append(cookie.getPath());
        }

        if (cookie.getSecure()) {
            cookieBuilder.append(";").append("Secure");
        }

        if (cookie.isHttpOnly()) {
            cookieBuilder.append(";").append("HttpOnly");
        }

        if (cookie.getVersion() > 0) {
            cookieBuilder.append(";").append("Version=").append(cookie.getVersion());
        }

        if (cookie.hasExpired()) {
            cookieBuilder.append(";").append("Max-Age=0");
        } else {
            cookieBuilder.append(";").append("Max-Age=").append(cookie.getMaxAge());
        }

        cookieBuilder.append(", ");
    }

    return cookieBuilder.deleteCharAt(cookieBuilder.length() - 1).toString();
}

From source file:java.net.HttpCookie.java

/**
 * Returns true if {@code cookie} should be sent to or accepted from {@code uri} with respect
 * to the cookie's path. Cookies match by directory prefix: URI "/foo" matches cookies "/foo",
 * "/foo/" and "/foo/bar", but not "/" or "/foobar".
 *//*from  w w w.  j  ava  2 s .c o  m*/
static boolean pathMatches(HttpCookie cookie, URI uri) {
    String uriPath = matchablePath(uri.getPath());
    String cookiePath = matchablePath(cookie.getPath());
    return uriPath.startsWith(cookiePath);
}