Search in sources :

Example 1 with KsqlRestClientException

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));
    }
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) Set(java.util.Set) DiscoverRemoteHostsUtil(io.confluent.ksql.rest.util.DiscoverRemoteHostsUtil) Map(java.util.Map) Test(org.junit.Test)

Example 2 with KsqlRestClientException

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();
    }
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) SSLException(javax.net.ssl.SSLException) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage)

Example 3 with KsqlRestClientException

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"));
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) URI(java.net.URI) Test(org.junit.Test)

Example 4 with KsqlRestClientException

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"));
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) URI(java.net.URI) Test(org.junit.Test)

Example 5 with KsqlRestClientException

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"));
}
Also used : KsqlRestClientException(io.confluent.ksql.rest.client.exception.KsqlRestClientException) Test(org.junit.Test)

Aggregations

KsqlRestClientException (io.confluent.ksql.rest.client.exception.KsqlRestClientException)16 Test (org.junit.Test)12 IOException (java.io.IOException)4 IntegrationTest (io.confluent.common.utils.IntegrationTest)3 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)3 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)2 ListQueries (io.confluent.ksql.parser.tree.ListQueries)2 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)2 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)2 URI (java.net.URI)2 KsqlErrorMessage (io.confluent.ksql.rest.entity.KsqlErrorMessage)1 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)1 Queries (io.confluent.ksql.rest.entity.Queries)1 QueryDescriptionList (io.confluent.ksql.rest.entity.QueryDescriptionList)1 ServerInfo (io.confluent.ksql.rest.entity.ServerInfo)1 DiscoverRemoteHostsUtil (io.confluent.ksql.rest.util.DiscoverRemoteHostsUtil)1 KsqlQueryStatus (io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus)1 Context (io.vertx.core.Context)1 VertxException (io.vertx.core.VertxException)1 JksOptions (io.vertx.core.net.JksOptions)1