本文整理汇总了Java中io.dropwizard.client.HttpClientBuilder类的典型用法代码示例。如果您正苦于以下问题:Java HttpClientBuilder类的具体用法?Java HttpClientBuilder怎么用?Java HttpClientBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpClientBuilder类属于io.dropwizard.client包,在下文中一共展示了HttpClientBuilder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildHttpClient
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
public HttpClient buildHttpClient(HttpClientConfiguration configuration, String clientName)
{
Preconditions.checkState(providers.size() == 0, "HttpClient does not support providers");
Preconditions.checkState(providerClasses.size() == 0, "HttpClient does not support providers");
Preconditions.checkState(connectorProvider == null, "HttpClient does not support ConnectorProvider");
HttpRequestRetryHandler nullRetry = new HttpRequestRetryHandler()
{
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context)
{
return false;
}
};
HttpClient httpClient = new HttpClientBuilder(environment)
.using(configuration)
.using(nullRetry) // Apache's retry mechanism does not allow changing hosts. Do retries manually
.build(clientName);
HttpClient client = new WrappedHttpClient(httpClient, retryComponents);
SoaBundle.getFeatures(environment).putNamed(client, HttpClient.class, clientName);
return client;
}
示例2: build
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
public AnalysisServiceClient build(Environment environment) {
final HttpClientConfiguration httpConfig = new HttpClientConfiguration();
httpConfig.setTimeout(Duration.milliseconds(getTimeout()));
final HttpClient httpClient = new HttpClientBuilder(environment).using(httpConfig)
.build("analysis-http-client");
AnalysisServiceClient client = new AnalysisServiceClientAdapter(getHost(), getPort(),
getPortFailover(), getPath(), httpClient);
environment.lifecycle().manage(new Managed() {
@Override
public void start() {
}
@Override
public void stop() {
}
});
return client;
}
示例3: configure
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
@Override
protected void configure() {
bind(CassandraSchedulerConfiguration.class).toInstance(this.configuration);
bind(new TypeLiteral<Serializer<Integer>>() {}).toInstance(IntegerStringSerializer.get());
bind(new TypeLiteral<Serializer<Boolean>>() {}).toInstance(BooleanStringSerializer.get());
bind(new TypeLiteral<Serializer<CassandraTask>>() {}).toInstance(CassandraTask.PROTO_SERIALIZER);
bind(MesosConfig.class).toInstance(mesosConfig);
bind(ServiceConfig.class)
.annotatedWith(Names.named("ConfiguredIdentity"))
.toInstance(configuration.getServiceConfig());
bindConstant()
.annotatedWith(Names.named("ConfiguredEnableUpgradeSSTableEndpoint"))
.to(configuration.getEnableUpgradeSSTableEndpoint());
HttpClientConfiguration httpClient = new HttpClientConfiguration();
bind(HttpClient.class)
.toInstance(new HttpClientBuilder(environment).using(httpClient).build("http-client-test"));
bind(ExecutorService.class).toInstance(Executors.newCachedThreadPool());
bind(CuratorFrameworkConfig.class).toInstance(curatorConfig);
bind(ClusterTaskConfig.class).toInstance(configuration.getClusterTaskConfig());
bind(ScheduledExecutorService.class).toInstance(Executors.newScheduledThreadPool(8));
bind(SchedulerClient.class).asEagerSingleton();
bind(IdentityManager.class).asEagerSingleton();
bind(ConfigurationManager.class).asEagerSingleton();
bind(PersistentOfferRequirementProvider.class);
bind(CassandraState.class).asEagerSingleton();
bind(EventBus.class).asEagerSingleton();
bind(BackupManager.class).asEagerSingleton();
bind(ClusterTaskOfferRequirementProvider.class);
bind(Reconciler.class).to(DefaultReconciler.class).asEagerSingleton();
bind(RestoreManager.class).asEagerSingleton();
bind(CleanupManager.class).asEagerSingleton();
bind(RepairManager.class).asEagerSingleton();
bind(SeedsManager.class).asEagerSingleton();
}
示例4: createDefaultJerseyClient
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) {
HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
return new ApacheHttpClient4(handler, config);
}
示例5: createDefaultJerseyClient
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
return new ApacheHttpClient4(handler, config);
}
示例6: createDefaultJerseyClient
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
return new ApacheHttpClient4(handler, config);
}
示例7: buildJerseyClient
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
public Client buildJerseyClient(JerseyClientConfiguration configuration, String clientName)
{
ConnectorProvider localConnectorProvider;
if ( connectorProvider != null )
{
localConnectorProvider = connectorProvider;
}
else
{
HttpClientBuilder apacheHttpClientBuilder = new HttpClientBuilder(environment).using(configuration);
CloseableHttpClient closeableHttpClient = apacheHttpClientBuilder.build(clientName);
localConnectorProvider = new JerseyRetryConnectorProvider(retryComponents, closeableHttpClient, configuration.isChunkedEncodingEnabled());
}
JerseyClientBuilder builder = new JerseyClientBuilder(environment)
.using(configuration)
.using(localConnectorProvider);
for ( Class<?> klass : providerClasses )
{
builder = builder.withProvider(klass);
}
for ( Object provider : providers )
{
builder = builder.withProvider(provider);
}
Client client = builder
.build(clientName);
SoaBundle.getFeatures(environment).putNamed(client, Client.class, clientName);
return client;
}
示例8: getWebHook
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
public Webhooks getWebHook(Environment environment) {
if (vreAdded != null || dataSetUpdated != null) {
final HttpClient httpClient = new HttpClientBuilder(environment)
.using(httpClientConfig)
.build("solr-webhook-client");
return new CallingWebhooks(vreAdded, dataSetUpdated, httpClient);
} else {
return new NoOpWebhooks();
}
}
示例9: run
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
@Override
public void run(ThirdEyeDashboardConfiguration config, Environment environment) throws Exception {
LOG.error("running the Dashboard application with configs, {}", config.toString());
final HttpClient httpClient =
new HttpClientBuilder(environment)
.using(config.getHttpClient())
.build(getName());
ExecutorService queryExecutor = environment.lifecycle().executorService("query_executor").build();
ConfigCache configCache = new ConfigCache();
DataCache dataCache = new DataCache(httpClient, environment.getObjectMapper());
QueryCache queryCache = new QueryCache(httpClient, environment.getObjectMapper(), queryExecutor);
CustomDashboardResource customDashboardResource = null;
if (config.getCustomDashboardRoot() != null) {
File customDashboardDir = new File(config.getCustomDashboardRoot());
configCache.setCustomDashboardRoot(customDashboardDir);
customDashboardResource = new CustomDashboardResource(customDashboardDir, config.getServerUri(), queryCache, dataCache, configCache);
environment.jersey().register(customDashboardResource);
}
FunnelsDataProvider funnelsResource = null;
if (config.getFunnelConfigRoot() != null) {
funnelsResource = new FunnelsDataProvider(new File(config.getFunnelConfigRoot()), config.getServerUri(), queryCache, dataCache);
environment.jersey().register(funnelsResource);
}
if (config.getCollectionConfigRoot() != null) {
File collectionConfigDir = new File(config.getCollectionConfigRoot());
configCache.setCollectionConfigRoot(collectionConfigDir);
CollectionConfigResource collectionConfigResource = new CollectionConfigResource(collectionConfigDir, configCache);
environment.jersey().register(collectionConfigResource);
}
environment.jersey().register(new DashboardResource(
config.getServerUri(),
dataCache,
config.getFeedbackEmailAddress(),
queryCache,
environment.getObjectMapper(),
customDashboardResource,
configCache, funnelsResource));
environment.jersey().register(new FlotTimeSeriesResource(
config.getServerUri(),
dataCache,
queryCache,
environment.getObjectMapper(),
configCache,
config.getAnomalyDatabaseConfig()));
environment.jersey().register(new MetadataResource(config.getServerUri(), dataCache));
environment.admin().addTask(new ClearCachesTask(dataCache, queryCache, configCache));
}
示例10: run
import io.dropwizard.client.HttpClientBuilder; //导入依赖的package包/类
@Override
public void run(DjConfiguration configuration,
Environment environment) {
final HttpClient client = new HttpClientBuilder(environment).using(configuration.getHttpClientConfiguration())
.build("http-client");
final DBIFactory factory = new DBIFactory();
final DBI jdbi = factory.build(environment, configuration.getDataSourceFactory(), "postgresql");
final DbMetaDAO meta = jdbi.onDemand(DbMetaDAO.class);
int currentDbVersion = 1; //if this is ever incremented, you need to fix the below code to be a "real" migration system!
if(!meta.songqueueTableExists()) {
//we are creating a fresh new db
meta.createSongqueueTable();
meta.createMetaTable();
meta.insertDbVersion(currentDbVersion);
}
if(!meta.metaTableExists()) {
//we are updating from version 0 of the db when there was no meta table
meta.createMetaTable();
meta.insertDbVersion(currentDbVersion);
meta.addSiteColumn();
meta.populateLegacySoundcloudIds();
meta.populateLegacyYoutubeIds();
}
jdbi.close(meta);
final SongQueueDAO dao = jdbi.onDemand(SongQueueDAO.class);
DjResource resource = new DjResource(configuration, client, dao);
environment.jersey().register(resource);
final ChannelCheck channelCheck = new ChannelCheck(resource);
if(configuration.isDjbotPublic()) {
String adminUsername = configuration.getAdminUsername();
String adminPassword = configuration.getAdminPassword();
if(StringUtils.isBlank(adminUsername) || StringUtils.isBlank(adminPassword)) {
throw new RuntimeException("Djbot is set to public, so it needs an adminUsername and adminPassword");
}
environment.jersey().register(AuthFactory.binder(
new BasicAuthFactory<User>(
new ConfiguredUserAuthenticator(adminUsername, adminPassword),
"djBotRealm",
User.class )));
}
environment.healthChecks().register("currentSong", channelCheck);
}