本文整理匯總了Java中com.ning.http.client.AsyncHttpClientConfig類的典型用法代碼示例。如果您正苦於以下問題:Java AsyncHttpClientConfig類的具體用法?Java AsyncHttpClientConfig怎麽用?Java AsyncHttpClientConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AsyncHttpClientConfig類屬於com.ning.http.client包,在下文中一共展示了AsyncHttpClientConfig類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
public static void main(final String[] args) throws InterruptedException, ExecutionException {
String apiKey = "dd6b9d2beb614611c5eb9f56c34b743d1d86f385";
ApiClient apiClient = OrgSync.newApiClient(apiKey);
ProxyServer proxy = new ProxyServer("localhost", 8888);
AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().
setProxyServer(proxy).
build();
AsyncHttpClient httpClient = new AsyncHttpClient(config);
apiClient.setHttpClient(httpClient);
try {
AccountsResource accountsResource = apiClient.getResource(Resources.ACCOUNTS);
ApiResponse<List<Account>> apiResponse = accountsResource.getAccounts().get();
System.out.println("Call successful? " + apiResponse.isSuccess());
} finally {
apiClient.destroy();
}
}
示例2: httpClientConfig
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
@Provides
@Singleton
public AsyncHttpClientConfig httpClientConfig( ) {
return new AsyncHttpClientConfig.Builder( )
.setUserAgent( "TeamCity Wall Client" )
.setFollowRedirects( true )
.setRemoveQueryParamsOnRedirect( false )
.setAllowPoolingConnection( true )
.setAllowSslConnectionPool( true )
.setMaximumNumberOfRedirects( 5 )
.setMaximumConnectionsPerHost( 10 )
.setConnectionTimeoutInMs( 60000 )
.setRequestTimeoutInMs( 30000 )
.setIdleConnectionInPoolTimeoutInMs( 600000 ) // 10 min idle
.build( );
}
示例3: 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);
}
}
示例4: 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);
}
示例5: newNettyAsyncHttpClient
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
public static AsyncHttpClient newNettyAsyncHttpClient(final int timeout, final PoolConfig poolConfig) {
final NettyConnectionsPool pool = new NettyConnectionsPool( //
poolConfig.getMaxTotalConnections(), //
poolConfig.getMaxNrConnectionsPerHost(), //
poolConfig.getMaxIdleTime(), //
poolConfig.getMaxConnectionLifetime(), //
false, //
new HashedWheelTimer());
final AsyncHttpClientConfig config =
new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout) //
.setRequestTimeoutInMs(timeout) //
.setMaximumConnectionsPerHost(poolConfig.getMaxNrConnectionsPerHost()) //
.setConnectionsPool(pool) //
.build();
return new AsyncHttpClient(config);
}
示例6: createCamelContext
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
@Override
protected CamelContext createCamelContext() throws Exception {
CamelContext context = super.createCamelContext();
// use netty provider to reuse address
NettyAsyncHttpProviderConfig provider = new NettyAsyncHttpProviderConfig();
provider.addProperty("reuseAddress", Boolean.TRUE);
AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()
.setAsyncHttpClientProviderConfig(provider)
.setFollowRedirect(true)
.setMaxRequestRetry(3)
.build();
AhcComponent ahc = context.getComponent("ahc", AhcComponent.class);
ahc.setClientConfig(config);
return context;
}
示例7: 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);
}
示例8: getUri
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
private String getUri(boolean incremental) {
MiosUnit unit = getMiosUnit();
if (incremental) {
AsyncHttpClientConfig c = getAsyncHttpClient().getConfig();
// Use a timeout on the MiOS URL call that's about 2/3 of what
// the connection timeout is.
int t = Math.min(c.getIdleConnectionTimeoutInMs(), unit.getTimeout()) / 500 / 3;
int d = unit.getMinimumDelay();
return String.format(Locale.US, STATUS2_INCREMENTAL_URL, unit.getHostname(), unit.getPort(), loadTime,
dataVersion, new Integer(t), new Integer(d));
} else {
return String.format(Locale.US, STATUS2_URL, unit.getHostname(), unit.getPort());
}
}
示例9: 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;
}
示例10: DatastoreImpl
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
DatastoreImpl(final DatastoreConfig config) {
this.config = config;
final AsyncHttpClientConfig httpConfig = new AsyncHttpClientConfig.Builder()
.setConnectTimeout(config.getConnectTimeout())
.setRequestTimeout(config.getRequestTimeout())
.setMaxConnections(config.getMaxConnections())
.setMaxRequestRetry(config.getRequestRetry())
.setCompressionEnforced(true)
.build();
client = new AsyncHttpClient(httpConfig);
prefixUri = String.format("%s/%s/projects/%s:", config.getHost(), config.getVersion(), config.getProject());
executor = Executors.newSingleThreadScheduledExecutor();
if (config.getCredential() != null) {
// block while retrieving an access token for the first time
refreshAccessToken();
// wake up every 10 seconds to check if access token has expired
executor.scheduleAtFixedRate(this::refreshAccessToken, 10, 10, TimeUnit.SECONDS);
}
}
示例11: replay
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
public void replay(final InputStream inputStream, final CliOptions options) throws IOException {
final AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().build();
final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config));
final LogLineParserProvider logLineParserProvider = new LogLineParserProvider();
final LogLineParser logLineParser = logLineParserProvider.getImplementation(options.getLogparser());
final ResultDataLogger resultDataLogger = new ResultDataLogger();
resultDataLogger.logColumnTitles();
final LineReplayer lineReplayer = new LineReplayer(options.getHost(), asyncHttpClient, resultDataLogger);
lineReplayer.setHostHeader(options.getHostheader());
lineReplayer.setHeaders(options.getHeader());
lineReplayer.setFollowRedirects(options.getFollowRedirects());
final LogReplayReader logReplayReader = new LogReplayReader(lineReplayer, logLineParser, new LogSourceReaderFactoryProvider().getImplementation(options.getLogreader()));
logReplayReader.setDelay(options.getDelay());
logReplayReader.setWaitForTermination(options.getWaitForTermination());
logReplayReader.readAndReplay(inputStream, convertToDateTime(options.getFrom()), convertToDateTime(options.getUntil()));
close(asyncHttpClient);
}
示例12: 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);
}
示例13: 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;
}
示例14: 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;
}
示例15: LenientHttpsConfig
import com.ning.http.client.AsyncHttpClientConfig; //導入依賴的package包/類
private LenientHttpsConfig() {
AsyncHttpClientConfig configTmp = null;
SSLContext sslContextTmp = null;
try {
AsyncHttpClient client = new AsyncHttpClient();
configTmp = client.getConfig();
IOUtils.closeQuietly(client);
client = null;
X509Certificate cert = (X509Certificate) CertificateFactory.getInstance("X.509")
.generateCertificate(new FileInputStream(new File("./screenslicer.internal.cert")));
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null);
keyStore.setCertificateEntry(cert.getSubjectX500Principal().getName(), cert);
KeyManagerFactory keyManager = KeyManagerFactory.getInstance("SunX509");
keyManager.init(keyStore, null);
TrustManagerFactory trustManager = TrustManagerFactory.getInstance("X509");
trustManager.init(keyStore);
sslContextTmp = SSLContext.getInstance("TLS");
sslContextTmp.init(keyManager.getKeyManagers(), trustManager.getTrustManagers(), null);
} catch (Throwable t) {}
config = configTmp;
sslContext = sslContextTmp;
}