当前位置: 首页>>代码示例>>Java>>正文


Java HttpClientBuilder.setRoutePlanner方法代码示例

本文整理汇总了Java中org.apache.http.impl.client.HttpClientBuilder.setRoutePlanner方法的典型用法代码示例。如果您正苦于以下问题:Java HttpClientBuilder.setRoutePlanner方法的具体用法?Java HttpClientBuilder.setRoutePlanner怎么用?Java HttpClientBuilder.setRoutePlanner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.impl.client.HttpClientBuilder的用法示例。


在下文中一共展示了HttpClientBuilder.setRoutePlanner方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureProxy

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private void configureProxy(HttpClientBuilder builder, CredentialsProvider credentialsProvider, HttpSettings httpSettings) {
    HttpProxySettings.HttpProxy httpProxy = httpSettings.getProxySettings().getProxy();
    HttpProxySettings.HttpProxy httpsProxy = httpSettings.getSecureProxySettings().getProxy();

    for (HttpProxySettings.HttpProxy proxy : Lists.newArrayList(httpProxy, httpsProxy)) {
        if (proxy != null) {
            if (proxy.credentials != null) {
                useCredentials(credentialsProvider, proxy.host, proxy.port, Collections.singleton(new AllSchemesAuthentication(proxy.credentials)));
            }
        }
    }
    builder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:HttpClientConfigurer.java

示例2: createRequestFactory

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
public ClientHttpRequestFactory createRequestFactory(HttpProxyConfiguration httpProxyConfiguration, boolean
        trustSelfSignedCerts) {
    HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties();

    if (trustSelfSignedCerts) {
        httpClientBuilder.setSslcontext(buildSslContext());
        httpClientBuilder.setHostnameVerifier(BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
    }

    if (httpProxyConfiguration != null) {
        HttpHost proxy = new HttpHost(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort());
        httpClientBuilder.setProxy(proxy);

        if (httpProxyConfiguration.isAuthRequired()) {
            BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(
                    new AuthScope(httpProxyConfiguration.getProxyHost(), httpProxyConfiguration.getProxyPort()),
                    new UsernamePasswordCredentials(httpProxyConfiguration.getUsername(), httpProxyConfiguration
                            .getPassword()));
            httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        }

        HttpRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
        httpClientBuilder.setRoutePlanner(routePlanner);
    }

    HttpClient httpClient = httpClientBuilder.build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);

    return requestFactory;
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:32,代码来源:RestUtil.java

示例3: build

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
@Override
public HttpClientBuilder build(final TranscriptListener listener, final LoginCallback prompt) {
    final HttpClientBuilder builder = super.build(listener, prompt);
    // Add filter to inject custom headers to authenticate with proxy
    builder.setRequestExecutor(
            new CustomHeaderHttpRequestExecutor(headers)
    );
    // Set proxy router planer
    builder.setRoutePlanner(new DefaultProxyRoutePlanner(
            new HttpHost(proxy.getHostname(), proxy.getPort(), proxy.getProtocol().getScheme().name()),
            new DefaultSchemePortResolver()));
    return builder;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:14,代码来源:UDTProxyConfigurator.java

示例4: addProxyConfig

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private void addProxyConfig(HttpClientBuilder builder,
                            ProxyConfiguration proxyConfiguration) {
    if (isProxyEnabled(proxyConfiguration)) {

        LOG.info("Configuring Proxy. Proxy Host: " + proxyConfiguration.endpoint());

        builder.setRoutePlanner(new SdkProxyRoutePlanner(proxyConfiguration.endpoint().getHost(),
                                                         proxyConfiguration.endpoint().getPort(),
                                                         proxyConfiguration.nonProxyHosts()));

        if (isAuthenticatedProxy(proxyConfiguration)) {
            builder.setDefaultCredentialsProvider(ApacheUtils.newProxyCredentialsProvider(proxyConfiguration));
        }
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:16,代码来源:ApacheHttpClientFactory.java

示例5: addProxy

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private void addProxy(RESTPool pool, HttpClientBuilder builder) {
    if (pool.getProxy() == null) return;

    Proxy proxy = pool.getProxy();

    if (proxy.getUsername() != null) {
        CredentialsProvider provider = makeProxyCredentialsProvider(proxy);
        builder.setDefaultCredentialsProvider(provider);
    }

    HttpHost proxyHost = new HttpHost(proxy.getHostname(), proxy.getPort());
    builder.setRoutePlanner(new DefaultProxyRoutePlanner(proxyHost));
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:14,代码来源:HTTPCBuilder.java

示例6: addProxyConfig

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
private void addProxyConfig(HttpClientBuilder builder,
                            HttpClientSettings settings) {
    if (settings.isProxyEnabled()) {

        LOG.info("Configuring Proxy. Proxy Host: " + settings.getProxyHost() + " " +
                "Proxy Port: " + settings.getProxyPort());

        builder.setRoutePlanner(new SdkProxyRoutePlanner(
                settings.getProxyHost(), settings.getProxyPort(), settings.getNonProxyHosts()));

        if (settings.isAuthenticatedProxy()) {
            builder.setDefaultCredentialsProvider(ApacheUtils.newProxyCredentialsProvider(settings));
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:16,代码来源:ApacheHttpClientFactory.java

示例7: usingHttpComponents

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
static ClientHttpRequestFactory usingHttpComponents(ClientOptions options,
                                                    SslConfiguration sslConfiguration) throws GeneralSecurityException,
        IOException {

    HttpClientBuilder httpClientBuilder = HttpClients.custom();

    httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(
            DefaultSchemePortResolver.INSTANCE, ProxySelector.getDefault()));

    if (hasSslConfiguration(sslConfiguration)) {

        SSLContext sslContext = getSSLContext(sslConfiguration);
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
                sslContext);
        httpClientBuilder.setSSLSocketFactory(sslSocketFactory);
        httpClientBuilder.setSslcontext(sslContext);
    }

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(options.getConnectionTimeout())
            .setSocketTimeout(options.getReadTimeout())
            .setAuthenticationEnabled(true)
            .build();

    httpClientBuilder.setDefaultRequestConfig(requestConfig);

    // Support redirects
    httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());

    // Fix weird problem `ProtocolException: Content-Length header already present` from `org.apache.http.protocol.RequestContent`
    httpClientBuilder.addInterceptorFirst(new HttpRequestInterceptor() {
        @Override
        public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
            if (request instanceof HttpEntityEnclosingRequest) {
                request.removeHeaders(HTTP.TRANSFER_ENCODING);
                request.removeHeaders(HTTP.CONTENT_LEN);
            }
        }
    });

    return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:43,代码来源:ClientHttpRequestFactoryFactory.java

示例8: initialzeInternalClient

import org.apache.http.impl.client.HttpClientBuilder; //导入方法依赖的package包/类
protected void initialzeInternalClient() {

        if (!needsInternalClientInialization) {
            // internal client is already initialized
            return;
        }

        // release any resources if this client was already used
        close();

        // rebuild the client
        HttpClientBuilder httpClientBuilder = HttpClients.custom();

        // Add this interceptor to get the values of all HTTP headers in the request.
        // Some of them are provided by the user while others are generated by Apache HTTP Components.
        httpClientBuilder.addInterceptorLast(new HttpRequestInterceptor() {
            @Override
            public void process( HttpRequest request, HttpContext context ) throws HttpException,
                                                                            IOException {

                Header[] requestHeaders = request.getAllHeaders();
                actualRequestHeaders = new ArrayList<HttpHeader>();
                for (Header header : requestHeaders) {
                    addHeaderToList(actualRequestHeaders, header.getName(), header.getValue());
                }
                if (debugLevel != HttpDebugLevel.NONE) {
                    logHTTPRequest(requestHeaders, request);
                }
            }
        });

        // connect and read timeouts
        httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom()
                                                               .setConnectTimeout(connectTimeoutSeconds
                                                                                  * 1000)
                                                               .setSocketTimeout(readTimeoutSeconds
                                                                                 * 1000)
                                                               .build());

        // socket buffer size
        if (this.socketBufferSize > 0) {
            httpClientBuilder.setDefaultSocketConfig(SocketConfig.custom()
                                                                 .setRcvBufSize(this.socketBufferSize)
                                                                 .setSndBufSize(this.socketBufferSize)
                                                                 .build());
        }

        // SSL
        if (isOverSsl) {
            setupSSL(httpClientBuilder);
        }

        // setup authentication
        if (!StringUtils.isNullOrEmpty(username)) {
            setupAuthentication(httpClientBuilder);
        }

        // set proxy
        if (AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST != null
            && AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT != null) {

            HttpHost proxy = new HttpHost(AtsSystemProperties.SYSTEM_HTTP_PROXY_HOST,
                                          Integer.parseInt(AtsSystemProperties.SYSTEM_HTTP_PROXY_PORT));
            DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
            httpClientBuilder.setRoutePlanner(routePlanner);
        }

        // now build the client after we have already set everything needed on the client builder
        httpClient = httpClientBuilder.build();

        // do not come here again until not needed
        needsInternalClientInialization = false;
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:74,代码来源:HttpClient.java


注:本文中的org.apache.http.impl.client.HttpClientBuilder.setRoutePlanner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。