io.dropwizard.client.HttpClientConfiguration Java Examples

The following examples show how to use io.dropwizard.client.HttpClientConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientBuilder.java    From soabase with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: BenchConfiguration.java    From kudu-ts with Apache License 2.0 6 votes vote down vote up
@JsonCreator
public BenchConfiguration(@JsonProperty("metrics") List<String> metrics,
                          @JsonProperty("tags") Map<String, List<String>> tags,
                          @JsonProperty("sampleFrequency") @DefaultValue("1.0") double sampleFrequency,
                          @JsonProperty("start") @DefaultValue("0") long start,
                          @JsonProperty("end") @DefaultValue("0") long end,
                          @JsonProperty("ktsdHost") @DefaultValue("localhost") String host,
                          @JsonProperty("ktsdPort") @DefaultValue("4242") int port,
                          @JsonProperty("sync") @DefaultValue("true") boolean sync,
                          @JsonProperty("httpClient") HttpClientConfiguration httpClient) {
  this.metrics = metrics;
  this.tags = tags;
  this.sampleFrequency = sampleFrequency;
  this.start = start;
  this.end = end;
  this.ktsdHost = host;
  this.ktsdPort = port;
  this.sync = sync;
  this.httpClient = httpClient;
}
 
Example #3
Source File: CassandraSchedulerConfiguration.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public static CassandraSchedulerConfiguration create(
  @JsonProperty("executor") final ExecutorConfig executorConfig,
  @JsonProperty("servers") final int servers,
  @JsonProperty("seeds") final int seeds,
  @JsonProperty("placement_constraint") final String placementConstraint,
  @JsonProperty("cassandra") final CassandraConfig cassandraConfig,
  @JsonProperty("cluster_task") final ClusterTaskConfig clusterTaskConfig,
  @JsonProperty("api_port") final int apiPort,
  @JsonProperty("service") final ServiceConfig serviceConfig,
  @JsonProperty("external_dc_sync_ms") final long externalDcSyncMs,
  @JsonProperty("external_dcs") final String externalDcs,
  @JsonProperty("dc_url") final String dcUrl,
  @JsonProperty("phase_strategy") final String phaseStrategy,
  @JsonProperty("enable_upgrade_sstable_endpoint") final boolean enableUpgradeSSTableEndpoint,
  @JsonProperty("http_client") final HttpClientConfiguration httpClientConfiguration) {

  return new CassandraSchedulerConfiguration(
    executorConfig,
    servers,
    seeds,
    placementConstraint,
    cassandraConfig,
    clusterTaskConfig,
    apiPort,
    serviceConfig,
    externalDcSyncMs,
    externalDcs,
    dcUrl,
    phaseStrategy,
    enableUpgradeSSTableEndpoint,
    httpClientConfiguration
  );
}
 
Example #4
Source File: CassandraSchedulerConfiguration.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
private CassandraSchedulerConfiguration(
  ExecutorConfig executorConfig,
  int servers,
  int seeds,
  String placementConstraint,
  CassandraConfig cassandraConfig,
  ClusterTaskConfig clusterTaskConfig,
  int apiPort, ServiceConfig serviceConfig,
  long externalDcSyncMs,
  String externalDcs,
  String dcUrl,
  String phaseStrategy,
  boolean enableUpgradeSSTableEndpoint,
  HttpClientConfiguration httpClientConfiguration) {
  this.executorConfig = executorConfig;
  this.servers = servers;
  this.seeds = seeds;
  this.placementConstraint = placementConstraint;
  this.cassandraConfig = cassandraConfig;
  this.clusterTaskConfig = clusterTaskConfig;
  this.apiPort = apiPort;
  this.serviceConfig = serviceConfig;
  this.externalDcSyncMs = externalDcSyncMs;
  this.externalDcs = externalDcs;
  this.dcUrl = dcUrl;
  this.phaseStrategy = phaseStrategy;
  this.enableUpgradeSSTableEndpoint = enableUpgradeSSTableEndpoint;
  this.httpClientConfiguration = httpClientConfiguration;
}
 
Example #5
Source File: HelloApp.java    From soabase with Apache License 2.0 5 votes vote down vote up
@Override
protected void internalRun(Configuration configuration, Environment environment)
{
    ClientBuilder builder = new ClientBuilder(environment);
    builder.buildJerseyClient(new JerseyClientConfiguration(), "jersey");
    builder.buildHttpClient(new HttpClientConfiguration(), "apache");

    environment.jersey().register(HelloResourceJersey.class);
    environment.jersey().register(HelloResourceApache.class);
}
 
Example #6
Source File: QueueClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: TestModule.java    From dcos-cassandra-service with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #8
Source File: DedupQueueClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #9
Source File: HadoopDataStoreManager.java    From emodb with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a ServiceFactory for a cluster with reasonable configurations.
 */
private MultiThreadedServiceFactory<AuthDataStore> createDataStoreServiceFactory(String cluster, MetricRegistry metricRegistry) {
    HttpClientConfiguration clientConfig = new HttpClientConfiguration();
    clientConfig.setKeepAlive(Duration.seconds(1));
    clientConfig.setConnectionTimeout(Duration.seconds(10));
    clientConfig.setTimeout(Duration.minutes(5));

    return DataStoreClientFactory.forClusterAndHttpConfiguration(cluster, clientConfig, metricRegistry);
}
 
