Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.RequestWrapper


        HttpRequest downgraded = new BasicHttpRequest("GET", "/foo", HttpVersion.HTTP_1_1);
        downgraded.removeHeaders("Connection");
        downgraded.addHeader("X-Unknown-Header", "some-value");

        RequestWrapper downgradedWrapper = new RequestWrapper(downgraded);

        EasyMock.expect(
                mockBackend.execute(EasyMock.isA(HttpHost.class), eqRequest(downgradedWrapper),
                        (HttpContext) EasyMock.isNull())).andReturn(originResponse);
        replayMocks();
View Full Code Here


                    }

                });
            }
            this.params = new ClientParamsStack(null, this.clientParams, request.getParams(), null);
            final RequestWrapper wrapper = wrapRequest(request);
            wrapper.setParams(this.params);
            final HttpRoute route = determineRoute(target, wrapper, this.localContext);
            this.mainRequest = new RoutedRequest(wrapper, route);
            final RequestConfig config = ParamConfig.getRequestConfig(params);
            this.localContext.setAttribute(ClientContext.REQUEST_CONFIG, config);
            this.requestContentProduced = false;
View Full Code Here

    private RequestWrapper wrapRequest(final HttpRequest request) throws ProtocolException {
        if (request instanceof HttpEntityEnclosingRequest) {
            return new EntityEnclosingRequestWrapper((HttpEntityEnclosingRequest) request);
        } else {
            return new RequestWrapper(request);
        }
    }
View Full Code Here

    private RoutedRequest handleRedirect() throws HttpException {
        if (this.redirectStrategy.isRedirected(
                this.currentRequest, this.currentResponse, this.localContext)) {

            final HttpRoute route = this.mainRequest.getRoute();
            final RequestWrapper request = this.mainRequest.getRequest();

            final int maxRedirects = this.params.getIntParameter(ClientPNames.MAX_REDIRECTS, 100);
            if (this.redirectCount >= maxRedirects) {
                throw new RedirectException("Maximum redirects ("
                        + maxRedirects + ") exceeded");
            }
            this.redirectCount++;

            final HttpUriRequest redirect = this.redirectStrategy.getRedirect(
                    this.currentRequest, this.currentResponse, this.localContext);
            final HttpRequest orig = request.getOriginal();
            redirect.setHeaders(orig.getAllHeaders());

            final URI uri = redirect.getURI();
            if (uri.getHost() == null) {
                throw new ProtocolException("Redirect URI does not specify a valid host name: " + uri);
            }
            final HttpHost newTarget = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());

            // Reset auth states if redirecting to another host
            if (!route.getTargetHost().equals(newTarget)) {
                if (this.log.isDebugEnabled()) {
                    this.log.debug("[exchange: " + this.id + "] Resetting target auth state");
                }
                this.targetAuthState.reset();
                final AuthScheme authScheme = this.proxyAuthState.getAuthScheme();
                if (authScheme != null && authScheme.isConnectionBased()) {
                    if (this.log.isDebugEnabled()) {
                        this.log.debug("[exchange: " + this.id + "] Resetting proxy auth state");
                    }
                    this.proxyAuthState.reset();
                }
            }

            final RequestWrapper newRequest = wrapRequest(redirect);
            newRequest.setParams(this.params);

            final HttpRoute newRoute = determineRoute(newTarget, newRequest, this.localContext);

            if (this.log.isDebugEnabled()) {
                this.log.debug("[exchange: " + this.id + "] Redirecting to '" + uri + "' via " + newRoute);
View Full Code Here

        }
    }

    private HttpRequest upgradeRequestTo(HttpRequest request, ProtocolVersion version)
            throws ClientProtocolException {
        RequestWrapper newRequest;
        try {
            newRequest = new RequestWrapper(request);
        } catch (ProtocolException pe) {
            throw new ClientProtocolException(pe);
        }
        newRequest.setProtocolVersion(version);

        return newRequest;
    }
