Java 类io.dropwizard.client.HttpClientBuilder 实例源码

项目:soabase    文件:ClientBuilder.java   
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;
}
项目:resilience-tutorial    文件:AnalysisServiceFactory.java   
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;
}
项目:dcos-cassandra-service    文件:TestModule.java   
@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();
}
项目:emodb    文件:BlobStoreClientFactory.java   
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);
}
项目:emodb    文件:PurgeDatabusEventsCommand.java   
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);
}
项目:emodb    文件:UserAccessControlClientFactory.java   
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);
}
项目:emodb    文件:DataStoreClientFactory.java   
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);
}
项目:emodb    文件:QueueClientFactory.java   
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);
}
项目:emodb    文件:DedupQueueClientFactory.java   
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);
}
项目:emodb    文件:DatabusClientFactory.java   
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);
}
项目:soabase    文件:ClientBuilder.java   
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;
}
项目:timbuctoo    文件:WebhookFactory.java   
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();
  }
}
项目:Pinot    文件:ThirdEyeDashboard.java   
@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));
}
项目:DJBot    文件:DjApplication.java   
@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);
}