Package com.volantis.shared.net.http

Examples of com.volantis.shared.net.http.HTTPMessageEntities


        String name2 = "name2";
        String value1a = "value1a";
        String value1b = "value1b";
        String value2 = "value2";

        HTTPMessageEntities entities = factory.createHTTPMessageEntities();
        WebRequestCookie cookie1 = new WebRequestCookie();
        cookie1.setName(name1);
        cookie1.setValue(value1a);
        entities.add(cookie1);

        WebRequestCookie cookie2 = new WebRequestCookie();
        cookie2.setName(name1);
        cookie2.setValue(value1b);
        entities.add(cookie2);

        WebRequestCookie cookie3 = new WebRequestCookie();
        cookie3.setName(name2);
        cookie3.setValue(value2);
        entities.add(cookie3);


        AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext
                context = new AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext();
        context.setProperty(WebRequestCookie.class, entities, false);

        HTTPMessageEntities cookieJar =
                HTTPManagerUtilities.retrieveRequestCookies(null, context);


        assertEquals("There should be 3 cookies", 3, cookieJar.size());

        assertEquals("Checking cookie 1",
                     cookie1,
                     cookieJar.retrieve(cookie1.getIdentity())[0]);
        assertEquals("Checking cookie 2",
                     cookie2,
                     cookieJar.retrieve(cookie2.getIdentity())[1]);
        assertEquals("Checking cookie 3",
                     cookie3,
                     cookieJar.retrieve(cookie3.getIdentity())[0]);
    }
View Full Code Here


        String name1 = "name1";
        String name2 = "name2";
        String value1 = "value1";
        String value2 = "value2";

        HTTPMessageEntities entities = factory.createHTTPMessageEntities();
        WebRequestCookie cookie1 = new WebRequestCookie();
        cookie1.setName(name1);
        cookie1.setFrom(name1);
        entities.add(cookie1);

        WebRequestCookie cookie2 = new WebRequestCookie();
        cookie2.setName(name2);
        cookie2.setFrom(name2);
        entities.add(cookie2);

        AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext context =
                new AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext();
        context.setProperty(WebRequestCookie.class, entities, false);

        WebDriverRequest request = new WebDriverRequestImpl();
     //   WebDriverAccessor accessor = createWebDriverAccessor(request, null);

    //    context.setProperty(WebDriverAccessor.class, accessor, false);

        HTTPMessageEntities requestEntities =
                factory.createHTTPMessageEntities();
        request.setCookies(requestEntities);

        WebRequestCookie cookie3 = new WebRequestCookie();
        cookie3.setName(name1);
        cookie3.setValue(value1);
        requestEntities.add(cookie3);

        WebRequestCookie cookie4 = new WebRequestCookie();
        cookie4.setName(name2);
        cookie4.setValue(value2);
        requestEntities.add(cookie4);

        HTTPMessageEntities cookieJar = HTTPManagerUtilities.
                retrieveRequestCookies(request, context);


        assertEquals("There should be 2 cookies", 2, cookieJar.size());

        assertEquals("Checking cookie 1",
                     cookie3,
                     cookieJar.retrieve(cookie3.getIdentity())[0]);
        assertEquals("Checking cookie 2",
                     cookie4,
                     cookieJar.retrieve(cookie4.getIdentity())[0]);
    }
