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

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


            // check the cookies

            // check that we have the correct number of cookies
            assertEntityCount(response.getCookies(), 3);
            // check the browser cookie
            Cookie browser = HTTPFactory.getDefaultInstance().createCookie(
                    "BROWSER",
                    "cnn.com",
                    "/");
            browser.setValue("Netscape");
            assertSingleCookie(response,
                               browser);

            Cookie device1 = HTTPFactory.getDefaultInstance().createCookie(
                    "DEVICE",
                    "volantis.com",
                    "/");
            device1.setValue("PC");
            device1.setSecure(true);

            Cookie device2 = HTTPFactory.getDefaultInstance().createCookie(
                    "DEVICE",
                    "volantis.com",
                    "/");
            device2.setValue("PALM");
            device2.setSecure(false);
            List expectedCookies = new ArrayList();
            expectedCookies.add(device1);
            expectedCookies.add(device2);
            // check the device cookie
            assertMultipleCookies(response,
View Full Code Here


            // check that we have the expected number of cookies
            assertEntityCount(response.getCookies(), 4);

            // check that we have the correct cookies
        Cookie browser = HTTPFactory.getDefaultInstance().createCookie("BROWSER",
                    "localhost",
                    "/");
            browser.setValue("Netscape");
            assertSingleCookie(response,
                               browser);

            assertSingleCookie(response, browser);

        Cookie device1 = HTTPFactory.getDefaultInstance().createCookie("DEVICE",
                    "localhost",
                    "/");
            device1.setValue("PC");
            device1.setSecure(true);

        Cookie device2 = HTTPFactory.getDefaultInstance().createCookie("DEVICE",
                    "localhost",
                    "/");
            device2.setValue("PALM");
            device2.setSecure(false);

        Cookie device3 = HTTPFactory.getDefaultInstance().createCookie("DEVICE",
                    "localhost",
                    "/");
            device3.setValue("NOKIA");
            device3.setSecure(false);

            List expectedCookies = new ArrayList();
            expectedCookies.add(device1);
            expectedCookies.add(device2);
            expectedCookies.add(device3);
View Full Code Here

                                       String expectedName,
                                       List expectedCookies) {

        HTTPMessageEntities cookies = response.getCookies();
        // the multiple cookies should have the same identity
        Cookie cookie = (Cookie) expectedCookies.get(0);
        CookieIdentity expectedIdentity = (CookieIdentity) cookie.getIdentity();

        int expectedCount = expectedCookies.size();
        Cookie[] cookieArray = (Cookie[]) cookies.retrieve(expectedIdentity);

        assertNotNull("Should be " + expectedName + " cookies", cookieArray);
        assertEquals("Should only be " + expectedCount + " " + expectedName +
                     " cookies",
                     expectedCount,
                     cookieArray.length);

        for (int i = 0; i < expectedCount; i++) {
            Cookie actual = cookieArray[i];
            // check to see if the cookie exists in the expected list.
            assertTrue("Response did not contain the expected cookie " +
                       expectedName, expectedCookies.contains(actual));
            // remove the expected from the list
            expectedCookies.remove(actual);
View Full Code Here

        WebRequestCookie cookie = new WebRequestCookie();
        cookie.setName(masterCookie.getName());
        cookie.setDomain(masterCookie.getDomain());
        cookie.setPath(masterCookie.getPath());

        Cookie altCookie = (Cookie) alternative;

        if (masterCookie.getValue() != null) {
            cookie.setValue(masterCookie.getValue());
        } else {
            cookie.setValue(altCookie.getValue());
        }

        if (masterCookie.getComment() != null) {
            cookie.setComment(masterCookie.getComment());
        } else {
            cookie.setComment(altCookie.getComment());
        }

        if (masterCookie.secureHasBeenSet()) {
            cookie.setSecure(masterCookie.isSecure());
        } else {
            cookie.setSecure(altCookie.isSecure());
        }

        if (masterCookie.maxAgeHasBeenSet()) {
            cookie.setMaxAge(masterCookie.getMaxAge());
        } else {
            cookie.setMaxAge(altCookie.getMaxAge());
        }

        // Set the version to that of the master if the master has been set
        // otherwise set to the value of the alternate.
        if (masterCookie.versionHasBeenSet()) {
            cookie.setVersion(masterCookie.getVersion());
        } else {
            cookie.setVersion(altCookie.getVersion());
        }

        return cookie;
    }
View Full Code Here

                    request.getCookies() != null) {

                for(Iterator i = request.getCookies().iterator();
                    i.hasNext(); ) {

                    Cookie cookie = (Cookie) i.next();
                    cookies.add(cookie);
                }
            }
        }
        // return the cookies
