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


Java PlainConnectionSocketFactory.getSocketFactory方法代碼示例

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


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

示例1: 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

示例2: createHttpClientConnectionManager

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
/**
 * Create connection manager for http client.
 *
 * @return The connection manager for http client.
 */
private HttpClientConnectionManager createHttpClientConnectionManager() {
    ConnectionSocketFactory socketFactory = PlainConnectionSocketFactory.getSocketFactory();
    LayeredConnectionSocketFactory sslSocketFactory;
    try {
        sslSocketFactory = new SSLConnectionSocketFactory(SSLContext.getDefault(),
                SSLConnectionSocketFactory.STRICT_HOSTNAME_VERIFIER);
    } catch (NoSuchAlgorithmException e) {
        throw new BceClientException("Fail to create SSLConnectionSocketFactory", e);
    }
    Registry<ConnectionSocketFactory> registry =
            RegistryBuilder.<ConnectionSocketFactory>create().register(Protocol.HTTP.toString(), socketFactory)
                    .register(Protocol.HTTPS.toString(), sslSocketFactory).build();
    PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
    connectionManager.setDefaultMaxPerRoute(this.config.getMaxConnections());
    connectionManager
            .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(this.config.getSocketTimeoutInMillis())
                    .setTcpNoDelay(true).build());
    connectionManager.setMaxTotal(this.config.getMaxConnections());
    return connectionManager;
}
 
開發者ID:baidubce,項目名稱:bce-sdk-java,代碼行數:26,代碼來源:BceHttpClient.java

示例3: buildHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
/**
 * Build a HTTP client based on the current properties.
 *
 * @return the built HTTP client
 */
private CloseableHttpClient buildHttpClient() {
    try {

        final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;

        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", plainsf)
                .register("https", sslsf)
                .build();

        final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
        connMgmr.setMaxTotal(this.maxPooledConnections);
        connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
        connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);

        final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
        final HttpRoute httpRoute = new HttpRoute(httpHost);
        connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);

        final RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(this.readTimeout)
                .setConnectTimeout(this.connectionTimeout)
                .setConnectionRequestTimeout(this.connectionTimeout)
                .setCircularRedirectsAllowed(this.circularRedirectsAllowed)
                .setRedirectsEnabled(this.redirectsEnabled)
                .setAuthenticationEnabled(this.authenticationEnabled)
                .build();


        final HttpClientBuilder builder = HttpClients.custom()
                .setConnectionManager(connMgmr)
                .setDefaultRequestConfig(requestConfig)
                .setSSLSocketFactory(sslsf)
                .setSSLHostnameVerifier(this.hostnameVerifier)
                .setRedirectStrategy(this.redirectionStrategy)
                .setDefaultCredentialsProvider(this.credentialsProvider)
                .setDefaultCookieStore(this.cookieStore)
                .setConnectionReuseStrategy(this.connectionReuseStrategy)
                .setConnectionBackoffStrategy(this.connectionBackoffStrategy)
                .setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
                .setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
                .setDefaultHeaders(this.defaultHeaders)
                .useSystemProperties();

        return builder.build();

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:58,代碼來源:SimpleHttpClientFactoryBean.java

示例4: buildHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
/**
 * Build a HTTP client based on the current properties.
 *
 * @return the built HTTP client
 */
private CloseableHttpClient buildHttpClient() {
    try {

        final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;

        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", plainsf)
                .register("https", sslsf)
                .build();

        final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
        connMgmr.setMaxTotal(this.maxPooledConnections);
        connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);
        connMgmr.setValidateAfterInactivity(DEFAULT_TIMEOUT);

        final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
        final HttpRoute httpRoute = new HttpRoute(httpHost);
        connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);

        final RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(this.readTimeout)
                .setConnectTimeout(Long.valueOf(this.connectionTimeout).intValue())
                .setConnectionRequestTimeout(Long.valueOf(this.connectionTimeout).intValue())
                .setCircularRedirectsAllowed(this.circularRedirectsAllowed)
                .setRedirectsEnabled(this.redirectsEnabled)
                .setAuthenticationEnabled(this.authenticationEnabled)
                .build();


        final HttpClientBuilder builder = HttpClients.custom()
                .setConnectionManager(connMgmr)
                .setDefaultRequestConfig(requestConfig)
                .setSSLSocketFactory(sslsf)
                .setSSLHostnameVerifier(this.hostnameVerifier)
                .setRedirectStrategy(this.redirectionStrategy)
                .setDefaultCredentialsProvider(this.credentialsProvider)
                .setDefaultCookieStore(this.cookieStore)
                .setConnectionReuseStrategy(this.connectionReuseStrategy)
                .setConnectionBackoffStrategy(this.connectionBackoffStrategy)
                .setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
                .setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
                .setDefaultHeaders(this.defaultHeaders)
                .useSystemProperties();

        return builder.build();

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw Throwables.propagate(e);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:58,代碼來源:SimpleHttpClientFactoryBean.java

