Package com.volantis.shared.net.http.cookies

Examples of com.volantis.shared.net.http.cookies.Cookie


        javax.servlet.http.Cookie[] httpCookies = httpRequest.getCookies();

        if (httpCookies != null) {
            for (int i = 0; i < httpCookies.length; i++) {
                javax.servlet.http.Cookie httpCookie = httpCookies[i];
                final Cookie cookie = httpFactory.createCookie(httpCookie.getName(),
                        defaultDomain, defaultPath);
                cookie.setMaxAge(httpCookie.getMaxAge());
                cookie.setSecure(httpCookie.getSecure());

                cookie.setValue(httpCookie.getValue());
                cookie.setVersion(CookieVersion.getCookieVersion(httpCookie.getVersion()));
                cookies.add(cookie);
            }
        }

        request.setHeaders(headers);
View Full Code Here


     * Utility method for copying cookies.
     * @param entity the cookie to copy.
     * @return A copy of the Cookie or null if a problem occurs.
     */
    private static Cookie copyCookie(HTTPMessageEntity entity) {
        Cookie result = null;
        if (entity instanceof Cookie) {
            // create a copy of the Cookie
            Cookie cookie = (Cookie) entity;
            result = HTTPFactory.getDefaultInstance().
                    createCookie(cookie.getName(), cookie.getDomain(),
                                 cookie.getPath());
            result.setComment(cookie.getComment());
            result.setMaxAge(cookie.getMaxAge());
            result.setValue(cookie.getValue());
            result.setSecure(cookie.isSecure());
        }
        return result;
    }
View Full Code Here

    public void addCookie(Cookie cookie) {

        // Do we already have a cookie stored with the same
        // name, path and domain values as the cookie we are trying
        // to add?
        Cookie storedCookieWithMatchingNamePathAndDomain =
                getCookieWithMatchingNamePathAndDomain(cookie);

        if (storedCookieWithMatchingNamePathAndDomain != null) {

            // Handle the requirement of RFC 2109, Section 4.3.3, i.e
            // If a user agent receives a Set-Cookie response header
            // whose NAME is the same as a pre-existing cookie, and whose
            // Domain and Path attribute values exactly (string) match those
            // of a pre-existing cookie, the new cookie supersedes the old.
            // However, if the Set-Cookie has a value for Max-Age of zero,
            // the (old and new) cookie is discarded.
            cookieJar.remove(
                     storedCookieWithMatchingNamePathAndDomain.getIdentity());
            addCookieImpl(cookie);
        } else {
            // we dont have any existing cookies with the same name so
            // simply add the supplied cookie to the jar if the max age
            // is greater than zero.
View Full Code Here

     * name, path and domain as the given cookie, or null if no such
     * cookie exists.
     */
    private Cookie getCookieWithMatchingNamePathAndDomain(Cookie cookie) {

        Cookie storedCookieWithMatchingNamePathAndDomain = null;

        // Obtain all of the cookies in the jar with the same name as the
        // given cookie.
        Collection cookiesWithSameName = getCookiesWithName(cookie.getName());
        Iterator cookiesWithSameNameIter = cookiesWithSameName.iterator();

        boolean foundCookieWithIdenticalNamePathAndDomain = false;
        // Search for a cookie that has the same name, path and domain values
        // as the given cookie.
        while (cookiesWithSameNameIter.hasNext() &&
                !foundCookieWithIdenticalNamePathAndDomain) {


            Cookie currentCookie = (Cookie)cookiesWithSameNameIter.next();

            //todo we have already tested for the name - only need to
            //check the domains.
            if (cookiesNamePathAndDomainsMatch(currentCookie, cookie)) {

View Full Code Here

    private Collection getCookiesWithName(String name) {

        Collection cookiesMatchingName = new ArrayList();
        Iterator cookiesInJar = iterator();
        while (cookiesInJar.hasNext()) {
            Cookie currentCookie = (Cookie)cookiesInJar.next();
            if (currentCookie.getName().equals(name)) {
                cookiesMatchingName.add(currentCookie);
            }
        }
        return cookiesMatchingName;
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.cookies.Cookie

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.