Package org.apache.http.conn.routing

Examples of org.apache.http.conn.routing.HttpRoute


        this.state.setValidDuration(0);
        this.state.setNonReusable();
        this.state.setRouteEstablished(false);
        this.state.setRouteTracker(null);

        final HttpRoute route = this.state.getRoute();
        final Object userToken = this.localContext.getUserToken();
        final RequestConfig config = this.localContext.getRequestConfig();
        this.connmgr.requestConnection(
                route,
                userToken,
View Full Code Here


        if (redirectLocations != null) {
            redirectLocations.clear();
        }

        final HttpRequestWrapper request = HttpRequestWrapper.wrap(original);
        final HttpRoute route = this.routePlanner.determineRoute(target, request, localContext);
        state.setRoute(route);
        state.setMainRequest(request);
        state.setCurrentRequest(request);

        prepareRequest(state);
View Full Code Here

    public HttpRequest generateRequest(
            final InternalState state,
            final InternalConnManager connManager) throws IOException, HttpException {
        final HttpClientContext localContext = state.getLocalContext();
        final HttpRoute route = state.getRoute();
        final NHttpClientConnection managedConn = connManager.getConnection();
        if (!state.isRouteEstablished() && state.getRouteTracker() == null) {
            state.setRouteEstablished(this.connmgr.isRouteComplete(managedConn));
            if (!state.isRouteEstablished()) {
                this.log.debug("Start connection routing");
                state.setRouteTracker(new RouteTracker(route));
            } else {
                this.log.debug("Connection route already established");
            }
        }

        if (!state.isRouteEstablished()) {
            final RouteTracker routeTracker = state.getRouteTracker();
            int step;
            loop:
            do {
                final HttpRoute fact = routeTracker.toRoute();
                step = this.routeDirector.nextStep(route, fact);
                switch (step) {
                case HttpRouteDirector.CONNECT_TARGET:
                    this.connmgr.startRoute(managedConn, route, localContext);
                    routeTracker.connectTarget(route.isSecure());
View Full Code Here

                if (newTarget == null) {
                    throw new ProtocolException("Redirect URI does not specify a valid host name: " + uri);
                }

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

                if (!redirect.headerIterator().hasNext()) {
                    final HttpRequest original = state.getMainRequest().getOriginal();
                    redirect.setHeaders(original.getAllHeaders());
                }

                final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(redirect);
                final HttpRoute newRoute = this.routePlanner.determineRoute(
                    newTarget, newRequest, localContext);
                state.setRoute(newRoute);
                state.setMainRequest(newRequest);
                state.setCurrentRequest(newRequest);
                if (!route.equals(newRoute)) {
View Full Code Here

        state.setCurrentResponse(null);
    }

    private void rewriteRequestURI(final InternalState state) throws ProtocolException {
        final HttpRequestWrapper request = state.getCurrentRequest();
        final HttpRoute route = state.getRoute();
        try {
            URI uri = request.getURI();
            if (uri != null) {
                if (route.getProxyHost() != null && !route.isTunnelled()) {
                    // Make sure the request URI is absolute
                    if (!uri.isAbsolute()) {
                        final HttpHost target = route.getTargetHost();
                        uri = URIUtils.rewriteURI(uri, target, true);
                    } else {
                        uri = URIUtils.rewriteURI(uri);
                    }
                } else {
View Full Code Here

    }

    private void prepareRequest(final InternalState state) throws IOException, HttpException {
        final HttpClientContext localContext = state.getLocalContext();
        final HttpRequestWrapper currentRequest = state.getCurrentRequest();
        final HttpRoute route = state.getRoute();

        final HttpRequest original = currentRequest.getOriginal();
        URI uri = null;
        if (original instanceof HttpUriRequest) {
            uri = ((HttpUriRequest) original).getURI();
        } else {
            final String uriString = original.getRequestLine().getUri();
            try {
                uri = URI.create(uriString);
            } catch (final IllegalArgumentException ex) {
                if (this.log.isDebugEnabled()) {
                    this.log.debug("Unable to parse '" + uriString + "' as a valid URI; " +
                        "request URI and Host header may be inconsistent", ex);
                }
            }

        }
        currentRequest.setURI(uri);

        // Re-write request URI if needed
        rewriteRequestURI(state);

        HttpHost target = null;
        if (uri != null && uri.isAbsolute() && uri.getHost() != null) {
            target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
        }
        if (target == null) {
            target = route.getTargetHost();
        }

        // Get user info from the URI
        if (uri != null) {
            final String userinfo = uri.getUserInfo();
View Full Code Here

        final HttpClientContext localContext = state.getLocalContext();
        final RequestConfig config = localContext.getRequestConfig();
        if (config.isAuthenticationEnabled()) {
            final CredentialsProvider credsProvider = localContext.getCredentialsProvider();
            if (credsProvider != null) {
                final HttpRoute route = state.getRoute();
                final HttpHost proxy = route.getProxyHost();
                final HttpResponse currentResponse = state.getCurrentResponse();
                final AuthState proxyAuthState = localContext.getProxyAuthState();
                if (this.authenticator.isAuthenticationRequested(proxy, currentResponse,
                        this.proxyAuthStrategy, proxyAuthState, localContext)) {
                    return this.authenticator.handleAuthChallenge(proxy, currentResponse,
View Full Code Here

    private boolean needAuthentication(final InternalState state) throws HttpException {
        final HttpClientContext localContext = state.getLocalContext();
        final CredentialsProvider credsProvider = localContext.getCredentialsProvider();
        if (credsProvider != null) {
            final HttpRoute route = state.getRoute();
            final HttpResponse currentResponse = state.getCurrentResponse();
            HttpHost target = localContext.getTargetHost();
            if (target == null) {
                target = route.getTargetHost();
            }
            if (target.getPort() < 0) {
                target = new HttpHost(
                        target.getHostName(),
                        route.getTargetHost().getPort(),
                        target.getSchemeName());
            }
            final AuthState targetAuthState = localContext.getTargetAuthState();
            final AuthState proxyAuthState = localContext.getProxyAuthState();

            final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(
                    target, currentResponse, this.targetAuthStrategy, targetAuthState, localContext);

            HttpHost proxy = route.getProxyHost();
            // if proxy is not set use target host instead
            if (proxy == null) {
                proxy = route.getTargetHost();
            }
            final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(
                    proxy, currentResponse, this.proxyAuthStrategy, proxyAuthState, localContext);

            if (targetAuthRequested) {
View Full Code Here

        } else {
            log.debug("Cache entry not usable; calling backend");
            callBackend(future, target, request, clientContext);
            return;
        }
        clientContext.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(target));
        clientContext.setAttribute(HttpClientContext.HTTP_TARGET_HOST, target);
        clientContext.setAttribute(HttpClientContext.HTTP_REQUEST, request);
        clientContext.setAttribute(HttpClientContext.HTTP_RESPONSE, out);
        clientContext.setAttribute(HttpClientContext.HTTP_REQ_SENT, Boolean.TRUE);
        future.completed(out);
View Full Code Here

    }

    @Test
    public void testRequestReleaseConnection() throws Exception {
        final HttpHost target = new HttpHost("localhost");
        final HttpRoute route = new HttpRoute(target);
        final Future<NHttpClientConnection> future = connman.requestConnection(
            route, "some state", 1000L, 2000L, TimeUnit.MILLISECONDS, connCallback);
        Assert.assertNotNull(future);

        Mockito.verify(pool).lease(
View Full Code Here

TOP

Related Classes of org.apache.http.conn.routing.HttpRoute

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.