@Override
 public UUID replaceFacts(Facts facts) throws IOException {
   // TODO: This is rather odd since we json encode something that will
   // be json encoded again.
   String jsonFacts = connector.toJSON(facts);
   return postCommand("replace facts", 1, jsonFacts);
 }
  protected UUID postCommand(String command, int version, Object payload) throws IOException {
    CommandObject cmdObj = new CommandObject();
    cmdObj.setCommand(command);
    cmdObj.setVersion(version);
    cmdObj.setPayload(payload);

    String json = connector.toJSON(cmdObj);
    Map<String, String> params = new HashMap<String, String>();
    params.put("payload", json);
    try {
      MessageDigest md = MessageDigest.getInstance("SHA-1");
      params.put("checksum", Hex.encodeHexString(md.digest(json.getBytes(HttpConnector.UTF_8))));
    } catch (NoSuchAlgorithmException e) {
      throw new IllegalArgumentException(e);
    }

    CommandResponse response = connector.post("/commands/", params, CommandResponse.class);
    return response == null ? null : UUID.fromString(response.getUuid());
  }