View Full Code Here

        return newRequest;
    }

    private HttpRequest downgradeRequestTo(HttpRequest request, ProtocolVersion version)
            throws ClientProtocolException {
        RequestWrapper newRequest;
        try {
            newRequest = new RequestWrapper(request);
        } catch (ProtocolException pe) {
            throw new ClientProtocolException(pe);
        }
        newRequest.setProtocolVersion(version);

        return newRequest;
    }
View Full Code Here

     * @return the wrapped request
     * @throws ProtocolException when I am unable to build a new origin request.
     */
    public HttpRequest buildConditionalRequest(HttpRequest request, HttpCacheEntry cacheEntry)
            throws ProtocolException {
        RequestWrapper wrapperRequest = new RequestWrapper(request);
        wrapperRequest.resetHeaders();
        Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG);
        if (eTag != null) {
            wrapperRequest.setHeader(HeaderConstants.IF_NONE_MATCH, eTag.getValue());
        }
        Header lastModified = cacheEntry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
        if (lastModified != null) {
            wrapperRequest.setHeader(HeaderConstants.IF_MODIFIED_SINCE, lastModified.getValue());
        }
        boolean mustRevalidate = false;
        for(Header h : cacheEntry.getHeaders(HeaderConstants.CACHE_CONTROL)) {
            for(HeaderElement elt : h.getElements()) {
                if (HeaderConstants.CACHE_CONTROL_MUST_REVALIDATE.equalsIgnoreCase(elt.getName())
                    || HeaderConstants.CACHE_CONTROL_PROXY_REVALIDATE.equalsIgnoreCase(elt.getName())) {
                    mustRevalidate = true;
                    break;
                }
            }
        }
        if (mustRevalidate) {
            wrapperRequest.addHeader(HeaderConstants.CACHE_CONTROL, HeaderConstants.CACHE_CONTROL_MAX_AGE + "=0");
        }
        return wrapperRequest;

    }
View Full Code Here

     * @param variants
     * @return the wrapped request
     */
    public HttpRequest buildConditionalRequestFromVariants(HttpRequest request,
            Map<String, Variant> variants) {
        RequestWrapper wrapperRequest;
        try {
            wrapperRequest = new RequestWrapper(request);
        } catch (ProtocolException pe) {
            log.warn("unable to build conditional request", pe);
            return request;
        }
        wrapperRequest.resetHeaders();

        // we do not support partial content so all etags are used
        StringBuilder etags = new StringBuilder();
        boolean first = true;
        for(String etag : variants.keySet()) {
            if (!first) {
                etags.append(",");
            }
            first = false;
            etags.append(etag);
        }

        wrapperRequest.setHeader(HeaderConstants.IF_NONE_MATCH, etags.toString());
        return wrapperRequest;
    }
View Full Code Here

     * @param request client request we are trying to satisfy
     * @param entry existing cache entry we are trying to validate
     * @return an unconditional validation request
     */
    public HttpRequest buildUnconditionalRequest(HttpRequest request, HttpCacheEntry entry) {
        RequestWrapper wrapped;
        try {
            wrapped = new RequestWrapper(request);
        } catch (ProtocolException e) {
            log.warn("unable to build proper unconditional request", e);
            return request;
        }
        wrapped.resetHeaders();
        wrapped.addHeader(HeaderConstants.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE);
        wrapped.addHeader(HeaderConstants.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE);
        wrapped.removeHeaders(HeaderConstants.IF_RANGE);
        wrapped.removeHeaders(HeaderConstants.IF_MATCH);
        wrapped.removeHeaders(HeaderConstants.IF_NONE_MATCH);
        wrapped.removeHeaders(HeaderConstants.IF_UNMODIFIED_SINCE);
        wrapped.removeHeaders(HeaderConstants.IF_MODIFIED_SINCE);
        return wrapped;
    }
View Full Code Here

                    }

                });
            }
            this.params = new ClientParamsStack(null, this.clientParams, request.getParams(), null);
            RequestWrapper wrapper = wrapRequest(request);
            wrapper.setParams(this.params);
            HttpRoute route = determineRoute(target, wrapper, this.localContext);
            this.mainRequest = new RoutedRequest(wrapper, route);
            this.requestContentProduced = false;
            requestConnection();
        } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.RequestWrapper

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.