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


Java SystemDefaultRoutePlanner类代码示例

本文整理汇总了Java中org.apache.http.impl.conn.SystemDefaultRoutePlanner的典型用法代码示例。如果您正苦于以下问题:Java SystemDefaultRoutePlanner类的具体用法?Java SystemDefaultRoutePlanner怎么用?Java SystemDefaultRoutePlanner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SystemDefaultRoutePlanner类属于org.apache.http.impl.conn包,在下文中一共展示了SystemDefaultRoutePlanner类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureProxy

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的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: usingHttpComponents

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的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(
					Math.toIntExact(options.getConnectionTimeout().toMillis())) //
			.setSocketTimeout(
					Math.toIntExact(options.getReadTimeout().toMillis())) //
			.setAuthenticationEnabled(true) //
			.build();

	httpClientBuilder.setDefaultRequestConfig(requestConfig);

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

	return new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:36,代码来源:ClientHttpRequestFactoryFactory.java

示例3: getDefaultClientBuilder

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
public static HttpClientBuilder getDefaultClientBuilder(int connectTimeoutInSeconds) {
    RequestConfig config = RequestConfig
            .custom()
            .setConnectTimeout(connectTimeoutInSeconds * 1000)
            .setConnectionRequestTimeout(connectTimeoutInSeconds * 1000)
            .build();

    SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault());

    return HttpClients
            .custom()
            .setDefaultRequestConfig(config)
            .setRoutePlanner(routePlanner);
}
 
开发者ID:pbauerochse,项目名称:youtrack-worklog-viewer,代码行数:15,代码来源:HttpClientUtil.java

示例4: configureHttpClient

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
private CloseableHttpClient configureHttpClient() {
    final String userAgentString = UI.BUNDLE.getString("useragent");
    final ProxySelector proxySelector = ProxySelector.getDefault();
    LOGGER.debug("Using proxy selector: {}", proxySelector);
    final SystemDefaultRoutePlanner routePlanner = new SystemDefaultRoutePlanner(proxySelector);
    final CloseableHttpClient client = HttpClientBuilder
            .create()
            .setUserAgent(userAgentString)
            .setRoutePlanner(routePlanner)
            .build();
    LOGGER.info("ComeOn! uses \"{}\" as User-Agent", userAgentString);
    return client;
}
 
开发者ID:edouardhue,项目名称:comeon,代码行数:14,代码来源:ComeOn.java

示例5: createHttpClient

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
@Override
public CloseableHttpClient createHttpClient(HttpHost httpHost,
        boolean acceptAnyCertificate, HttpRequestInterceptor requestInterceptor,
        HttpResponseInterceptor responseInterceptor) {
    HttpClientBuilder builder = HttpClientBuilder.create();
    
    //configure proxy from system environment
    builder.setRoutePlanner(new SystemDefaultRoutePlanner(null));
    
    //accept any certificate if necessary
    if ("https".equals(httpHost.getSchemeName()) && acceptAnyCertificate) {
        SSLConnectionSocketFactory icsf = getInsecureSSLSocketFactory();
        builder.setSSLSocketFactory(icsf);
        Registry<ConnectionSocketFactory> registry =
                RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("https", icsf)
                    .build();
        HttpClientConnectionManager cm =
                new BasicHttpClientConnectionManager(registry);
        builder.setConnectionManager(cm);
    }
    
    //add an interceptor that replaces the invalid Content-Type
    //'none' by 'identity'
    builder.addInterceptorFirst(new ContentEncodingNoneInterceptor());
    
    //add interceptors
    if (requestInterceptor != null) {
        builder.addInterceptorLast(requestInterceptor);
    }
    if (responseInterceptor != null) {
        builder.addInterceptorLast(responseInterceptor);
    }

    CloseableHttpClient client = builder.build();
    return client;
}
 
开发者ID:michel-kraemer,项目名称:gradle-download-task,代码行数:38,代码来源:DefaultHttpClientFactory.java

示例6: usingHttpComponents

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的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

示例7: proxy

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
@Override
public SystemDefaultRoutePlanner proxy() {
    // implement?
    return null;
}
 
开发者ID:testmycode,项目名称:tmc-intellij,代码行数:6,代码来源:SettingsTmc.java

示例8: proxy

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
@Override
public SystemDefaultRoutePlanner proxy() {
    return null;
}
 
开发者ID:testmycode,项目名称:tmc-cli,代码行数:5,代码来源:Settings.java

