use of io.confluent.ksql.test.util.secure.Credentials in project ksql by confluentinc.
the class RestIntegrationTestUtil method rawRestRequest.
static VertxCompletableFuture<Void> rawRestRequest(final TestKsqlRestApp restApp, final HttpVersion httpVersion, final HttpMethod method, final String uri, final Object requestBody, final String mediaType, final Consumer<Buffer> chunkConsumer, final Optional<BasicCredentials> credentials) {
final byte[] bytes;
try {
bytes = ApiJsonMapper.INSTANCE.get().writeValueAsBytes(requestBody);
} catch (Exception e) {
throw new RuntimeException(e);
}
HttpClientOptions options = new HttpClientOptions().setDefaultPort(restApp.getHttpListener().getPort()).setDefaultHost(restApp.getHttpListener().getHost()).setVerifyHost(false);
if (httpVersion == HttpVersion.HTTP_2) {
options.setProtocolVersion(HttpVersion.HTTP_2);
}
final Vertx vertx = Vertx.vertx();
final HttpClient httpClient = vertx.createHttpClient(options);
final VertxCompletableFuture<Void> vcf = new VertxCompletableFuture<>();
final HttpClientRequest httpClientRequest = httpClient.request(method, uri, resp -> {
resp.handler(buffer -> {
try {
chunkConsumer.accept(buffer);
} catch (final Throwable t) {
vcf.completeExceptionally(t);
}
});
resp.endHandler(v -> {
chunkConsumer.accept(null);
vcf.complete(null);
});
}).exceptionHandler(vcf::completeExceptionally);
httpClientRequest.putHeader("Accept", mediaType);
credentials.ifPresent(basicCredentials -> httpClientRequest.putHeader("Authorization", createBasicAuthHeader(basicCredentials)));
Buffer bodyBuffer = Buffer.buffer(bytes);
httpClientRequest.end(bodyBuffer);
// cleanup
vcf.handle((v, throwable) -> {
httpClient.close();
vertx.close();
return null;
});
return vcf;
}
Aggregations