use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class RemoteHostExecutorTest method testReturnsHostsThatHaveThrownAnException.
@Test
public void testReturnsHostsThatHaveThrownAnException() {
when(ksqlClient.makeKsqlRequest(any(), any(), any())).thenThrow(new KsqlRestClientException("error"));
try (MockedStatic<DiscoverRemoteHostsUtil> hdu = mockStatic(DiscoverRemoteHostsUtil.class)) {
hdu.when(() -> DiscoverRemoteHostsUtil.getRemoteHosts(any(), any())).thenReturn(hosts);
Pair<Map<HostInfo, KsqlEntity>, Set<HostInfo>> remoteResults = augmenter.fetchAllRemoteResults();
assertEquals(hosts, remoteResults.getRight());
assertThat(remoteResults.getLeft().entrySet(), hasSize(0));
}
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class RemoteServerSpecificCommand method validateClient.
public static void validateClient(final PrintWriter writer, final KsqlRestClient restClient) {
try {
final RestResponse<ServerInfo> restResponse = restClient.getServerInfo();
if (restResponse.isErroneous()) {
final KsqlErrorMessage ksqlError = restResponse.getErrorMessage();
if (Errors.toStatusCode(ksqlError.getErrorCode()) == NOT_ACCEPTABLE.code()) {
writer.format("This CLI version no longer supported: %s%n%n", ksqlError);
return;
}
writer.format("Couldn't connect to the KSQL server: %s%n%n", ksqlError.getMessage());
} else {
maybeSetIsCCloudServer(restClient, restResponse.getResponse());
}
} catch (final IllegalArgumentException exception) {
writer.println("Server URL must begin with protocol (e.g., http:// or https://)");
} catch (final KsqlRestClientException exception) {
writer.println();
writer.println(StringUtils.center("ERROR", CONSOLE_WIDTH, "*"));
final String errorMsg;
if (exception.getCause().getCause() instanceof SSLException) {
errorMsg = " looks to be configured to use HTTPS / SSL. " + "Please refer to the KSQL documentation on how to configure the CLI for SSL: " + DocumentationLinks.SECURITY_CLI_SSL_DOC_URL;
} else {
errorMsg = " does not appear to be a valid KSQL server." + " Please ensure that the URL provided is for an active KSQL server.";
}
writer.println(WordUtils.wrap("Remote server at " + restClient.getServerAddress() + errorMsg, CONSOLE_WIDTH));
writer.println("");
writer.println("The server responded with the following error: ");
writer.println(ErrorMessageUtil.buildErrorMessage(exception));
writer.println(StringUtils.repeat('*', CONSOLE_WIDTH));
writer.println();
} finally {
writer.flush();
}
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class KsqlClientTest method shouldFailtoMakeHttpRequestWhenServerIsHttps.
@Test
public void shouldFailtoMakeHttpRequestWhenServerIsHttps() throws Exception {
ksqlClient.close();
stopServer();
// Given:
startServerWithTls();
startClientWithTls();
// When:
URI uri = URI.create("http://localhost:" + server.getPort());
KsqlTarget target = ksqlClient.target(uri);
final KsqlRestClientException e = assertThrows(KsqlRestClientException.class, () -> target.postKsqlRequest("ssl test", Collections.emptyMap(), Optional.of(123L)));
// Then:
assertThat(e.getMessage(), containsString("Error issuing POST to KSQL server. path:/ksql"));
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class KsqlClientTest method shouldFailtoMakeHttpsRequestWhenServerIsHttp.
@Test
public void shouldFailtoMakeHttpsRequestWhenServerIsHttp() {
// When:
URI uri = URI.create("https://localhost:" + server.getPort());
KsqlTarget target = ksqlClient.target(uri);
final KsqlRestClientException e = assertThrows(KsqlRestClientException.class, () -> target.postKsqlRequest("ssl test", Collections.emptyMap(), Optional.of(123L)));
// Then:
assertThat(e.getMessage(), containsString("Error issuing POST to KSQL server. path:/ksql"));
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class KsqlClientTest method shouldFailToStartClientRequestWithInvalidKeystorePassword.
@Test
public void shouldFailToStartClientRequestWithInvalidKeystorePassword() throws Exception {
ksqlClient.close();
stopServer();
// Given:
startServerWithTls();
// When:
final KsqlRestClientException e = assertThrows(KsqlRestClientException.class, () -> startClientWithTlsAndTruststorePassword("iquwhduiqhwd"));
// Then:
assertThat(e.getMessage(), containsString("java.io.IOException: Keystore was tampered with, or password was incorrect"));
}
Aggregations