use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class KsqlClientTest method shouldFailToStartClientRequestWithNullKeystorePassword.
@Test
public void shouldFailToStartClientRequestWithNullKeystorePassword() throws Exception {
ksqlClient.close();
stopServer();
// Given:
startServerWithTls();
// When:
final KsqlRestClientException e = assertThrows(KsqlRestClientException.class, () -> startClientWithTlsAndTruststorePassword(null));
// Then:
assertThat(e.getMessage(), containsString("java.io.IOException: Keystore was tampered with, or password was incorrect"));
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class KsqlTarget method executeRequestSync.
private <R, T> RestResponse<R> executeRequestSync(final HttpMethod httpMethod, final String path, final Object requestBody, final Supplier<R> responseSupplier, final Function<Buffer, T> chunkMapper, final String delimiter, final Consumer<T> chunkHandler, final CompletableFuture<Void> shouldCloseConnection) {
return executeSync(httpMethod, path, Optional.empty(), requestBody, resp -> responseSupplier.get(), (resp, vcf) -> {
final RecordParser recordParser = RecordParser.newDelimited(delimiter, resp);
final AtomicBoolean end = new AtomicBoolean(false);
recordParser.exceptionHandler(vcf::completeExceptionally);
recordParser.handler(buff -> {
try {
chunkHandler.accept(chunkMapper.apply(buff));
} catch (Throwable t) {
log.error("Error while handling chunk", t);
vcf.completeExceptionally(t);
}
});
recordParser.endHandler(v -> {
try {
end.set(true);
chunkHandler.accept(null);
vcf.complete(new ResponseWithBody(resp, Buffer.buffer()));
} catch (Throwable t) {
log.error("Error while handling end", t);
vcf.completeExceptionally(t);
}
});
// Closing after the end handle was called resulted in errors about the connection being
// closed, so we even turn this on the context so there's no race.
final Context context = Vertx.currentContext();
shouldCloseConnection.handle((v, t) -> {
context.runOnContext(v2 -> {
if (!end.get()) {
try {
resp.request().connection().close();
vcf.completeExceptionally(new KsqlRestClientException("Closing connection"));
} catch (Throwable closing) {
log.error("Error while handling close", closing);
vcf.completeExceptionally(closing);
}
}
});
return null;
});
});
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class KsqlTarget method executeSync.
private <T> RestResponse<T> executeSync(final HttpMethod httpMethod, final String path, final Optional<String> mediaType, final Object requestBody, final Function<ResponseWithBody, T> mapper, final BiConsumer<HttpClientResponse, CompletableFuture<ResponseWithBody>> responseHandler) {
final CompletableFuture<ResponseWithBody> vcf = execute(httpMethod, path, mediaType, requestBody, responseHandler);
final ResponseWithBody response;
try {
response = vcf.get();
} catch (Exception e) {
throw new KsqlRestClientException("Error issuing " + httpMethod + " to KSQL server. path:" + path, e);
}
return KsqlClientUtil.toRestResponse(response, path, mapper);
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class CliTest method shouldPrintErrorIfCantConnectToRestServerOnRunInteractively.
@Test
public void shouldPrintErrorIfCantConnectToRestServerOnRunInteractively() throws Exception {
givenRunInteractivelyWillExit();
final KsqlRestClient mockRestClient = givenMockRestClient();
when(mockRestClient.getServerInfo()).thenThrow(new KsqlRestClientException("Boom", new IOException("")));
new Cli(1L, 1L, mockRestClient, console).runInteractively();
assertThat(terminal.getOutputString(), containsString("Please ensure that the URL provided is for an active KSQL server."));
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class CliTest method shouldPrintErrorIfCantConnectToRestServerOnRunScript.
@Test
public void shouldPrintErrorIfCantConnectToRestServerOnRunScript() throws Exception {
// Given
final KsqlRestClient mockRestClient = givenMockRestClient();
when(mockRestClient.getServerInfo()).thenThrow(new KsqlRestClientException("Boom", new IOException("")));
new Cli(1L, 1L, mockRestClient, console).runScript("script_file_ignored");
assertThat(terminal.getOutputString(), containsString("Please ensure that the URL provided is for an active KSQL server."));
}
Aggregations