{"record":{"id":"04c439f2ae72ffd1","repo":"testcontainers/testcontainers-java","slug":"cannot-determine-http-scheme-environment-variables-are-not","errorCode":null,"errorMessage":"Cannot determine HTTP scheme: environment variables are not set and container is not running for curl probe","messagePattern":"Cannot determine HTTP scheme: environment variables are not set and container is not running for curl probe","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/ElasticsearchContainer.java","lineNumber":291,"sourceCode":"     * Detects the HTTP scheme used by Elasticsearch. Respects explicit env-var config first;\n     * when ambiguous, probes the live socket with curl (requires a running container on port 9200).\n     *\n     * @return \"http\" or \"https\"\n     */\n    String getHttpScheme() {\n        String securityEnabled = getEnvMap().get(\"xpack.security.enabled\");\n        String httpSslEnabled = getEnvMap().get(\"xpack.security.http.ssl.enabled\");\n\n        // Respect explicit user config\n        if (\"false\".equalsIgnoreCase(securityEnabled) || \"false\".equalsIgnoreCase(httpSslEnabled)) {\n            return \"http\";\n        }\n        if (\"true\".equalsIgnoreCase(httpSslEnabled)) {\n            return \"https\";\n        }\n\n        if (!isRunning()) {\n            throw new IllegalStateException(\n                \"Cannot determine HTTP scheme: environment variables are not set and container is not running for curl probe\"\n            );\n        }\n\n        ExecResult httpsResult = null;\n        ExecResult httpResult = null;\n        try {\n            // HTTPS probe: any HTTP response (200/401/403/...) => scheme is HTTPS.\n            // http_code == 000 means we didn't get an HTTP response (TLS/connect failure/timeout).\n            httpsResult =\n                execInContainer(\n                    \"curl\",\n                    \"-sS\",\n                    \"-k\",\n                    \"--connect-timeout\",\n                    \"2\",\n                    \"--max-time\",\n                    \"4\",","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/ElasticsearchContainer.java#L273-L309","documentation":"ElasticsearchContainer.getHttpScheme determines whether to use http or https: it first checks the ELASTIC_PASSWORD/xpack.security.enabled env vars, then httpSslEnabled; if neither is set it probes the container via curl — but only when the container is running. If no env configuration exists and the container is not running, it throws IllegalStateException because the curl probe cannot be executed.","triggerScenarios":"Calling url(), getHttpHost(), or scheme-related accessors before start() on a container created without ELASTIC_PASSWORD, xpack.security.enabled, or withEnabledFlags/withSsl env configuration.","commonSituations":"Building the client URL at field-initialization time before the container starts; computing the endpoint in a config class instantiated before container startup.","solutions":["Start the container before calling url()/getHttpHost() — derive endpoints lazily in the test body or an @Before callback.","Set the scheme explicitly by configuring security env (e.g. withPassword or withEnabledFlags/withEnv(\"xpack.security.enabled\",\"false\")) so no runtime probe is needed.","If you must precompute URLs, run the container as a static/singleton started before endpoint resolution."],"exampleFix":"// before\nString url = container.getHttpHostAddress(); // before start, no env set -> throws\ncontainer.start();\n// after\ncontainer.start();\nString url = container.getHttpHostAddress();","handlingStrategy":"validation","validationCode":"if (!container.isRunning()) {\n    throw new IllegalStateException(\"Call url()/getHttpHostAddress() only after container.start()\");\n}\nString host = container.getHttpHostAddress();","typeGuard":null,"tryCatchPattern":"try {\n    String address = container.getHttpHostAddress();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Cannot determine HTTP scheme\")) {\n        // container not started and no security env configured\n    }\n    throw e;\n}","preventionTips":["Resolve container endpoints lazily, only after start().","Configure security env vars explicitly (withPassword or xpack.security.enabled) so the scheme is known without a probe.","Use static singleton containers when endpoints must be computed early in test setup."],"tags":["elasticsearch","lifecycle","http-scheme","premature-access"],"backgroundTag":"invalid-state-transition","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}