Example #10
Source File: BlobStoreClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: PurgeDatabusEventsCommand.java    From emodb with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #12
Source File: DatabusClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #13
Source File: UserAccessControlClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #14
Source File: DataStoreClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #15
Source File: DedupQueueClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static DedupQueueClientFactory forClusterAndHttpConfiguration(String clusterName, HttpClientConfiguration configuration, MetricRegistry metricRegistry) {
    return new DedupQueueClientFactory(clusterName, createDefaultJerseyClient(configuration, getServiceName(clusterName), metricRegistry));
}
 
Example #16
Source File: TimbuctooConfiguration.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
@JsonProperty("httpClient")
@Valid
@Value.Default
public HttpClientConfiguration getHttpClientConfiguration() {
  return new HttpClientConfiguration();
}
 
Example #17
Source File: DatabusClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static DatabusClientFactory forCluster(String clusterName, MetricRegistry metricRegistry) {
    HttpClientConfiguration httpClientConfiguration = new HttpClientConfiguration();
    httpClientConfiguration.setKeepAlive(Duration.seconds(1));
    return new DatabusClientFactory(clusterName, createDefaultJerseyClient(httpClientConfiguration, metricRegistry, getServiceName(clusterName)));
}
 
Example #18
Source File: DatabusClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static DatabusClientFactory forClusterAndHttpConfiguration(String clusterName, HttpClientConfiguration configuration, MetricRegistry metricRegistry) {
    return new DatabusClientFactory(clusterName, createDefaultJerseyClient(configuration, metricRegistry, getServiceName(clusterName)));
}
 
Example #19
Source File: BenchConfiguration.java    From kudu-ts with Apache License 2.0 4 votes vote down vote up
@JsonProperty
public HttpClientConfiguration getHttpClient() {
  return httpClient;
}
 
Example #20
Source File: ReaperApplicationConfiguration.java    From cassandra-reaper with Apache License 2.0 4 votes vote down vote up
public HttpClientConfiguration getHttpClientConfiguration() {
  return httpClient;
}
 
Example #21
Source File: ReaperApplicationConfiguration.java    From cassandra-reaper with Apache License 2.0 4 votes vote down vote up
public void setHttpClientConfiguration(HttpClientConfiguration httpClient) {
  this.httpClient = httpClient;
}
 
Example #22
Source File: HelloServiceConfiguration.java    From talk-kafka-zipkin with MIT License 4 votes vote down vote up
@JsonProperty("httpClient")
public HttpClientConfiguration getHttpClientConfiguration() {
	return httpClient;
}
 
Example #23
Source File: DedupQueueClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static DedupQueueClientFactory forCluster(String clusterName, MetricRegistry metricRegistry) {
    HttpClientConfiguration httpClientConfiguration = new HttpClientConfiguration();
    httpClientConfiguration.setKeepAlive(Duration.seconds(1));
    return new DedupQueueClientFactory(clusterName, createDefaultJerseyClient(httpClientConfiguration, getServiceName(clusterName), metricRegistry));
}
 
Example #24
Source File: QueueClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static QueueClientFactory forClusterAndHttpConfiguration(String clusterName, HttpClientConfiguration configuration, MetricRegistry metricRegistry) {
    return new QueueClientFactory(clusterName, createDefaultJerseyClient(configuration, getServiceName(clusterName), metricRegistry));
}
 
Example #25
Source File: QueueClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static QueueClientFactory forCluster(String clusterName, MetricRegistry metricRegistry) {
    HttpClientConfiguration httpClientConfiguration = new HttpClientConfiguration();
    httpClientConfiguration.setKeepAlive(Duration.seconds(1));
    return new QueueClientFactory(clusterName, createDefaultJerseyClient(httpClientConfiguration, getServiceName(clusterName), metricRegistry));
}
 
Example #26
Source File: DataStoreClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static DataStoreClientFactory forClusterAndHttpConfiguration(String clusterName, HttpClientConfiguration configuration, MetricRegistry metricRegistry) {
    return new DataStoreClientFactory(clusterName, createDefaultJerseyClient(configuration, getServiceName(clusterName), metricRegistry));
}
 
Example #27
Source File: DataStoreClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static DataStoreClientFactory forCluster(String clusterName, MetricRegistry metricRegistry) {
    HttpClientConfiguration httpClientConfiguration = new HttpClientConfiguration();
    httpClientConfiguration.setKeepAlive(Duration.seconds(1));
    return new DataStoreClientFactory(clusterName, createDefaultJerseyClient(httpClientConfiguration, getServiceName(clusterName), metricRegistry));
}
 
Example #28
Source File: UserAccessControlClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static UserAccessControlClientFactory forClusterAndHttpConfiguration(String clusterName, HttpClientConfiguration configuration, MetricRegistry metricRegistry) {
    return new UserAccessControlClientFactory(clusterName, createDefaultJerseyClient(configuration, getServiceName(clusterName), metricRegistry));
}
 
Example #29
Source File: UserAccessControlClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static UserAccessControlClientFactory forCluster(String clusterName, MetricRegistry metricRegistry) {
    HttpClientConfiguration httpClientConfiguration = new HttpClientConfiguration();
    httpClientConfiguration.setKeepAlive(Duration.seconds(1));
    return new UserAccessControlClientFactory(clusterName, createDefaultJerseyClient(httpClientConfiguration, getServiceName(clusterName), metricRegistry));
}
 
Example #30
Source File: BlobStoreClientFactory.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static BlobStoreClientFactory forClusterAndHttpConfiguration(String clusterName, HttpClientConfiguration configuration, MetricRegistry metricRegistry) {
    return new BlobStoreClientFactory(clusterName, createDefaultJerseyClient(configuration, metricRegistry, getServiceName(clusterName)));
}