Search in sources :

Example 1 with SuiteContext

use of org.keycloak.testsuite.arquillian.SuiteContext in project keycloak by keycloak.

the class KeycloakQuarkusServerDeployableContainer method waitForReadiness.

private void waitForReadiness() throws MalformedURLException, LifecycleException {
    SuiteContext suiteContext = this.suiteContext.get();
    // TODO: not sure if the best endpoint but it makes sure that everything is properly initialized. Once we have
    // support for MP Health this should change
    URL contextRoot = new URL(getBaseUrl(suiteContext) + "/auth/realms/master/");
    HttpURLConnection connection;
    long startTime = System.currentTimeMillis();
    while (true) {
        if (System.currentTimeMillis() - startTime > getStartTimeout()) {
            stop();
            throw new IllegalStateException("Timeout [" + getStartTimeout() + "] while waiting for Quarkus server");
        }
        try {
            // wait before checking for opening a new connection
            Thread.sleep(1000);
            if ("https".equals(contextRoot.getProtocol())) {
                HttpsURLConnection httpsConnection = (HttpsURLConnection) (connection = (HttpURLConnection) contextRoot.openConnection());
                httpsConnection.setSSLSocketFactory(createInsecureSslSocketFactory());
                httpsConnection.setHostnameVerifier(createInsecureHostnameVerifier());
            } else {
                connection = (HttpURLConnection) contextRoot.openConnection();
            }
            connection.setReadTimeout((int) getStartTimeout());
            connection.setConnectTimeout((int) getStartTimeout());
            connection.connect();
            if (connection.getResponseCode() == 200) {
                break;
            }
            connection.disconnect();
        } catch (Exception ignore) {
        }
    }
    log.infof("Keycloak is ready at %s", contextRoot);
}
Also used : SuiteContext(org.keycloak.testsuite.arquillian.SuiteContext) HttpURLConnection(java.net.HttpURLConnection) URL(java.net.URL) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Aggregations

IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)1 LifecycleException (org.jboss.arquillian.container.spi.client.container.LifecycleException)1 SuiteContext (org.keycloak.testsuite.arquillian.SuiteContext)1