@Override public Future<Response> getJsonObject( SuccessCallback success, HttpErrorCallback error, FailureCallback failure, String resourcePath ) { String url = String.format("%s%s", serviceConfig.getUrl(), resourcePath); BoundRequestBuilder requestBuilder = webClient.prepareGet(url); headersToAppend.get().forEach(requestBuilder::addHeader); return sendRequest( success, error, failure, requestBuilder, DRUID_SEGMENT_METADATA_TIMER, new AtomicLong(1) ); }
/** * IOC constructor. * * @param config the configuration for this druid service * @param asyncHttpClient the HTTP client * @param mapper A shared jackson object mapper resource * @param headersToAppend Supplier for map of headers for Druid requests * @param jsonNodeBuilderStrategy A function to build JSON nodes from the response */ public AsyncDruidWebServiceImpl( DruidServiceConfig config, AsyncHttpClient asyncHttpClient, ObjectMapper mapper, Supplier<Map<String, String>> headersToAppend, Function<Response, JsonNode> jsonNodeBuilderStrategy ) { this.serviceConfig = config; if (serviceConfig.getUrl() == null) { String msg = DRUID_URL_INVALID.format(config.getNameAndUrl()); LOG.error(msg); throw new IllegalStateException(msg); } LOG.info("Configured with druid server config: {}", config.toString()); this.headersToAppend = headersToAppend; this.webClient = asyncHttpClient; this.writer = mapper.writer(); this.httpErrorMeter = REGISTRY.meter("druid.errors.http"); this.exceptionMeter = REGISTRY.meter("druid.errors.exceptions"); this.jsonNodeBuilderStrategy = jsonNodeBuilderStrategy; }
BoundRequestBuilder requestBuilder = webClient.preparePost(serviceConfig.getUrl()) .setBody(entityBody) .addHeader("Content-Type", "application/json; charset=UTF-8");