示例5: createHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
private static CloseableHttpClient createHttpClient(int maxTotal, int maxPerRoute, int maxRoute, 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);

    // 請求重試處理
    HttpRequestRetryHandler httpRequestRetryHandler = (exception, executionCount, context) -> {
        if (executionCount >= 5) {// 如果已經重試了5次,就放棄
            return false;
        }
        if (exception instanceof NoHttpResponseException) {// 如果服務器丟掉了連接,那麽就重試
            return true;
        }
        if (exception instanceof SSLHandshakeException) {// 不要重試SSL握手異常
            return false;
        }
        if (exception instanceof InterruptedIOException) {// 超時
            return false;
        }
        if (exception instanceof UnknownHostException) {// 目標服務器不可達
            return false;
        }
        if (exception instanceof ConnectTimeoutException) {// 連接被拒絕
            return false;
        }
        if (exception instanceof SSLException) {// SSL握手異常
            return false;
        }

        HttpClientContext clientContext = HttpClientContext.adapt(context);
        HttpRequest request = clientContext.getRequest();
        // 如果請求是冪等的,就再次嘗試
        if (!(request instanceof HttpEntityEnclosingRequest)) {
            return true;
        }
        return false;
    };

    CloseableHttpClient httpClient = HttpClients.custom()
            .setConnectionManager(cm)
            .setRetryHandler(httpRequestRetryHandler)
            .build();

    return httpClient;
}
 
開發者ID:Evan1120,項目名稱:wechat-api-java,代碼行數:64,代碼來源:HttpRequestUtil.java

示例6: createHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
public static CloseableHttpClient createHttpClient() {
    ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
    ConnectionSocketFactory sslsf = new EasySSLConnectionSocketFactory();
    //SSLConnectionSocketFactory.getSocketFactory();
    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", plainsf)
            .register("https", sslsf)
            .build();
    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
    // 將最大連接數增加到200
    cm.setMaxTotal(200);
    // 將每個路由基礎的連接增加到20
    cm.setDefaultMaxPerRoute(20);
    //請求重試處理
    HttpRequestRetryHandler httpRequestRetryHandler = new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            if (executionCount >= 5) {// 如果已經重試了5次,就放棄
                return false;
            }
            if (exception instanceof NoHttpResponseException) {// 如果服務器丟掉了連接,那麽就重試
                return true;
            }
            if (exception instanceof SSLHandshakeException) {// 不要重試SSL握手異常
                return false;
            }
            if (exception instanceof InterruptedIOException) {// 超時
                return false;
            }
            if (exception instanceof UnknownHostException) {// 目標服務器不可達
                return false;
            }
            if (exception instanceof ConnectTimeoutException) {// 連接被拒絕
                return false;
            }
            if (exception instanceof SSLException) {// ssl握手異常
                return false;
            }

            HttpClientContext clientContext = HttpClientContext.adapt(context);
            HttpRequest request = clientContext.getRequest();
            // 如果請求是冪等的,就再次嘗試
            if (!(request instanceof HttpEntityEnclosingRequest)) {
                return true;
            }
            return false;
        }
    };
    CloseableHttpClient httpClient =  HttpClients.custom()
            .setConnectionManager(cm)
            .setRetryHandler(httpRequestRetryHandler)
            .build();
    return httpClient;

}
 
開發者ID:1991wangliang,項目名稱:lorne_core,代碼行數:55,代碼來源:HttpClientFactory.java

