Search in sources :

Example 1 with Credentials

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;
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) MultiMap(io.vertx.core.MultiMap) CommandStatuses(io.confluent.ksql.rest.entity.CommandStatuses) RestResponse(io.confluent.ksql.rest.client.RestResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) HttpVersion(io.vertx.core.http.HttpVersion) ACCEPT(io.netty.handler.codec.http.HttpHeaderNames.ACCEPT) Map(java.util.Map) URI(java.net.URI) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) UrlEscapers(com.google.common.net.UrlEscapers) ApiJsonMapper(io.confluent.ksql.rest.ApiJsonMapper) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) Status(io.confluent.ksql.rest.entity.CommandStatus.Status) Optional(java.util.Optional) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) AUTHORIZATION(io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION) HttpClient(io.vertx.core.http.HttpClient) HttpResponse(io.vertx.ext.web.client.HttpResponse) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) WebClient(io.vertx.ext.web.client.WebClient) POST(io.vertx.core.http.HttpMethod.POST) BodyCodec(io.vertx.ext.web.codec.BodyCodec) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) CompletableFuture(java.util.concurrent.CompletableFuture) WebsocketVersion(io.vertx.core.http.WebsocketVersion) ServerClusterId(io.confluent.ksql.rest.entity.ServerClusterId) ArrayList(java.util.ArrayList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Charset(java.nio.charset.Charset) WriteStream(io.vertx.core.streams.WriteStream) HttpClientOptions(io.vertx.core.http.HttpClientOptions) TestDataProvider(io.confluent.ksql.util.TestDataProvider) HTTP_1_1(io.vertx.core.http.HttpVersion.HTTP_1_1) Credentials(io.confluent.ksql.test.util.secure.Credentials) Vertx(io.vertx.core.Vertx) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) ServerMetadata(io.confluent.ksql.rest.entity.ServerMetadata) KsqlMediaType(io.confluent.ksql.rest.entity.KsqlMediaType) HttpRequest(io.vertx.ext.web.client.HttpRequest) Consumer(java.util.function.Consumer) HttpMethod(io.vertx.core.http.HttpMethod) HealthCheckResponse(io.confluent.ksql.rest.entity.HealthCheckResponse) Collections(java.util.Collections) Buffer(io.vertx.core.buffer.Buffer) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) Vertx(io.vertx.core.Vertx) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 UrlEscapers (com.google.common.net.UrlEscapers)1 ApiJsonMapper (io.confluent.ksql.rest.ApiJsonMapper)1 BasicCredentials (io.confluent.ksql.rest.client.BasicCredentials)1 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)1 RestResponse (io.confluent.ksql.rest.client.RestResponse)1 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)1 Status (io.confluent.ksql.rest.entity.CommandStatus.Status)1 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)1 CommandStatuses (io.confluent.ksql.rest.entity.CommandStatuses)1 HealthCheckResponse (io.confluent.ksql.rest.entity.HealthCheckResponse)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)1 KsqlMediaType (io.confluent.ksql.rest.entity.KsqlMediaType)1 KsqlRequest (io.confluent.ksql.rest.entity.KsqlRequest)1 ServerClusterId (io.confluent.ksql.rest.entity.ServerClusterId)1 ServerInfo (io.confluent.ksql.rest.entity.ServerInfo)1 ServerMetadata (io.confluent.ksql.rest.entity.ServerMetadata)1 StreamedRow (io.confluent.ksql.rest.entity.StreamedRow)1