Example usage for org.apache.http.cookie Cookie getPorts

List of usage examples for org.apache.http.cookie Cookie getPorts

Introduction

In this page you can find the example usage for org.apache.http.cookie Cookie getPorts.

Prototype

int[] getPorts();

Source Link

Document

Get the Port attribute.

Usage

From source file:net.fizzl.redditengine.impl.SerializableCookie.java

public SerializableCookie(Cookie cookie) {
    this.comment = cookie.getComment();
    this.commentURL = cookie.getCommentURL();
    this.domain = cookie.getDomain();
    this.expiryDate = cookie.getExpiryDate();
    this.name = cookie.getName();
    this.path = cookie.getPath();
    this.ports = cookie.getPorts();
    this.value = cookie.getValue();
    this.version = cookie.getVersion();
    this.secure = cookie.isSecure();
}

From source file:com.grendelscan.commons.http.apache_overrides.serializable.SerializableBasicCookie.java

@Override
public boolean equals(final Object obj) {
    if (obj == null || !(obj instanceof Cookie)) {
        return false;
    }/*  ww  w .  jav  a 2 s.  c om*/
    Cookie c = (Cookie) obj;
    boolean goodPorts = false;
    if (ports == null) {
        goodPorts = c.getPorts() == null;
    } else if (ports.length == c.getPorts().length) {
        Set<Integer> p1 = new HashSet<Integer>(ports.length);
        Set<Integer> p2 = new HashSet<Integer>(ports.length);
        for (int i = 0; i < ports.length; i++) {
            p1.add(ports[i]);
            p2.add(c.getPorts()[i]);
        }
        goodPorts = p1.equals(p2);
    }
    return goodPorts & cookieDomain.equalsIgnoreCase(c.getDomain()) && cookiePath.equalsIgnoreCase(c.getPath())
            && value.equals(c.getValue()) && name.equalsIgnoreCase(c.getName());

}

From source file:org.tellervo.desktop.wsi.util.WSCookieWrapper.java

public WSCookieWrapper(Cookie cookie) {
    name = cookie.getName();/* w w w.  j  ava  2s  .  c  om*/
    value = cookie.getValue();
    cookieComment = cookie.getComment();
    cookieDomain = cookie.getDomain();
    cookieExpiryDate = cookie.getExpiryDate();
    cookiePath = cookie.getPath();
    isSecure = cookie.isSecure();
    cookieVersion = cookie.getVersion();
    commentURL = cookie.getCommentURL();
    ports = cookie.getPorts();

    /*
    if(cookie instanceof ClientCookie) {
       isClientCookie = true;
               
       // copy over the attributes array (yuck)
       attribs = new HashMap<String, String>();
       for(String attr : ATTR_LIST) {
    String value;
    if((value = ((ClientCookie)cookie).getAttribute(attr)) != null) {
       attribs.put(attr, value);
    }
       }
    }
    */

}

From source file:org.tellervo.desktop.wsi.util.WSCookieWrapper.java

@Override
public boolean equals(Object o) {
    if (o instanceof WSCookieWrapper) {
        WSCookieWrapper w = (WSCookieWrapper) o;

        return (iseq(name, w.name) && iseq(attribs, w.attribs) && iseq(value, w.value)
                && iseq(cookieComment, w.cookieComment) && iseq(cookieDomain, w.cookieDomain)
                && iseq(cookiePath, w.cookiePath) && iseq(isSecure, w.isSecure)
                && iseq(cookieVersion, w.cookieVersion) && iseq(commentURL, w.commentURL)
                && iseq(ports, w.ports));
    }//from www  .j  a  v a 2 s  . co m

    if (o instanceof Cookie) {
        Cookie c = (Cookie) o;
        boolean match;

        match = iseq(name, c.getName()) && iseq(value, c.getValue()) && iseq(cookieComment, c.getComment())
                && iseq(cookieDomain, c.getDomain()) && iseq(cookiePath, c.getPath())
                && iseq(isSecure, c.isSecure()) && iseq(cookieVersion, c.getVersion())
                && iseq(commentURL, c.getCommentURL()) && iseq(ports, c.getPorts());

        if (!match)
            return false;

        /*
        if(c instanceof ClientCookie) {
           ClientCookie cc = (ClientCookie) c;
                   
           for(String attr : ATTR_LIST) {
              if(!iseq(attribs.get(attr), cc.getAttribute(attr)))
          return false;
           }
        }
        */

        return true;
    }

    return false;
}

