Example #1
0
  @Override
  public void handleHttpRequest(
      HttpRequest httpRequest, HttpResponse httpResponse, HttpControl httpControl)
      throws Exception {
    if (!"GET".equals(httpRequest.method())) {
      httpResponse.status(500);
      httpResponse.end();
      return;
    }

    JSONObject build = new JSONObject();
    build.put("version", seledendroidServer.getServerVersion());
    build.put("browserName", "selendroid");

    JSONObject os = new JSONObject();
    os.put("arch", seledendroidServer.getCpuArch());
    os.put("name", seledendroidServer.getOsName());
    os.put("version", seledendroidServer.getOsVersion());

    JSONObject json = new JSONObject();
    json.put("build", build);
    json.put("os", os);

    JSONArray devices = null;
    try {
      devices = seledendroidServer.getSupportedDevices();
    } catch (Exception e) {
      devices = new JSONArray();
    }

    json.put("supportedDevices", devices);

    if (apps == null || devices.length() == 0) {
      try {
        apps = seledendroidServer.getSupportedApps();
      } catch (Exception e) {
        apps = new JSONArray();
      }
    }
    json.put("supportedApps", apps);

    // httpResponse.header("Content-Type", "text/plain");
    httpResponse.header("Content-Type", "application/json");

    httpResponse.content("{status: 0, value: " + json + "}");
    httpResponse.end();
  }