{"record":{"id":"fde5206b047d7bb3","repo":"SonarSource/sonarqube","slug":"fail-to-request-url","errorCode":null,"errorMessage":"Fail to request url: ","messagePattern":"Fail to request url: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java","lineNumber":218,"sourceCode":"\n  private Request.Builder prepareOkRequestBuilder(WsRequest getRequest, HttpUrl.Builder urlBuilder) {\n    Request.Builder okHttpRequestBuilder = new Request.Builder()\n      .url(urlBuilder.build())\n      .header(\"Accept\", getRequest.getMediaType())\n      .header(\"Accept-Charset\", \"UTF-8\");\n    if (systemPassCode != null) {\n      okHttpRequestBuilder.header(\"X-Sonar-Passcode\", systemPassCode);\n    }\n    getRequest.getHeaders().getNames().forEach(name -> okHttpRequestBuilder.header(name, getRequest.getHeaders().getValue(name).get()));\n    return okHttpRequestBuilder;\n  }\n\n  private static Response doCall(OkHttpClient client, Request okRequest) {\n    Call call = client.newCall(okRequest);\n    try {\n      return call.execute();\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Fail to request url: \" + okRequest.url(), e);\n    }\n  }\n\n  private Response checkRedirect(Response response, RequestWithPayload<?> postRequest) {\n    if (List.of(HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_TEMP_REDIRECT, HTTP_PERM_REDIRECT).contains(response.code())) {\n      // OkHttpClient does not follow the redirect with the same HTTP method. A POST is\n      // redirected to a GET. Because of that the redirect must be manually implemented.\n      // See:\n      // https://github.com/square/okhttp/blob/07309c1c7d9e296014268ebd155ebf7ef8679f6c/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L316\n      // https://github.com/square/okhttp/issues/936#issuecomment-266430151\n      return followPostRedirect(response, postRequest);\n    } else {\n      return response;\n    }\n  }\n\n  private Response followPostRedirect(Response response, RequestWithPayload<?> postRequest) {\n    String location = response.header(\"Location\");","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java#L200-L236","documentation":"HttpConnector.doCall() executes an OkHttp Call synchronously; when call.execute() throws IOException (connection failure, DNS failure, timeout, SSL error, connection reset), it wraps it in IllegalStateException(\"Fail to request url: <url>\"). The original IOException is the cause and pinpoints the network-level problem.","triggerScenarios":"Calling any WS operation when the SonarQube host is unreachable: wrong host/port in the connector configuration, server down, TLS certificate issues, socket/read timeout on slow responses, or no network route/firewall blocking the connection.","commonSituations":"SonarQube server stopped or restarting during CI; DNS not resolving the server hostname; corporate proxy required but not configured on the OkHttpClient; self-signed certificate not trusted; read timeout on large requests.","solutions":["Inspect the wrapped IOException cause to distinguish timeout vs connection-refused vs SSL error.","Verify the server URL (host, port, context path) and that SonarQube is up (curl the URL).","Configure proxy settings or trust store on the OkHttpClient passed to HttpConnector if behind a proxy or using self-signed TLS.","Increase connect/read timeouts for large requests, and add retry logic for transient network failures."],"exampleFix":"// before\nHttpConnector connector = HttpConnector.newBuilder().url(\"http://sonar.example.com\").build();\n// after\nHttpConnector connector = HttpConnector.newBuilder()\n  .url(\"https://sonar.example.com\")\n  .connectTimeoutMs(10_000)\n  .readTimeoutMs(60_000)\n  .build();","handlingStrategy":"try-catch","validationCode":"// before calling: verify reachability\nHttpURLConnection c = (HttpURLConnection) new URL(baseUrl + \"/api/system/status\").openConnection();\nc.setConnectTimeout(5000);\nif (c.getResponseCode() != 200) throw new IllegalStateException(\"SonarQube unreachable at \" + baseUrl);","typeGuard":null,"tryCatchPattern":"try {\n  WsResponse r = connector.call(request);\n} catch (IllegalStateException e) {\n  if (e.getCause() instanceof java.net.SocketTimeoutException) {\n    // retry with backoff or increase timeouts\n  } else if (e.getCause() instanceof java.net.ConnectException) {\n    // server down / wrong host: alert operator\n  }\n  throw e;\n}","preventionTips":["Validate the server URL and connectivity at application startup.","Set explicit connect/read timeouts appropriate for request size.","Implement retry with backoff for transient IOExceptions.","Configure proxy and TLS trust store when operating behind corporate infrastructure."],"tags":["network","http","okhttp","timeout"],"backgroundTag":"network-request-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}