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


Java HttpAsyncClientBuilder類代碼示例

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


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

示例1: FiberApacheHttpClientRequestExecutor

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
public FiberApacheHttpClientRequestExecutor(final Validator<CloseableHttpResponse> resValidator, final int maxConnections, final int timeout, final int parallelism) throws IOReactorException {
  final DefaultConnectingIOReactor ioreactor = new DefaultConnectingIOReactor(IOReactorConfig.custom().
    setConnectTimeout(timeout).
    setIoThreadCount(parallelism).
    setSoTimeout(timeout).
    build());

  final PoolingNHttpClientConnectionManager mngr = new PoolingNHttpClientConnectionManager(ioreactor);
  mngr.setDefaultMaxPerRoute(maxConnections);
  mngr.setMaxTotal(maxConnections);

  final CloseableHttpAsyncClient ahc = HttpAsyncClientBuilder.create().
    setConnectionManager(mngr).
    setDefaultRequestConfig(RequestConfig.custom().setLocalAddress(null).build()).build();

  client = new FiberHttpClient(ahc);
  validator = resValidator;
}
 
開發者ID:pinterest,項目名稱:jbender,代碼行數:19,代碼來源:FiberApacheHttpClientRequestExecutor.java

示例2: sourceWithMockedClient

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
private RemoteScrollableHitSource sourceWithMockedClient(boolean mockRemoteVersion, CloseableHttpAsyncClient httpClient)
        throws Exception {
    HttpAsyncClientBuilder clientBuilder = mock(HttpAsyncClientBuilder.class);
    when(clientBuilder.build()).thenReturn(httpClient);

    RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200))
            .setHttpClientConfigCallback(httpClientBuilder -> clientBuilder).build();

    TestRemoteScrollableHitSource hitSource = new TestRemoteScrollableHitSource(restClient) {
        @Override
        void lookupRemoteVersion(Consumer<Version> onVersion) {
            if (mockRemoteVersion) {
                onVersion.accept(Version.CURRENT);
            } else {
                super.lookupRemoteVersion(onVersion);
            }
        }
    };
    if (mockRemoteVersion) {
        hitSource.remoteVersion = Version.CURRENT;
    }
    return hitSource;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:RemoteScrollableHitSourceTests.java

示例3: createHttpClient

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
private CloseableHttpAsyncClient createHttpClient() {
    //default timeouts are all infinite
    RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
            .setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS)
            .setSocketTimeout(DEFAULT_SOCKET_TIMEOUT_MILLIS)
            .setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT_MILLIS);
    if (requestConfigCallback != null) {
        requestConfigBuilder = requestConfigCallback.customizeRequestConfig(requestConfigBuilder);
    }

    HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create().setDefaultRequestConfig(requestConfigBuilder.build())
            //default settings for connection pooling may be too constraining
            .setMaxConnPerRoute(DEFAULT_MAX_CONN_PER_ROUTE).setMaxConnTotal(DEFAULT_MAX_CONN_TOTAL);
    if (httpClientConfigCallback != null) {
        httpClientBuilder = httpClientConfigCallback.customizeHttpClient(httpClientBuilder);
    }
    return httpClientBuilder.build();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:RestClientBuilder.java

示例4: ElasticBulkSender

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
public ElasticBulkSender(String user, String password, HttpHost... hosts) {
	this.user = user;
	this.password = password;
	this.hosts = hosts;
	this.restClient = RestClient.builder(hosts)
			.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
				@Override
				public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
					if (!Strings.isBlank(user)) {
						CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
						credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password));
		                return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
					} else {
						return httpClientBuilder;
					}
				}
	        })
			.build();
}
 
開發者ID:magrossi,項目名稱:es-log4j2-appender,代碼行數:20,代碼來源:ElasticBulkSender.java

示例5: setUp

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    /**
     * 如果es集群安裝了x-pack插件則以此種方式連接集群
     * 1. java客戶端的方式是以tcp協議在9300端口上進行通信
     * 2. http客戶端的方式是以http協議在9200端口上進行通信
     */
    Settings settings = Settings.builder(). put("xpack.security.user", "elastic:changeme").build();
    client = new PreBuiltXPackTransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    elasticsearchTemplate = new ElasticsearchTemplate(client);
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("elastic", "changeme"));
    restClient = RestClient.builder(new HttpHost("localhost",9200,"http"))
            .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                @Override
                public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                    return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                }
            }).build();
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:23,代碼來源:XPackBaseDemo.java

示例6: createCloseableHttpAsyncClient

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
private CloseableHttpAsyncClient createCloseableHttpAsyncClient() throws Exception {
        HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create();
        builder.useSystemProperties();
        builder.setSSLContext(SSLContext.getDefault());
        builder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
        builder.setMaxConnPerRoute(2);
        builder.setMaxConnTotal(2);
        builder.setDefaultRequestConfig(RequestConfig
            .custom()
            .setConnectionRequestTimeout(1000)
            .setConnectTimeout(2000)
            .setSocketTimeout(2000)
        .build()
        );
//        builder.setHttpProcessor()
        CloseableHttpAsyncClient hc = builder.build();
        hc.start();
        return hc;
    }
 