示例7: createHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
public CloseableHttpClient createHttpClient(int maxTotal, int maxPerRoute, int maxRoute,
                                                   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);

    // 請求重試處理
    HttpRequestRetryHandler httpRequestRetryHandler = new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception,
                                    int executionCount, HttpContext context) {
            if (executionCount >= _maxRetryTimes) {
                return false;
            }
            if (exception instanceof NoHttpResponseException) {// 如果服務器丟掉了連接,那麽就重試
                return true;
            }
            if (exception instanceof SSLHandshakeException) {// 不要重試SSL握手異常
                return false;
            }
            if (exception instanceof InterruptedIOException) {// 超時
                return false;
            }
            if (exception instanceof UnknownHostException) {// 目標服務器不可達
                return false;
            }
            if (exception instanceof ConnectTimeoutException) {// 連接被拒絕
                return false;
            }
            if (exception instanceof SSLException) {// SSL握手異常
                return false;
            }

            HttpClientContext clientContext = HttpClientContext
                    .adapt(context);
            HttpRequest request = clientContext.getRequest();
            // 如果請求是冪等的,就再次嘗試
            if (!(request instanceof HttpEntityEnclosingRequest)) {
                return true;
            }
            return false;
        }
    };

    CloseableHttpClient httpClient = HttpClients.custom()
            .setConnectionManager(cm)
            .setRetryHandler(httpRequestRetryHandler).build();

    return httpClient;

}
 
開發者ID:jpush,項目名稱:jiguang-java-client-common,代碼行數:64,代碼來源:ApacheHttpClient.java

示例8: httpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
@Bean
public HttpClient httpClient() {
	LOG.info("Using development (trust-self-signed) http client");

	try {
		ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
		SSLContext sslContext = SSLContexts.custom()
				.loadTrustMaterial(null, new TrustSelfSignedStrategy())
				.build();
		LayeredConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
		Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create()
		        .register("http", plainsf)
		        .register("https", sslsf)
		        .build();

		HttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(r);

		RequestConfig requestConfig = RequestConfig
				.custom()
				.setSocketTimeout(30000)
				.setConnectTimeout(30000)
				.setTargetPreferredAuthSchemes(ImmutableList.of(AuthSchemes.BASIC))
				.setProxyPreferredAuthSchemes(ImmutableList.of(AuthSchemes.BASIC)).build();

		CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
		credentialsProvider.setCredentials(AuthScope.ANY, getUsernamePasswordCredentials());
		
		
		return HttpClients.custom().setConnectionManager(cm)
				.setDefaultCredentialsProvider(credentialsProvider)
				.setDefaultRequestConfig(requestConfig).build();
	} catch (Exception e) {
		throw new RuntimeException("Cannot build HttpClient using self signed certificate", e);
	}
}
 
開發者ID:cloudfoundry-incubator,項目名稱:apache-brooklyn-service-broker,代碼行數:36,代碼來源:HttpClientConfig.java

示例9: createHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
public void createHttpClient()
{
  PlainConnectionSocketFactory sf = PlainConnectionSocketFactory.getSocketFactory();
  SSLContext sslContext = SSLContexts.createSystemDefault();
  SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
    sslContext, 
    NoopHostnameVerifier.INSTANCE);
  
  Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create()
          .register("http", sf)
          .register("https", sslsf)
          .build();
  
  this.cm = new PoolingHttpClientConnectionManager(r);
}
 
開發者ID:ot4i,項目名稱:splunk-log-connector,代碼行數:16,代碼來源:SplunkHttpConnection.java

示例10: createHttpClientInfo

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
public HttpClientInfo createHttpClientInfo() {
	
	SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslctx,new AllowAllHostnameVerifier());
	PlainConnectionSocketFactory sf = PlainConnectionSocketFactory.getSocketFactory();
	Registry<ConnectionSocketFactory> r = RegistryBuilder.<ConnectionSocketFactory>create()
	        .register("http", sf)
	        .register("https", sslsf)
	        .build();
	
	RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).setRedirectsEnabled(true).build();
	
	PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(r);
	
	return new HttpClientInfo(cm,globalConfig);
}
 
開發者ID:TremoloSecurityRetired,項目名稱:Scale,代碼行數:16,代碼來源:ScaleCommonConfig.java

