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


Java Registry類代碼示例

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


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

示例1: getConnctionManager

import org.apache.http.config.Registry; //導入依賴的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

示例2: createConnectionManager

import org.apache.http.config.Registry; //導入依賴的package包/類
public PoolingHttpClientConnectionManager createConnectionManager(final Registry<ConnectionSocketFactory> registry) {
    if(log.isDebugEnabled()) {
        log.debug(String.format("Setup connection pool with registry %s", registry));
    }
    final PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry);
    manager.setMaxTotal(preferences.getInteger("http.connections.total"));
    manager.setDefaultMaxPerRoute(preferences.getInteger("http.connections.route"));
    manager.setValidateAfterInactivity(5000);
    return manager;
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:11,代碼來源:HttpConnectionPoolBuilder.java

示例3: createConnectionManager

import org.apache.http.config.Registry; //導入依賴的package包/類
protected HttpClientConnectionManager createConnectionManager(Registry<ConnectionSocketFactory> registry, int maxTotalConnections, int connectionsPerRoute) {
    // setup the connection live time
    PoolingHttpClientConnectionManager answer = 
        new PoolingHttpClientConnectionManager(registry, null, null, null, getConnectionTimeToLive(), TimeUnit.MILLISECONDS);
    int localMaxTotalConnections = maxTotalConnections;
    if (localMaxTotalConnections == 0) {
        localMaxTotalConnections = getMaxTotalConnections();
    }
    if (localMaxTotalConnections > 0) {
        answer.setMaxTotal(localMaxTotalConnections);
    }
    int localConnectionsPerRoute = connectionsPerRoute;
    if (localConnectionsPerRoute == 0) {
        localConnectionsPerRoute = getConnectionsPerRoute();
    }
    if (localConnectionsPerRoute > 0) {
        answer.setDefaultMaxPerRoute(localConnectionsPerRoute);
    }
    LOG.info("Created ClientConnectionManager " + answer);

    return answer;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:23,代碼來源:HttpComponent.java

示例4: getSslFactoryRegistry

import org.apache.http.config.Registry; //導入依賴的package包/類
private static Registry<ConnectionSocketFactory> getSslFactoryRegistry(String certPath) throws IOException {
    try {
        KeyStore keyStore = KeyStoreUtils.createDockerKeyStore(certPath);

        SSLContext sslContext =
                SSLContexts.custom()
                        .useTLS()
                        .loadKeyMaterial(keyStore, "docker".toCharArray())
                        .loadTrustMaterial(keyStore)
                        .build();

        SSLConnectionSocketFactory sslsf =

                new SSLConnectionSocketFactory(sslContext);
        return RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslsf).build();
    } catch (GeneralSecurityException e) {
        throw new IOException(e);
    }
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:20,代碼來源:JSONClient.java

示例5: init

import org.apache.http.config.Registry; //導入依賴的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

示例6: httpsGet

import org.apache.http.config.Registry; //導入依賴的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

示例7: initPoolingHttpClientManager

import org.apache.http.config.Registry; //導入依賴的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

示例8: getCustomClient

import org.apache.http.config.Registry; //導入依賴的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

示例9: createSocketFactoryRegistry

import org.apache.http.config.Registry; //導入依賴的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

示例10: createHttpClient

import org.apache.http.config.Registry; //導入依賴的package包/類
public static CloseableHttpClient createHttpClient(final int maxRedirects) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
    s_logger.info("Creating new HTTP connection pool and client");
    final Registry<ConnectionSocketFactory> socketFactoryRegistry = createSocketFactoryConfigration();
    final BasicCookieStore cookieStore = new BasicCookieStore();
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
    connManager.setDefaultMaxPerRoute(MAX_ALLOCATED_CONNECTIONS_PER_ROUTE);
    connManager.setMaxTotal(MAX_ALLOCATED_CONNECTIONS);
    final RequestConfig requestConfig = RequestConfig.custom()
                                                     .setCookieSpec(CookieSpecs.DEFAULT)
                                                     .setMaxRedirects(maxRedirects)
                                                     .setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
                                                     .setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
                                                     .setConnectTimeout(DEFAULT_CONNECT_TIMEOUT)
                                                     .build();
    return HttpClientBuilder.create()
                            .setConnectionManager(connManager)
                            .setRedirectStrategy(new LaxRedirectStrategy())
                            .setDefaultRequestConfig(requestConfig)
                            .setDefaultCookieStore(cookieStore)
                            .setRetryHandler(new StandardHttpRequestRetryHandler())
                            .build();
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:23,代碼來源:HttpClientHelper.java

示例11: createConnection

import org.apache.http.config.Registry; //導入依賴的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

示例12: SimpleHttpClient

import org.apache.http.config.Registry; //導入依賴的package包/類
public SimpleHttpClient(final SSLContext sslContext, final int listenPort, final boolean useCompression) {
    HttpClientBuilder builder = HttpClientBuilder.create();
    if (!useCompression) {
        builder.disableContentCompression();
    }
    if (sslContext != null) {
        SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(
                sslContext,
                SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        builder.setSSLSocketFactory(sslConnectionFactory);

        Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("https", sslConnectionFactory)
                .build();
        builder.setConnectionManager(new BasicHttpClientConnectionManager(registry));
        scheme = "https";
    } else {
        scheme = "http";
    }
    this.delegate = builder.build();
    this.listenPort = listenPort;
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:23,代碼來源:SimpleHttpClient.java

示例13: createHttpClient

import org.apache.http.config.Registry; //導入依賴的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

示例14: createConnectionRegistry

import org.apache.http.config.Registry; //導入依賴的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

示例15: testDontTryToAuthenticateEndlessly

import org.apache.http.config.Registry; //導入依賴的package包/類
/**
 * Tests that the client will stop connecting to the server if
 * the server still keep asking for a valid ticket.
 */
@Test
public void testDontTryToAuthenticateEndlessly() throws Exception {
    this.serverBootstrap.registerHandler("*", new PleaseNegotiateService());
    final HttpHost target = start();

    final AuthSchemeProvider nsf = new NegotiateSchemeProviderWithMockGssManager();
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    final Credentials use_jaas_creds = new UseJaasCredentials();
    credentialsProvider.setCredentials(new AuthScope(null, -1, null), use_jaas_creds);

    final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register(AuthSchemes.SPNEGO, nsf)
        .build();
    this.httpclient = HttpClients.custom()
        .setDefaultAuthSchemeRegistry(authSchemeRegistry)
        .setDefaultCredentialsProvider(credentialsProvider)
        .build();

    final String s = "/path";
    final HttpGet httpget = new HttpGet(s);
    final HttpResponse response = this.httpclient.execute(target, httpget);
    EntityUtils.consume(response.getEntity());

    Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:30,代碼來源:TestSPNegoScheme.java


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