開發者ID:eeichinger,項目名稱:jcurl,代碼行數:20,代碼來源:HCNIOEngine.java

示例7: open

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
private void open() {
   if (open) {
      // Ignore
      return;
   }

   final HttpAsyncClientBuilder builder = HttpAsyncClients.custom()
         .setMaxConnPerRoute(1000)
         .setMaxConnTotal(1000)
         .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy())
         .setThreadFactory(threadFactory);
   if (credentialsProvider != null) {
      builder.setDefaultCredentialsProvider(credentialsProvider);
   }

   httpclient = builder.build();
   httpclient.start();
   this.open = true;
}
 
開發者ID:Qyotta,項目名稱:axon-eventstore,代碼行數:20,代碼來源:ESHttpEventStore.java

示例8: defaultSettingsOfHttpAsyncClientLostOnExecutorCustomization

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
@Test
public void defaultSettingsOfHttpAsyncClientLostOnExecutorCustomization() throws Exception {
	CloseableHttpAsyncClient client = HttpAsyncClientBuilder.create()
			.setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(1234).build())
			.build();
	HttpComponentsAsyncClientHttpRequestFactory factory = new HttpComponentsAsyncClientHttpRequestFactory(client);

	URI uri = new URI(baseUrl + "/status/ok");
	HttpComponentsAsyncClientHttpRequest request = (HttpComponentsAsyncClientHttpRequest)
			factory.createAsyncRequest(uri, HttpMethod.GET);

	assertNull("No custom config should be set with a custom HttpClient",
			request.getHttpContext().getAttribute(HttpClientContext.REQUEST_CONFIG));

	factory.setConnectionRequestTimeout(4567);
	HttpComponentsAsyncClientHttpRequest request2 = (HttpComponentsAsyncClientHttpRequest)
			factory.createAsyncRequest(uri, HttpMethod.GET);
	Object requestConfigAttribute = request2.getHttpContext().getAttribute(HttpClientContext.REQUEST_CONFIG);
	assertNotNull(requestConfigAttribute);
	RequestConfig requestConfig = (RequestConfig) requestConfigAttribute;

	assertEquals(4567, requestConfig.getConnectionRequestTimeout());
	// No way to access the request config of the HTTP client so no way to "merge" our customizations
	assertEquals(-1, requestConfig.getConnectTimeout());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:HttpComponentsAsyncClientHttpRequestFactoryTests.java

示例9: newHttpAsyncClient

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
/**
 * Creates an asynchronous HTTP client configuration with default timeouts.
 *
 * @see #newHttpAsyncClient(boolean)
 */
protected static CloseableHttpAsyncClient newHttpAsyncClient(boolean useSSL) {
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(DEFAULT_SOCKET_TIMEOUT)
            .setConnectTimeout(DEFAULT_CONNECT_TIMEOUT).build();

    HttpAsyncClientBuilder builder = HttpAsyncClients.custom();

    if (useSSL) {
        try {
            SSLContext context = SSLContext.getInstance("SSL");
            context.init(null, new TrustManager[]{new TrustAllX509Manager()}, new SecureRandom());

            SSLIOSessionStrategy strategy = new SSLIOSessionStrategy(context,
                    SSLIOSessionStrategy.getDefaultHostnameVerifier());

            builder.setSSLStrategy(strategy);
        } catch (Exception e) {
            log.error("Failed initializing SSL context! Skipped.", e);
        }
    }

    return builder.setDefaultRequestConfig(requestConfig).build();
}
 
開發者ID:vexelon-dot-net,項目名稱:currencybg.server,代碼行數:28,代碼來源:AbstractSource.java