示例9: getClient

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
/**
 * Returns a HTTP client doing Basic Auth if needed.
 * @param url The URL to browse.
 * @param user The user. Maybe null.
 * @param password The password. Maybe null.
 * @return The HTTP client.
 */
public static CloseableHttpClient getClient(
    URL url, String user, String password
) {
    int timeout = DEFAULT_TIMEOUT;

    ApplicationSettings set = Config
        .getInstance()
        .getApplicationSettings();

    String ts = set.getApplicationSetting("requestTimeout_s");
    if (ts != null) {
        try {
            timeout = S_TO_MS * Integer.parseInt(ts);
        } catch (NumberFormatException nfe) {
            log.log(Level.SEVERE, nfe.getMessage());
        }
    }

    // Use JVM proxy settings.
    SystemDefaultRoutePlanner routePlanner
        = new SystemDefaultRoutePlanner(ProxySelector.getDefault());

    RequestConfig requestConfig = RequestConfig.
            custom().
            setSocketTimeout(timeout).build();
    HttpClientBuilder builder = HttpClientBuilder.create()
            .setDefaultRequestConfig(requestConfig);
    builder.setRetryHandler(new StandardHttpRequestRetryHandler(1, true));
    builder.setRoutePlanner(routePlanner);

    builder.setUserAgent(getUserAgent());
    if (user != null && password != null) {

        UsernamePasswordCredentials defaultCreds =
            new UsernamePasswordCredentials(user, password);

        BasicCredentialsProvider credsProv = new BasicCredentialsProvider();

        credsProv.setCredentials(
            new AuthScope(url.getHost(), url.getPort()), defaultCreds);

        HttpClientContext context = HttpClientContext.create();
        context.setCredentialsProvider(credsProv);

        BasicAuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        HttpHost target = new HttpHost(url.getHost(), url.getPort());

        authCache.put(target, basicAuth);
        context.setAuthCache(authCache);

        builder.setDefaultCredentialsProvider(credsProv);
    }


    return builder.build();
}
 
开发者ID:gdi-by,项目名称:downloadclient,代码行数:65,代码来源:HTTP.java

示例10: getRoutePlanner

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
protected HttpRoutePlanner getRoutePlanner() {
    return new SystemDefaultRoutePlanner(ProxySelector.getDefault());
}
 
开发者ID:petalmd,项目名称:armor,代码行数:4,代码来源:HeaderAwareJestClientFactory.java

示例11: createProxyRoutePlanner

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
private static HttpRoutePlanner createProxyRoutePlanner() {
    // use the standard JRE ProxySelector to get proxy information
    Message.verbose("Using JRE standard ProxySelector for configuring HTTP proxy");
    return new SystemDefaultRoutePlanner(ProxySelector.getDefault());
}
 
开发者ID:apache,项目名称:ant-ivy,代码行数:6,代码来源:HttpClientHandler.java

示例12: createHttpClient

import org.apache.http.impl.conn.SystemDefaultRoutePlanner; //导入依赖的package包/类
/**
 * Build an HttpClient
 *
 * @param customiser
 *
 * @return
 */
public CloseableHttpClient createHttpClient(final Consumer<HttpClientBuilder> customiser)
{
	final HttpClientBuilder builder = HttpClientBuilder.create();

	// By default set long call timeouts
	{
		RequestConfig.Builder requestBuilder = RequestConfig.custom();

		requestBuilder.setConnectTimeout((int) connectionTimeout.getMilliseconds())
		              .setSocketTimeout((int) socketTimeout.getMilliseconds());

		builder.setDefaultRequestConfig(requestBuilder.build());
	}

	// Set the default keepalive setting
	if (noKeepalive)
		builder.setConnectionReuseStrategy(new NoConnectionReuseStrategy());

	// By default share the common connection provider
	builder.setConnectionManager(connectionManager);

	// By default use the JRE default route planner for proxies
	builder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));

	// If a correlation id is set locally then make sure we pass it along to the remote service
	// N.B. we use the value from the MDC because the correlation id could be for a internal task
	builder.addInterceptorFirst(new HttpRequestInterceptor()
	{
		@Override
		public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException
		{
			final String traceId = MDC.get(LoggingMDCConstants.TRACE_ID);

			if (traceId != null)
				request.addHeader("X-Correlation-ID", traceId);
		}
	});

	// Allow customisation
	if (customiser != null)
		customiser.accept(builder);

	return builder.build();
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:52,代码来源:ResteasyClientFactoryImpl.java


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