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


Java AsyncHttpClientConfig.Builder方法代碼示例

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


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

示例1: AsyncHttpClientHelper

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
/**
 * Constructor that gives you maximum control over configuration and behavior.
 *
 * @param builder
 *     The builder that will create the {@link #asyncHttpClient} and execute all the async downstream HTTP
 *     requests.
 * @param performSubSpanAroundDownstreamCalls
 *     Pass in true to have a distributed tracing subspan added to each downstream call to measure the time spent
 *     on the downstream call, false if you do not want subspans performed. The subspans can be used to determine
 *     how much time is spent processing in your app vs. waiting for downstream requests.
 */
public AsyncHttpClientHelper(AsyncHttpClientConfig.Builder builder, boolean performSubSpanAroundDownstreamCalls) {
    this.performSubSpanAroundDownstreamCalls = performSubSpanAroundDownstreamCalls;

    Map<String, String> mdcContextMap = MDC.getCopyOfContextMap();
    Deque<Span> distributedTraceStack = null;

    try {
        // We have to unlink tracing and MDC from the current thread before we setup the async http client library,
        //      otherwise all the internal threads it uses to do its job will be attached to the current thread's
        //      trace/MDC info forever and always.
        distributedTraceStack = Tracer.getInstance().unregisterFromThread();
        MDC.clear();
        AsyncHttpClientConfig cf = builder.build();
        asyncHttpClient = new AsyncHttpClient(cf);
    }
    finally {
        // Reattach the original tracing and MDC before we leave
        if (mdcContextMap == null)
            MDC.clear();
        else
            MDC.setContextMap(mdcContextMap);

        Tracer.getInstance().registerWithThread(distributedTraceStack);
    }
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:37,代碼來源:AsyncHttpClientHelper.java

示例2: kitchen_sink_constructor_sets_up_underlying_client_with_expected_config

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
@DataProvider(value = {
    "true",
    "false"
}, splitBy = "\\|")
@Test
public void kitchen_sink_constructor_sets_up_underlying_client_with_expected_config(boolean performSubspan) {
    // given
    int customRequestTimeoutVal = 4242;
    AsyncHttpClientConfig config =
        new AsyncHttpClientConfig.Builder().setRequestTimeout(customRequestTimeoutVal).build();
    AsyncHttpClientConfig.Builder builderMock = mock(AsyncHttpClientConfig.Builder.class);
    doReturn(config).when(builderMock).build();

    // when
    AsyncHttpClientHelper instance = new AsyncHttpClientHelper(builderMock, performSubspan);

    // then
    assertThat(instance.performSubSpanAroundDownstreamCalls).isEqualTo(performSubspan);
    assertThat(instance.asyncHttpClient.getConfig()).isSameAs(config);
    assertThat(instance.asyncHttpClient.getConfig().getRequestTimeout()).isEqualTo(customRequestTimeoutVal);
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:22,代碼來源:AsyncHttpClientHelperTest.java

示例3: MiosUnitConnector

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
/**
 * @param unit
 *            The host to connect to. Give a reachable hostname or IP address, without protocol or port
 */
public MiosUnitConnector(MiosUnit unit, MiosBinding binding) {
	logger.debug("Constructor: unit '{}', binding '{}'", unit, binding);

	this.unit = unit;
	this.binding = binding;

	Builder builder = new AsyncHttpClientConfig.Builder();
	builder.setRequestTimeoutInMs(unit.getTimeout());

	// Use the JDK Provider for now, we're not looking for server-level
	// scalability, and we'd like to lighten the load for folks wanting to
	// run atop RPi units.
	this.client = new AsyncHttpClient(new JDKAsyncHttpProvider(builder.build()));

	pollCall = new LongPoll();
	pollThread = new Thread(pollCall);
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:22,代碼來源:MiosUnitConnector.java

示例4: customize

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
@Override
public AsyncHttpClientConfig.Builder customize(
    Client client, Configuration config, AsyncHttpClientConfig.Builder configBuilder
) {
  if (useProxy && !StringUtils.isEmpty(username)) {
    Realm realm = new Realm.RealmBuilder().setScheme(Realm.AuthScheme.BASIC)
        .setUsePreemptiveAuth(true)
        .setTargetProxy(true)
        .setPrincipal(username)
        .setPassword(password)
        .build();

    configBuilder.setRealm(realm);
  }
  return configBuilder;
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:17,代碼來源:GrizzlyClientCustomizer.java

示例5: build

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
/**
 * Creates new HttpClient from the configuration set
 *
 * @return new HttpClient instance
 */
public HttpClient build() {

  final AsyncHttpClientConfig.Builder configBuilder = new AsyncHttpClientConfig.Builder().
    setConnectTimeout(connectionTimeout).
    setMaxRequestRetry(retries).
    setRequestTimeout(requestTimeout).
    setCompressionEnforced(compressionEnforced).
    setDisableUrlEncodingForBoundedRequests(disableUrlEncoding).
    setMaxConnectionsPerHost(maxConnectionsPerHost).
    setMaxConnections(maxTotalConnections).
    setAsyncHttpClientProviderConfig(NettyConfigHolder.INSTANCE).
    setFollowRedirect(followRedirect).
    setAcceptAnyCertificate(acceptAnySslCertificate);

  if (readTimeout != null) {
    configBuilder.setReadTimeout(readTimeout);
  }

  return new HttpClient(new AsyncHttpClient(configBuilder.build()), responseMaxSize, marshallingStrategy);
}
 
開發者ID:outbrain,項目名稱:ob1k,代碼行數:26,代碼來源:HttpClient.java

示例6: TestCaseExecutorUtil

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
public TestCaseExecutorUtil(AcceptanceTestContext context)
{
	int numConcurrentConns = context.getGatfExecutorConfig().getNumConcurrentExecutions();
	if(context.getGatfExecutorConfig().getConcurrentUserSimulationNum()!=null) {
		numConcurrentConns = context.getGatfExecutorConfig().getConcurrentUserSimulationNum();
	}
	
	int maxConns = numConcurrentConns>100?numConcurrentConns:100;
	
	Builder builder = new AsyncHttpClientConfig.Builder();
	builder.setConnectionTimeoutInMs(context.getGatfExecutorConfig().getHttpConnectionTimeout())
			.setMaximumConnectionsPerHost(numConcurrentConns)
			.setMaximumConnectionsTotal(maxConns)
			.setRequestTimeoutInMs(context.getGatfExecutorConfig().getHttpRequestTimeout())
			.setAllowPoolingConnection(true)
			.setCompressionEnabled(context.getGatfExecutorConfig().isHttpCompressionEnabled())
			.setIOThreadMultiplier(2)
			.build();
	
	client = new AsyncHttpClient(builder.build());
	this.context = context;
}
 
開發者ID:sumeetchhetri,項目名稱:gatf,代碼行數:23,代碼來源:TestCaseExecutorUtil.java

示例7: getSingleConnection

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
public static TestCaseExecutorUtil getSingleConnection(AcceptanceTestContext context)
{
	int maxConns = 1;
	
	Builder builder = new AsyncHttpClientConfig.Builder();
	builder.setConnectionTimeoutInMs(10000)
			.setMaximumConnectionsPerHost(1)
			.setMaximumConnectionsTotal(maxConns)
			.setRequestTimeoutInMs(100000)
			.setAllowPoolingConnection(true)
			.setCompressionEnabled(false)
			.setIOThreadMultiplier(2)
			.build();
	
	TestCaseExecutorUtil util = new TestCaseExecutorUtil();
	util.client = new AsyncHttpClient(builder.build());
	util.context = context;
	return util;
}
 
開發者ID:sumeetchhetri,項目名稱:gatf,代碼行數:20,代碼來源:TestCaseExecutorUtil.java

示例8: MiosUnitConnector

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
/**
 * @param unit
 *            The host to connect to. Give a reachable hostname or IP address, without protocol or port
 */
public MiosUnitConnector(MiosUnit unit, MiosBinding binding) {
    logger.debug("Constructor: unit '{}', binding '{}'", unit, binding);

    this.unit = unit;
    this.binding = binding;

    Builder builder = new AsyncHttpClientConfig.Builder();
    builder.setRequestTimeoutInMs(unit.getTimeout());

    // Use the JDK Provider for now, we're not looking for server-level
    // scalability, and we'd like to lighten the load for folks wanting to
    // run atop RPi units.
    this.client = new AsyncHttpClient(new JDKAsyncHttpProvider(builder.build()));

    pollCall = new LongPoll();
    pollThread = new Thread(pollCall);
}
 
開發者ID:openhab,項目名稱:openhab1-addons,代碼行數:22,代碼來源:MiosUnitConnector.java

示例9: createClient

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
/**
 * Creates a AsyncHttpClient object that can be used for talking to elasticsearch
 *
 * @param configuration The configuration object containing properties for configuring the http connections
 * @param numberOfHostsBeingConnectedTo the number of hosts that are currently known about in the es cluster
 *
 * @return
 */
public static AsyncHttpClient createClient(Configuration configuration, int numberOfHostsBeingConnectedTo) {


    AsyncHttpClientConfig.Builder cf = createClientConfig(configuration);
    // A Bug exists in the AsyncConnection library that leak permits on a
    // Connection exception (i.e. when host not listening .. hard fail)
    // So we do not enable connection tracking.  Which is fine as the ring
    // buffer does the job of having a single thread talking to the backend repo (ES)
    // So the connection should not grow in an unmanaged way, as the ring buffer
    // is restricting the connections
    // cf.setMaximumConnectionsTotal(numberOfHostsBeingConnectedTo);
    cf.setMaximumConnectionsTotal(-1);
    cf.setMaximumConnectionsPerHost(-1);
    cf.setExecutorService(getExecutorService(numberOfHostsBeingConnectedTo));

    return createClient(cf);
}
 
開發者ID:tootedom,項目名稱:related,代碼行數:26,代碼來源:AHCFactory.java

示例10: createClientConfig

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
public static AsyncHttpClientConfig.Builder createClientConfig(Configuration configuration) {
    AsyncHttpProviderConfig providerConfig =  new NettyAsyncHttpProviderConfig();
    // We use nio, instead of having a thread per backend ES server node.
    // providerConfig.addProperty(NettyAsyncHttpProviderConfig.USE_BLOCKING_IO,true);
    providerConfig.addProperty(NettyAsyncHttpProviderConfig.EXECUTE_ASYNC_CONNECT,false);

    AsyncHttpClientConfig.Builder cf = new AsyncHttpClientConfig.Builder();

    cf.setAsyncHttpClientProviderConfig(providerConfig);
    cf.setIOThreadMultiplier(1);
    cf.setCompressionEnabled(configuration.getElasticSearchHttpCompressionEnabled());
    cf.setConnectionTimeoutInMs(configuration.getElasticSearchHttpConnectionTimeoutMs());
    cf.setFollowRedirects(configuration.getElasticSearchHttpFollowRedirects());
    cf.setMaximumConnectionsPerHost(1);
    cf.setMaxRequestRetry(configuration.getElasticSearchHttpNoOfRetries());
    cf.setAllowPoolingConnection(configuration.getElasticSearchHttpConnectionPoolingEnabled());
    cf.setRequestTimeoutInMs(configuration.getElasticSearchHttpRequestTimeoutMs());

    return cf;
}
 
開發者ID:tootedom,項目名稱:related,代碼行數:21,代碼來源:AHCFactory.java

示例11: login

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
/**
 * Executes and replays a login request until one is found which satisfies the
 * {@link net.adamcin.httpsig.api.Challenge} being returned by the server, or until there are no more keys in the
 * keychain.
 *
 * @since 1.0.4
 *
 * @param client the {@link AsyncHttpClient} to which the {@link Signer} will be attached
 * @param signer the {@link Signer} used for login and subsequent signature authentication
 * @param loginRequest the login {@link Request} to be executed and replayed while rotating the keychain
 * @param responseHandler an {@link AsyncCompletionHandler} of type {@code T}
 * @param calcBefore provide another {@link SignatureCalculator} to call (such as a Content-MD5 generator) prior to
 *                   generating the signature for authentication.
 * @param <T> type parameter for completion handler
 * @return a {@link Future} of type {@code T}
 * @throws IOException if thrown by a login request
 */
public static <T> Future<T> login(final AsyncHttpClient client,
                         final Signer signer,
                         final Request loginRequest,
                         final AsyncCompletionHandler<T> responseHandler,
                         final SignatureCalculator calcBefore) throws IOException {

    final AsyncHttpClientConfig.Builder configBuilder = new AsyncHttpClientConfig.Builder(client.getConfig());
    configBuilder.addResponseFilter(new RotateAndReplayResponseFilter(signer));
    AsyncHttpClient loginClient = new AsyncHttpClient(configBuilder.build());

    enableAuth(loginClient, signer, calcBefore);
    Future<T> response = loginClient.executeRequest(loginClient
                                                            .prepareRequest(loginRequest)
                                                            .setUrl(loginRequest.getUrl()).build(),
                                                    responseHandler);
    enableAuth(client, signer, calcBefore);
    return response;
}
 
開發者ID:adamcin,項目名稱:httpsig-java,代碼行數:36,代碼來源:AsyncUtil.java

示例12: URLCheckerService

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
public URLCheckerService()
{
	Builder bc = new AsyncHttpClientConfig.Builder();
	bc.setAllowPoolingConnections(false); // Avoid keep-alive
	bc.setCompressionEnforced(true);
	bc.setUseProxyProperties(true);
	bc.setFollowRedirect(true);
	bc.setMaxConnectionsPerHost(2);
	bc.setMaxConnections(200);
	bc.setMaxRedirects(25);
	bc.setUserAgent("Mozilla/5.0 (compatible; equellaurlbot/1.0; +http://support.equella.com/)");

	// These are actually the defaults, but let's specify in case they
	// change
	bc.setConnectTimeout(60000);
	bc.setRequestTimeout(60000);
	// ^^ note the massive request timeout, this not a per-request timeout,
	// it's the whole redirection round trip

	// Just because a URL uses a self-signed certificate doesn't mean it's
	// not a working URL. We also don't care about MITM attacks since we're
	// just checking the URL.
	bc.setSSLContext(BlindSSLSocketFactory.createBlindSSLContext());

	// Configure a fake authentication in case some the URLs are using it.
	// http://jira.pearsoncmg.com/jira/browse/EQ-411
	Realm realm = new Realm.RealmBuilder().setPrincipal("").setPassword("").setUsePreemptiveAuth(true)
		.setScheme(AuthScheme.BASIC).build();
	bc.setRealm(realm);

	client = new AsyncHttpClient(bc.build());
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:33,代碼來源:URLCheckerService.java

示例13: providesHttpClient

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
@Provides
@Singleton
@Named(LOCAL_DOWNLOAD_HTTP_CLIENT)
public AsyncHttpClient providesHttpClient(SingularityExecutorConfiguration configuration) {
  AsyncHttpClientConfig.Builder configBldr = new AsyncHttpClientConfig.Builder();
  configBldr.setRequestTimeoutInMs((int) configuration.getLocalDownloadServiceTimeoutMillis());
  configBldr.setIdleConnectionTimeoutInMs((int) configuration.getLocalDownloadServiceTimeoutMillis());
  configBldr.addRequestFilter(new ThrottleRequestFilter(configuration.getLocalDownloadServiceMaxConnections()));

  return new AsyncHttpClient(configBldr.build());
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:12,代碼來源:SingularityExecutorModule.java

示例14: getClient

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
public AsyncHttpClient getClient() {
    AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
    builder.setCompressionEnabled(true)
            .setAllowPoolingConnection(true)
            .setRequestTimeoutInMs(REQUEST_TIMEOUT_IN_MILLISECONDS)
            .build();
    AsyncHttpClient client = new AsyncHttpClient(builder.build());
    return client;
}
 
開發者ID:viant,項目名稱:jdsunit,代碼行數:10,代碼來源:ClientFactoryImpl.java

示例15: createRegistry

import com.ning.http.client.AsyncHttpClientConfig; //導入方法依賴的package包/類
@Override
protected JndiRegistry createRegistry() throws Exception {
    AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
    AsyncHttpClientConfig config = builder.setFollowRedirect(true).setMaxRequestRetry(3).build();

    JndiRegistry jndi = super.createRegistry();
    jndi.bind("myConfig", config);
    return jndi;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:10,代碼來源:AhcProduceClientConfigTest.java


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