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

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

Introduction

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

Prototype

int getVersion();

Source Link

Document

Returns the version of the cookie specification to which this cookie conforms.

Usage

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

public static void getJavaCookieStore(java.net.CookieStore jCookieStore) {
    if (cookieStore == null)
        return;/*from www . j a  va  2  s.c  o m*/

    for (Cookie h : cookieStore.getCookies()) {
        HttpCookie newCookie = new HttpCookie(h.getName(), h.getValue());
        newCookie.setVersion(h.getVersion());
        newCookie.setDomain(h.getDomain());
        newCookie.setPath(h.getPath());
        newCookie.setSecure(h.isSecure());
        newCookie.setComment(h.getComment());
        jCookieStore.add(URI.create("http://" + h.getDomain()), newCookie);
    }
}

From source file:Main.java

@Deprecated
// Deprecated because this uses org.apache.http, which is itself deprecated
public static HttpCookie servletCookieFromApacheCookie(org.apache.http.cookie.Cookie apacheCookie) {
    if (apacheCookie == null) {
        return null;
    }//from w  w  w .j ava2s  .c  om

    String name = apacheCookie.getName();
    String value = apacheCookie.getValue();

    HttpCookie cookie = new HttpCookie(name, value);

    value = apacheCookie.getDomain();
    if (value != null) {
        cookie.setDomain(value);
    }
    value = apacheCookie.getPath();
    if (value != null) {
        cookie.setPath(value);
    }
    cookie.setSecure(apacheCookie.isSecure());

    value = apacheCookie.getComment();
    if (value != null) {
        cookie.setComment(value);
    }

    // version
    cookie.setVersion(apacheCookie.getVersion());

    // From the Apache source code, maxAge is converted to expiry date using the following formula
    // if (maxAge >= 0) {
    //     setExpiryDate(new Date(System.currentTimeMillis() + maxAge * 1000L));
    // }
    // Reverse this to get the actual max age

    Date expiryDate = apacheCookie.getExpiryDate();
    if (expiryDate != null) {
        long maxAge = (expiryDate.getTime() - System.currentTimeMillis()) / 1000;
        // we have to lower down, no other option
        cookie.setMaxAge((int) maxAge);
    }

    // return the servlet cookie
    return cookie;
}

From source file:fr.mixit.android.utils.NetworkUtils.java

static Cookie getCookie(DefaultHttpClient httpClient) {
    Cookie c = null;/*from ww  w . j ava 2 s .c  o m*/
    for (final Cookie cookie : httpClient.getCookieStore().getCookies()) {
        if (cookie != null) {
            c = cookie;
            if (DEBUG_MODE) {
                Log.i("AppInfosFragment", "cookieInfos : "//
                        + "comment:" + cookie.getComment() + //
                        " commentURL:" + cookie.getCommentURL() + //
                        " domain:" + cookie.getDomain() + //
                        " name:" + cookie.getName() + //
                        " path:" + cookie.getPath() + //
                        " value:" + cookie.getValue() + //
                        " version:" + cookie.getVersion() + //
                        " expiryDate:" + cookie.getExpiryDate());
            }
        }
    }

    return c;
}

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

@Test
public void testToApacheCookie() throws Exception {
    Cookie cookie = cookieMapper.toApacheCookie(fakeCookie);
    assertThat("Failed to map cookie path", cookie.getPath(), is(fakeCookie.getPath()));
    assertThat("Failed to map cookie domain", cookie.getDomain(), is(fakeCookie.getDomain()));
    assertThat("Failed to map cookie version", cookie.getVersion(), is(fakeCookie.getVersion()));
    assertThat("Failed to map cookie value", cookie.getValue(), is(fakeCookie.getValue()));
    assertThat("Failed to map cookie name", cookie.getName(), is(fakeCookie.getName()));
    assertThat("Failed to map cookie expiry date", cookie.getExpiryDate(), is(notNullValue()));
}

From source file:org.exoplatform.utils.image.CookieAwarePicassoDownloader.java

