Java 类org.apache.http.conn.routing.RouteInfo 实例源码

项目:purecloud-iot    文件:WindowsNegotiateScheme.java   
private String getServicePrincipalName(final HttpContext context) {
    final String spn;
    if (this.servicePrincipalName != null) {
        spn = this.servicePrincipalName;
    } else {
        final HttpClientContext clientContext = HttpClientContext.adapt(context);
        final HttpHost target = clientContext.getTargetHost();
        if (target != null) {
            spn = "HTTP/" + target.getHostName();
        } else {
            final RouteInfo route = clientContext.getHttpRoute();
            if (route != null) {
                spn = "HTTP/" + route.getTargetHost().getHostName();
            } else {
                // Should not happen
                spn = null;
            }
        }
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Using SPN: " + spn);
    }
    return spn;
}
项目:purecloud-iot    文件:URIUtils.java   
/**
 * A convenience method that optionally converts the original {@link java.net.URI} either
 * to a relative or an absolute form as required by the specified route.
 *
 * @param uri
 *            original URI.
 * @throws URISyntaxException
 *             If the resulting URI is invalid.
 *
 * @since 4.4
 */
public static URI rewriteURIForRoute(final URI uri, final RouteInfo route) throws URISyntaxException {
    if (uri == null) {
        return null;
    }
    if (route.getProxyHost() != null && !route.isTunnelled()) {
        // Make sure the request URI is absolute
        if (!uri.isAbsolute()) {
            final HttpHost target = route.getTargetHost();
            return rewriteURI(uri, target, true);
        } else {
            return rewriteURI(uri);
        }
    } else {
        // Make sure the request URI is relative
        if (uri.isAbsolute()) {
            return rewriteURI(uri, null, true);
        } else {
            return rewriteURI(uri);
        }
    }
}
项目:remote-files-sync    文件:RequestClientConnControl.java   
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;
    }

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    // Obtain the client connection (required)
    final RouteInfo route = clientContext.getHttpRoute();
    if (route == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Connection route not set in the context");
        }
        return;
    }

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}
项目:purecloud-iot    文件:RequestClientConnControl.java   
@Override
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;
    }

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    // Obtain the client connection (required)
    final RouteInfo route = clientContext.getHttpRoute();
    if (route == null) {
        this.log.debug("Connection route not set in the context");
        return;
    }

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}
项目:purecloud-iot    文件:TestMainClientExec.java   
@Test(expected = HttpException.class)
public void testEstablishRouteViaProxyTunnelMultipleHops() throws Exception {
    final AuthState authState = new AuthState();
    final HttpHost proxy1 = new HttpHost("this", 8888);
    final HttpHost proxy2 = new HttpHost("that", 8888);
    final HttpRoute route = new HttpRoute(target, null, new HttpHost[] {proxy1, proxy2},
            true, RouteInfo.TunnelType.TUNNELLED, RouteInfo.LayerType.LAYERED);
    final HttpClientContext context = new HttpClientContext();
    final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));

    Mockito.when(managedConn.isOpen()).thenReturn(Boolean.TRUE);

    mainClientExec.establishRoute(authState, managedConn, route, request, context);
}
项目:Visit    文件:RequestClientConnControl.java   
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;
    }

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    // Obtain the client connection (required)
    final RouteInfo route = clientContext.getHttpRoute();
    if (route == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Connection route not set in the context");
        }
        return;
    }

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}
项目:artifactory    文件:ProxyPreemptiveAuthInterceptor.java   
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    AuthState proxyAuthState = clientContext.getProxyAuthState();

    // If there's no auth scheme available yet, try to initialize it preemptively
    if (proxyAuthState.getAuthScheme() == null) {
        CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
        RouteInfo route = clientContext.getHttpRoute();
        if (route == null) {
            log.debug("No route found for {}", clientContext.getTargetHost());
            return;
        }

        HttpHost proxyHost = route.getProxyHost();
        if (proxyHost == null) {
            log.warn("No proxy host found in route {} for host {}", route, clientContext.getTargetHost());
            return;
        }

        Credentials creds = credsProvider.getCredentials(
                new AuthScope(proxyHost.getHostName(), proxyHost.getPort()));
        if (creds == null) {
            log.info("No credentials found for proxy: " + proxyHost);
            return;
        }
        proxyAuthState.update(new BasicScheme(ChallengeState.PROXY), creds);
    }
}
项目:ZTLib    文件:RequestClientConnControl.java   
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;
    }

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    // Obtain the client connection (required)
    final RouteInfo route = clientContext.getHttpRoute();
    if (route == null) {
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Connection route not set in the context");
        }
        return;
    }

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}
项目:bintray-client-java    文件:HttpClientConfigurator.java   
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    AuthState proxyAuthState = clientContext.getProxyAuthState();

    // If there's no auth scheme available yet, try to initialize it preemptively
    if (proxyAuthState.getAuthScheme() == null) {
        CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
        RouteInfo route = clientContext.getHttpRoute();
        if (route == null) {
            if (log.isDebugEnabled()) {
                log.debug("No route found for {}", clientContext.getTargetHost());
            }
            return;
        }

        HttpHost proxyHost = route.getProxyHost();
        if (proxyHost == null) {
            log.warn("No proxy host found in route {} for host {}", route, clientContext.getTargetHost());
            return;
        }

        Credentials creds = credsProvider.getCredentials(
                new AuthScope(proxyHost.getHostName(), proxyHost.getPort()));
        if (creds == null) {
            log.info("No credentials found for proxy: " + proxyHost);
            return;
        }
        proxyAuthState.update(new BasicScheme(ChallengeState.PROXY), creds);
    }
}
项目:remote-files-sync    文件:HttpClientContext.java   
public RouteInfo getHttpRoute() {
    return getAttribute(HTTP_ROUTE, HttpRoute.class);
}
项目:purecloud-iot    文件:HttpClientContext.java   
public RouteInfo getHttpRoute() {
    return getAttribute(HTTP_ROUTE, HttpRoute.class);
}
项目:Visit    文件:HttpClientContext.java   
public RouteInfo getHttpRoute() {
    return getAttribute(HTTP_ROUTE, HttpRoute.class);
}
项目:ZTLib    文件:HttpClientContext.java   
public RouteInfo getHttpRoute() {
    return getAttribute(HTTP_ROUTE, HttpRoute.class);
}