Пример #1
0
  public static JSONObject getVersionInfo() {
    synchronized (LOGGER) {
      final JSONObject o = new JSONObject();
      try {
        final InputStream stream = Stats.class.getResourceAsStream("/version.prop");
        if (props == null) {
          props = new Properties();
          try {
            props.load(stream);
            stream.close();
          } catch (Exception e) {
            LOGGER.warn(e, e);
            props = null;
          }
        }
        props.put("uptime", Long.toString(MonitorApplication.getUptime()));

        final List<CacheDataModel> cwProps = CacheWatcher.getProps();
        for (CacheDataModel m : cwProps) {
          props.put(m.getKey(), m.getValue());
        }
        o.put("stats", props);

      } catch (JSONException e) {
        LOGGER.warn(e, e);
      }
      return o;
    }
  }
  private void respond(Iterator<String> words, String cmd, String id) {
    JSONArray array = new JSONArray();
    if (words != null) {
      while (words.hasNext()) array.put(words.next());
    }

    JSONObject response = new JSONObject();
    try {
      response.put("id", id);
      response.put("error", (String) null);
      response.put("result", array);
      setResponse(response.toString());
    } catch (JSONException e) {
      jsonError("Failed to construct response");
    }
  }
Пример #3
0
  protected String generateJsonResponse(
      ServletWebRequest webRequest, WebResponse webResponse, List<FileItem> files) {
    JSONArray json = new JSONArray();

    for (FileItem fileItem : files) {
      JSONObject fileJson = new JSONObject();

      try {
        fileJson.put("name", fileItem.getName());
        fileJson.put("size", fileItem.getSize());
        fileJson.put("delete_type", "POST");
      } catch (JSONException e) {
        try {
          fileJson.put("error", e.getMessage());
        } catch (JSONException e1) {
          e1.printStackTrace();
        }
      }

      json.put(fileJson);
    }

    return json.toString();
  }