From source file:com.google.corp.productivity.specialprojects.android.comm.SerializableCookieStore.java

public synchronized void save(SharedPreferences preferences) {
    List<Cookie> cookies = getCookies();
    int n = cookies.size();
    JSONArray array = new JSONArray();
    for (int i = 0; i < n; i++) {
        Cookie cookie = cookies.get(i);
        putJs(array, i, ATTR_NAME, cookie.getName());
        putJs(array, i, ATTR_VALUE, cookie.getValue());
        putJs(array, i, ATTR_COMMENT, cookie.getComment());
        putJs(array, i, ATTR_COMMENT_URL, cookie.getCommentURL());
        putJs(array, i, ATTR_DOMAIN, cookie.getDomain());
        putJs(array, i, ATTR_PATH, cookie.getPath());
        putJs(array, i, ATTR_VERSION, cookie.getVersion());
        putJs(array, i, ATTR_SECURE, cookie.isSecure());
        putJs(array, i, ATTR_PORTS, cookie.getPorts());
        if (cookie.getExpiryDate() != null) {
            putJs(array, i, ATTR_EXPIRY_DATE, cookie.getExpiryDate().getTime());
        }/*from   w  w w .j a  v a  2  s.  c om*/
    }
    Editor editor = preferences.edit();
    editor.putString(UserPreferences.COOKIE_PREFERENCE_KEY, array.toString());
    editor.commit();
    dirty = false;
}

From source file:com.grendelscan.commons.http.apache_overrides.serializable.SerializableBasicCookie.java

public SerializableBasicCookie(final Cookie cookie) {
    cookieVersion = cookie.getVersion();
    cookieExpiryDate = cookie.getExpiryDate();
    cookiePath = cookie.getPath();//from  w ww  .ja va2s . c o m
    name = cookie.getName();
    value = cookie.getValue();
    cookieComment = cookie.getComment();
    cookieDomain = cookie.getDomain();
    isSecure = cookie.isSecure();
    ports = cookie.getPorts();

    try {
        if (cookie instanceof BasicClientCookie2) {
            BasicClientCookie2 b2c = (BasicClientCookie2) cookie;
            discard = b2c.getClass().getField("discard").getBoolean(b2c);
        }
        if (cookie instanceof BasicClientCookie) {
            BasicClientCookie bCookie = (BasicClientCookie) cookie;
            Field field = bCookie.getClass().getDeclaredField("attribs");
            field.setAccessible(true);
            attribs = (HashMap) field.get(bCookie);
        }
    } catch (Exception e) {
        System.err.println(e.toString());
        e.printStackTrace();
    } finally {
        if (attribs == null) {
            attribs = new HashMap<String, String>();
        }
    }
}

From source file:org.geometerplus.zlibrary.ui.android.network.SQLiteCookieDatabase.java

@Override
protected void saveCookies(List<Cookie> cookies) {
    for (Cookie c : cookies) {
        if (!c.isPersistent()) {
            continue;
        }/* ww w . j  av a 2  s .c  om*/
        SQLiteUtil.bindString(myInsertStatement, 1, c.getDomain());
        SQLiteUtil.bindString(myInsertStatement, 2, c.getPath());
        SQLiteUtil.bindString(myInsertStatement, 3, c.getName());
        SQLiteUtil.bindString(myInsertStatement, 4, c.getValue());
        SQLiteUtil.bindDate(myInsertStatement, 5, c.getExpiryDate());
        myInsertStatement.bindLong(6, c.isSecure() ? 1 : 0);
        final long id = myInsertStatement.executeInsert();
        myDeletePortsStatement.bindLong(1, id);
        myDeletePortsStatement.execute();
        if (c.getPorts() != null) {
            myInsertPortsStatement.bindLong(1, id);
            for (int port : c.getPorts()) {
                myInsertPortsStatement.bindLong(2, port);
                myInsertPortsStatement.execute();
            }
        }
    }
}