View Full Code Here

            HTTPMessageEntities webDriverCookies) {
        HTTPFactory factory = HTTPFactory.getDefaultInstance();
        for (int i = 0; i < httpClientCookies.length; i++) {
            org.apache.commons.httpclient.Cookie httpClientCookie =
                    httpClientCookies[i];
            Cookie cookie = factory.createCookie(httpClientCookie.getName(),
                    httpClientCookie.getDomain(),
                    httpClientCookie.getPath());
            cookie.setComment(httpClientCookie.getComment());

            // Need to work out max age from the HttpClient expiry date and
            // the current time on the client.
            int maxAge =
                HttpClientUtils.calculateResponseCookieMaxAge(httpClientCookie);
            cookie.setMaxAge(maxAge);

            cookie.setSecure(httpClientCookie.getSecure());
            cookie.setValue(httpClientCookie.getValue());
            cookie.setVersion(CookieVersion.getCookieVersion(
                    httpClientCookie.getVersion()));

            // Use add since we do not currently distinguish between cookies
            // with the same name but different path/domain - though we might
            // expect HttpClient to not provide us with duplicate cookies so
View Full Code Here

        private void storeCookies() throws HTTPException {
            final HTTPMessageEntities cookieEntities = accessor.getCookies();
            if (cookieEntities != null) {
                cookies = new LinkedList();
                for (Iterator iter = cookieEntities.iterator(); iter.hasNext(); ) {
                    final Cookie cookie = (Cookie) iter.next();
                    final com.volantis.shared.net.url.http.Cookie dstCookie =
                        new com.volantis.shared.net.url.http.Cookie() {
                            public boolean isSecure() {
                                return cookie.isSecure();
                            }
                            public String getComment() {
                                return cookie.getComment();
                            }
                            public String getPath() {
                                return cookie.getPath();
                            }
                            public String getDomain() {
                                return cookie.getDomain();
                            }
                            public String getName() {
                                return cookie.getName();
                            }
                            public String getValue() {
                                return cookie.getValue();
                            }
                            public int getVersion() {
                                return cookie.getVersion().getNumber();
                            }
                            public int getMaxAge() {
                                return cookie.getMaxAge();
                            }
                        };
                    cookies.add(dstCookie);
                }
            } else {
View Full Code Here

            LOG.debug("Converting Volantis cookie to Servlet cookie");
        }
        javax.servlet.http.Cookie result = null;

        if (entity instanceof Cookie) {
            Cookie c = (Cookie) entity;
            result = new javax.servlet.http.Cookie(c.getName(), c.getValue());
            result.setDomain(c.getDomain());
            result.setPath(c.getPath());
            result.setMaxAge(c.getMaxAge());
            result.setComment(c.getComment());
            result.setSecure(c.isSecure());
        }
        if (LOG.isDebugEnabled()) {
            if (result == null) {
                LOG.debug("Converting Volantis cookie to Servlet " +
                          "cookie failed");
View Full Code Here

            LOG.debug("Converting Volantis cookie to Servlet cookie");
        }
        HTTPMessageEntity result = null;

        if (cookie != null) {
            Cookie c = factory.createCookie(
                    cookie.getName(), cookie.getDomain(), cookie.getPath());
            c.setComment(cookie.getComment());
            c.setSecure(cookie.getSecure());
            c.setMaxAge(cookie.getMaxAge());
            c.setValue(cookie.getValue());

        }
        if (LOG.isDebugEnabled()) {
            if (result == null) {
                LOG.debug("Converting Servlet cookie to Volantis " +
View Full Code Here


        if (cookies != null) {
            Iterator cookiesIter = cookies.iterator();
            while (cookiesIter.hasNext()) {
                Cookie cookie = (Cookie)cookiesIter.next();

                // Not setting the domain explicitly as the domain of the
                // created cookie will default to the host that made the
                // request to the remote resource, in this case this is
                // the host running MCS, which is correct.
                String newDomain = null;
               
                String originalCookiePath = cookie.getPath();
                // If the cookie path is unspecified then use the
                // root path, as per RFC 2109
                if (originalCookiePath == null ||
                    originalCookiePath.length() == 0) {
                    originalCookiePath = "/";
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.