@NotNull
  public String executeMethod(@NotNull HttpMethod method) throws Exception {
    LOG.debug("URI: " + method.getURI());

    HttpClient client = getHttpClient();
    // Fix for https://jetbrains.zendesk.com/agent/#/tickets/24566
    // See https://confluence.atlassian.com/display/ONDEMANDKB/Getting+randomly+logged+out+of+OnDemand for details
    // IDEA-128824, IDEA-128706 Use cookie authentication only for JIRA on-Demand
    // TODO Make JiraVersion more suitable for such checks
    if (BASIC_AUTH_ONLY) {
      // to override persisted settings
      setUseHttpAuthentication(true);
    }
    else if (!isInCloud()) {
      if (isUseBearerTokenAuthentication()) {
        setUseHttpAuthentication(false);
        method.addRequestHeader(new Header(HttpAuthenticator.WWW_AUTH_RESP, "Bearer " + getPassword()));
      }
      else {
        setUseHttpAuthentication(true);
      }
    }
    else {
      boolean enableBasicAuthentication = !(isRestApiSupported() && containsCookie(client, AUTH_COOKIE_NAME));
      if (enableBasicAuthentication != isUseHttpAuthentication()) {
        LOG.info("Basic authentication for subsequent requests was " + (enableBasicAuthentication ? "enabled" : "disabled"));
      }
      setUseHttpAuthentication(enableBasicAuthentication);
    }

    int statusCode = client.executeMethod(method);
    LOG.debug("Status code: " + statusCode);
    // may be null if 204 No Content received
    InputStream stream = method.getResponseBodyAsStream();
    String entityContent = "";
    if (stream != null) {
      try (Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
        entityContent = StreamUtil.readText(reader);
      }
    }
    //TaskUtil.prettyFormatJsonToLog(LOG, entityContent);
    // besides SC_OK, can also be SC_NO_CONTENT in issue transition requests
    // see: JiraRestApi#setTaskStatus
    //if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_NO_CONTENT) {
    if (statusCode >= 200 && statusCode < 300) {
      return entityContent;
    }
    clearCookies();
    if (method.getResponseHeader("Content-Type") != null) {
      Header header = method.getResponseHeader("Content-Type");
      if (header.getValue().startsWith("application/json")) {
        JsonObject object = GSON.fromJson(entityContent, JsonObject.class);
        if (object.has("errorMessages")) {
          String reason = StringUtil.join(object.getAsJsonArray("errorMessages"), " ");
          // If anonymous access is enabled on server, it might reply only with a cryptic 400 error about inaccessible issue fields,
          // e.g. "Field 'assignee' does not exist or this field cannot be viewed by anonymous users."
          // Unfortunately, there is no better way to indicate such errors other than by matching by the error message itself.
          LOG.warn(reason);
          if (statusCode ==  HttpStatus.SC_BAD_REQUEST && reason.contains("cannot be viewed by anonymous users")) {
            // Oddly enough, in case of JIRA Cloud issues are access anonymously only if API Token is correct, but email is wrong.
            throw new Exception(isInCloud() ? TaskBundle.message("jira.failure.email.address") : TaskBundle.message("failure.login"));
          }
          // something meaningful to user, e.g. invalid field name in JQL query
          throw new Exception(TaskBundle.message("failure.server.message", reason));
        }
      }
    }
    if (method.getResponseHeader("X-Authentication-Denied-Reason") != null) {
      Header header = method.getResponseHeader("X-Authentication-Denied-Reason");
      // only in JIRA >= 5.x.x
      if (header.getValue().startsWith("CAPTCHA_CHALLENGE")) {
        throw new Exception(TaskBundle.message("jira.failure.captcha"));
      }
    }
    if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
      throw new Exception(TaskBundle.message("failure.login"));
    }
    String statusText = HttpStatus.getStatusText(method.getStatusCode());
    throw new Exception(TaskBundle.message("failure.http.error", statusCode, statusText));
  }
@NotNull
  public String executeMethod(@NotNull HttpMethod method)