當前位置: 首頁>>代碼示例>>Java>>正文


Java PlainConnectionSocketFactory類代碼示例

本文整理匯總了Java中org.apache.http.conn.socket.PlainConnectionSocketFactory的典型用法代碼示例。如果您正苦於以下問題:Java PlainConnectionSocketFactory類的具體用法?Java PlainConnectionSocketFactory怎麽用?Java PlainConnectionSocketFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PlainConnectionSocketFactory類屬於org.apache.http.conn.socket包,在下文中一共展示了PlainConnectionSocketFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: afterPropertiesSet

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
@PostConstruct
public void afterPropertiesSet() throws Exception {
	RegistryBuilder<ConnectionSocketFactory> schemeRegistry = RegistryBuilder.create();

	schemeRegistry.register("http", PlainConnectionSocketFactory.getSocketFactory());

	SSLContext sslcontext = SSLContext.getInstance("TLS");
	sslcontext.init(new KeyManager[0], new TrustManager[]{new SimpleTrustManager()}, null);
	SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslcontext);
	schemeRegistry.register("https", sf);

	pool = new PoolingHttpClientConnectionManager(schemeRegistry.build());
	pool.setMaxTotal(maxConnection);
	pool.setDefaultMaxPerRoute(maxConnection);
	pool.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(sotimeout).build());
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:17,代碼來源:HttpClientUtil.java

示例2: getConnctionManager

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
public static PoolingHttpClientConnectionManager getConnctionManager(){

        Registry<ConnectionSocketFactory> socketFactoryRegistry = null;
        try {
            SSLConnectionSocketFactory trustSelfSignedSocketFactory = new SSLConnectionSocketFactory(
                        new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
                        new TrustAllHostNameVerifier());
            socketFactoryRegistry = RegistryBuilder
                    .<ConnectionSocketFactory> create()
                    .register("http", new PlainConnectionSocketFactory())
                    .register("https", trustSelfSignedSocketFactory)
                    .build();
        } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
            Data.logger.warn("", e);
        }
        
        PoolingHttpClientConnectionManager cm = (socketFactoryRegistry != null) ? 
                new PoolingHttpClientConnectionManager(socketFactoryRegistry):
                new PoolingHttpClientConnectionManager();
        
        // twitter specific options
        cm.setMaxTotal(2000);
        cm.setDefaultMaxPerRoute(200);
        
        return cm;
    }
 
開發者ID:yacy,項目名稱:yacy_grid_mcp,代碼行數:27,代碼來源:ClientConnection.java

示例3: OAuthHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
public OAuthHttpClient(int maxConnection, int connectTimeout, int socketTimeout) {
    PoolingHttpClientConnectionManager connectionManager =
            new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("https", SSLConnectionSocketFactory.getSocketFactory())
                    .build());
    // set max connection
    connectionManager.setMaxTotal(maxConnection);

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(connectTimeout)
            .setSocketTimeout(socketTimeout)
            .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
            .build();

    httpClient = HttpClientBuilder.create()
            .setConnectionManager(connectionManager)
            .setDefaultRequestConfig(requestConfig)
            .setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
            .build();
}
 
開發者ID:xiaomi-passport,項目名稱:oauth-java-sdk,代碼行數:22,代碼來源:OAuthHttpClient.java