示例11: getConnectionManager

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
public static HttpClientConnectionManager getConnectionManager() {

        // ConnectionSocketFactory plainsf = null;
        LayeredConnectionSocketFactory sslsf = null;

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

        PlainConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        registryBuilder.register("http", plainsf);

        try {

            // Trust own CA and all self-signed certs
            SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new TrustStrategy() {
                @Override
                public boolean isTrusted(X509Certificate[] chain, String authType)
                        throws CertificateException {
                    return true;
                }
            }).build();

            HostnameVerifier allowAllHostnameVerifier = NoopHostnameVerifier.INSTANCE;
            sslsf = new SSLConnectionSocketFactory(sslcontext, allowAllHostnameVerifier);

            registryBuilder.register("https", sslsf);

        } catch (Throwable e) {

            logger.error("https ssl init failed", e);
        }

        Registry<ConnectionSocketFactory> r = registryBuilder.build();

        PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(r);
        connManager.setMaxTotal(100);// 連接池最大並發連接數
        connManager.setDefaultMaxPerRoute(100);// 單路由最大並發數
        return connManager;

    }
 
開發者ID:jiucai,項目名稱:appframework,代碼行數:40,代碼來源:HttpClientUtil.java

示例12: buildHttpClient

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
/**
 * Build a HTTP client based on the current properties.
 *
 * @return the built HTTP client
 */
private CloseableHttpClient buildHttpClient() {
    try {

        final ConnectionSocketFactory plainsf = PlainConnectionSocketFactory.getSocketFactory();
        final LayeredConnectionSocketFactory sslsf = this.sslSocketFactory;

        final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                .register("http", plainsf)
                .register("https", sslsf)
                .build();

        final PoolingHttpClientConnectionManager connMgmr = new PoolingHttpClientConnectionManager(registry);
        connMgmr.setMaxTotal(this.maxPooledConnections);
        connMgmr.setDefaultMaxPerRoute(this.maxConnectionsPerRoute);

        final HttpHost httpHost = new HttpHost(InetAddress.getLocalHost());
        final HttpRoute httpRoute = new HttpRoute(httpHost);
        connMgmr.setMaxPerRoute(httpRoute, MAX_CONNECTIONS_PER_ROUTE);

        final RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(this.readTimeout)
                .setConnectTimeout(this.connectionTimeout)
                .setConnectionRequestTimeout(this.connectionTimeout)
                .setStaleConnectionCheckEnabled(true)
                .setCircularRedirectsAllowed(this.circularRedirectsAllowed)
                .setRedirectsEnabled(this.redirectsEnabled)
                .setAuthenticationEnabled(this.authenticationEnabled)
                .build();


        final HttpClientBuilder builder = HttpClients.custom()
                .setConnectionManager(connMgmr)
                .setDefaultRequestConfig(requestConfig)
                .setSSLSocketFactory(sslsf)
                .setSSLHostnameVerifier(this.hostnameVerifier)
                .setRedirectStrategy(this.redirectionStrategy)
                .setDefaultCredentialsProvider(this.credentialsProvider)
                .setDefaultCookieStore(this.cookieStore)
                .setConnectionReuseStrategy(this.connectionReuseStrategy)
                .setConnectionBackoffStrategy(this.connectionBackoffStrategy)
                .setServiceUnavailableRetryStrategy(this.serviceUnavailableRetryStrategy)
                .setProxyAuthenticationStrategy(this.proxyAuthenticationStrategy)
                .setDefaultHeaders(this.defaultHeaders)
                .useSystemProperties();

        return builder.build();

    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:58,代碼來源:SimpleHttpClientFactoryBean.java

示例13: testAbortDuringConnecting

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
@Test
public void testAbortDuringConnecting() throws Exception {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
            connectLatch, WaitPolicy.BEFORE_CONNECT, PlainConnectionSocketFactory.getSocketFactory());
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", stallingSocketFactory)
        .build();

    this.connManager = new PoolingHttpClientConnectionManager(registry);
    this.clientBuilder.setConnectionManager(this.connManager);

    this.connManager.setMaxTotal(1);

    final HttpHost target = start();
    final HttpRoute route = new HttpRoute(target, null, false);
    final HttpContext context = new BasicHttpContext();

    final HttpClientConnection conn = getConnection(this.connManager, route);

    final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
    final Thread abortingThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                stallingSocketFactory.waitForState();
                conn.shutdown();
                connManager.releaseConnection(conn, null, -1, null);
                connectLatch.countDown();
            } catch (final Throwable e) {
                throwRef.set(e);
            }
        }
    });
    abortingThread.start();

    try {
        this.connManager.connect(conn, route, 0, context);
        this.connManager.routeComplete(conn, route, context);
        Assert.fail("expected SocketException");
    } catch(final SocketException expected) {}

    abortingThread.join(5000);
    if(throwRef.get() != null) {
        throw new RuntimeException(throwRef.get());
    }

    Assert.assertFalse(conn.isOpen());

    // the connection is expected to be released back to the manager
    final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
    Assert.assertFalse("connection should have been closed", conn2.isOpen());

    this.connManager.releaseConnection(conn2, null, -1, null);
    this.connManager.shutdown();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:57,代碼來源:TestConnectionManagement.java

