io.dropwizard.client.HttpClientBuilder Java Examples

The following examples show how to use io.dropwizard.client.HttpClientBuilder. 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: 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 #3
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 #4
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 #5
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 #6
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 #7
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 #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: 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 #10
Source File: ClientBuilder.java    From soabase with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: WebhookFactory.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
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();
  }
}
 
Example #12
Source File: PutBench.java    From kudu-ts with Apache License 2.0 4 votes vote down vote up
protected void run(Environment environment,
                   Namespace namespace,
                   KTSDConfiguration config) throws Exception {

  final CloseableHttpClient client =
      new HttpClientBuilder(environment).using(config.getBench().getHttpClient())
                                        .build(getName());

  long start = config.getBench().getStart();
  long end = config.getBench().getEnd();
  if (end == 0) end = System.currentTimeMillis();
  if (start == 0) start = end - TimeUnit.HOURS.toMillis(1);
  if (start < 0) start = end - start;

  URI uri = new URIBuilder()
      .setScheme("http")
      .setHost(config.getBench().getKtsdHost())
      .setPort(config.getBench().getKtsdPort())
      .setPath("/api/put")
      .setParameter("summary", "true")
      .build();

  List<SortedMap<String, String>> tags = new ArrayList<>();
  tags.add(new TreeMap<String, String>());
  for (Map.Entry<String, List<String>> tag : config.getBench().getTags().entrySet()) {
    List<SortedMap<String, String>> original = tags;
    tags = new ArrayList<>();
    for (String value : tag.getValue()) {
      for (SortedMap<String, String> ts : original) {
        SortedMap<String, String> copy = new TreeMap<>(ts);
        copy.put(tag.getKey(), value);
        tags.add(copy);
      }
    }
  }

  CountDownLatch latch = new CountDownLatch(config.getBench().getMetrics().size() * tags.size());
  LatencyStats stats = new LatencyStats();

  List<Thread> threads = new ArrayList<>();
  for (String metric : config.getBench().getMetrics()) {
    for (SortedMap<String, String> tagset : tags) {
      DatapointGenerator datapoints = new DatapointGenerator(threads.size(), start, end,
                                                             config.getBench().getSampleFrequency());
      threads.add(new Thread(new PutSeries(uri, metric, tagset, datapoints, stats,
                                           client, environment.getObjectMapper(), latch)));
    }
  }

  for (Thread thread : threads) {
    thread.start();
  }

  Histogram hist = stats.getIntervalHistogram();
  while (!latch.await(10, TimeUnit.SECONDS)) {
    Histogram latest = stats.getIntervalHistogram();
    hist.add(latest);

    LOG.info("Progress:");
    LOG.info("puts: {}/{}", latest.getTotalCount(), hist.getTotalCount());
    LOG.info("mean latency: {}/{}", TimeUnit.NANOSECONDS.toMillis((long) latest.getMean()),
                                    TimeUnit.NANOSECONDS.toMillis((long) hist.getMean()));
    LOG.info("min: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getMinValue()),
                           TimeUnit.NANOSECONDS.toMillis(hist.getMinValue()));
    LOG.info("max: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getMaxValue()),
                           TimeUnit.NANOSECONDS.toMillis(hist.getMaxValue()));
    LOG.info("p50: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getValueAtPercentile(50)),
                           TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(50)));
    LOG.info("p99: {}/{}", TimeUnit.NANOSECONDS.toMillis(latest.getValueAtPercentile(99)),
                           TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(99)));
  }

  LOG.info("Benchmark complete");
  LOG.info("puts: {}", hist.getTotalCount());
  LOG.info("mean latency: {}", TimeUnit.NANOSECONDS.toMillis((long) hist.getMean()));
  LOG.info("stddev: {}", TimeUnit.NANOSECONDS.toMillis((long) hist.getStdDeviation()));
  LOG.info("min: {}", TimeUnit.NANOSECONDS.toMillis(hist.getMinValue()));
  LOG.info("max: {}", TimeUnit.NANOSECONDS.toMillis(hist.getMaxValue()));
  LOG.info("p50: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(50)));
  LOG.info("p90: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(90)));
  LOG.info("p95: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(95)));
  LOG.info("p99: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(99)));
  LOG.info("p999: {}", TimeUnit.NANOSECONDS.toMillis(hist.getValueAtPercentile(99.9)));
}
 
Example #13
Source File: ReaperApplication.java    From cassandra-reaper with Apache License 2.0 4 votes vote down vote up
private HttpClient createHttpClient(ReaperApplicationConfiguration config, Environment environment) {
  return new HttpClientBuilder(environment).using(config.getHttpClientConfiguration()).build(getName());
}