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

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


                        // SimpleDateFormat is not thread safe
                        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


        private void storeHeaders() throws HTTPException {
            final HTTPMessageEntities headerEntities = accessor.getHeaders();
            if (headerEntities != null) {
                headers = new LinkedList();
                for (Iterator iter = headerEntities.iterator(); iter.hasNext(); ) {
                    final Header header = (Header) iter.next();
                    final com.volantis.shared.net.url.http.Header dstCookie =
                        new com.volantis.shared.net.url.http.Header() {
                            public String getName() {
                                return header.getName();
                            }
                            public String getValue() {
                                return header.getValue();
                            }
                        };
                    headers.add(dstCookie);
                }
            } else {
View Full Code Here

                                request.getContextURL());
                        // If the remap has failed then the URL will be null,
                        // so only modify Location header if the remap
                        // succeeded.
                        if (remappedURL != null) {
                            Header location =
                                    retrieveHeader(LOCATION_HEADER,
                                            responseAccessor);
                            location.setValue(remappedURL);
                        }
                    }

                    // We have now remapped the URL (either successfully or
                    // unsuccessfully). However, if we are not to follow
                    // redirects then ensure there is no URL to follow.
                    // (If the remap were successful then the Location header
                    // contains the remapped URL.)
                    if (request.isFollowRedirects()) {
                        if (configuration.remapRedirects()) {
                            urlToFollow = remappedURL;
                        } else {
                            urlToFollow = redirectURL;
                        }
                    } else {
                        urlToFollow = null;
                    }

                    if (urlToFollow != null) {
                        // release the existing executor
                        requestExecutor.release();

                        if (redirectCycles.contains(urlToFollow)) {
                            throw new HTTPException(
                                    "Cyclical redirect has been detected.");
                        } else {
                            redirectCycles.add(urlToFollow);
                        }
                        if (redirectCycles.size() >= MAX_REDIRECTS) {
                            throw new HTTPException(
                                    "Maximum number of redirects (" +
                                    MAX_REDIRECTS + ") has been exceeded.");
                        }
                    }

                } else {
                    // not a redirect so stop this variable from containing the
                    // request url. Only do so if a redirect was not followed
                    // to get this response.
                    if (redirectCycles.size() == 0) {
                        urlToFollow = null;
                    }
                }

            } while (isRedirect(responseAccessor.getStatusCode()) &&
                    urlToFollow != null);

            // populate the resoponse
            if (request.getResponse() != null) {
                if (urlToFollow != null) {
                    // We have been redirected but because urlToFollow is
                    // not null we know that the redirect has been remapped.
                    // So we need to set the location header to the remapped
                    // redirect url.
                    Header location = retrieveHeader(LOCATION_HEADER,
                            responseAccessor);
                    if (location != null) {
                        // update the header so that it points to the remapped
                        // redirect url
                        location.setValue(urlToFollow);
                    }

                }
                populateWebDriverResponse(request.getResponse(),
                        responseAccessor,
                        cookieJar);
            }
            // initalise the statusCode
            statusCode = responseAccessor.getStatusCode();

            // stream the output to the responseProcessor
            InputStream responseStream = null;
            try {
                responseStream = responseAccessor.getResponseStream();
                // process the response
                Header contentTypeHeader = retrieveHeader(CONTENT_TYPE,
                        responseAccessor);
                String contentType = (contentTypeHeader == null) ?
                        null : contentTypeHeader.getValue();
                Header header = retrieveHeader(CONTENT_ENCODING,
                        responseAccessor);
                String contentEncoding = (header != null) ?
                        header.getValue() : null;
                request.getResponseProcessor().processHTTPResponse(
                        urlToFollow,
                        responseStream,
                        statusCode,
                        contentType,
View Full Code Here

        response.setStatusCode(accessor.getStatusCode());

        response.setHTTPVersion(accessor.getHTTPVersion());

        // add the content type
        Header contentType = retrieveHeader(CONTENT_TYPE, accessor);
        if (contentType != null) {
            response.setContentType(contentType.getValue());
        }
    }
View Full Code Here

     */
    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

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

TOP

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

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.