Package com.volantis.shared.net.http.headers

Examples of com.volantis.shared.net.http.headers.HeaderImpl


        cookieHeader.setValue(cookieValue);
        cookieHeader.setVersion(cookieVersion);

        String headerName = "Other-Header";
        String headerValue = "o-h-value";
        final Header otherHeader = new HeaderImpl(headerName);
        otherHeader.setValue(headerValue);

        String method = "populateWebDriverResponse";
        Class paramTypes [] = {
            WebDriverResponse.class,
            HTTPResponseAccessor.class,
            HTTPMessageEntities.class};
        Object args [] = {
            response,
            new HTTPResponseAccessor() {
                public HTTPMessageEntities getCookies() {
                    HTTPMessageEntities cookies =
                                new SimpleHTTPMessageEntities();
                    cookies.add(cookieHeader);
                    return cookies;
                }

                public HTTPMessageEntities getHeaders() {
                    HTTPMessageEntities headers =
                                new SimpleHTTPMessageEntities();
                    headers.add(otherHeader);
                    return headers;
                }

                public InputStream getResponseStream() {
                    return null;
                }

                public int getStatusCode() {
                    return 200;
                }

                /**
                 * Get the HTTP version returned by the server.
                 * @return The HTTP version returned by the server.
                 */
                public HTTPVersion getHTTPVersion() {
                    return HTTPVersion.HTTP_1_1;
                }

            },
            new SimpleHTTPMessageEntities()
        };
        PrivateAccessor.invoke(manager, method, paramTypes, args);

        HTTPMessageEntities responseHeaders = response.getHeaders();
        HTTPMessageEntities responseCookies = response.getCookies();

        assertTrue("Expected one header.", responseHeaders.size() == 1);
        assertTrue("Expected one cookies.", responseCookies.size() == 1);

        Iterator headers = responseHeaders.iterator();
        while (headers.hasNext()) {
            HeaderImpl header = (HeaderImpl) headers.next();
            assertEquals("Unexpected header name.",
                         headerName, header.getName());
            assertEquals("Unexpected header value.",
                         headerValue, header.getValue());
        }

        Iterator cookiesIterator = responseCookies.iterator();
        while (cookiesIterator.hasNext()) {
            CookieImpl cookie = (CookieImpl) cookiesIterator.next();
View Full Code Here


        final Cookie cookie1 = new CookieImpl(cookieName, "localhost", "/");
        cookie1.setValue(cookieValue);

        String headerName = "Other-Header";
        String headerValue = "o-h-value";
        final Header otherHeader = new HeaderImpl(headerName);
        otherHeader.setValue(headerValue);

        HTTPMessageEntities additionalCookies = new SimpleHTTPMessageEntities();
        Cookie additionalCookie = new CookieImpl("additionalName",
                                                 "localhost",
                                                 "/");
        additionalCookie.setValue("additionalValue");
        additionalCookies.add(additionalCookie);

        String method = "populateWebDriverResponse";

        Class paramTypes [] = {
            WebDriverResponse.class,
            HTTPResponseAccessor.class,
            HTTPMessageEntities.class};

        Object[] args  = {
            response,
            new HTTPResponseAccessor() {
                public HTTPMessageEntities getCookies() {
                    HTTPMessageEntities cookies =
                                new SimpleHTTPMessageEntities();
                    cookies.add(cookie1);
                    return cookies;
                }

                public HTTPMessageEntities getHeaders() {
                    HTTPMessageEntities headers =
                                new SimpleHTTPMessageEntities();
                    headers.add(otherHeader);
                    return headers;
                }

                public InputStream getResponseStream() {
                    return null;
                }

                public int getStatusCode() {
                    return 200;
                }

                /**
                 * Get the HTTP version returned by the server.
                 * @return The HTTP version returned by the server.
                 */
                public HTTPVersion getHTTPVersion() {
                    return HTTPVersion.HTTP_1_1;
                }
            },
            additionalCookies
        };
        PrivateAccessor.invoke(manager, method, paramTypes, args);

        HTTPMessageEntities responseHeaders = response.getHeaders();
        HTTPMessageEntities responseCookies = response.getCookies();

        final int expectedCookies = 2;
        assertEquals("Expected one header.", 1, responseHeaders.size());
        assertEquals("Expected number of cookies to match", expectedCookies,
                     responseCookies.size());

        Iterator headers = responseHeaders.iterator();
        while (headers.hasNext()) {
            HeaderImpl header = (HeaderImpl) headers.next();
            assertEquals("Unexpected header name.",
                         headerName, header.getName());
            assertEquals("Unexpected header value.",
                         headerValue, header.getValue());
        }

        CookieImpl[] cookies = new CookieImpl[expectedCookies];

        int count = 0;
View Full Code Here

            WebDriverRequest request = accessor.getRequest(context);

            HTTPMessageEntities headers =
                    HTTPFactory.getDefaultInstance().
                    createHTTPMessageEntities();
            Header header1 = new HeaderImpl("name");
            header1.setValue("fred");
            Header header2 = new HeaderImpl("request2");
            header2.setValue("jane");
            headers.add(header1);
            headers.add(header2);
            request.setHeaders(headers);

            context.setProperty(WebDriverAccessor.class, accessor, false);
View Full Code Here

                        synchronized (RFC1123) {
                            lastModifiedAsString = RFC1123.format(
                                new Date(lastModified.inMillis()));
                        }
                        final Header header =
                            new HeaderImpl(HeaderNames.IF_MODIFIED_SINCE_HEADER);
                        header.setValue(lastModifiedAsString);
                        executor.addRequestHeader(header);
                    }

                    // set the If-None-Match header with the eTag value, if
                    // there is any
                    final String eTag = existingState.getETag();
                    if (eTag != null && eTag.trim().length() > 0) {
                        final Header header =
                            new HeaderImpl(HeaderNames.IF_NONE_MATCH_HEADER);
                        header.setValue(eTag);
                        executor.addRequestHeader(header);
                    }
                }
            }
View Full Code Here

        return new CookieImpl(name, domain, path);
    }

    // javadoc inherited
    public Header createHeader(String name) {
        return new HeaderImpl(name);
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.headers.HeaderImpl

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.