示例10: getAsyncProxyHttpClient

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
private CloseableHttpAsyncClient getAsyncProxyHttpClient(URI proxyUri) {
  LOG.info("Creating async proxy http client");
  PoolingNHttpClientConnectionManager cm = getAsyncConnectionManager();
  HttpHost proxy = new HttpHost(proxyUri.getHost(), proxyUri.getPort());
  
  HttpAsyncClientBuilder clientBuilder = HttpAsyncClients.custom();
  if (cm != null) {
    clientBuilder = clientBuilder.setConnectionManager(cm);
  }

  if (proxy != null) {
    clientBuilder = clientBuilder.setProxy(proxy);
  }
  clientBuilder = setRedirects(clientBuilder);
  return clientBuilder.build();
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:17,代碼來源:HttpProxyClient.java

示例11: setRedirects

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
private HttpAsyncClientBuilder setRedirects(HttpAsyncClientBuilder clientBuilder) {
  clientBuilder.setRedirectStrategy(new DefaultRedirectStrategy() {
    /** Redirectable methods. */
    private String[] REDIRECT_METHODS = new String[] { 
      HttpGet.METHOD_NAME, HttpPost.METHOD_NAME, 
      HttpPut.METHOD_NAME, HttpDelete.METHOD_NAME, HttpHead.METHOD_NAME 
    };

    @Override
    protected boolean isRedirectable(String method) {
      for (String m : REDIRECT_METHODS) {
        if (m.equalsIgnoreCase(method)) {
          return true;
        }
      }
      return false;
    }
  });
  return clientBuilder;
}
 
開發者ID:apache,項目名稱:zeppelin,代碼行數:21,代碼來源:HttpProxyClient.java

示例12: QueryExecutor

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
private QueryExecutor(String userAgent, ObjectMapper mapper, HttpHost proxy)
{
    checkNotNull(userAgent, "userAgent is null");
    checkNotNull(mapper, "mapper is null");

    this.userAgent = userAgent;
    this.mapper = mapper;

    HttpClientBuilder builder = HttpClients.custom();
    HttpAsyncClientBuilder asyncBuilder = HttpAsyncClients.custom();

    if (proxy != null) {
        DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
        builder.setRoutePlanner(routePlanner);
        asyncBuilder.setRoutePlanner(routePlanner);
    }

    this.httpClient = asyncBuilder.build();
    this.httpClient.start();
}
 
開發者ID:prestodb,項目名稱:presto-jdbc-java6,代碼行數:21,代碼來源:QueryExecutor.java

示例13: defaultClientBuilder

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
/**
 * Used internally to initialize the internal HTTP client used by all
 * instances of a client.
 * <p>
 * This method can be overriden to provide a client with different options.
 * The client built gets an extra interceptor to add the credentials headers.
 *
 * @return HTTP default async client builder
 */
protected static HttpAsyncClientBuilder defaultClientBuilder() {
  
  try {
    DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
    connMgr = new PoolingNHttpClientConnectionManager(ioReactor);
    connMgr.setMaxTotal(maxConnections);
    connMgr.setDefaultMaxPerRoute(maxConnections);
  } catch (IOReactorException e) {
  }
  
  return HttpAsyncClients
      .custom()
      .addInterceptorLast(new GzipInterceptors.GzipRequestInterceptor())
      .setConnectionManager(connMgr)
      .setDefaultRequestConfig(
          RequestConfig.custom()
          .setSocketTimeout(3600 * 1000) // 1 hour
              .build())
      .setKeepAliveStrategy(keepAliveStrategy);
}
 
開發者ID:Idilia,項目名稱:idilia-java-sdk,代碼行數:30,代碼來源:AsyncClientBase.java

示例14: HttpClient

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
public HttpClient(Auth auth, String apiAddress, int maxConnections) {
    this.auth = auth;
    if(apiAddress != null) {
        this.apiAddress = apiAddress;
    } else {
        this.apiAddress = AlgorithmiaConf.apiAddress();
    }

    client = HttpAsyncClientBuilder.create()
        .setMaxConnTotal(maxConnections)
        .setMaxConnPerRoute(maxConnections)
        .useSystemProperties()
        .build();

    synchronized (clients) {
        clients.add(client);
    }
    client.start();
}
 
開發者ID:algorithmiaio,項目名稱:algorithmia-java,代碼行數:20,代碼來源:HttpClient.java

示例15: createClient

import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; //導入依賴的package包/類
/**
 * Creates asynchronous Apache HTTP client.
 *
 * @param settings
 *         settings to use to create client.
 * @param conf
 *         configuration related to async connection.
 * @return Instance of {@link CloseableHttpAsyncClient}.
 */
private CloseableHttpAsyncClient createClient(HttpSettings settings, ApacheHttpClientConfiguration conf) {
    IOReactorConfig ioReactor = IOReactorConfig.custom().setIoThreadCount(conf.getMaxThreadCount()).build();
    HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClients.custom()
            .useSystemProperties()
                    // allow POST redirects
            .setRedirectStrategy(new LaxRedirectStrategy()).setMaxConnTotal(conf.getMaxTotalConnectionCount()).setMaxConnPerRoute(conf.getMaxRouteConnectionCount()).setDefaultIOReactorConfig(ioReactor)
            .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()).setDefaultRequestConfig(createDefaultRequestConfig(settings));
    if (settings.getProxyUrl() != null) {
        DefaultProxyRoutePlanner routePlanner = createProxyRoutePlanner(settings, httpClientBuilder);
        httpClientBuilder.setRoutePlanner(routePlanner);
    }
    CloseableHttpAsyncClient httpClient = httpClientBuilder.build();
    httpClient.start();
    return httpClient;
}
 
開發者ID:guardtime,項目名稱:ksi-java-sdk,代碼行數:25,代碼來源:AbstractApacheHttpClient.java


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