From source file:com.google.sampling.experiential.android.lib.GoogleAccountLoginHelper.java

/**
 * Store a new Paco AppEngine server cookie.
 * This will only be used publicly when the other communications with the Paco server send us
 * back a new cookie instead of the existing cookie. 
 * /*  ww w .  j a v a  2  s  . c  o  m*/
 * @param authCookie Cookie from logging into Paco AppEngine instance.
 */
public synchronized void storePacoAuthCookie(Cookie authCookie) {
    Editor editor = authTokenPreferences.edit();
    editor.putString("comment", authCookie.getComment());
    editor.putString("commentURL", authCookie.getCommentURL());
    editor.putString("domain", authCookie.getDomain());
    editor.putString("name", authCookie.getName());
    editor.putString("path", authCookie.getPath());
    editor.putString("value", authCookie.getValue());
    SimpleDateFormat df = new SimpleDateFormat(Constants.DATE_TIME_FORMAT);
    editor.putString("expiration", df.format(authCookie.getExpiryDate()));
    if (authCookie.getPorts() != null) {
        editor.putString("ports", stringify(authCookie.getPorts()));
    }
    editor.putInt("version", authCookie.getVersion());
    editor.commit();
}

From source file:org.archive.modules.fetcher.BdbCookieStoreTest.java

protected void assertCookiesIdentical(Cookie c1, Cookie c2) {
    assertEquals(c1.getComment(), c2.getComment());
    assertEquals(c1.getCommentURL(), c2.getCommentURL());
    assertEquals(c1.getDomain(), c2.getDomain());
    assertEquals(c1.getName(), c2.getName());
    String p1 = c1.getPath() != null ? c1.getPath() : "/";
    String p2 = c2.getPath() != null ? c2.getPath() : "/";
    assertEquals(p1, p2);/*from   www  .j  av  a  2  s .  c om*/
    assertEquals(c1.getValue(), c2.getValue());
    assertEquals(c1.getVersion(), c2.getVersion());
    assertEquals(c1.getExpiryDate(), c2.getExpiryDate());
    assertTrue(Arrays.equals(c1.getPorts(), c2.getPorts()));
}

From source file:org.esxx.js.protocol.CookieJar.java

private Scriptable cookieToScriptable(Context cx, Cookie cookie) {
    Scriptable js = cx.newObject(jsuri);
    Scriptable raw = cx.newObject(js);/*  w w w  .j a  v  a2s . c  o  m*/

    js.put("raw", js, raw);

    setValue(cx, cookie, js, raw, "name", cookie.getName());
    setValue(cx, cookie, js, raw, "value", cookie.getValue());

    setValue(cx, cookie, js, raw, ClientCookie.COMMENT_ATTR, cookie.getComment());
    setValue(cx, cookie, js, raw, ClientCookie.COMMENTURL_ATTR, cookie.getCommentURL());
    setValue(cx, cookie, js, raw, ClientCookie.DISCARD_ATTR, null);
    setValue(cx, cookie, js, raw, ClientCookie.DOMAIN_ATTR, cookie.getDomain());
    setValue(cx, cookie, js, raw, ClientCookie.EXPIRES_ATTR, cookie.getExpiryDate());
    setValue(cx, cookie, js, raw, ClientCookie.MAX_AGE_ATTR, null);
    setValue(cx, cookie, js, raw, ClientCookie.PATH_ATTR, cookie.getPath());
    setValue(cx, cookie, js, raw, ClientCookie.PORT_ATTR, cookie.getPorts());
    setValue(cx, cookie, js, raw, ClientCookie.SECURE_ATTR, cookie.isSecure());
    setValue(cx, cookie, js, raw, ClientCookie.VERSION_ATTR, cookie.getVersion());

    return js;
}