/**
 * Syncs all cookies from ExoConnectionUtils cookieStore from Apache's
 * HttpClient to HttpURLConnection./*from  w w  w . j  a va  2 s. co m*/
 * 
 * @param manager the CookieManager in which to store the retrieved cookies
 */
private void syncCookies(CookieManager manager) {
    CookieStore store = ExoConnectionUtils.cookiesStore;
    if (store == null)
        return;

    for (Cookie cookie : store.getCookies()) {
        HttpCookie c = new HttpCookie(cookie.getName(), cookie.getValue());
        c.setDomain(cookie.getDomain());
        c.setPath(cookie.getPath());
        c.setVersion(cookie.getVersion());
        String url = AccountSetting.getInstance().getDomainName() + "/" + cookie.getPath();
        try {
            manager.getCookieStore().add(new URI(url), c);
        } catch (URISyntaxException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
}

From source file:org.xwiki.wysiwyg.internal.plugin.alfresco.server.SiteMinderAuthenticator.java

/**
 * @return the list of SiteMinder cookies that have to be added to the HTTP request in order to authenticate it.
 *//* w ww .j a v a 2s. com*/
private List<Cookie> getSiteMinderCookies() {
    javax.servlet.http.Cookie[] receivedCookies = ((ServletRequest) container.getRequest())
            .getHttpServletRequest().getCookies();
    List<Cookie> cookies = new ArrayList<Cookie>();
    // Look for the SMSESSION cookie.
    for (int i = 0; i < receivedCookies.length; i++) {
        javax.servlet.http.Cookie receivedCookie = receivedCookies[i];
        if (SITE_MINDER_COOKIES.contains(receivedCookie.getName())) {
            BasicClientCookie cookie = new BasicClientCookie(receivedCookie.getName(),
                    receivedCookie.getValue());
            cookie.setVersion(receivedCookie.getVersion());
            cookie.setDomain(receivedCookie.getDomain());
            cookie.setPath(receivedCookie.getPath());
            cookie.setSecure(receivedCookie.getSecure());
            // Set attributes EXACTLY as sent by the browser.
            cookie.setAttribute(ClientCookie.VERSION_ATTR, String.valueOf(receivedCookie.getVersion()));
            cookie.setAttribute(ClientCookie.DOMAIN_ATTR, receivedCookie.getDomain());
            cookies.add(cookie);
        }
    }
    return cookies;
}

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  www . j ava2s .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: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.partnet.automation.http.ApacheHttpAdapter.java

private List<CookieAdapter> convertCookieToAdapter(List<Cookie> cookies) {
    List<CookieAdapter> adapt = new ArrayList<>();

    for (Cookie cookie : cookies) {
        adapt.add(new CookieAdapter.Builder().setDomain(cookie.getDomain()).setName(cookie.getName())
                .setExpiryDate(cookie.getExpiryDate()).setPath(cookie.getPath()).setValue(cookie.getValue())
                .setVersion(cookie.getVersion()).build());
    }/*  w  w  w  .  ja va 2s .c  om*/
    return adapt;
}

From source file:com.kynetx.api.java

protected void storeCookies(CookieStore toStore) throws IOException {
    if (isWritable()) {
        File path = new File(context.getExternalFilesDir(null), "cookies");

        OutputStream output = new FileOutputStream(path);
        ObjectOutputStream oos = new ObjectOutputStream(output);

        List<Cookie> cookies = toStore.getCookies();

        oos.writeInt(cookies.size());/*from  w w  w  . j  ava2s . c o  m*/

        for (int i = 0; i < cookies.size(); i++) {
            Cookie cookie = cookies.get(i);
            oos.writeObject(cookie.getName());
            oos.writeObject(cookie.getValue());
            oos.writeObject(cookie.getDomain());
            oos.writeObject(cookie.getPath());
            oos.writeInt(cookie.getVersion());
        }

        oos.close();
    } else {
        throw new IOException();
    }
}