View Full Code Here

            // response that is telling us to redirect). If there are any
            // cookies we should store these so that when we eventually get the
            // real response (when we stop being redirected) we can add the
            // cookies we have found on redirects to the response we send to
            // the client.
            HTTPMessageEntities cookieJar =
                    HTTPFactory.getDefaultInstance().
                    createHTTPMessageEntities();

            // If redirection occurs this will reference the location of the
            // redirect URL
            String urlToFollow = request.getUrl();
            ProxyManager proxyManager = retrieveProxyManager(xmlPipelineContext);
            HTTPResponseAccessor responseAccessor;
            // used to store urls that I've been redirected too. This
            // can be probed to check for cyclic redirects.
            Set redirectCycles = new HashSet();
            do {
                // obtain the request parameters
                HTTPMessageEntities parameters = HTTPManagerUtilities.
                        retrieveRequestParameters(request.getRequest(),
                                xmlPipelineContext);
                // obtain the request headers
                HTTPMessageEntities headers = HTTPManagerUtilities.
                        retrieveRequestHeaders(request.getRequest(),
                                xmlPipelineContext);
                // obtain the request cookies
                HTTPMessageEntities cookies = HTTPManagerUtilities.
                            retrieveRequestCookies(request.getRequest(),
                                xmlPipelineContext);

                HTTPRequestPreprocessor requestPreprocessor =
                        request.getRequestPreprocessor();
                if (requestPreprocessor != null) {
                    urlToFollow = requestPreprocessor.preprocessRequest(
                            headers, cookies, parameters, urlToFollow);
                }

                // need to create the appropriate RequestExecutor
                requestExecutor = createHTTPRequestExecutor(urlToFollow,
                    request.getRequestType(), request.getVersion(),
                    proxyManager, xmlPipelineContext);

                // Add the request parameters to the executor for the original
                // request only, not any subsequent redirections.
                // it is up to the executor to determine how to process them
                // ie add them as headers to POST or as query strings to GET
                if (redirectCycles.isEmpty()) {
                    for (Iterator i = parameters.iterator(); i.hasNext();) {
                        requestExecutor.addRequestParameter((RequestParameter) i.next());
                    }
                }

                // add the cookies to the request
                for (Iterator i = cookies.iterator(); i.hasNext();) {
                    requestExecutor.addRequestCookie((Cookie) i.next());
                }
                // add the headers to the request
                for (Iterator i = headers.iterator(); i.hasNext();) {
                    requestExecutor.addRequestHeader((Header) i.next());
View Full Code Here

    private void populateWebDriverResponse(WebDriverResponse response,
                                           HTTPResponseAccessor accessor,
                                           HTTPMessageEntities cookieJar)
            throws HTTPException {
        // add the headers
        HTTPMessageEntities headers = accessor.getHeaders();
        if (headers != null) {
            response.setHeaders(headers);
        }

        // add the cookies
View Full Code Here

        String name2 = "name2";
        String value1a = "value1a";
        String value1b = "value1b";
        String value2 = "value2";

        HTTPMessageEntities entities = factory.createHTTPMessageEntities();
        WebRequestHeader header1 = new WebRequestHeader();
        header1.setName(name1);
        header1.setValue(value1a);
        entities.add(header1);

        WebRequestHeader header2 = new WebRequestHeader();
        header2.setName(name1);
        header2.setValue(value1b);
        entities.add(header2);

        WebRequestHeader header3 = new WebRequestHeader();
        header3.setName(name2);
        header3.setValue(value2);
        entities.add(header3);

        AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext context =
                new AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext();
        context.setProperty(WebRequestHeader.class, entities, false);

        HTTPMessageEntities headers =
                HTTPManagerUtilities.retrieveRequestHeaders(null, context);

        assertEquals("There should be 3 headers", 3, headers.size());
        assertEquals("checking header 1",
                     header1,
                     headers.retrieve(header1.getIdentity())[0]);
        assertEquals("checking header 2",
                     header2,
                     headers.retrieve(header2.getIdentity())[1]);
        assertEquals("checking header 3",
                     header3,
                     headers.retrieve(header3.getIdentity())[0]);
    }
View Full Code Here

     * @param responseAccessor
     */
    private void extractCookies(HTTPMessageEntities cookieJar,
                                HTTPResponseAccessor responseAccessor)
            throws HTTPException {
        HTTPMessageEntities cookies = responseAccessor.getCookies();
        if (cookies != null) {
            for (Iterator i = cookies.iterator(); i.hasNext();) {
                cookieJar.add((HTTPMessageEntity)i.next());
            }
        }
    }
View Full Code Here

     * or more that one match was found.
     */
    private Header retrieveHeader(String headerName,
                                  HTTPResponseAccessor responseAccessor)
            throws HTTPException {
        HTTPMessageEntities headers = responseAccessor.getHeaders();
        Header header =
                HTTPFactory.getDefaultInstance().createHeader(headerName);
        HTTPMessageEntity[] matches = headers.retrieve(header.getIdentity());
        Header value = null;
        if (matches != null && matches.length > 0) {
            value = (Header)matches[0];
        }
        return value;
View Full Code Here

        String name2 = "name2";
        String value1a = "value1a";
        String value1b = "value1b";
        String value2 = "value2";

        HTTPMessageEntities entities = factory.createHTTPMessageEntities();
        WebRequestHeader header1 = new WebRequestHeader();
        header1.setName(name1);
        header1.setFrom(name1);
        entities.add(header1);

        WebRequestHeader header2 = new WebRequestHeader();
        header2.setName(name1);
        header2.setFrom(name1);
        entities.add(header2);

        WebRequestHeader header3 = new WebRequestHeader();
        header3.setName(name2);
        header3.setFrom(name2);
        entities.add(header3);

//       PluggableHTTPManager manager = createTestablePluggableHTTPManager();
        AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext context =
                new AbstractPluggableHTTPManagerTestAbstract.MockXMLPipelineContext();
        context.setProperty(WebRequestHeader.class, entities, false);
  //      WebDriverConfiguration config = createTestWebDriverConfig();

        WebDriverRequest request = new WebDriverRequestImpl();
  //      WebDriverAccessor accessor = createWebDriverAccessor(request, null);

   //     context.setProperty(WebDriverAccessor.class, accessor, false);
  //      manager.initialize(config);

        HTTPMessageEntities requestEntities =
                factory.createHTTPMessageEntities();
        request.setHeaders(requestEntities);

        WebRequestHeader header4 = new WebRequestHeader();
        header4.setName(name1);
        header4.setValue(value1a);
        requestEntities.add(header4);


        WebRequestHeader header5 = new WebRequestHeader();
        header5.setName(name1);
        header5.setValue(value1b);
        requestEntities.add(header5);

        WebRequestHeader header6 = new WebRequestHeader();
        header6.setName(name2);
        header6.setValue(value2);
        requestEntities.add(header6);

        HTTPMessageEntities headers =
                HTTPManagerUtilities.retrieveRequestHeaders(request, context);

        assertEquals("There should be 3 headers", 3, headers.size());
        assertEquals("checking header 1",
                     header4,
                     headers.retrieve(header4.getIdentity())[0]);
        assertEquals("checking header 2",
                     header5,
                     headers.retrieve(header5.getIdentity())[1]);
        assertEquals("checking header 3",
                     header6,
                     headers.retrieve(header6.getIdentity())[0]);

    }
View Full Code Here

                                HttpServletRequest httpRequest,
                                String remoteProjectName,
                                GenericURLRemapper urlRemapper) {

        // Get the cookies sent from the remote target server, if any
        HTTPMessageEntities cookies = webdResponse.getCookies();


        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
View Full Code Here

        WebDriverRequest request = new WebDriverRequestImpl();

        final HTTPFactory httpFactory = HTTPFactory.getDefaultInstance();

        HTTPMessageEntities headers = httpFactory.createHTTPMessageEntities();
        Enumeration headerNames = httpRequest.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            final String name = (String) headerNames.nextElement();
            final Header header = httpFactory.createHeader(name);
            header.setValue(httpRequest.getHeader(name));
            headers.add(header);
        }

        HTTPMessageEntities parameters = httpFactory.createHTTPMessageEntities();
        // get parameters from marinerRequestContext if available
        // ported from 4.2.0, see vbm 2007070313
        Enumeration parameterNames = (marinerRequestContext != null) ?
            marinerRequestContext.getParameterNames() :
            httpRequest.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            final String name = (String) parameterNames.nextElement();
            final RequestParameter parameter =
                    httpFactory.createRequestParameter(name);
            final String value = (marinerRequestContext != null) ?
                    marinerRequestContext.getParameter(name) :
                    httpRequest.getParameter(name);  
            parameter.setValue(value);
            parameters.add(parameter);
        }

        // HTTP-Client will only send cookies if a domain and path is supplied.
        // Unfortunately when using Netscape cookies, (Version 0), domain
        // and path information is not sent in the COOKIE header, hence when
        // Netscape cookies are used we do not have values for the domain
        // and path.
        URL remoteMCSProjectLocation =
                urlRemapper.getRemoteSiteRootURL(remoteProjectName);

        // However, the fact that non JSESSIONID cookies have been sent to
        // MCS indicates that they should be sent to the target server.  So
        // we can just set the domain equal to the remote target host
        // and the path to "/".
        final String defaultDomain = remoteMCSProjectLocation.getHost();
        final String defaultPath = "/";

        HTTPMessageEntities cookies = httpFactory.createHTTPMessageEntities();
        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);
        request.setRequestParameters(parameters);
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.HTTPMessageEntities

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.