{"record":{"id":"4728975919fdd1c3","repo":"karatelabs/karate","slug":"http-client-not-set","errorCode":null,"errorMessage":"http client not set","messagePattern":"http client not set","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java","lineNumber":143,"sourceCode":"        request.setUrl(getUri());\n        if (multiPart != null) {\n            request.setBodyDisplay(multiPart.getBodyForDisplay());\n        }\n        if (body != null) {\n            request.setBody(Json.toBytes(body));\n        }\n        request.setHeaders(headers);\n        // Also set params on request so InMemoryHttpClient and others can access them\n        if (params != null) {\n            request.setParams(params);\n        }\n        return request;\n    }\n\n    public HttpResponse invoke() {\n        HttpRequest request = build();\n        if (client == null) {\n            throw new RuntimeException(\"http client not set\");\n        }\n        reset();\n        HttpResponse response = client.invoke(request);\n        response.setRequest(request);\n        // conversion-side stamp for ANY client, on every lane that reaches this builder —\n        // the step executor re-stamps the gherkin lanes, but karate.http() has only this\n        if (configSupplier != null) {\n            io.karatelabs.core.KarateConfig config = configSupplier.get();\n            if (config != null) {\n                response.setStrictParsing(config.isStrictResponseParsing());\n            }\n        }\n        return response;\n    }\n\n    public HttpResponse invoke(String method) {\n        this.method = method;\n        return invoke();","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java#L125-L161","documentation":"HttpRequestBuilder.invoke() sends the built HttpRequest through the configured HttpClient. The builder was created without a client (never passed via the constructor or a setter), so there is nothing to execute the request with, and the builder throws before doing any I/O.","triggerScenarios":"Calling invoke()/response()/method()/request()/proceed()/exception() on an HttpRequestBuilder constructed with new HttpRequestBuilder() and no client set; obtaining a builder through a code path that bypasses the HttpClientFactory; holding a builder beyond a scope where its client was reset.","commonSituations":"Embedding Karate's HTTP DSL in custom Java code and forgetting to create a client via new DefaultHttpClientFactory().create(); framework integrations that build requests for serialization (curl export) but then attempt to execute them; configuration errors where the client bean was never injected.","solutions":["Create and set a client: new HttpRequestBuilder(new DefaultHttpClientFactory().create())","Prefer high-level entry points such as karate.http(...) / HttpRequest helpers that wire a client for you","If you only need a curl representation, call toCurlCommand() instead of invoke()","Audit custom integration code for builders constructed without a client parameter"],"exampleFix":"// before\nHttpRequestBuilder builder = new HttpRequestBuilder();\nbuilder.url(\"http://example.com\").invoke(); // throws\n// after\nHttpRequestBuilder builder = new HttpRequestBuilder(new DefaultHttpClientFactory().create());\nbuilder.url(\"http://example.com\").invoke();","handlingStrategy":"try-catch","validationCode":"if (client == null) throw new IllegalStateException('set an HttpClient on the builder before invoke()');","typeGuard":null,"tryCatchPattern":"try {\n  builder.invoke();\n} catch (RuntimeException e) {\n  if (e.getMessage().equals(\"http client not set\")) {\n    builder = new HttpRequestBuilder(new DefaultHttpClientFactory().create()).url(builderUrl);\n    // retry the invoke\n  } else { throw e; }\n}","preventionTips":["Construct builders with a client: new HttpRequestBuilder(httpClient)","Prefer karate.http(...) or library helpers that wire a client automatically","Use toCurlCommand() for inspection-only flows instead of invoking a client-less builder"],"tags":["http","client","configuration","builder"],"backgroundTag":"internal-invariant-violation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}