示例14: testAbortBeforeSocketCreate

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
@Test
public void testAbortBeforeSocketCreate() throws Exception {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
            connectLatch, WaitPolicy.BEFORE_CREATE, PlainConnectionSocketFactory.getSocketFactory());
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", stallingSocketFactory)
        .build();

    this.connManager = new PoolingHttpClientConnectionManager(registry);
    this.clientBuilder.setConnectionManager(this.connManager);

    this.connManager.setMaxTotal(1);

    final HttpHost target = start();
    final HttpRoute route = new HttpRoute(target, null, false);
    final HttpContext context = new BasicHttpContext();

    final HttpClientConnection conn = getConnection(this.connManager, route);

    final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
    final Thread abortingThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                stallingSocketFactory.waitForState();
                conn.shutdown();
                connManager.releaseConnection(conn, null, -1, null);
                connectLatch.countDown();
            } catch (final Throwable e) {
                throwRef.set(e);
            }
        }
    });
    abortingThread.start();

    try {
        this.connManager.connect(conn, route, 0, context);
        this.connManager.routeComplete(conn, route, context);
        Assert.fail("IOException expected");
    } catch(final IOException expected) {
    }

    abortingThread.join(5000);
    if(throwRef.get() != null) {
        throw new RuntimeException(throwRef.get());
    }

    Assert.assertFalse(conn.isOpen());

    // the connection is expected to be released back to the manager
    final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
    Assert.assertFalse("connection should have been closed", conn2.isOpen());

    this.connManager.releaseConnection(conn2, null, -1, null);
    this.connManager.shutdown();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:58,代碼來源:TestConnectionManagement.java

示例15: testAbortAfterSocketConnect

import org.apache.http.conn.socket.PlainConnectionSocketFactory; //導入方法依賴的package包/類
@Test
public void testAbortAfterSocketConnect() throws Exception {
    final CountDownLatch connectLatch = new CountDownLatch(1);
    final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
            connectLatch, WaitPolicy.AFTER_CONNECT, PlainConnectionSocketFactory.getSocketFactory());
    final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
        .register("http", stallingSocketFactory)
        .build();

    this.connManager = new PoolingHttpClientConnectionManager(registry);
    this.clientBuilder.setConnectionManager(this.connManager);

    this.connManager.setMaxTotal(1);

    final HttpHost target = start();
    final HttpRoute route = new HttpRoute(target, null, false);
    final HttpContext context = new BasicHttpContext();

    final HttpClientConnection conn = getConnection(this.connManager, route);

    final AtomicReference<Throwable> throwRef = new AtomicReference<Throwable>();
    final Thread abortingThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                stallingSocketFactory.waitForState();
                conn.shutdown();
                connManager.releaseConnection(conn, null, -1, null);
                connectLatch.countDown();
            } catch (final Throwable e) {
                throwRef.set(e);
            }
        }
    });
    abortingThread.start();

    try {
        this.connManager.connect(conn, route, 0, context);
        this.connManager.routeComplete(conn, route, context);
        Assert.fail("IOException expected");
    } catch(final IOException expected) {
    }

    abortingThread.join(5000);
    if(throwRef.get() != null) {
        throw new RuntimeException(throwRef.get());
    }

    Assert.assertFalse(conn.isOpen());

    // the connection is expected to be released back to the manager
    final HttpClientConnection conn2 = getConnection(this.connManager, route, 5L, TimeUnit.SECONDS);
    Assert.assertFalse("connection should have been closed", conn2.isOpen());

    this.connManager.releaseConnection(conn2, null, -1, null);
    this.connManager.shutdown();
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:58,代碼來源:TestConnectionManagement.java


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