public DispatcherResult killDispatcherExecution(final String execId)
      throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();
    params.put("id", execId);
    params.put("xmlreq", "true");

    // 2. send request via ServerService
    final WebserviceResponse response;
    try {
      response = serverService.makeRundeckRequest(RUNDECK_KILL_JOB_PATH, params, null, null);
    } catch (MalformedURLException e) {
      throw new CentralDispatcherServerRequestException("Failed to make request", e);
    }

    final Envelope envelope = validateResponse(response);

    final boolean result = envelope.isSuccessResult();
    final StringBuffer sb = envelope.successMessages();
    return new DispatcherResult() {
      public boolean isSuccessful() {
        return result;
      }

      public String getMessage() {
        return sb.toString();
      }
    };
  }
  public DispatcherResult killDispatcherExecution(final String execId)
      throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();

    final String rundeckApiKillJobPath =
        substitutePathVariable(RUNDECK_API_KILL_JOB_PATH, "id", execId);
    // 2. send request via ServerService
    final WebserviceResponse response;
    try {
      response = serverService.makeRundeckRequest(rundeckApiKillJobPath, params, null, null);
    } catch (MalformedURLException e) {
      throw new CentralDispatcherServerRequestException("Failed to make request", e);
    }

    final Envelope envelope = validateResponse(response);

    final Node result1 = envelope.doc.selectSingleNode("result");
    final String abortStatus = result1.selectSingleNode("abort/@status").getStringValue();
    final boolean result = !"failed".equals(abortStatus);
    final StringBuffer sb = envelope.successMessages();
    return new DispatcherResult() {
      public boolean isSuccessful() {
        return result;
      }

      public String getMessage() {
        return sb.toString();
      }
    };
  }
  /**
   * Validate the response is in expected envlope form with &lt;result&gt; content.
   *
   * @param response response
   * @return Envelope if format is correct and there is no error
   * @throws CentralDispatcherException if the format is incorrect, or the Envelope indicates an
   *     error response.
   */
  private Envelope validateResponse(final WebserviceResponse response)
      throws CentralDispatcherException {
    if (null == response) {
      throw new CentralDispatcherServerRequestException("Response was null");
    }

    if (null != response.getResponseMessage()) {
      logger.info("Response: " + response.getResponseMessage());
    }
    final Document resultDoc = response.getResultDoc();
    if (null == resultDoc) {
      throw new CentralDispatcherServerRequestException(
          "Response content unexpectedly empty. "
              + (response.getResponseMessage() != null ? response.getResponseMessage() : ""));
    }
    try {
      logger.debug(serialize(resultDoc));
    } catch (IOException e) {
      logger.debug("ioexception serializing result doc", e);
    }

    if (!"result".equals(resultDoc.getRootElement().getName())) {
      throw new CentralDispatcherServerRequestException(
          "Response had unexpected content: " + resultDoc);
    }
    final Envelope envelope = new Envelope(response.getResultDoc());
    if (envelope.isErrorResult()) {
      final StringBuffer sb = new StringBuffer();
      final StringBuffer buffer = envelope.errorMessages();
      if (sb.length() > 0) {
        sb.append(buffer);
      } else {
        sb.append("Server reported an error");
        if (null != response.getResponseMessage()) {
          sb.append(": ").append(response.getResponseMessage());
        }
      }
      if (null != response.getResponseMessage()) {
        logger.error("Server reported an error: " + response.getResponseMessage());
      } else {
        logger.error("Server reported an error.");
      }
      throw new CentralDispatcherFailureResponseException(sb.toString());
    }
    return envelope;
  }