示例4: init

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
public void init() {
	try {
		SSLContextBuilder builder = new SSLContextBuilder();
		builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
		/* 配置同時支持 HTTP 和 HTPPS */
		Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
				.register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
		/* 初始化連接管理器 */
		poolConnManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
		poolConnManager.setMaxTotal(maxTotal);
		poolConnManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
		requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
				.setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
		httpClient = getConnection();
		log.info("HttpConnectionManager初始化完成...");
	} catch (Exception e) {
		log.error("error", e);
	}
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:21,代碼來源:HttpConnectionManager.java

示例5: httpsGet

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
public static String httpsGet(String getUrl, String defaultCharset, Map<String, String> headerParas)
		throws KeyManagementException, NoSuchAlgorithmException {
	// 采用繞過驗證的方式處理https請求
	SSLContext sslcontext = createIgnoreVerifySSL();

	// 設置協議http和https對應的處理socket鏈接工廠的對象
	Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
			.register("http", PlainConnectionSocketFactory.INSTANCE).register("https", new SSLConnectionSocketFactory(sslcontext))
			.build();
	PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
	HttpClients.custom().setConnectionManager(connManager);

	// 創建自定義的httpclient對象
	CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(connManager).build();

	return getInner(getUrl, defaultCharset, headerParas, httpclient);
}
 
開發者ID:rongwei84n,項目名稱:Auts_Assert_manager,代碼行數:18,代碼來源:PhicommHttpClient.java

示例6: initPoolingHttpClientManager

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
private void initPoolingHttpClientManager () {
    final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("https", SSLConnectionSocketFactory.getSocketFactory())
            .register("http", PlainConnectionSocketFactory.getSocketFactory()).build();

    final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    connectionManager.setMaxTotal(MAX_CONNECTION);
    connectionManager.setDefaultMaxPerRoute(MAX_CONNECTION_PER_ROUTE);

    final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom().setConnectTimeout(CONNECTION_TIMEOUT)
            .setConnectionRequestTimeout(CONNECTION_TIMEOUT).setSocketTimeout(SOCKET_TIMEOUT);

    final RequestConfig requestConfig = requestConfigBuilder.build();

    HashSet<Header> defaultHeaders = new HashSet<Header>();
    defaultHeaders.add(new BasicHeader(HttpHeaders.PRAGMA, "no-cache"));
    defaultHeaders.add(new BasicHeader(HttpHeaders.CACHE_CONTROL, "no-cache"));

    final HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultHeaders(defaultHeaders).disableAuthCaching().disableContentCompression();
    this.httpClient = httpClientBuilder.setConnectionManager(connectionManager).setDefaultRequestConfig(requestConfig).build();
}
 
開發者ID:LeeKyoungIl,項目名稱:illuminati,代碼行數:22,代碼來源:IlluminatiHttpClient.java

示例7: getCustomClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
/**
 * custom http client for server with SSL errors
 *
 * @return
 */
public final CloseableHttpClient getCustomClient() {
    try {
        HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties();
        SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null,
                (TrustStrategy) (X509Certificate[] arg0, String arg1) -> true).build();
        builder.setSSLContext(sslContext);
        HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .register("https", sslSocketFactory)
                .build();
        PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
        builder.setConnectionManager(connMgr);
        return builder.build();
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return getSystemClient();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:26,代碼來源:AbstractHttpClient.java

示例8: createSocketFactoryRegistry

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
private Registry<ConnectionSocketFactory> createSocketFactoryRegistry(ConnectionSocketFactory sslSocketFactory) {

        /*
         * If SSL cert checking for endpoints has been explicitly disabled,
         * register a new scheme for HTTPS that won't cause self-signed certs to
         * error out.
         */
        if (SDKGlobalConfiguration.isCertCheckingDisabled()) {
            if (LOG.isWarnEnabled()) {
                LOG.warn("SSL Certificate checking for endpoints has been " +
                        "explicitly disabled.");
            }
            sslSocketFactory = new TrustingSocketFactory();
        }

        return RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", PlainConnectionSocketFactory.getSocketFactory())
                .register("https", sslSocketFactory)
                .build();
    }
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:21,代碼來源:ApacheConnectionManagerFactory.java

示例9: init

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
private void init() {
    final URI originalUri = URI.create(DEFAULT_UNIX_ENDPOINT);
    sanitizeUri = UnixFactory.sanitizeUri(originalUri);

    final RegistryBuilder<ConnectionSocketFactory> registryBuilder =
            RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("https", SSLConnectionSocketFactory.getSocketFactory())
                    .register("http", PlainConnectionSocketFactory.getSocketFactory())
                    .register("unix", new UnixFactory(originalUri));

    final PoolingHttpClientConnectionManager cm =
            new PoolingHttpClientConnectionManager(registryBuilder.build());

    final RequestConfig requestConfig = RequestConfig.custom()
            .setConnectionRequestTimeout((int) SECONDS.toMillis(5))
            .setConnectTimeout((int) SECONDS.toMillis(5))
            .setSocketTimeout((int) SECONDS.toMillis(30))
            .build();

    final ClientConfig config = new ClientConfig()
            .connectorProvider(new ApacheConnectorProvider())
            .property(ApacheClientProperties.CONNECTION_MANAGER, cm)
            .property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);

    client = ClientBuilder.newBuilder().withConfig(config).build();
}
 
開發者ID:ozlerhakan,項目名稱:rapid,代碼行數:27,代碼來源:DockerClient.java

示例10: createConnection

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
/**
 * Creates a new configured instance of {@link CloseableHttpClient} based
 * on the factory's configuration.
 *
 * @return new connection object instance
 */
public CloseableHttpClient createConnection() {
    final ConnectionSocketFactory socketFactory =
            new CloudApiSSLConnectionSocketFactory(config);

    final RegistryBuilder<ConnectionSocketFactory> registryBuilder =
            RegistryBuilder.create();

    final Registry<ConnectionSocketFactory> socketFactoryRegistry = registryBuilder
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", socketFactory)
            .build();

    final PoolingHttpClientConnectionManager connectionManager =
            new PoolingHttpClientConnectionManager(socketFactoryRegistry,
                    DNS_RESOLVER);

    httpClientBuilder.setConnectionManager(connectionManager);

    return httpClientBuilder.build();
}
 
開發者ID:joyent,項目名稱:java-triton,代碼行數:27,代碼來源:CloudApiConnectionFactory.java

示例11: createHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
private CloseableHttpClient createHttpClient(String hostname, int port) {
    ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
    LayeredConnectionSocketFactory sslsf = SSLConnectionSocketFactory.getSocketFactory();
    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory> create()
            .register("http", plainsf).register("https", sslsf).build();
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
    // 將最大連接數增加
    cm.setMaxTotal(maxTotal);
    // 將每個路由基礎的連接增加
    cm.setDefaultMaxPerRoute(maxPerRoute);
    HttpHost httpHost = new HttpHost(hostname, port);
    // 將目標主機的最大連接數增加
    cm.setMaxPerRoute(new HttpRoute(httpHost), maxRoute);
    // 請求重試處理
    return HttpClients.custom().setConnectionManager(cm).setRetryHandler(httpRequestRetryHandler).build();
}
 
開發者ID:adealjason,項目名稱:dtsopensource,代碼行數:17,代碼來源:HttpProtocolParent.java

示例12: initInsecureSslHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
private void initInsecureSslHttpClient() throws NoSuchAlgorithmException, KeyManagementException,
        KeyStoreException {

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build();
    httpClientBuilder.setSslcontext(sslContext);

    HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

    SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
    RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", sslSocketFactory)
            .build();

    insecureSslClient = httpClientBuilder.build();
}
 
開發者ID:Capoot,項目名稱:build-status-traffic-light,代碼行數:18,代碼來源:SimpleHttpClient.java

示例13: createConnectionRegistry

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
protected Registry<ConnectionSocketFactory> createConnectionRegistry(X509HostnameVerifier x509HostnameVerifier, SSLContextParameters sslContextParams)
    throws GeneralSecurityException, IOException {
    // create the default connection registry to use
    RegistryBuilder<ConnectionSocketFactory> builder = RegistryBuilder.<ConnectionSocketFactory>create();
    builder.register("http", PlainConnectionSocketFactory.getSocketFactory());
    builder.register("http4", PlainConnectionSocketFactory.getSocketFactory());
    if (sslContextParams != null) {
        builder.register("https", new SSLConnectionSocketFactory(sslContextParams.createSSLContext(getCamelContext()), x509HostnameVerifier));
        builder.register("https4", new SSLConnectionSocketFactory(sslContextParams.createSSLContext(getCamelContext()), x509HostnameVerifier));
    } else {
        builder.register("https4", new SSLConnectionSocketFactory(SSLContexts.createDefault(), x509HostnameVerifier));
        builder.register("https", new SSLConnectionSocketFactory(SSLContexts.createDefault(), x509HostnameVerifier));
    }
    return builder.build();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:16,代碼來源:HttpComponent.java

示例14: getSchemeRegistry

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
public static Registry<ConnectionSocketFactory> getSchemeRegistry(final DockerCertificates dc) {
    final SSLConnectionSocketFactory https;
    if (dc == null) {
        https = SSLConnectionSocketFactory.getSocketFactory();
    } else {
        https = new SSLConnectionSocketFactory(dc.sslContext(),
                                               dc.hostnameVerifier());
    }

    final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder
            .<ConnectionSocketFactory>create()
            .register("https", https)
            .register("http",
                      PlainConnectionSocketFactory.getSocketFactory());

    return registryBuilder.build();
}
 
開發者ID:bhaab01,項目名稱:DockerMonitoring,代碼行數:18,代碼來源:DockerMonitor.java

示例15: createInsecureSslHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入依賴的package包/類
private static CloseableHttpClient createInsecureSslHttpClient() throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
    final SSLContext sslContext = new SSLContextBuilder()
            .useProtocol(INSECURE_SSL_PROTOCOL)
            .loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true).build();
    final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());

    final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", PlainConnectionSocketFactory.getSocketFactory())
            .register("https", sslsf)
            .build();
    final HttpClientConnectionManager connectionManager = createConnectionManager(socketFactoryRegistry);

    return HttpClients.custom()
            .setConnectionManager(connectionManager)
            .setSSLSocketFactory(
            sslsf).build();
}
 
開發者ID:SpectraLogic,項目名稱:ds3_java_sdk,代碼行數:18,代碼來源:NetworkClientImpl.java


注:本文中的org.apache.http.conn.socket.PlainConnectionSocketFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。